akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;

//firstで初期化された、葉がn要素を超えるように2のべき乗個用意されたリストを返す
vector<int> make_ST(int n,int first){

    int i = 0;
    vector<int> ret(0,0);

    while ((1<<(i-1)) < n){
        
        for (int j = 0 ; j < (1<<i) ; j++){
            ret.push_back(first);
        }

        i++;

    }

    return ret;
}

void RMQ_update_point(int num,int point,vector<int>& tree){

    int i = (tree.size()-1)/2 + point;
    tree[i] = num;
    while (i > 0){
        i = (i-1)/2;
        tree[i] = min(tree[i*2+2] , tree[i*2+1]);
    }
    return ;
}

int RMQ_query(int a,int b,int k,int l,int r,vector<int>& tree){

    if ((r <= a) || (b <= l)) return INT_MAX;
    if ((a <= l) && (r <= b)) return tree[k];

    int c1 = RMQ_query(a,b,2*k+1,l,(l+r)/2,tree);
    int c2 = RMQ_query(a,b,2*k+2,(l+r)/2,r,tree);

    return min(c1,c2);
}

int main(){

    int n,q;
    cin >> n >> q;
    vector<int> tree = make_ST(n,INT_MAX);

    int com,x,y;
    rep(i,0,q){

        cin >> com >> x >> y;

        if (com == 0){
            RMQ_update_point(y,x,tree);
        }else{
            cout << RMQ_query(x,y+1,0,0,(tree.size()+1)/2,tree) << endl;
        }

        //rep(i,0,tree.size()) cout << tree[i] << endl;

    }
    
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

int main()
{
    fast
    int h1,m1,h2,m2,k,m,x;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    m = m2-m1;
    if(m<0)
    {
        m+=60;
        x = (h2 - h1 - 1)*60 + m - k;
    }
    else{
        x = (h2-h1)*60+m - k;
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    REP(i,N){
        ll a, b;
        cin >> a >> b;
        A[i] = a;
        B[i] = b;
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    ll ans = 0;
    if(N % 2){
        ll left = A[N/2];
        ll right = B[N/2];
        ans = right - left + 1;
    }
    else{
        ll left = A[N/2] + A[(N-1)/2];
        ll right = B[N/2] + B[(N-1)/2];
        ans = right - left + 1;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6364
#include <bits/stdc++.h>

#define SZ(a) (int)a.size()
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;

int main() {

  int n;
  string s;
  
  cin >> n >> s;
  
  for(int i = 0; i < SZ(s); i++) {
    s[i] += n;
    if(s[i] > 'Z') s[i] -= 26;
  }
  
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    string o,e;
    cin >> o >> e;
    int olen, elen;
    olen = o.length();
    elen = e.length();

    for (int i = 0; i < elen; i++) {
        cout << o[i];
        cout << e[i];
    }
    if (olen > elen) {
        cout << o[olen-1];
    }
    cout << endl;
    
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


Measured memory_bytes: 256
while True:
    datasets = input().split()
    a, op, b = int(datasets[0]), datasets[1], int(datasets[2])
    ans = 0
    if op == "+":
        ans = a + b
    elif op == "-":
        ans = a - b
    elif op == "*":
        ans = a * b
    elif op == "/":
        ans = a // b
    elif op == "?":
        break
    print(ans)



Measured memory_bytes: 5600
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> c1 = new ArrayList<>();
        List<Integer> c2 = new ArrayList<>();
        List<Integer> c3 = new ArrayList<>();
        IntStream.range(0, 3).forEach(i -> c1.add(sc.nextInt()));
        IntStream.range(0, 3).forEach(i -> c2.add(sc.nextInt()));
        IntStream.range(0, 3).forEach(i -> c3.add(sc.nextInt()));

        int a1 = 0;
        int b1 = c1.get(0) - a1;
        int a2 = c2.get(0) - b1;
        int b2 = c2.get(1) - a2;
        int a3 = c3.get(0) - b1;
        int b3 = c3.get(2) - a3;

        if (c1.get(0) == a1 + b1 && c1.get(1) == a1 + b2 && c1.get(2) == a1 + b3
                && c2.get(0) == a2 + b1 && c2.get(1) == a2 + b2 && c2.get(2) == a2 + b3
                && c3.get(0) == a3 + b1 && c3.get(1) == a3 + b2 && c3.get(2) == a3 + b3) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 26836
#include<bits/stdc++.h>
using namespace std;
int ans;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int M, D;
    cin >> M >> D;
    
    for (int i = 22; i <= D; i++) {
        int D10 = i/10, D1 = i%10;
        if (D10 < 2 || D1 < 2) continue;
        if (D10*D1 <= M) ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
 int n;
 cin>>n;
 while(n){
  int o=0,a=0,b=0;
  while(o!=3){
   string s;
   cin>>s;
   if(s=="HIT"){
    if(b==3)a++;
    else b++;
   }
   else if(s=="OUT")o++;
   else{
   a+=++b;
   b=0;
   }
  }
  cout<<a<<endl;
  n--;
 }
}

Measured memory_bytes: 3136
#include<stdio.h>

int main(){
int A,B,C,D,P;
scanf("%d%d%d%d%d",&A,&B,&C,&D,&P);
printf("%d\n",(A*P<(P<C?B:B+D*(P-C))?A*P:(P<C?B:B+D*(P-C))));
return 0;
}

Measured memory_bytes: 1024
/*
 * 競技プログラミング用テンプレート
 * by yuma140902
 * 2019/12/07
 * ver 0.0.0
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 900000;
const ll INFL = 9000000;

#define vi vector<int>
#define vii vector<vector<int> >
#define vi_def(n) vector<int>((n))
#define vii_def(n,m) vector<vector<int> >((n), vector<int>((m)))
#define vi_def_dflt(n, def) vector<int>((n), (def))
#define vii_def_dflt(n, m, def) vector<vector<int> >((n), vector<int>((m), (def)))

#define rep(i, n) for(int i=0; i < (n); ++i)
#define per(i, n) for(int i=(n)-1; i >= 0; --i)
#define range(i, begin, end) for(int i=(begin); i < (end); ++i)

string S, T;
int main(){
  cin >> S >> T;
  vector<char> R('a'+26, ' ');  // S -> T の置換表
  vector<char> Q('a'+26, ' ');  // T -> S の置換表

  bool ans = true;
  rep(i, S.size()){
    if(R[S[i]] < 'a') {
      R[S[i]] = T[i];
    }
    else if(R[S[i]] >= 'a'){
      if(R[S[i]] != T[i]) {
        ans = false;
        break;
      }
    }
    if(Q[T[i]] < 'a'){
      Q[T[i]] = S[i];
    }
    else if(Q[T[i]] >= 'a'){
      if(Q[T[i]] != S[i]){
        ans = false;
        break;
      }
    }
  }

  cerr << "A: ";
  for(char i='a'; i <= 'z'; ++i){
    cerr << i;
    if(i != 'z')
      cerr << ", ";
    else
      cerr << endl;
  }

  cerr << "R: ";
  for(int i='a'; i < R.size(); ++i){
    cerr << R[i];
    if(i != R.size()-1)
      cerr << ", ";
    else
      cerr << endl;
  }

  cerr << "Q: ";
  for(int i='a'; i < Q.size(); ++i){
    cerr << Q[i];
    if(i != Q.size()-1)
      cerr << ", ";
    else
      cerr << endl;
  }

  cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 776
/*
1st way - dp(i, j, k) = expected #times needed to reach from curr state to (0,0,0)
 (Reversed edges single source shortest path)
 (will give dist from all vertices to source)
2nd way - dp(i, j, k) = expected #times needed to reach to reach curr state from (initial_)
 (singe source shortest path from initial_ to 0,0,0)
 (depends on starting point)
going with way - 1
*/
#include <bits/stdc++.h>
using namespace std;

int N, cnt1, cnt2, cnt3;
int a[301];
long double dp[302][302][302];

/* 1 way:
	prob = (i + j + k)/N;
	dp(i, j, k) = (1 - prob)*(1 + dp(i, j, k)) + (i/N)*(1 + dp(i - 1, j, k)) + (j/N)*(1 + dp(i + 1, j - 1, k)) + (k/N)*(1 + dp(i, j + 1, k - 1))
	dp(i, j, k) = (1/prob) + (()*()*())/(i+j+k)
	order - k, j, i
*/

void solve () {
	dp[0][0][0] = 0.0;
	for (int k = 0; k <= N; k++) {
		for (int j = 0; j <= N; j++) { 
			for (int i = 0; i <= N; i++) {
				if (i == 0 and j == 0 and k == 0)
					continue;
				if (i + j + k > N)
					continue;
				dp[i][j][k] = 1.0 * N;
				if (k > 0)
					dp[i][j][k] += (1.0 * k * dp[i][j + 1][k - 1]);
				if (j > 0)
					dp[i][j][k] += (1.0 * j * dp[i + 1][j - 1][k]);
				if (i > 0)
					dp[i][j][k] += (1.0 * i * dp[i - 1][j][k]);
				dp[i][j][k] /= (i + j + k);
			}
		}
	}
	cout << fixed;
	cout << setprecision(15);
	cout << dp[cnt1][cnt2][cnt3] << "\n";
}

int main () {
	cin >> N;
	cnt1 = cnt2 = cnt3 = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] == 1)
			cnt1++;
		else if (a[i] == 2)
			cnt2++;
		else
			cnt3++;
	}
	solve();
	return 0;
}

Measured memory_bytes: 428288
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 10000;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)

int n;
char s[105];
ll dp[105][25];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) cin >> s[i];
    dp[0][0] = 1;
    rep(i, n - 1)rep(j, 21) {
        int num = s[i] - '0';
        if (i == 0 && j == 0 && num == 0) {
            dp[i + 1][0] = 1;
            continue; 
        }
        if (j - num >= 0) dp[i + 1][j] += dp[i][j - num];
        if (j + num <= 20) dp[i + 1][j] += dp[i][j + num];
    }
    cout << dp[n - 1][s[n - 1] - '0'] << endl;

}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int,int>mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    ll my=1000,kabu=0;
    rep(i,n){
        ll p=0;
        if(a[i]<a[i+1]){    
            p=my/a[i];          
        }
       my +=(a[i+1]-a[i])*p;
        
    }
    cout<<my<<endl;
    return 0;
}


