akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

bool isprime[1010];
//エラトステネス
void eratos(int m){
    for (int i = 0; i <= m; ++i) isprime[i] = true;
    isprime[0] = isprime[1] = false;
    //iを残してiの倍数を消していく
    for (int i = 2; i <= m; ++i){
        if(isprime[i]){
            for (int j = 2 * i; j <= m; j += i){
                isprime[j] = false;
            }
        }
    }
}

int cnt[1010];
int main(void){
    int n; cin >> n;
    eratos(n + 1);
    rep(i, n + 1){
        int d = i;
        reps(j, 2, i + 1){
            while(d % j == 0){
                d /= j;
                // printf("j %d\n", j);
                cnt[j]++;
            }
        }
    }
    ll ans = 1;
    rep(i, n + 1){
        ans *= (cnt[i] + 1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <limits>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define ft first
#define sd second
#define pb push_back
#define mp(x,y) make_pair(x,y)
//#define int LL
using namespace std;
const int N   = 1e3+23;
//const int mod = ;
const int INF =numeric_limits<int >::max();
#define For(n) for (int i=1;i<=n;++i)
#define rep(i,n) for (int i=1;i<=n;++i)
#define repp(i,x,y) for (int i=x;i<=y;++i)
void read(int &x)
{
	x=0;
	char ch=getchar();
	int f=1;
	while (!isdigit(ch)) (ch=='-'?f=-1:0),ch=getchar();
	while ( isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	x*=f;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
char s[N][N];
int d[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
int n,m,qx[N*N],qy[N*N],h,t,vis[N][N],f[N][N];
void dfs(int x,int y)
{
	repp(i,0,3)	
	{
		int a=x+d[i][0];
		int b=y+d[i][1];
		if (1<=a&&a<=n&&1<=b&&b<=m&&s[a][b]=='.'&&!vis[a][b])
		  qx[++t]=a,qy[t]=b,f[a][b]=f[x][y],vis[a][b]=1,dfs(a,b);
	}
	return ;
}

void solve(int x,int y)
{
	repp(i,-2,2)
	  repp(j,-2,2)
	    {
	    	int a=x+i;
	    	int b=y+j;
	    	if (1<=a&&a<=n&&1<=b&&b<=m&&s[a][b]=='.'&&!vis[a][b])
	    	  vis[a][b]=1,f[a][b]=f[x][y]+1,qx[++t]=a,qy[t]=b,dfs(a,b); 
	    }
}
int x1,y1,x2,y2;
signed main()
{
	read(n);read(m);
	LL ans=0;
	read(x1);read(y1);
	read(x2);read(y2);
	rep(i,n) scanf("%s",s[i]+1);
	
	h=0,t=1;qx[1]=x1;qy[1]=y1;
	f[x2][y2]=-1;vis[x1][y1]=1;
	while (h<t)
	{
		//int ll=h+1;
		int rr=t;
		++h;
		dfs(qx[h],qy[h]);
	
		int kk=t;
		repp(i,rr+1,kk)  solve(qx[i],qy[i]);
		solve(qx[h],qy[h]);
		
		//h=rr+1;
	}
	printf("%d",f[x2][y2]);
	return 0;
}



Measured memory_bytes: 16560
#include<iostream>
#include<queue>
using namespace std;
main()
{
	long long int k;
	cin >> k;
	long long int i, idx = 0;
	queue<string>q;
	q.push("1");
	q.push("2");
	q.push("3");
	q.push("4");
	q.push("5");
	q.push("6");
	q.push("7");
	q.push("8");
	q.push("9");
	  
	while(true)
	{
	   string ans = q.front();q.pop();
	    	idx++;
	    	if(idx == k)
	    	{
	    		cout << ans << endl;
	    		return 0;
			}
		long long int x = ans[ans.size()-1] - '0';
			char ch = (x-1)+'0', ch1 =(x+1)+'0', ch2 = x+'0';
		
		if(x>0 && x<9)
		{
			string tmp = ans+ch, tmp1 = ans+ch1, tmp2 = ans+ch2;
			q.push(tmp);q.push(tmp2);q.push(tmp1);
		}
		else if(x == 9)
		{
			string tmp = ans+ch, tmp2 = ans+ch2;
			q.push(tmp);q.push(tmp2);
		}
		else if(x == 0)
		{
		    string   tmp1 = ans+ch1, tmp2 = ans+ch2;
			q.push(tmp2);q.push(tmp1);	
		}
		
	}
	
	
	return 0;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int INF=1001001001;


int main(){

  ll n;
  cin>>n;
  vector<ll> h(n);
  rep(i,n)cin>>h[i];
  ll dp[n+2];
  rep(i,n+2)dp[i]=INF;
  dp[0]=0;
  rep(i,n){
    if (i+2<=n-1)dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    if (i+1<=n-1)dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
  }
cout<<dp[n-1];

}


Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
long long a,b,ans = 0;
long long  f(long long num){
	long long r = (num + 1) / 2 % 2;	
	if (num % 2 == 0) r = r ^ num;
	return r;
}
int main(){
	cin >> a >> b;
	ans = f(a - 1) ^ f(b);
	cout << ans << endl;
	return 0;
} 

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

int main()
{
  int a,b,k = 0;
  cin >> a >> b >>k;
  int counter = 0;
  int r = 0;

  for(int i = min(a,b); i >= 1 ; i--){
    if(a % i == 0 && b % i == 0){
      counter ++ ;
    }
    if(counter == k){
      r = i;
      break;
    }
  }

  cout << r << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
	int N; string S; cin>>N>>S;
	vector<int> v(3,0);
	for(int i=0;i<N;i++){
		v[(S[i]-'0')%3]++;
	}
	int ans=v[0]*v[1]*v[2];
	for(int i=0;i<N-1;i++){
		for(int j=i;j<N;j++){
			int d=j-i,now=j+d;
			if(now<N){
				if(S[i]!=S[j] and S[i]!=S[now] and S[j]!=S[now])ans--;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,c=0;
cin >> n;
char a;
while(n--){
  cin >>a;
  if(a=='Y'){
    c++;
  }
}
if(c>0){
cout << "Four" << endl;
  
}else{
  cout << "Three" << endl;
}
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll ans = 1 << 30;
    ans = min(ans, ll(a * x + b * y));
    if (x > y)
    {
        ans = min(ans, ll(2 * c * y + a * (x - y)));
        ans = min(ans, ll(2 * c * x));
    }
    else
    {
        ans = min(ans, ll(2 * c * x + b * (y - x)));
        ans = min(ans, ll(2 * c * y));
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int m1,moto,g=0,minx=9999;
	cin>>m1>>moto;
    int a[m1+1];
    for(int i=1;i<=m1;i++)
    cin>>a[i];
    for(int i=1;i<=m1;i++)
    {
    	g+=a[i];
    	if(a[i]<minx)  minx=a[i];
    }
    moto-=g;
    cout<<moto/minx+m1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[51][51];
int b[51][51];
int n,m;
int main(){
	cin>>n>>m;
	memset(b,0,sizeof(b));
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	cin>>a[i][j];
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		if(a[i][j]=='.')
		{
			if(a[i+1][j]=='#')
			b[i][j]++;
			if(a[i-1][j]=='#')
			b[i][j]++;
			if(a[i][j+1]=='#')
			b[i][j]++;
			if(a[i][j-1]=='#')
			b[i][j]++;
			if(a[i+1][j+1]=='#')
			b[i][j]++;
			if(a[i+1][j-1]=='#')
			b[i][j]++;
			if(a[i-1][j+1]=='#')
			b[i][j]++;
			if(a[i-1][j-1]=='#')
			b[i][j]++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
	{
		if(a[i][j]=='#')
		cout<<a[i][j];
		else
		cout<<b[i][j];
	}
	cout<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long int64;

int N;
int64 v[40], w[40], W, ret;

void dfs(int idx, int sz, int64 vv, int64 ww, vector< pair< int64, int64 > > &kk)
{
  if(idx == sz) {
    if(ww <= W) {
      kk.emplace_back(ww, vv);
      ret = max(ret, vv);
    }
    return;
  }
  dfs(idx + 1, sz, vv + v[idx], ww + w[idx], kk);
  dfs(idx + 1, sz, vv, ww, kk);
}

int main()
{
  cin >> N >> W;
  for(int i = 0; i < N; i++) cin >> v[i] >> w[i];

  vector< pair< int64, int64 > > a, b;
  dfs(0, N >> 1, 0, 0, a);
  dfs(N >> 1, N, 0, 0, b);
  sort(begin(b), end(b));

  for(int i = 1; i < b.size(); i++) {
    b[i].second = max(b[i].second, b[i - 1].second);
  }
  
  for(auto &ss : a) {
    auto get = lower_bound(begin(b), end(b), make_pair(W - ss.first + 1, 0LL));
    if(get != begin(b)) {
      --get;
      if(ss.first + get->first > W) continue;
      ret = max(ret, ss.second + get->second);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 43736
#include <iostream>
#include <algorithm>

using namespace std;

int a[11];

bool dfs(int I, int A, int B) {
	if (I == 10) return true;
	if (a[I] > A) {
		if (dfs (I + 1, a[I], B)) {
			return true;
		}
	}
	if (a[I] > B) {
		if (dfs(I + 1, A, a[I])) {
			return true;
		}
   	}
   	return false;
}

int main () {
	int T;
	cin >> T; 
	while (T--) {
		for (int i=0; i<10; i++) {
			cin >> a[i];
		}
		if (dfs(0,0,0)) {
			cout << "YES" <<endl;
		}
		else cout << "NO" <<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <list>
 
using namespace std;
 
int main() {
	int h,w,m;
	cin >> h >> w >> m;
	std::map<std::string,bool> bomb;
	int row[h+1];
	int column[w+1];
	for(int i=0;i<h+1;i++){
	    row[i]=0;
	}
	for(int i=0;i<w+1;i++){
	    column[i]=0;
	}
	
    for(int i=0; i<m; i++){
        int bh,bw;
        cin >> bh >> bw;
        row[bh-1]++;
        column[bw-1]++;
        string key=std::to_string(bh)+"_"+std::to_string(bw);
        bomb[key]=true;
    }
    list<int> maxrows;
    int rowmax = 0;
    for(int i=0; i<h; i++){
        int rownum = row[i];
        if(rownum > rowmax){
            rowmax = rownum;
            maxrows.clear();
            maxrows.push_back(i);
        }else if(rownum == rowmax){
            maxrows.push_back(i);
        }
    }
    list<int> maxcolumns;
    int columnmax = 0;
    for(int i=0; i<w; i++){
        int columnnum = column[i];
        if(columnnum > columnmax){
            columnmax = columnnum;
            maxcolumns.clear();
            maxcolumns.push_back(i);
        }else if(columnnum == columnmax){
            maxcolumns.push_back(i);
        }
    }
    for(auto r : maxrows){
        for(auto c : maxcolumns){
            int r1 = r+1;
            int c1 = c+1;
            string rckey = std::to_string(r1) +"_" +std::to_string(c1);
            if(!bomb[rckey]){
                cout << rowmax + columnmax << endl;
                return 0;
            }
        }
    }
    cout << rowmax + columnmax -1 << endl;
	return 0;
}

Measured memory_bytes: 48172
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
	return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
	return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
	return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
	return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
	a += rhs.a;
	if (a >= Modulus) {
	  a -= Modulus;
	}
	return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
	if (a < rhs.a) {
	  a += Modulus;
	}
	a -= rhs.a;
	return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
	a = a * rhs.a % Modulus;
	return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
	u64 exp = Modulus - 2;
	while (exp) {
	  if (exp % 2) {
		*this *= rhs;
	  }
	  rhs *= rhs;
	  exp /= 2;
	}
	return *this;
  }
};

using mint = modint<MOD>;


struct ModCombination {
    vector<mint> Fac;
    vector<mint> Facinv;

    ModCombination(int x) {
        Fac.resize(x+1);
        Facinv.resize(x+1);
        Fac[0] = 1;
        for (int i = 0; i < x; ++i) Fac[i+1] = Fac[i]*(i+1);
        Facinv[x] = Fac[0]/Fac[x];
        for (int i = x; i > 0; --i) Facinv[i-1] = Facinv[i]*i;
    }

    mint get(int n, int k) {
        if (k < 0 || k > n) return 0;
        return Fac[n]*Facinv[k]*Facinv[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int B,W; cin >> B >> W;

	ModCombination MC(B+W+5);
	vector<mint> dp1(B+W+1),dp2(B+W+1);

	rep(i,B+W) {
		dp1[i+1] = dp1[i]*2 + MC.get(i-1,B-1);
		dp2[i+1] = dp2[i]*2 + MC.get(i-1,W-1);
		//cout << dp1[i+1].a << " " << dp2[i+1].a << ln;
	}
	vector<mint> ans(B+W);
	mint b = 1;
	rep(i,B+W) {
		mint k = b - dp1[i+1] - dp2[i+1];
		b *= 2;
		ans[i] = (dp2[i+1]*2 + k)/b;
		cout << ans[i].a << ln;
	}
}


Measured memory_bytes: 9984
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  string S;
  int n=0,w=0,s=0,e=0;
  cin >> S;
  REP(i,S.size()){
    if(S[i] == 'N')
      n = 1;
    else if(S[i] == 'E')
      e = 1;
    else if(S[i] == 'W')
      w = 1;
    else
      s = 1;
  }
  if(n+e+w+s == 4)
    cout << "Yes" << endl;
  else if(n+e+w+s == 3){
    cout << "No" << endl;
  }else if(n+s == 2){
    cout << "Yes" << endl;
  }else if(w+e == 2){
    cout << "Yes" << endl;
  }else
    cout << "No" << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0index
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1index
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //逆
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;  //最大値兼MOD
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  int n;
  cin >> n;
  cout << (n - 30) / 2 << endl;
  return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string S;
  cin >> S;
  int lenS = sz(S);
  int ans = 0;
  for (int i = 0; i < lenS/2; i++) {
    if (S[i] != S[lenS-1-i]) ++ans;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>

int main()
{
    // std::cout << std::fixed << std::setprecision(5);
    int n; std::cin >> n;
    long long int ans = 1;
    for(int i=1; i<n+1; i++)
    {
        i %= 1000000007;
        ans *= i;
        ans %= 1000000007;
    }
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000

int main(){
  int n, i;
  int A[MAX+1];
  
  scanf("%d", &n);
  for ( i = 1; i <= n; i++ ){
    scanf("%d", &A[i]);
  }
  for ( i = 1; i <= n; i++ ) {
    printf("node %d: key = %d, ", i, A[i]);
    if ( i / 2 >= 1 ){
      printf("parent key = %d, ", A[i/2]);
    }
    if ( i*2 <= n ){
      printf("left key = %d, ", A[i*2]);
    }
    if ( i*2+1 <= n ){
      printf("right key = %d, ", A[i*2+1]);
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2108
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


int main() {
    ll n, k;
    cin >> n >> k;
    ll b = n/k;
    ll ans1 = b * b * b;
    ll ans2 = 0;


    if ( k % 2 == 0 && n >= k/2) {
        ll c = (n - k/2) / k;
        c++;
        ans2 = c * c*c;
    }


    cout << ans1 + ans2 << endl;
    return 0;
}

Measured memory_bytes: 256
import math

A, B = list(map(int, input().split()))

price_a = math.ceil(A*100/8)
price_b = int(B*100/10)

if(int(price_a * 1.10) - B == price_a) :
  print(price_a)
  exit()
if(int(price_b * 1.08) - A == price_b) :
  print(price_b)
  exit()
  
print(-1)

Measured memory_bytes: 3064
from collections import deque
k=int(input())
ans=deque([1,2,3,4,5,6,7,8,9])

for i in range(k):
    p=ans.popleft()
    if i==k-1:
        print(p)
    q=p%10
    if q==0:
        ans.append(10*p+0)
        ans.append(10*p+1)
    elif q==9:
        ans.append(10*p+8)
        ans.append(10*p+9)
    else:
        ans.append(10*p+q-1)
        ans.append(10*p+q)
        ans.append(10*p+q+1)

        


    





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

int main()
{
	int A, B;
	cin >> A >> B;

	int K = A + B;
	if (K % 2 == 0)
		cout << K /2 << endl;
	else
		cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,m1,x1,x2,x3,max,min,ans;
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
	if(a<=b){
		x1=a;
	}
	else if(b<=a){
		x1=b;
	}
	if(x1<=c){
		x2=x1;
	}
	else if(c<=x1){
		x2=c;
	}
	if(x2<=d){
		x3=x2;
	}
	else if(d<=x2){
		x3=d;
	}
	if(e<=f){
		m1=e;
	}
	else if(f<=e){
		m1=f;
	}	
	max=a+b+c+d+e+f;
	min=m1+x3;
	ans=max-min;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2700
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl;
#define y() cout << "Yes" << endl;
#define n() cout << "No" << endl;
using lint = long long;
using vi = vector<int>;

int main() {
	int N;
	cin >> N;
	vi file(N);
	int r;
	rep(i, N) {
		cin >> r;
		file[i] = r;
	}
	rep(i, N) {
		if (file[i] % 2 == 0) {
			if (file[i] % 3 != 0 && file[i] % 5 != 0) {
				cou("DENIED")
				exit(0);
			}
		}
	}
	cou("APPROVED")
}

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

int main(){
    int ab,bc,ca;
    cin >> ab >> bc >> ca;
    vector<int> t={ab,bc,ca};
    sort(t.begin(),t.end());
    cout << (t[0]*t[1])/2 << endl;
}


Measured memory_bytes: 256
import math
from collections import defaultdict

mod = pow(10, 9)+7

def digits_parade(strr, n):
	dp = [[0]*13 for i in range(n)]
	if strr[0]=="?":
		for k in range(10):
			dp[0][k] = 1
	else:
		dp[0][int(strr[0])] = 1

	for i in range(1, n):
		if strr[i]=="?":
			for j in range(10):
				temp = j
				for k in range(13):
					dp[i][(10*k + temp)%13] += dp[i-1][k]
					dp[i][(10*k + temp)%13] %= mod
		else:
			temp = int(strr[i])
			for k in range(13):
				dp[i][(10*k + temp)%13] += dp[i-1][k]
				dp[i][(10*k + temp)%13] %= mod
	return dp[n-1][5]

strr = input()
n = len(strr)

ans =digits_parade(strr, n)
print(ans)

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

int main(){
  int n, d;
  cin >> n >> d;
  
  int res = 0;
  while(n > 0){
    n -= (2*d + 1);
    ++ res;
  }
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        s: usize,
    }

    let mut cnt = 0;
    let mut a: Vec<usize> = Vec::new();
    a.push(s);
    loop {
        if a[a.len()-1]%2==0 {
            a.push(a[a.len()-1]/2);
        } else {
            a.push(a[a.len()-1]*3+1);
        }
        for i in 0..a.len()-1 {
            if a[a.len()-1]==a[i] {
                println!("{}", a.len());
                return;
            }
        }
    }

}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const ll INFL = (1L<<60);

int main() {
  int N, M, R; cin >> N >> M >> R;
  ll ans = INFL;
  vvl dist(N, vl(N, INFL));
  rep(i,N) dist[i][i] = 0;
  vl r(R);
  rep(i,R) {
    cin >> r[i]; r[i]--;
  }
  rep(i,M) {
    ll a, b, c; cin >> a >> b >> c;
    a--; b--;
    dist[a][b] = min(dist[a][b], c);
    dist[b][a] = min(dist[b][a], c);
  }
  rep(k,N) {
    rep(i,N) {
      rep(j,N) {
        dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
  // rep(i,N) {
  //   outa(dist[i],N);
  // }
  sort(all(r));
  do {
    ll d = 0;
    rep(i,R-1) {
      d += dist[r[i]][r[i+1]];
    }
    ans = min(ans, d);
  } while (next_permutation(all(r)));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
-- Vicfred
-- https://atcoder.jp/contests/abc125/tasks/abc125_b
-- greedy
n = io.read("*n")
v, c = {}, {}
for i = 1, n do v[i] = io.read("*n") end
for i = 1, n do c[i] = io.read("*n") end
ans = 0
for i = 1, n do
    if(c[i] < v[i]) then
        ans = ans + v[i] - c[i]
    end
end
print(ans)



Measured memory_bytes: 2716
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
	string s;
	vector<string> t = {"dream", "dreamer", "erase", "eraser"};
	cin >> s;
	reverse(s.begin(), s.end());
	for(int i = 0; i < 4; i++){
		reverse(t[i].begin(), t[i].end());
	}
	int p = 0;
	while(p < s.size()){
		bool f = false;
		for(int i = 0; i < 4; i++){
			if(s.find(t[i], p) == p){
				p += t[i].size();
				f = true;
				break;
			}
		}
		if(!f) break;
	}
	if(p == s.size()){
		cout << "YES" << endl;
	} else{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=1005;
int n,val[N],sd[N][N],sx[N][N];
lint dp[N][N],xp[N][N];

namespace utils{
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=c=='-'&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

void oput(const int l,const int r,const int shift){
	if(l==r) return;
	int p2=sd[l][r],p1=sx[l][p2-1];
	oput(l,p1,shift+0);
	oput(p1+1,p2-1,shift+1);
	oput(p2,r,shift+2);
	printf("%d\n",shift+2);
}

int main(){
	memset(xp,-10,sizeof(xp));
	memset(dp,-10,sizeof(dp));
	n=nxi();
	for(int i=1; i<=n; ++i){
		sx[i][i+1]=i;
		xp[i][i+1]=dp[i][i]=val[i]=nxi();
	}
	for(int i=1; i<=n; ++i){
		for(int j=i-2; j>=1; j-=2){
			for(int k=j+2; k<=i; k+=2){
				lint v=xp[j][k-1]+dp[k][i];
				if(dp[j][i]<v){
					sd[j][i]=k,dp[j][i]=v;
				}
			}
			if(dp[j][i]>xp[j][i-1]){
				xp[j][i+1]=dp[j][i],sx[j][i+1]=i;
			}
			else{
				xp[j][i+1]=xp[j][i-1];
				sx[j][i+1]=sx[j][i-1];
			}
		}
	}
	{
		int pl=1,pr=1;
		for(int i=1; i<=n; ++i){
			for(int j=i; j<=n; j+=2){
				if(dp[i][j]>dp[pl][pr]) pl=i,pr=j;
			}
		}
		assert(((pr-pl)&1)==0);
		printf("%lld\n",dp[pl][pr]);
		printf("%d\n",(pl-1)+(n-pr)+(pr-pl)/2);
		for(int i=n; i>pr; --i) printf("%d\n",i);
		for(int i=1; i<pl; ++i) printf("%d\n",1);
		oput(pl,pr,0);
	}
	return 0;
}


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

using namespace std;
using ll = long long;

ll n, a, b;
vector<ll> h;

bool solve(ll total) {
  ll cnt_a = total;
  ll cnt_b = 0;
  for (int i = 0; i < n; i++) {
    ll rest = h[i] - a * cnt_a - b * cnt_b;
    if (rest > 0) {
      return false;
    }
    ll cnt = - rest / (a - b);
    cnt_a = cnt;
    cnt_b = total - cnt_a;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> a >> b;
  h = vector<ll>(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end(), greater<ll>());
  ll ok = (h[0] + b - 1) / b;
  ll ng = (h[0] + a - 1) / a - 1;
  while (ok - ng > 1) {
    ll mid = (ok + ng) / 2;
    if (solve(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}

Measured memory_bytes: 1024
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy

T=int(input())
ABCD=[list(map(int,input().split())) for i in range(T)]
for A,B,C,D in ABCD:
    if B>D or A<B:
        print("No")
    elif B==D:
        if A%B<=C:
            print("Yes")
        else:
            print("No")
    else:
        E=B-C-1
        if E>0:
            F=D-B
            if E>F:
                print("No")
            else:
                _gcd=gcd(F,B)
                st=(A-B)%_gcd
                #if A==14 and B==10 and C==8 and D==12:
                #    print(B-C-1)
                if B-_gcd+A%_gcd>C:
                    print("No")
                else:
                    print("Yes")
        else:
            print("Yes")


Measured memory_bytes: 64620
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,char> Q;
ll longinf=1ll<<60;
int inf=1<<29;
int dh[]={0,1,0,-1};
int dw[]={1,0,-1,0};

bool v[401][401]={};
char c[401][401];
ll wt[401][401];
ll bk[401][401];
int H,W;

//1→# 0→.
void dfs(int sh,int sw,int nh,int nw,char ncolor){
      rep0(p,4){
            int hh=nh+dh[p];
            int ww=nw+dw[p];
            char color=((ncolor=='#')?'.':'#');
            //cout<<hh<<" "<<ww<<endl;
            //cout<<H<<" "<<W<<endl;
            //cout<<(int)(hh>=0&&hh<H&&ww>=0&&ww<W)<<endl;
            if(hh>=0&&hh<H&&ww>=0&&ww<W&&!v[hh][ww]&&c[hh][ww]==color){
                  v[hh][ww]=true;
                  if(color=='#') bk[sh][sw]++;
                  else wt[sh][sw]++;
                  dfs(sh,sw,hh,ww,color);
                  //cout<<hh<<" "<<ww<<endl;
            }
      }
};
int main(){
      cin>>H>>W;
      rep0(h,H) rep0(w,W) cin>>c[h][w];
      rep0(h,H) rep0(w,W){
            v[h][w]=false;
            wt[h][w]=0;
            bk[h][w]=0;
      }
      ll ans=0;
      rep0(i,H)rep0(j,W){
            dfs(i,j,i,j,c[i][j]);
      }
      rep0(i,H)rep0(j,W){
            ans+=(wt[i][j]*bk[i][j]);
            //cout<<wt[i][j]<<" "<<bk[i][j]<<"|";
            //if(j==W-1) cout<<endl;
      }
      cout<<ans<<endl;
      return 0;
}

Measured memory_bytes: 15616
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

// func init() {
// 	// read one word/char/int separated by space(s).
// 	//sc.Split(bufio.ScanWords)

// 	// read one line.
// 	sc.Split(bufio.ScanLines)
// }

func main() {
	var S string
	sc.Split(bufio.ScanLines)
	fmt.Scan(&S)
	o := str{chrs: []byte(S), memo: make([][4]int64, len(S)+20)}
	if len(S) == 1 {
		fmt.Println(1)
		return
	}
	one := o.solve(0, 0)
	two := o.solve(0, 1)
	if one > two {
		fmt.Println(one)
		return
	}
	fmt.Println(two)
}

type str struct {
	chrs []byte
	memo [][4]int64
}

// prev
// 1: 前の文字列と、その前の文字列が異なる
// 2: 前の文字列と、その前の文字列が一致
// 3: 前の文字列が2文字

func (s *str) solve(prev, idx int) int64 {
	if idx == len(s.chrs)-1 {
		if prev == 2 || prev == 3 {
			return 1
		}
		if s.chrs[idx] == s.chrs[idx-1] {
			return 0
		}
		return 1
	}
	if s.memo[idx][prev] != 0 {
		return s.memo[idx][prev]
	}
	var ans int64
	switch prev {
	case 1:
		if s.chrs[idx] == s.chrs[idx-1] {
			ans = s.solve(2, idx+1)
		} else {
			ans = s.solve(1, idx+1) + 1
		}
	case 2:
		ans = s.solve(3, idx+1) + 1
	case 3:
		ans = s.solve(1, idx+1) + 1
	default:
		ans = s.solve(1, idx+1) + 1
	}
	s.memo[idx][prev] = ans
	return ans
}


Measured memory_bytes: 61952
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		int X = Integer.parseInt(br.readLine());
		boolean found=false;
		int num=X,count=0,ans=-1;
		
		while(found!=true)
		{
			count=0;
			for(int i=2;i<num;i++)
			{
				if(num%i==0)
					count++;
					
				if(count>0)//not a prime
					break;
			}
			if(count==0)
			{
				found=true;
				ans=num;
				break;		
			}
			
			else
				num++;
		}
		
		out.println(ans);
	
	}
}




Measured memory_bytes: 21460
N = str(input())
#100-999
hundred=N[0]
ten=N[1]
one=N[2]

if hundred>ten:
    x=int(hundred+hundred+hundred)
elif hundred<ten:
    x=int(str((int(hundred)+1))+str((int(hundred)+1))+str((int(hundred)+1)))
else:
    if ten>=one:
        x=int(hundred+hundred+hundred)
    else:
        x=int(str((int(hundred)+1))+str((int(hundred)+1))+str((int(hundred)+1)))
print(x)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<40;
const ll MOD = 1000000007;

ll dp[10010][105][2];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n;
  cin >> n;
  vector<vector<ll>> a(n, vector<ll>(n));
  REP(i, n) REP(j, n) cin >> a[i][j];

  vector<ll> x(1LL<<n);
  REP(i, 1<<n) {
    vector<ll> v;
    REP(j, n) if(i&1<<j) v.push_back(j);
    REP(j, v.size()) FOR(k, j+1, v.size()) {
      x[i] += a[v[j]][v[k]];
    }
  }

  vector<ll> dp(1LL<<n);
  REP(i, 1<<n) {
    ll sub = i;
    dp[i] = x[i];
    do {
      chmax(dp[i], dp[sub] + x[i-sub]);
      sub = (sub-1) & i;
    } while(sub);
  }
  cout << dp[(1LL<<n)-1] << endl;

  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    vector<string> d = {"", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
    string s;
    cin >> s;
    cout << find(d.begin(), d.end(), s) - d.begin() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int nn;
  scanf("%d", &nn);
  if(nn / 100 == 7)
  {
    printf("Yes\n");
    return 0;
  }
  nn = nn - (nn / 100) * 100;
  if(nn / 10 == 7)
  {
    printf("Yes\n");
    return 0;
  }
  nn = nn - (nn / 10) * 10;
  if(nn == 7)
  {
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 1644
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()

	l,r := 0,n
	fmt.Println(0)
	ls := scanText()
	rs := ls

	for r > l+1 {
		mid := (r+l)/2
		fmt.Println(mid)
		mids := scanText()

		if mids=="Vacant" {
			return
		}

		var next bool
		if ls==mids {
			if (mid-l+1)%2==1 {
				next = false
			}
		} else {
			if (mid-l+1)%2==0 {
				next = false
			}
		}
		if mids==rs {
			if (r-mid+1)%2==0 {
				next = true
			}
		} else {
			if (r-mid+1)%2==1 {
				next = true
			}
		}

		if next {
			ls = mids
			l = mid
		} else {
			rs = mids
			r = mid
		}
	}
	fmt.Println(l)
}


Measured memory_bytes: 1232
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <limits>
#include <numeric>
#include <valarray>
#include <fstream>
#include <array>
#include <random>
#include <unordered_set>
#include <unordered_map>

using namespace std;
using uint = uint32_t;
using LL = int64_t;
using ULL = uint64_t;
using PP = pair<LL, LL>;
template <typename T> using PriorityQ = priority_queue<T, vector<T>, greater<T> >;
#define REP(i, a, n) for(LL i = (a), i##_max_ = (n); i < i##_max_; ++i)
#define REM(i, a, n) for(LL i = (LL)(n) - 1, i##_min_ = (a); i >= i##_min_; --i)
#define FLOAT fixed << setprecision(16)
#define SPEEDUP { cin.tie(NULL); ios::sync_with_stdio(false); }
const int INF = 0x3FFFFFFF;
const LL INFLL = 0x3FFFFFFF3FFFFFFF;
const double INFD = 1.0e+308;
const double EPS = 1.0e-9;

void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
template <class T, class U> istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; }
template <class T, class U> ostream& operator<<(ostream& ost, const pair<T, U>& right) { return ost << right.first << ' ' << right.second; }
template <class T, class TCompatible, size_t N> void Fill(T(&dest)[N], const TCompatible& val) { fill(dest, dest + N, val); }
template <class T, class TCompatible, size_t M, size_t N> void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); }
template <class T> T Next() { T buf; cin >> buf; return buf; }
istream& Ignore(istream& ist) { string s; ist >> s; return ist; }
bool Inside(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; }

#ifdef ONLY_MY_ENVIR
#include "IntMod.h"
#include "Algebraic.h"
#include "BinaryMatrix.h"
#include "BinaryTree.h"
#include "Bipartite.h"
#include "BIT.h"
#include "DynamicMod.h"
#include "Factorization.h"
#include "FFT.h"
#include "FlowSolver.h"
#include "Graph.h"
#include "LazySegmentTree.h"
#include "Math.h"
#include "Matrix.h"
#include "MinCostFlowSolver.h"
#include "MinMax.h"
#include "Numbers.h"
#include "Polynomial.h"
#include "Position.h"
#include "Range.h"
#include "Rational.h"
#include "SegmentTree.h"
#include "SegmentTree2D.h"
#include "SuffixArray.h"
#include "Tree.h"
#include "UnionFind.h"
#endif

#ifdef __GNUC__
typedef __int128 LLL;
istream& operator>> (istream& ist, __int128& val) { LL tmp; ist >> tmp; val = tmp; return ist; }
ostream& operator<< (ostream& ost, __int128 val) { LL tmp = val; ost << tmp; return ost; }
#endif

int n;
LL a[200000];
int main() {
	cin >> n;
	LL sum = 0;
	REP(i, 0, n) {
		cin >> a[i];
		sum += a[i];
	}

	LL mn = INFLL;
	LL k = 0;
	REP(i, 0, n) {
		k += a[i];
		mn = min(mn, abs(k - (sum - k)));
	}
	cout << mn << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int a, p;

    cin >> a >> p;

    int re = a * 3 + p;

    cout << re / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

int main() {
  int five(0), seven(0), temp, t(3);
  while (t--) {
    
  	scanf("%d", &temp);
    if (temp != 5 && temp != 7) {
      std::cout << "NO\n";
      break;
    } else {
      temp == 5 ? five ^= 5 : seven ^= 7;
    }
  }
  std::cout << (!five && seven ? "YES\n" : "NO\n");
  
  return 0;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var h = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            if (h == 0 && w == 0) break;
            var map = new char[h, w];
            for (int i = 0; i < h; i++)
            {
                var s = Console.ReadLine().Trim();
                for (int j = 0; j < w; j++) map[i, j] = s[j];
            }
            gowithTile(map);
        }
    }
    public static void gowithTile(char[,] map)
    {
        var h = map.GetLength(0); var w = map.GetLength(1);
        var map2 = new int[h, w];
        var x = 0; var y = 0; var loop = false;
        while (true)
        {
            if (map2[x, y] == 1) { loop = true; break; }
            map2[x, y] = 1;
            if (map[x, y] == '^') x--;
            else if (map[x, y] == '>') y++;
            else if (map[x, y] == 'v') x++;
            else if (map[x, y] == '<') y--;
            else break;
        }
        if (loop) Console.WriteLine("LOOP");
        else Console.WriteLine("{0} {1}", y, x);
    }
}

Measured memory_bytes: 9280
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;

int head[N], to[M], nxt[M], ne, n;

void init(){
    ne = 0;
    memset(head, -1, n * sizeof head[0]);
}

void addEdge(int f, int t){
    to[ne] = t;
    nxt[ne] = head[f];
    head[f] = ne++;
}

void addBiEdge(int a, int b){
    addEdge(a, b);
    addEdge(b, a);
}

int a[N];
vector<int> v;
int idx[N], val[N];

void go(int i){
    int mkan = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
    if(mkan == (int)v.size()){
        v.emplace_back(a[i]);
        idx[i] = -1;
        return;
    }
    idx[i] = mkan;
    val[i] = v[mkan];
    v[mkan] = a[i];
}

void undo(int i){
    if(idx[i] == -1){
        v.pop_back();
        return;
    }
    v[idx[i]] = val[i];
}

int ans[N];

void dfs(int u = 0, int par = -1){
    go(u);
    ans[u] = (int)v.size();

    for(int e = head[u] ; ~e ; e = nxt[e]){
        int v = to[e];
        if(v == par)continue;
        dfs(v, u);
    }

    undo(u);
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    scanf("%d", &n);
    init();

    for(int i = 0 ; i < n ; ++i)
        scanf("%d", a + i);

    for(int i = 1 ; i < n ; ++i){
        int u, v;
        scanf("%d %d", &u, &v);
        addBiEdge(--u, --v);
    }

    dfs();

    for(int i = 0 ; i < n ; ++i)
        printf("%d\n", ans[i]);
}

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


void solve(long long K){
    long long s = 7;
    for (int i = 1; i <= 1e6; i++) {
        if (s % K == 0) {
            cout << i << endl;
            return;
        }
        s = (s * 10 + 7) % K;
    }
    cout << -1 << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <math.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(int i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(int i=(s), i##_len=(n); i<i##_len; ++i)


using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<int, int> a, pair<int, int> b) {
    return a.second > b.second;
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N;
    cin >> N;
    vector<ll> H(N);
    ll ans = 0;
    ll mv = 0;
    cin >> H[0];
    REP(i, N-1) {
        cin >> H[i+1];
        if (H[i]>=H[i+1]) ans = max(ans, ++mv);
        else mv = 0;
    }
    cout << ans << endl;
}


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

int main() {
	int N;
	cin >> N;

	vector<string> s( N );
	for( int i = 0; i < N; ++i ) {
		cin >> s.at( i );
	}

	int M;
	cin >> M;

	vector<string> t( M );
	for( int i = 0; i < M; ++i ) {
		cin >> t.at( i );
	}

	int x = 0;

	for( int i = 0; i < N; ++i ) {
		int tx = 1;

		for( int j = 0; j < N; ++j ) {
			if( i == j ) { continue; }

			if( s.at( i ) == s.at( j ) ) {
				tx++;
			}
		}

		for( int j = 0; j < M; ++j ) {
			if( s.at( i ) == t.at( j ) ) {
				tx--;
			}
		}

		x = max( x, tx );
	}

	cout << x << endl;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		String S = stdin.next();
		long sum=0;
		
		
		for(int bit=0;bit<(1<<S.length()-1);bit++) {
			int plus=0;
			for(int i=0;i<S.length();i++) {
				if((1&(bit>>i)) == 1) {
					sum+=Long.parseLong((S.substring(plus, i+1)));
					plus = i+1;
				}	
			}
			if(plus != S.length()) {
				sum += Long.parseLong(S.substring(plus));
			}
		}
		out.println(sum);

		out.flush();
	}

	
}

Measured memory_bytes: 21972
#include <iostream>
#include<vector>
using namespace std;
void solve()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    int ct_w = 0 ,ct_r = 0;
    for(auto it : str)
    {
        if(it=='W')ct_w++;
        else ct_r++;
    }
    int swap_count = 0;
    for(int i=0,j=n-1;i<n and j>=0 and i<j;++i,--j)
    {
        while(str[i]!='W' and i<n)++i;
        while(str[j]!='R' and j>=0)--j;
        if(i<j)swap_count++;
        else break;
    }
    cout<<min(min(ct_r,ct_w) , swap_count);
}
int main()
{
    int t=1;
    while(t--)
    {
        solve();
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3656