Measured memory_bytes: 3616
A,B,C=map(int,raw_input().split());
i=0
f=((A%2)==0)and((B%2)==0)and((C%2)==0)
while(f):
	da=A;db=B;dc=C
	A=(db+dc)/2
	B=(da+dc)/2
	C=(dc+da)/2
	i+=1
	f=((A%2)==0)and((B%2)==0)and((C%2)==0)
	if (da==A)and(db==B)and(dc==C):
		f=0
		i=-1
print i

Measured memory_bytes: 2696
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int N;
	cin >> N;
	if(N == 3){
		puts("2 5 63");
		return 0;
	}
	if(N == 4){
		puts("2 3 4 9");
		return 0;
	}
	if(N == 5){
		puts("2 3 6 4 9");
		return 0;
	}
	if(N == 6){
		puts("2 3 6 4 9 12");
		return 0;
	}
	if(N == 7){
		puts("2 3 6 4 9 12 18");
		return 0;
	}
	vector<int> vec;
	int t = N/8;
	for(int i = 0 ; i < t ; i ++){
		vec.pb(12*i+2);
		vec.pb(12*i+3);
		vec.pb(12*i+4);
		vec.pb(12*i+6);
		vec.pb(12*i+8);
		vec.pb(12*i+9);
		vec.pb(12*i+10);
		vec.pb(12*i+12);
	}
	if(N&1){
		vec.pb(12*t+6);
	}
	if(N%8 >= 2){
		vec.pb(12*t+2);
		vec.pb(12*t+4);
	}
	if(N%8 >= 4){
		vec.pb(12*t+3);
		vec.pb(12*t+9);
	}
	if(N%8 >= 6){
		vec.pb(12*t+8);
		vec.pb(12*t+10);
	}
	for(int i = 0 ; i < vec.size() ; i ++){
		printf("%d%c",vec[i],(i+1==vec.size())?'\n':' ');
	}
}	



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
	string s;
	bool ans = false;
	cin >> s;

	rep(i, s.size() - 1)
		if (s[i] == s[i + 1])
			ans = true;

	if (ans)
		cout << "Bad";
	else
		cout << "Good";

	cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

class Triangle{
public:
Triangle(){
}
void push(int num1,int num2,int num3){
if(num1>=num2){
if(num1>=num3){c=num1;a=num2;b=num3;}
else{c=num3;a=num1;b=num2;}
}
else{
if(num2>=num3){c=num2;a=num1;b=num3;}
else{c=num3;a=num1;b=num2;}
}
};
void checkRight(){
int cs=c*c;
if(cs==a*a+b*b) ans=1;
else ans=0;
};

void print(){
if(ans==0)
cout <<"NO"<< endl;
if(ans==1)
cout <<"YES"<< endl;
}

protected:
int a,b,c,ans;
};

int main(){
int num,a,b,c;
	Triangle *tri /* = Triangle[1000]*/;
	cin >> num;
	tri = new Triangle[num]/*(a,b,c)*/;
	for(int n=0;n<num;n++){
	cin >> a;
	cin >> b;
	cin >> c;
	tri[n].push(a,b,c);
	}
for(int n=0;n<num;n++){
tri[n].checkRight();
tri[n].print();
}
return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;
double F[45];

int fib(int n){
    F[0]=1;F[1]=1;
    for(int i=2;i<=n;i++){
        F[i]=F[i-1]+F[i-2];
       // cout<<F[i];
    }
    return F[n];
    }

int main(){
    int a;
    cin>>a;
    cout<<fib(a)<<endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define N 100005
#define debug(x) cout<<#x<<":"<<x<<endl;
using namespace std;
int n,m,s,t,ans;
vector<int>G[N];
bool mark[N][3];
bool flag=0;
struct node {
	int now,t,mod;
};
void bfs() {
	queue<node>q;
	q.push((node)<%s,0,0%>);
	mark[s][0]=1;
	while(q.size()) {
		node x=q.front();
		q.pop();
		for(int i=0; i<G[x.now].size(); i++) {
			int y=G[x.now][i],z=(x.mod+1)%3;
			if(mark[y][z])continue;
			mark[y][z]=1;
			if(y==t&&z==0) {
				flag=1;
				ans=x.t+1;
				ans/=3;
				return;
			}
			q.push((node)<%y,x.t+1,z%>);
		}
	}
}
int main() {
//	freopen("temp.txt","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=0; i<m; i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
	}
	scanf("%d%d",&s,&t);
	bfs();
	if(flag)printf("%d",ans);
	else puts("-1");
	return 0;
}


Measured memory_bytes: 6144
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int a[101][101], b[101][101];
	long long c[101][101], s;
	int i, j, k;
	int n, m, l;

	scanf("%d%d%d", &n, &m, &l);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
	}
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) scanf("%d", &b[i][j]);
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			s = 0;
			for (k = 0; k < m; k++) {
				s += a[i][k] * b[k][j];
			}
			c[i][j] = s;
		}
	}

	for (i = 0; i < n; i++) {
		printf("%lld", c[i][0]);
		for (j = 1; j < l; j++) printf(" %lld", c[i][j]);
		putchar('\n');
	}
	return 0;
}



Measured memory_bytes: 2088
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define str string
#define pb push_back
#define vc vector
#define ci cin
#define co cout
// remove fropen in online judge
int main()
{ 
    //  #ifndef ONLINE_JUDGE 
    //  freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    //  freopen("error.txt","w",stderr);
    // #endif 

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;ll f=0;
    for(int i=1;i<=n;i++)
    {
        ll sum=i*2+(n-i)*4;
        if(sum==m)
            {f=1;
                break;}
    }
    for(int i=1;i<=n;i++)
    {
        ll sum=i*4+(n-i)*2;
        if(sum==m)
            {f=1;
                break;}
    }
    if(f)
        cout<<"Yes";
    else
        cout<<"No";
    
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<numeric>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

int main()
{
    int N;  cin >> N;
    vector<int> v(N);
    for(int i=0; i<N; i++)  cin >> v[i];
    sort(all(v));
    int ans = 0;
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k<N; k++){
                if(v[k] < v[i] + v[j])  ans++;
                else    break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5;
int n, k;
int cnt[maxn];
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	vector<int> vc(n);
	for (auto &x : vc) {
		cin >> x;
		cnt[x]++;
	}
	sort(vc.begin(), vc.end());
	vc.resize( unique(vc.begin(), vc.end()) - vc.begin() );
	sort(vc.begin(), vc.end(), [](int a, int b) { return cnt[a] < cnt[b]; });
	int sum = 0;
	for (int i = 0; i < (int)vc.size() - k; i++)
		sum += cnt[ vc[i] ];
	cout << sum << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

string str;
int tmp, res;

int main() {
	cin >> str;
	int len = str.length();
	for (int i = 0; i < len; ++i) {
		tmp += str[i] - '0';
	}

	res = tmp;
	
	for (int i = len - 1; i >= 0; --i) {
		if (str[i] == '0') continue;
		res = max(res, tmp-1 + 9*(len-i-1));
		tmp -= str[i] - '0';
	}

	
	cout << res;
}

Measured memory_bytes: 256
N = int(input())
if N == 1:
    print(1)
    quit()
points = []
for _ in range(N):
    x, y = map(int, input().split())
    points.append((x, y))
diff = dict()
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        x1, y1 = points[i]
        x2, y2 = points[j]
        pq = x1-x2, y1-y2
        diff[pq] = diff.get(pq, 0) + 1
val, key = max((v, k) for k, v in diff.items())
print(N-val)


Measured memory_bytes: 3444
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n=int(readline())

    ans=0
    n_min=np.arange(1,n+1,dtype=np.int64)
    n_max=n//n_min*n_min
    kousu=n//n_min
    ans=(kousu*(n_min+n_max)//2).sum()

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 339660
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);

        long[] d = new long[n];
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            d[i] = long.Parse(input[i]);
        }

        Array.Sort(d);
        Array.Reverse(d);

        //int idx = 0;
        //for (int i = 0; i < m; i++)
        //{
        //    d[idx] /= 2;
        //    if (n > 1 && d[idx] < d[idx + 1])
        //    {
        //        idx++;
        //    }
        //}
        while (m > 0)
        {
            d[0] /= 2;
            m--;
            if (m == 0) break;

            for (int i = 1; i < n; i++)
            {
                if (d[0] > d[i])
                {
                    Array.Sort(d);
                    Array.Reverse(d);
                    break;
                }
                d[i] /= 2;
                m--;
                if (m == 0) break;
            }
        }

        long sum = 0;
        for (int i = 0; i < n; i++)
        {
            sum += d[i];
        }

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 29660
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
//const double EPS = 1e(-12);
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

int N;
int c[11][11];

int A[210][210];

int d[11][11];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);

    int H, W;
    cin >> H >> W;

    for (int i = 0; i < 10; ++i)
    {
        for (int j = 0; j < 10; ++j)
        {
            cin >> d[i][j];
        }
    }

    for (int i = 0; i < 10; ++i)
        d[i][i] = 0;

    for (int k = 0; k < 10; ++k)
    {
        for (int i = 0; i < 10; ++i)
        {
            for (int j = 0; j < 10; ++j)
            {
                d[i][j] = min({d[i][j], d[i][k] + d[k][j]});
            }
        }
    }
    //cout << d[4][9] << endl;
    //cout << d[8][1] << endl;
    int ans = 0;
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            int a;
            cin >> a;
            if (a != -1)
                ans += d[a][1];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    s = input()
    for i in range(len(s)):
        if i + 1 < len(s) and s[i] == s[i + 1]:
            print(i + 1, i + 2)
            return
        if i + 2 < len(s) and s[i] == s[i + 2]:
            print(i + 1, i + 3)
            return

    print("{0} {0}".format(-1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
int N, K;
ll A[103];
ll DP[103][100003]; //i人にあめがj個の分け方の場合の数
ll SUMDP[103][100003]; // DP[i][j]にはDP[i-1][j-a[i]]からDP[i-1][j]までの和が入る

int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  cin >> N >> K;
  rep(i, N) cin >> A[i];
  rep(i, A[0]+1) DP[0][i] = 1ll; // 一人だけだと1通りのみ(許容量を超えると0)

  rep(i, N) {
    if (i==0) continue;
    rep(j, K+1) {
      SUMDP[i][j] = j==0? DP[i-1][0]:SUMDP[i][j-1]+DP[i-1][j];
      if (j < A[i]+1) {
        DP[i][j] = SUMDP[i][j];
        DP[i][j] %= MOD;
      } else {
        DP[i][j] = SUMDP[i][j] - SUMDP[i][j-A[i]-1];
        DP[i][j] %= MOD;
      }
    }
  }

  cout << DP[N-1][K] << "\n";
  return 0;
}

Measured memory_bytes: 159232
import std.stdio;
import std.math;

const double R = 6378.1;

double a, b, c, d, ans;

void main(){
	while (readf("%s %s %s %s\n", &a, &b, &c, &d), [a, b, c, d] != [-1, -1, -1, -1]) {
		a *= PI / 180; 
		b *= PI / 180; 
		c *= PI / 180; 
		d *= PI / 180; 
		ans = R * acos(sin(a)*sin(c) + cos(a)*cos(c)*cos(b-d));
		writeln(lround(ans));
	}
}

Measured memory_bytes: 1036
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
N = INT()
uvw = [LIST() for _ in range(N-1)]

graph = [[] for _ in range(N)]

for u, v, w in uvw:
	graph[u-1].append([v-1, w])
	graph[v-1].append([u-1, w])

#print(graph)

step = [-1]*N
step[0] = 0

def DFS(n):
	for x, w in graph[n]:
		#print(x, w)
		if step[x] == -1:
			if (w+step[n])%2:
				step[x] = 1
			else:
				step[x] = 0
			#print(step)
			DFS(x)

DFS(0)

for ans in step:
	print(ans)
	


Measured memory_bytes: 106488
#include<iostream>
using namespace std;

int main(){

   long n, tmp, sum=0;

   cin >> n;

   int a[n];

   for(int i=0; i<n; i++){
       cin >> a[i];
   }

   for(int i=0; i<n; i++){
       for(int j=0; j<n-1; j++){
           if(a[j]>=a[j+1]){
               tmp = a[j+1];
               a[j+1] = a[j];
               a[j] = tmp;
           }
       }
       /*for(int k=0; k<n; k++){
       cout << a[k] << " ";
       }
       cout << "\n";*/
    }
   

   

   for(int i=0; i<n; i++){
       sum += a[i];
   }

   cout << a[0]<< " " << a[n-1] << " " << sum << "\n";


    return 0;  
}


Measured memory_bytes: 3140
s = [ord(i) - 97 for i in input()]
k = int(input())

for i in range(len(s)):
    diff = 26 - s[i]
    if (s[i] != 0) and (diff <= k):
        k -= diff
        s[i] = 0

s[-1] = (s[-1] + k) % 26

ans = "".join(chr(i+97) for i in s)
print(ans)

Measured memory_bytes: 4796
#include<stdio.h>
int main(void)
{
	int a,b[1001],x=0,x1=10000,X=100000000,cnt,i,j;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&b[i]);
		if(x<b[i]){
			x=b[i];
		}
		if(x1>b[i]){
			x1=b[i];
		}
	}
	for(i=x1;i<=x;i++){
		cnt=0;
		for(j=0;j<a;j++){
			cnt+=(b[j]-i)*(b[j]-i);
		}
		if(X>cnt){
			X=cnt;
		}
	}
	printf("%d\n",X);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <string>
#include <numeric>

typedef long long ll;

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;

    s[k - 1] = s[k - 1] + 32;
    cout << s;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    vec<vec<char>> v(a,vec<char>(a)),vv(b,vec<char>(b));
    rep(i,0,a)rep(j,0,a)cin>>v[i][j];
    rep(i,0,b)rep(j,0,b)cin>>vv[i][j];

    rep(i,0,a-b+1){
        rep(j,0,a-b+1){
            bool ok=true;
            rep(p,0,b){
                rep(q,0,b){
                    if(v[i+p][j+q]!=vv[p][q])ok=false;
                }
            }
            if(ok){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
typedef pair<string,int> P;
int puzzle[30];
bool check(string s){
	for(int i=0;i<9;i++){
		if(s[0]!=s[i])return false;
	}
	for(int i=9;i<21;i+=3){
		if(s[i]!=s[i+1]||s[i]!=s[i+2])return false;
	}
	for(int i=21;i<30;i++){
		if(s[21]!=s[i])return false;
	}
	return true;
}
string rec(string s,int x){
	string tmp=s;
	if(x==0){
		swap(tmp[0],tmp[23]);
		swap(tmp[3],tmp[26]);
		swap(tmp[6],tmp[29]);
		swap(tmp[9],tmp[20]);
		swap(tmp[15],tmp[17]);
	}else if(x==1){
		swap(tmp[2],tmp[21]);
		swap(tmp[5],tmp[24]);
		swap(tmp[8],tmp[27]);
		swap(tmp[11],tmp[18]);
		swap(tmp[12],tmp[14]);
	}else if(x==2){
		swap(tmp[0],tmp[27]);
		swap(tmp[1],tmp[28]);
		swap(tmp[2],tmp[29]);
		swap(tmp[14],tmp[15]);
		swap(tmp[18],tmp[20]);
	}else{
		swap(tmp[6],tmp[21]);
		swap(tmp[7],tmp[22]);
		swap(tmp[8],tmp[23]);
		swap(tmp[12],tmp[17]);
		swap(tmp[9],tmp[11]);
	}
	return tmp;
}
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		for(int j=0;j<30;j++){
			int x;
			cin>>x;
			s.PB('0'+x);
		}
		queue<P> data;
		set<string> f;
		data.push(MP(s,0));
		f.insert(s);
		while(data.size()){
			P p=data.front();data.pop();
			if(check(p.first)){
				cout<<p.second<<endl;
				break;
			}
			for(int i=0;i<4;i++){
				string tmp=rec(p.first,i);
				if(!f.count(tmp)){
					data.push(MP(tmp,p.second+1));
					f.insert(tmp);
				}
			}
		}
	}
}

Measured memory_bytes: 1264
a = input().split()
N = int(a[0])
M = int(a[1])
S = list(input())
T = list(input())

if N > M:
    pre = N
    lat = M
else:
    pre = M
    lat = N

while True:
    if pre % lat == 0:
        GCD = int(lat)
        break
    else:
        stp = lat
        lat = pre % lat
        pre = stp

LCM = int(N * M / GCD)

N_l = int(N / GCD)
M_l = int(M / GCD)

ch=0
for i in range(GCD):
    if S[i*N_l] != T[i*M_l]:
        ch = 1
        break

if ch == 0:
    print(LCM)
else:
    print(-1)

Measured memory_bytes: 4624
from collections import deque
N,M = map(int,input().split())
data = [[] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    data[a-1].append(b)
    data[b-1].append(a)

que = deque([1])
ans = [0 for i in range(N)]
while True:
    cur = que.popleft()
    for item in data[cur-1]:
        if ans[item-1] == 0:
            que.append(item)
            ans[item-1] = cur
    if len(que) == 0: break

if 0 in ans:
    print("No")
else:
    print("Yes")
    for i in range(1,N): print(ans[i])

Measured memory_bytes: 34020
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    char s[100];
    char p[100];
    char ss[200];
    
    scanf("%s",s);
    scanf("%s",p);
    strcpy(ss,s);
    
    strcat(ss,s);
    
    if(strstr(ss,p)==NULL){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }
    
    return 0;
    
}


Measured memory_bytes: 2112
#include <stdio.h>
#define MAX 105
#define INF 2e8

int G[MAX][MAX], n;

int minimum(int a, int b){
	if (a>b)
		return b;
	else return a;
}


int main(void) {
  int u,k,v,c,i,j,h;
 
  scanf("%d",&n);
  for(i=0; i<n; i++){
  	G[i][i] = 0;
	for(j=0; j<n ;j++)
  		G[i][j] = INF;
  }

  for(i=0; i<n; i++){
	scanf("%d%d",&u,&k);
	for(j=0; j<k; j++){
  		scanf("%d%d",&v, &c);
  		G[u][v] = c;
	}
  }

  for(h=0; h<n; h++){  
    for(i=0; i<n; i++){
		for(j=0; j<n; j++)
			G[i][j] = minimum(G[i][j], G[i][h]+G[h][j]);
  	}
  }
  
  printf("0 0\n");
  for(i=1; i<n; i++){
	printf("%d %d\n", i, G[0][i]);
  }
	

  return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int k;
    cin>>k;
    int odd = 0,eve = 0;
    rep(i,1,k){
        if(i % 2 == 0) eve++;
        else odd++;
    }
    cout<<odd * eve<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  int h0=0;
  int ans;
  REP(i,(int)s.size()-1){
    if(s[i]==s[i+1]) h0++;
  }
  REP(i,k){
    ans = min(n-1,h0+2*k);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n, q;
  while (cin >> n >> q, n && q) {
    vvi v(n, vi(100));
    rep(i, n) {
      int m;
      cin >> m;
      while (m--) {
        int d;
        cin >> d;
        v[i][d] = 1;
      }
    }
    int c = 0, d;
    rep(j, 100) {
      int s = 0;
      rep(i, n) s += v[i][j];
      if (cmax(c, s)) d = j;
    }
    if (c < q) d = 0;
    cout << d << endl;
  }
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define Pi 3.1415926
#define MAX_N 110
using namespace std;
int n;
long double ans;
struct node
{
	long double x,y,m;
}a[MAX_N];
bool cmp(node a,node b)
{
	return a.m>b.m;
}
int main()
{
	cin>>n;
	for(register int i=1;i<=n;++i)
		cin>>a[i].x>>a[i].y;
	for(register long double i=0;i<2*Pi;i+=0.0001)
	{
		long double sx=0,sy=0;
		for(register int j=1;j<=n;++j)
			a[j].m=a[j].x*cos(i)+a[j].y*sin(i);
		sort(a+1,a+n+1,cmp);
		for(register int j=1;j<=n;++j)
			if(a[j].m<0)
			{
				break;
			}
			else
				sx+=a[j].x,sy+=a[j].y;
		ans=max(ans,sqrt(sx*sx+sy*sy));
	}
	cout<<fixed<<setprecision(15)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;


int main() {
	string s;
	cin >> s;

	ll res = 0, pos = 0, ans = 0;
	for (int bit = 0; bit < (1 << s.length() - 1); ++bit) {

		res = 0, pos = 0;
		rep(i, s.length() - 1) {
			pos += int(s[i] - '0');//数値に変換
			if (bit & (1 << i)) {
				res += pos;
				pos = 0;
			}
			else {
				pos = pos * 10;
			}
		}
		pos += int(s[s.length() - 1] - '0');
		ans += res + pos;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  // ll N, K; cin >> N >> K;
  // ll x, y, z; cin >> x >> y >> z;
  // ll a, b, c; cin >> a >> b >> c;
  // string s; cin >> s;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  ll l = 0;
  rep(i, N) l+=a[i];
  ll ans = INF;
  ll l2 = 0;
  rep(i, N) {
    l2 += a[i];
    ll d = abs(l2 * 2 - l);
    ans = min(ans, d);
  }
  

  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 4816
#include <bits/stdc++.h>

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cout << #x << " = " << (x) << endl;
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

int main()
{
	cout << setprecision(10);
	cin >> n >> s;
	//n - 3 桁を消す
	vector<string> search(1000);
	for(int i = 0 ; i < 1000 ; i++){
		if(i<10){
			search[i] = "00" + to_string(i);
	//		debug(search[i]);
		}
		else if( i< 100){
			search[i] = "0" + to_string(i);
	///		debug(search[i]);
		}else{
	//		debug(search[i]);
			search[i] = to_string(i);
		//	
		}
	}
	int ans = 0 ;
	rep(i,1000){
		string look = search[i];
		int index = 0 ;
		int now = 0 ;
		for(int index = 0 ; index < n ; index ++){
			if(s[index] == look[now]){
				now ++ ;
			}
			if(now == 3){
				ans ++ ;
				break;
			}
		}
	}
	cout << ans << endl;



}


Measured memory_bytes: 384
N, Y = list(map(int, input().split()))

answer1 = -1
answer2 = -1
answer3 = -1
for i in range(N + 1):
    for j in range(N + 1):
        k = N - i - j
        if 10000 * i + 5000 * j + 1000 * k == Y and k >= 0:
            answer1 = i
            answer2 = j
            answer3 = k

print(str(answer1) + " " + str(answer2) + " " + str(answer3))

Measured memory_bytes: 42300
n = int(input())
card = list(list(input().split() for _ in range(n)))
ans = [0, 0]

for i in range(n):
    if card[i][0] < card[i][1]:
        ans[1] += 3
    elif card[i][0] > card[i][1]:
        ans[0] += 3
    else:
        ans[0] += 1
        ans[1] += 1

print(*ans)


Measured memory_bytes: 5716
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int P = 998244353;
const int MAX = 1000001;
int n;
int t[MAX];
int wyn[MAX];
void add(int &a,int b){
  a += b;
  if(a >= P)
    a -= P;
}
void sub(int &a,int b){
  a -= b;
  if(a < 0)
    a += P;
}
int pot(int a,int w){
  int r = 1;
  while(w){
    if(w & 1)
      r = r * a % P;
    w/=2;
    a = a * a % P;
  }
  return r;
}
int mul(int a,int b){
  return a * b % P;
}
int pier[MAX];
int bk[MAX];
int odw[MAX];
int ile[MAX];
int mn[MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  int res = 0;
  R(i,n){
    int pom;
    cin >> pom;
    add(t[pom], pom);
    sub(res, pom);
  }
  R(i,MAX){
    odw[i] = pot(i, P-2);
  }
  for(int i = 2; i * i < MAX; i++){
    for(int j = 1; i * i * j < MAX; j++)
      bk[i * i * j] = 1;
  }
  for(int i = 2; i < MAX; i++){
    if(pier[i] == 0){
      for(int j = 1; j * i < MAX; j++){
        ile[i * j]++;
        pier[i * j] = 1;
      }
    }
  }
  for(int i = 1; i < MAX; i ++){
    int sum = 0;
    for(int j = 1; j * i < MAX; j++){
      add(sum, t[i * j]);
      if(bk[j] == 0){
        if(ile[j] & 1){
          sub(mn[i * j], odw[i]);
        }else{
          add(mn[i * j], odw[i]);
        }
      }
    }
    add(res, mul(mul(sum,sum), mn[i]));
  }
  cout << mul(res,(P+1)/2) << "\n";
}


Measured memory_bytes: 50816
import math
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def f(m):
    res = 0
    r_m = math.sqrt(m)
    for i in range(1, int(r_m) + 1):
        for j in range(1, int(r_m) + 1):
            for k in range(1, int(r_m) + 1):
                if i ** 2 + j ** 2 + k ** 2 + i * j + j * k + k * i == m:
                    print(f'{(m, i, j, k)=}')
                    res += 1
    return res


n = I()
cnt = [0] * 10001
r_n = int(math.sqrt(n)) + 1
for x in range(1, r_n):
    for y in range(1, r_n):
        for z in range(1, r_n):
            v = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if v <= n:
                cnt[v] += 1

for i in range(1, n + 1):
    print(cnt[i])


Measured memory_bytes: 9284
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 305;
const Int MAX2 = MAX*2;
signed ex[MAX2][MAX2];
signed dp1[MAX2+2][MAX2+2];
signed dp2[MAX2+2][MAX2+2];
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(Int i=0;i<h;i++) cin>>s[i];

  using P = pair<Int, Int>;
  vector<P> vp;
  memset(ex,0,sizeof(ex));
  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      if(s[i][j]!='#') continue;
      vp.emplace_back(1+i+j,1+i-j+w);
      ex[1+i+j][1+i-j+w]=1;      
    }
  }
  
  auto ch=
    [&](Int i,Int j)->Int{
      if(i<0||i>=MAX2) return 0;
      if(j<0||j>=MAX2) return 0;
      return ex[i][j];
    };
  
  memset(dp1,0,sizeof(dp1));
  memset(dp2,0,sizeof(dp2));
  Int ans=0;
  
  const Int LIM = h+w;
  for(Int k=1;k<=LIM;k++){
    for(Int i=0;i<MAX2;i++){
      for(Int j=0;j<MAX2;j++){
        dp1[i][j+1]=dp1[i][j]+(ex[i][j]&&ch(i,j-k));
        dp2[j][i+1]=dp2[j][i]+(ex[i][j]&&ch(i-k,j));
      }
    }
    for(P p:vp){
      Int i,j;
      tie(i,j)=p;
      
      if(i-k>=0) ans+=dp1[i-k][min(MAX2,j+k+1)]-dp1[i-k][j];
      if(j-k>=0) ans+=dp2[j-k][min(MAX2,i+k+1)]-dp2[j-k][i];
      
      if(i+k<MAX2) ans+=dp1[i+k][min(MAX2,j+k+1)]-dp1[i+k][j];
      if(j+k<MAX2) ans+=dp2[j+k][min(MAX2,i+k+1)]-dp2[j+k][i];
    }            
  }

  //cout<<ans<<endl;
  for(P p:vp){
    Int i,j;
    tie(i,j)=p;
    for(Int k=1;k<=LIM;k++){
      if(ch(i+k,j)&&ch(i,j+k)) ans--;
      if(ch(i+k,j)&&ch(i,j-k)) ans--;
      if(ch(i-k,j)&&ch(i,j+k)) ans--;
      if(ch(i-k,j)&&ch(i,j-k)) ans--;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6388
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n;
    cin >> n;
    int h[n];
    rep(i, n) cin >> h[i];

    int cnt = 1;
    for (int i = 1; i < n; i++)
    {
        bool flag = 0;
        rep(j, i)
        {
            if (h[j] > h[i])
                flag = 1;
        }
        if (flag == 0)
            cnt++;
    }
    OP(cnt);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll; 




bool isprime(ll a)
{
	
	ll cnt=0;	
	for(ll i=1;i*i<a;i++)
	{
		
	 	if(a%i==0)
	 	{
	 		cnt+=2;
		 }
		
		
	}
	
		if(cnt==2)
		return true;
		else
		return false;
		
}
void solve()
{

	
	ll n;
	cin>>n;
	
	ll a[n],b[n];
	
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	
	sort(a,a+n);
	sort(b,b+n);
	
	
	if(n%2)
	{
		cout<<(b[n/2]-a[n/2])+1;
	}
	else
	{
		
		cout<< (b[n/2]+b[n/2 -1]-a[n/2]-a[n/2 -1]+1) ;
	}
		





	
	
	
	
		
	


}


int main()
{


ios::sync_with_stdio(0); 
	cin.tie(0);


		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 6744
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<time.h>
#include<algorithm>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector <int>P(N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> P[i];
		ans += P[i];
	}
	ans = ans - (*max_element(P.begin(), P.end()) / 2);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256