akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 200


int g[N][N],d[N];
int color[N],k[N],Q[N];
int time,num;
int head=0,tail=0;


int de(int Q[]){
  head++;
  return Q[head-1];
}
void en(int Q[],int s){
  Q[tail]=s;
  tail++;
}


void B_F_S(int s){
  int i,u;

  for(i = 1;i <= num; i++){
    color[i] = 0;
    d[i] = -1;
  }
  color[s]=1;
  d[s]=0;
  en(Q,s);

  while(head!=tail){
    u=de(Q);
    for(i=1;i<=num;i++){
      if(g[u][i]==1){
        if(color[i]==0){
          color[i]=1;
          d[i]=d[u]+1;
          en(Q,i);
        }
      }
    }
    color[u]=2;
  }
}

int main(){
  int i,j,l;
  int u,v;

  scanf("%d",&num);

  for(i = 0;i < num; i++){
    scanf("%d",&u);
    scanf("%d",&l);
    for(j = 0;j < l;j++){
      scanf("%d",&v);
      g[u][v] = 1;
    }
  }


  B_F_S(1);
  for(i = 1; i <=num;i++){
    printf("%d %d\n", i,d[i]);
  }
  return 0;
}

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

int main(int argc, char const *argv[])
{
    int s; cin >> s;
    long long int dp[2010];
    int sum = 0;
    dp[0] = 0; dp[1] = 0; dp[2] = 0; dp[3] = 1;
    for (int i = 4; i < s+1; i++)
    {
        dp[i] = dp[i-1] + dp[i-3];
        dp[i] %= 1000000007;
    }
    cout << dp[s] << endl;
    return 0;
}


Measured memory_bytes: 3608
for i in range(int(input())):
    x = input()
    y = input()
    a=[0]
    for i in x:
        for j in range(len(a) - 1, -1, -1):
            b = y.find(i, a[j]) + 1
            if b:
                if j + 1 < len(a):
                    a[j + 1] = min(a[j + 1], b)
                else:
                    a.append(b)
    print(len(a)-1)



Measured memory_bytes: 5616
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

    if (a % b == 0)
        return b;
    else
        return gcd(b, a % b);
}

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

int d(long long int N)
{
    int count = 0;

    while (N > 0)
    {
        N /= 10;
        count++;
    }

    return count;
}

int main()
{
    int K;
    char S[1000];

    scanf("%d%s", &K, S);

    if (strlen(S) <= K)
        printf("%s", S);
    else
    {
        for (int i = 0; i < K; i++)
            printf("%c", S[i]);
        printf("...");
    }
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
int main()
{
	int n;
	cin>>n;
	vector<lld>arr;
	for(int i=0;i<n;i++)
	{
		lld a;
		cin>>a;
		arr.push_back(a);
	}
	lld ans=arr[0];
	for(int i=1;i<n;i++)
	{
		ans=(ans/__gcd(ans,arr[i]))*arr[i];
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

// #define amari(x) ((x) % 1000000007)
#define amari(x) ((x) % 998244353)

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(long i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};


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

  int a, b, t;
  cin >> a >>  b >> t;

  int x =a ;
  int cnt = 0;
  while(x < t+0.5) {
    x+=a;
    cnt+=b;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 888
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	int a,b,c;
	int d[3];
	int A,B,C;
	A=B=C=0;
	while(cin>>a>>b>>c){
		d[0]=a;
		d[1]=b;
		d[2]=c;
		sort(d,d+3);
		if(d[0]+d[1]<=d[2]){
			cout <<A+B+C<<" "<<A<<" "<<B<<" "<<C<<endl;
			return 0;
		}
		int D =(d[0]*d[0]+d[1]*d[1]);
		int E =(d[2]*d[2]);
		if(D==E){
			A++;
		}else if(D >E){
			B++;
		}else if(D <E){
			C++;
		}
	}
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int R, C, K;
    cin >> R >> C >> K;
    vector<int> x(K), y(K), v(K);
    vector<vector<P>> table(R);
    for(int i = 0; i < R; ++i)  table[i].emplace_back(0, -1);
    for(int i = 0; i < K; ++i){
        cin >> x[i] >> y[i] >> v[i];
        --x[i], --y[i];
        table[x[i]].emplace_back(y[i], v[i]);
    }
    for(int i = 0; i < R; ++i){
        sort(table[i].begin(), table[i].end());
        table[i].emplace_back(C, -1);
    }
    
    vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(C + 1, vector<ll>(5, 0)));
    for(int i = 0; i < R; ++i){
        for(int j = 0; j < C; ++j){
            dp[1][j][0] = max({dp[0][j][0], dp[0][j][1], dp[0][j][2], dp[0][j][3]});
            for(int k = 1; k < 4; ++k){
                dp[1][j][k] = 0;
            }
        }
        for(int j = 0; j + 1 < (int)table[i].size(); ++j){
            int lb = table[i][j].first, ub = table[i][j + 1].first;
            int cost = table[i][j].second;
            if(cost > 0){
                for(int k = 2; k >= 0; --k){
                    chmax(dp[1][lb][k + 1], dp[1][lb][k] + cost);
                }
            }
            for(int k = lb; k < ub; ++k){
                for(int l = 0; l < 4; ++l){
                    chmax(dp[1][k + 1][l], dp[1][k][l]);
                }
            }
        }
        swap(dp[0], dp[1]);
    }

    ll ans = 0;
    for(int i = 0; i < C; ++i){
        for(int j = 0; j < 4; ++j){
            chmax(ans, dp[0][i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8896
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
using ll = long long;
using namespace std;
int gcd(int x,int y){
    if(y==0)return x;
    return gcd(y,x%y);
}
int main(){
    int n,k;
    cin >>n >> k;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin >> vec[i];
    }
    int Gcd=vec[0];
    for(int i=1;i<n;i++){
        Gcd=gcd(Gcd,vec[i]);
    }
  //  cout<<Gcd<<endl;
    sort(vec.begin(),vec.end(),greater<int>());
    if(k%Gcd==0&&vec[0]>=k){
        cout<<"POSSIBLE"<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            Console.WriteLine("2018" + S.Substring(4, 6));
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define ROF(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

const int N = 3003;
LL dp[N][N][4];
LL table[N][N];
void solve(){
    int r,c,K;
    scanf("%d %d %d",&r,&c,&K);
    FOR(i, 1, K){
        int a, b, c;
        scanf("%d %d %d",&a,&b,&c);
        table[a][b] = c;
    }
    FOR(i, 1, r){
        FOR(j, 1, c){
            FOR(k, 0, 3){
                LL v = dp[i][j-1][k];
                if(k == 0) FOR(l, 0, 3) v = max(v, dp[i-1][j][l]);
                if(k == 1) FOR(l, 0, 3) v = max(v, dp[i-1][j][l]+table[i][j]);
                if(k > 0) v = max(v, dp[i][j-1][k-1]+table[i][j]);
                dp[i][j][k] = max(dp[i][j][k], v);
            }
        }
    }
    LL ans = 0;
    FOR(i, 0, 3) ans = max(ans, dp[r][c][i]);
    printf("%lld",ans);
}

int main(){
    solve();
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

Measured memory_bytes: 355340
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  long long n,sum=0, mod=2019;
  cin>>n;
  vector<bool> vec(n+1,0);
  vector<int> ans;
  int a[n+1];
  for(int i=1; i<=n; i++){
    cin>>a[i];
  }
  for(int i=n; i>=1; i--){
    int j=i;
    sum=0;
    while(j+i<=n){
      j+=i;
      sum+=vec[j];
    }
    if(sum%2!=a[i]){
      vec[i]=1;
      ans.push_back(i);
    }
  }
  
  cout<<ans.size()<<endl;
  
  for(int i=ans.size()-1; i>=0 ;i--)
    cout<<ans[i]<<endl;
  
  
}

Measured memory_bytes: 2428
/*ex6_2
series2*/

#include <stdio.h>
#include <string.h>
#define STRINGLENGTH 101
int main(void){
    //各文字の箱を作って読み取り
    char inputs[STRINGLENGTH];
    scanf("%s",inputs);
    printf("%c",inputs[0]);//最初の文字の出力
    printf("%d",strlen(inputs)-2);//前後及び最後をなくした長さ
    printf("%c",inputs[strlen(inputs)-1]);//最後の文字の出力
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
int dx[4]={0,0,-1,1},dy[4]={1,-1,0,0};


int main(int argc, char const *argv[]) {
  int n,even=0,odd=0;
  ll a[200010];
  std::cin >> n;
  for(int i=0; i<n; i++){
    std::cin >> a[i];
    if(a[i]%2) odd++;
    else even++;
  }
  if(odd%2==0)std::cout << "YES" << '\n';
  else std::cout << "NO" << '\n';

  return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    int ans = max({a+b, a-b, a*b});
    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n;
  cin>>n;
  vll a(n);
  REP(i,n)cin>>a[i];
  ll q;
  cin>>q;
  vll b(q),c(q);
  REP(i,q)cin>>b[i]>>c[i];

  map<ll,ll> m;
  ll sum=0;
  REP(i,n){
    m[a[i]]+=1;
    sum+=a[i];
  }

  REP(i,q){
    ll num=m[b[i]];
    m[b[i]]-=num;
    m[c[i]]+=num;
    sum+=(c[i]-b[i])*num;
    cout<<sum<<endl;
  }

}



Measured memory_bytes: 11552
N, M = map(int, input().split())
X = list(map(int, input().split()))
X.sort()
Y = [0] * (M-1)
for i in range(1, M):
    Y[i-1] = X[i] - X[i-1]
Y.sort()
if N>=M:
    print(0)
    exit()
s = 0
for i in range(M-N):
    s += Y[i]
print(s)

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

int main(){
  int N;
  string S;
  cin >>N>>S;
	
  int ans=0;
  for(int i=1;i<N;i++){
    int k = 0;
    
    for(char c='a';c<='z';c++){
      bool left=false;
      bool right=false;
      
      for(int j=0;j<i;j++) if(S[j]==c) left=true;
      for(int j=i;j<N;j++) if(S[j]==c) right=true;
			
      if(left and right) k++;
    }
    
    if(ans<k) ans = k;
  }
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define rep(i,l,r) for(rint i=l;i<=r;i++)
#define per(i,l,r) for(rint i=l;i>=r;i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back 
#define fir first
#define sec second
template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
int read(){
  int x=0,f=0;
  char ch=getchar();
  while(!isdigit(ch))f|=ch=='-',ch=getchar();
  while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  return f?-x:x;
}
const int N=1005;
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};
char grid[N][N];
int step[N][N];
int n,m,sx,sy,ex,ey;
queue<pii>q;

int main(){
	scanf("%d%d",&n,&m);
	scanf("%d%d",&sx,&sy);
	scanf("%d%d",&ex,&ey);
	for(int i=1;i<=n;i++){
		scanf("%s",grid[i]+1);
	}
	memset(step,0x3f,sizeof(step));
	step[sx][sy]=0;
	q.push({sx,sy});
	while(true){
		vector<pii>used;
		while(!q.empty()){
			pii u=q.front();q.pop();
			used.pb(u);
			for(int d=0;d<4;d++){
				int fx=u.fir+dx[d],fy=u.sec+dy[d];
				if(fx>=1&&fx<=n&&fy>=1&&fy<=m&&grid[fx][fy]=='.'&&step[fx][fy]>step[u.fir][u.sec]){
					step[fx][fy]=step[u.fir][u.sec];
					q.push({fx,fy});
				}
			}
		}
		if(!used.size())break;
		for(auto _:used){
			int x=_.fir,y=_.sec;
			for(int fx=x-2;fx<=x+2;fx++)if(1<=fx&&fx<=n){
				for(int fy=y-2;fy<=y+2;fy++)if(1<=fy&&fy<=m){
					if(grid[fx][fy]=='.'&&step[fx][fy]>step[x][y]+1){
						step[fx][fy]=step[x][y]+1;
						q.push({fx,fy});
					}
				}
			}
		}
	}
	if(step[ex][ey]==step[0][0])puts("-1");
	else printf("%d\n",step[ex][ey]);
	return 0; 
}

Measured memory_bytes: 8736
N=str(input())
K=int(input())
length=len(N)
dp=[[0]*10 for _ in range(length+1)]
dp[0][0]=1
def index(flag_less,k):
  if flag_less==0 and k==0:
    return 0
  elif flag_less==1 and k==0:
    return 1
  elif flag_less==0 and k==1:
    return 2
  elif flag_less==1 and k==1:
    return 3
  elif flag_less==0 and k==2:
    return 4
  elif flag_less==1 and k==2:
    return 5
  elif flag_less==0 and k==3:
    return 6
  elif flag_less==1 and k==3:
    return 7
  elif flag_less==0 and k==4:
    return 8
  else:
    return 9
  
for i in range(length):
  max_digit=int(N[i])
  for state in range(10):
    range_digit=9 if state%2 else max_digit
    for d in range(range_digit+1):          # 注意
      flag_less_next=0
      if state%2==1 or d<max_digit:
        flag_less_next=1
      prev_k=state//2
      if d!=0:
        next_k=min(4,prev_k+1)      
      else:
        next_k=prev_k
      next_state=index(flag_less_next,next_k)  # flag_less_next+2*next_kでもいい
      dp[i+1][next_state]+=dp[i][state]

print(dp[length][2*K]+dp[length][2*K+1])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef pair<ll, ll> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    int n; cin >> n;
    ll m = INF;
    ll sum = 0;
    ll a[n];
    rep(i,n){
        cin >> a[i];
        sum += abs(a[i]);
        m = min(m,abs(a[i]));
    }
    ll cnt = 0;
    rep(i,n) if(a[i] < 0) cnt++;
    if(cnt % 2 == 0){
        cout << sum << endl;
    }else{
        cout << sum - 2 * m << endl;
    }
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  int N;
  scanf("%d",&N);

  char S[N];
  scanf("%s",S);

  int K;
  scanf("%d",&K);

  int chr = S[K-1];

  for(int i = 0;i < N;i++){
    if(S[i] == chr) printf("%c",chr);
    else printf("*");
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 128
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = input().strip()
    res = 0
    for n in N:
        res += int(n)
        res %= 9
    print("Yes" if res == 0 else "No")


if __name__ == "__main__":
    main()



Measured memory_bytes: 69156
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007



              
int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
      
    int t;
    t=1;
     //  cin>>t;
    while(t--){
        	string s;
        	getline(cin,s);
        	int n=s.length();
        	REP(i,0,n-1){
        		if(s.at(i)=='?'){
        			
        				s.at(i)='D';

        		}
        	}
        	cout<<s;
       


             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}


Measured memory_bytes: 3920
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	W := readInt()
	w := make([]int, n+1)
	v := make([]int, n+1)
	for i := 1; i <= n; i++ {
		w[i] = readInt()
		v[i] = readInt()
	}

	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, 100050)
		for j := range dp[i] {
			dp[i][j] = -1
		}
	}

	dp[0][0] = 0
	for i := 1; i <= n; i++ {
		for j := 0; j < 100050; j++ {
			dp[i][j] = dp[i-1][j]
			k := j - v[i]
			if k < 0 || dp[i-1][k] == -1 {
				continue
			}
			if dp[i][j] == -1 {
				dp[i][j] = dp[i-1][k] + w[i]
				continue
			}
			dp[i][j] = min(dp[i][j], dp[i-1][k]+w[i])
		}
	}
	for i := len(dp[n]) - 1; 0 <= i; i-- {
		if dp[n][i] == -1 {
			continue
		}
		if W < dp[n][i] {
			continue
		}
		println(i)
		break
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 82432
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int Vmax, Vmin;
  Vmax = 0;
  Vmin = 1000000;
  rep(i, N) {
    cin >> vec.at(i);
    Vmax = max(Vmax, vec.at(i));
    Vmin = min(Vmin, vec.at(i));
  }
  cout << Vmax - Vmin << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int N, S;
vector<int> A;
ll modpow(ll n, int k) {
	ll r = 1;
	while (k > 0) {
		if (k&1) (r *= n) %= mod;
		(n *= n) %= mod;
		k >>= 1;
	}
	return r;
}
int main() {
	cin >> N >> S;
	A.resize(N);
	for (auto& x : A) cin >> x;
	vector<ll> dp(S+1);
	dp[0] = modpow(2, N);
	ll inv2 = modpow(2, mod-2);
	for (auto x : A) {
		for (int i = S; i-x >= 0; -- i) {
			(dp[i] += dp[i-x] * inv2) %= mod;
		}
	}
	cout << dp[S] << endl;
}


Measured memory_bytes: 3668
while True:
    m,f,r = map(int,input().split())
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        print("F")
    elif m + f >= 80:
        print("A")
    elif 65 <= m + f and m + f < 80:
        print("B")
    elif 50 <= m + f and m + f <65:
        print("C")
    elif 30 <= m + f and m + f <50 and r >= 50:
        print("C")
    elif 30 <= m + f and m + f <50:
        print("D")
    else:
        print("F")


Measured memory_bytes: 5592
import sys

sys.setrecursionlimit(2000000)

N,M=map(int,input().split())

parent=[[] for _ in range(N)]
child=[[] for _ in range(N)]

for i in range(N-1+M):
  A,B=map(int,input().split())
  child[A-1].append(B-1)
  parent[B-1].append(A-1)
  
for i in range(N):
  if len(parent[i])==0:
    root=i
    break
#print(root)

kazu=[0]*N
for i in range(N):
  kazu[i]=len(parent[i])

answer=[0]*N

def dfs(index):
  search=[]
  for d in child[index]:
    kazu[d]-=1
    if kazu[d]==0:
      search.append(d)
      answer[d]=index+1
  for s in search:
    dfs(s)
    
 
dfs(root)

for i in range(N):
  print(answer[i])

Measured memory_bytes: 137060
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pii;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int 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;

        // merge by size
        // force size of x to be bigger than that of y
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;

        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, K, L;
    cin >> N >> K >> L;

    UnionFind uf0(N+1), uf1(N+1);

    REP(i, K) {
        int p, q;
        cin >> p >> q;
        uf0.merge(p, q);
    }

    REP(i, L) {
        int r, s;
        cin >> r >> s;
        uf1.merge(r, s);
    }

    map<Pll, int> m;
    FOR(i, 1, N+1) {
        m[{uf0.root(i), uf1.root(i)}] += 1;
    }

    FOR(i, 1, N+1) {
        if (i > 1) cout << " ";
        Pii p = {uf0.root(i), uf1.root(i)};
        cout << max(m[p], 1);
    }

    cout << endl;


    
}


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

signed main()
{   
    int N; cin>>N;
    vector<int> a(N);
    int X=0;
    for(int i=0;i<N;i++){
        int t; cin>>t;
        X^=t;
        a[i]=t&-t;
    }
    sort(a.rbegin(),a.rend());
    //a.erase(unique(a.begin(),a.end()),a.end());

    int ans=0;
    for(int b:a){
        if(X&b){
            X^=(b<<1)-1;
            ans++;
        }
    }
    cout<<(X==0? ans:-1)<<endl;
}


Measured memory_bytes: 1024
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a <= b:
    if a + v * t >= b + w * t:
        print("YES")
    else:
        print("NO")
        
else:
    if a > b:
        if a - v * t <= b - w * t:
            print("YES")
        else:
            print("NO")

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

int main() {
  int n,m,x;
  cin>>n>>m>>x;
  vector<vector<int>> a(n,vector<int>(m+1));
  for(int i=0;i<n;i++){
	for(int j=0;j<m+1;j++){
      cin>>a[i][j];
    }
  }
  int ans=1e7;
  for(int i=0;i<(1<<n);i++){
    vector<int> b(m+1,0);
    for(int j=0;j<12;j++){
      if(i>>j&1){
        for(int k=0;k<m+1;k++){
          b[k]+=a[j][k];
        }
      }
      bool flag=true;
      for(int k=1;k<m+1;k++){
        if(b[k]<x) flag=false;
      }
      if(flag) ans=min(ans,b[0]);
    }
  }
  if(ans==1e7) {cout<<-1<<endl; return 0;}
  cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<queue>
#include<vector>
#include<set>

using namespace std;
using ll = long long;

const int INF = 1001001001;
const int MOD = 1000000007;



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

	int r = 0;
	int g = 0;
	int b = 0;

	for (int i = 0;i < n;i++){
		if (s[i] == 'R'){
			++r;
		}else if (s[i] == 'G'){
			++g;
		}else{
			++b;
		}
	}

	ll R = r;ll G = g;ll B = b;
	const ll total = R * G * B;
	ll total_wrong = 0;
	for (int i = 0;i < n - 2;i++){
		for (int j = 1;i+2*j < n;j++){
			bool is_false = s[i] == s[i+j] || s[i] == s[i+2*j] || s[i+j] == s[i+2*j];
			if (!is_false){
				total_wrong++;
			}
		}
	}
	const ll ans = total - total_wrong;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3608
def solve():
    H, W = map(int, input().split())
    S = [list(input()) for i in range(H)]
    c = 0
    lis = [[0]*W for i in range(H)]
    for i in range(H):
        for j in range(W):
            c = 0

            if S[i][j] == '#':
                lis[i][j] = '#'
                continue
            else:
                for k in range(-1, 2):
                    for l in range(-1, 2):
                        if k == 0 and l == 0:
                            pass
                        elif judge(i + k, j + l, W, H, S) == True:
                            c += 1
                if c == 0:
                    lis[i][j]= '0'
                else:
                    lis[i][j] = str(c)


    for i in range(H):
        print(''.join(map(str, lis[i])))

# 位置が正しいかを判定
def judge(x, y, W, H, S):
    if (x < 0 or x > H - 1 or y < 0 or y >W - 1) == True:
        return False
    else:
        if S[x][y] == '#':
            return True
        else:
            return False

def main():
    solve()


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define in insert
#define ff first
#define ss second
#define mp make_pair
#define int long long
#define uint unsigned long long
#define rep(i,x,m) for(int i=x;i<m;i++)
#define repr(i,x,m) for(int i=x;i>=m;i--)
#define MOD 1000000007
#define endl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define vi vector<int>
#define vs vector<string>
#define print(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
using namespace std;
#define noob ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void ram5564()
{
    int n,k;
    cin>>n>>k;
  
    long double sum[n+2];
    sum[0]=0.0;
    int a[n+2];
    for(int i=1;i<=n;++i)
    {
        int x;
        cin>>x;
        sum[i]=((x+1)/2.0);
         //cout<<fixed<<setprecision(6)<<sum[i]<<" ";
    }
    sum[0]=0.0;
    for(int i=2;i<=n;++i)
    {
        sum[i]=sum[i]+sum[i-1];
    }
    double mx=-1;
    // for(auto x:sum)
    // {
    //     cout<<fixed<<setprecision(6)<<x<<" ";
    // }
    for(int i=k;i<=n;++i)
    {
       if((sum[i]-sum[i-k])>mx)
        mx=(sum[i]-sum[i-k]);
    }
   cout<<fixed<<setprecision(10)<<mx;




    
}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
       // cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 3456
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    A = list(map(int, input().split()))
    leaf = sum(A)
    M = [0]*(N+1)
    if N==0:
        if A[0]==1:
            print(1)
            exit()
        else:
            print(-1)
            exit()
    if A[0]==1:
        print(-1)
        exit()
    M[0] = 1
    for i in range(1,N+1):
        M[i] = 2*M[i-1] - A[i]
        leaf -= A[i]
        M[i] = min(M[i],leaf)
        if M[i] < 0:
            print(-1)
            exit()
    print(sum(M)+sum(A))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 19992
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    temp = 0
    Am = list(map(int, input().split()))
    for idx,t in enumerate(Am):
        temp += t*B[idx]
    temp += C
    if temp > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int N, K, a[100005];

int main(){
    scanf("%d %d", &N, &K);
    for(int i = 0; i < N; i++)  scanf("%d", a + i);
    int ans = ceil(1.0 * (N - 1) / (K - 1));
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

long long int sum(long long int h,long long int i,long long int ans){
  if(h>1){
    ans+=pow(2,i);
    i++;
    sum(h/2,i,ans);
  }
  else return ans+=pow(2,i);
}   

int main(){
  long long int h;
  long long int i=0;
  long long int ans;
  scanf("%lld",&h);
  ans = sum(h,i,ans);
  printf("%lld",ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   double v[N];
   for (int i = 0; i < N; i++) cin >> v[i];
   sort(v, v + N);

   double ans = (v[0] + v[1]) / 2.;
   for (int i = 2; i < N; i++) {
      ans = (ans + v[i]) / 2.;
   }
   cout << fixed << setprecision(6) << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll x;
    cin >> x;

    ll time = 0;
    ll sum = 0;
    while(sum < x)sum+= time++;

    cout << time-1;
}

Measured memory_bytes: 256
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
ab = []
for _ in range(n):
    abi = na()
    ab.append(abi)

ab.sort(key=lambda x:x[1])
t = 0
for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        print("No")
        quit()
print("Yes")


Measured memory_bytes: 53728
#include <cstdio>
using namespace std;

const int N = 100;
int k;
char s[N + 1];

int main() 
{
	scanf("%d%s", &k, &s);
	int i;
	for (i = 0; s[i] && i < k; ++i) printf("%c", s[i]);
	if (s[i]) printf("...");
	printf("\n");
	return 0;
}


Measured memory_bytes: 1704
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

void rev(char *s){
  int l=strlen(s),i;
  for(i = 0;i<l/2;i++){
  char t=s[i];
  s[i] = s[l - i -1];
  s[l-1-i]=t;
  }
}

int main(void){
    int i, j, k;
    char s[100001];
    char divide[4][8] = {"dream", "dreamer", "erase", "eraser"};
    int len;
  
    scanf("%s",s);
    len = strlen(s);
    
    for(i = 0; i < 4; i++) rev(divide[i]);
  
    rev(s);
    
    for(i = 0; i < len;){
        k = -1;
        for(j = 0; j < 4; j++){
            if(!strncmp(s+i, divide[j], strlen(divide[j]))){
                k = strlen(divide[j]);
                break;
            }
        }  
        if(k < 0){
            printf("NO");
            return 0;
        }
        i += k;
    }
    
    printf("YES");
    return 0;
}


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

using namespace std;

int main() {

  int A, B,C,D;

  cin>> A >> B >>C>>D ;

int left =A+B;
int right=C+D;
  
if (left>right) {

cout << "Left" << endl;

  }

  

  else if(left<right){

    // ここにプログラムを追記

    cout<<"Right"<<endl;
  }

  else if(left==right){
    cout<<"Balanced"<<endl;
    }

 

  }



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

using namespace std;

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

	if (A == B && A != C) {
		cout << "Yes" << endl;
	}
	else if (A == C && A != B) {
		cout << "Yes" << endl;
	}
	else if (B == C && A != B) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


}


Measured memory_bytes: 3620
#include <stdio.h>

int main(void){

  int x,a,b;
  scanf("%d %d %d", &x, &a, &b);
  int dis_a, dis_b;
  dis_a = x-a;
  if (dis_a < 0) {
    dis_a *= -1;
  }
  dis_b = x-b;
  if (dis_b < 0) {
    dis_b *= -1;
  }
  if (dis_a < dis_b) {
    printf("A\n");
  } else {
    printf("B\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

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

typedef pair<int, int> result;

result Areas(const string &s, int p = 0);
result OneArea(const string &s, int p = 0);

int majority(int n) {
  return n / 2 + 1;
}

int majority(vector<int> v) {
/*  cout << "majority called: ";
  REP(i, v.size()) {
    cout << v[i] << " ";
  }
  cout << endl;*/

  int sum = 0, least = majority(v.size());
  sort(v.begin(), v.end());
  for (int i = 0; i < least; i++) { sum += v[i]; }

  return sum;
}

result OneArea(const string &s, int p) {
/*  cout << "OneArea called: '" << s.substr(p) << "'" << endl;*/
  p++;
  if (isdigit(s[p])) {
    int people = 0;
    while (isdigit(s[p])){ people = people * 10 + (s[p++] - '0'); }
    p++;
/*    printf("OneArea returns: (%d, %s)\n", 
        majority(people), s.substr(p).c_str());*/
    return result(majority(people), p);
  } else {
    result r = Areas(s, p);
    r.second ++;
/*    printf("OneArea returns: (%d, %s)\n", 
        r.first, s.substr(r.second).c_str()); */
    return r;
  }
}

result Areas(const string &s, int p) {
/*  cout << "Areas called: '" << s.substr(p) << "'" << endl; */

  vector<int> areas;
  while(s[p] == '[') {
    result r = OneArea(s, p);
    areas.push_back(r.first);
    p = r.second;
  }
/*  printf("Areas returns: (%d, %s)\n",
      majority(areas), s.substr(p).c_str()); */
  return result(majority(areas), p);
}


int main() {
  int n;
  cin >> n;
  REP(i, n) {
    string s;
    cin >> s;
    result r = OneArea(s);
    cout << r.first << endl;
  }
}

Measured memory_bytes: 1296
import numpy as np
N = int(raw_input())

def length(x):
    return int(np.floor(np.log10(x))) + 1

def F(A, B):
    return max(length(A), length(B))

def EstimateRoot(y):
    return int(np.floor(np.sqrt(y)))
    
minF = 11
candidates = []
for i in xrange(EstimateRoot(N)):
    if N % (i + 1) == 0:
        candidates.append((i + 1, N/(i + 1)))
for c in candidates:
    f = F(c[0], c[1])
    if f < minF:
        minF = f
print minF


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

int main(){
	string S; cin >> S;
	string T; cin >> T;

	if (S == T){
		cout << "Yes" << endl;
		return 0;
	}
	for (int i=0; i < (int)S.size()-1; i++){
		S = S[S.size() - 1] + S;
		S.pop_back();
		if (S == T){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline

d, g = map(int, input().split())
pc = []
ans = []
bit = list(itertools.product([0, 1], repeat=d))
cnt_v = 0
cnt = 0

for i in range(d):
    p, c = map(int, input().split())
    pc.append([p, c])

for i in range(2 ** d):
    for j in range(d):
        if bit[i][j] == 1:
            p = pc[j][0]
            c = pc[j][1]
            p_index = j + 1
            cnt_v += p * 100 * p_index + c
            cnt += p

    if cnt_v >= g:
        ans.append(cnt)

    else:
        for j in range(d):
            cnt_check = cnt_v
            if bit[i][j] == 0:
                p = pc[j][0]
                p_index = j + 1

                for k in range(p):
                    if cnt_check >= g:
                        cnt += k
                        ans.append(cnt)
                        cnt -= k
                        break

                    cnt_check += 100 * p_index
    cnt = 0
    cnt_v = 0

print(min(ans))


Measured memory_bytes: 3188
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m, q;
	cin >> n >> m >> q;
	vvi v(n, vi(n + 1, 0));
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		v[a][b]++;
	}
	REP(i, n)REP(j, n)v[i][j + 1] += v[i][j];
	REP(i, q) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		int ans = 0;
		FOR(j, a, b + 1) {
			ans += v[j][b];
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 1920
#include<stdio.h>

int temp[200005];
long long count = 0 ;

void mergeSort(int *arr, int left, int right){
	if(left == right) return;
	if(left >= right) return;
	int mid = (left+right)/2;
	
	mergeSort(arr, left, mid);
	mergeSort(arr, mid+1, right);
	
	int x = left;	
	int n = mid;
	
	int y = mid+1;
	int m = right;
	
	int i = left;
	while(x <=n && y <= m){
		if(arr[x] <= arr[y]){
			temp[i++] = arr[x++];
		}
		else{
			count += (n+1)-x;
//			printf("-->%d %d %d<--\n", n, x ,count);
			temp[i++] = arr[y++];
		}
	}
	
	while(x <= n){
		temp[i++] = arr[x++];
	}
	while(y <= m){
		temp[i++] = arr[y++];
	}
	
	for(int j = left; j<=right; j++){
		arr[j] = temp[j];
	}
}

int main(){
	int n;
	int arr[200005];
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d", &arr[i]);
	}
	
	mergeSort(arr, 0, n-1);
	printf("%lld\n", count);
	
	return 0;
}



Measured memory_bytes: 4168
n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for _ in range(n)]
inf=float('inf')
ans=-inf
def func(multi):
  dp=[-inf]*(m+1)
  dp[0]=0
  for i in range(n):
    x,y,z=xyz[i]
    for j in range(min(i+1,m),0,-1):
      dp[j]=max(dp[j],dp[j-1]+x*multi[0]+y*multi[1]+z*multi[2])
  return dp[m]

for i in range(8):
  multi=[1]*3
  for j in range(3):
    if (i>>j)&1:
      multi[j]=-1
  ans=max(ans,func(multi))
print(ans)


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

#define  __  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define  int  long long
#define  endl  '\n'
const double pi = acos(-1);
const int mod = 1e9 + 7;
//______________________

std::vector<std::pair<int,std::pair<int,int>> > st;
int m;
void sweep(int n , int q )
{
     std::vector<int>ans(q,0);
     sort(st.begin(),st.end());
     
     int sum=0,nn=st.size();
 
     for(int i = 0 ; i < nn ; i++ )
     {
         int xx = st[i].first ;
         int type = st[i].second.first ;
         int id = st[i].second.second ;
         if(type == -1)
         {
            sum++;
         }
         else if(type == 1 )
         {
            sum--;
         }
         else 
         {
             ans[id]=sum;
         }
     }
     int tot=0;
     for(int i = 0 ; i < q ; i++ )
     {
       // printf("%d\n", ans[i]);
        if(ans[i]==m)
            tot++;
     }

     cout<<tot;
}


int32_t main()
{ 
  __
 
  
     int n ;

     scanf("%d %d",&n,&m);
     
     int x , y ;

     for(int i = 0 ; i < m ; i++ )
     {
         scanf("%d %d",&x,&y) ;
         st.push_back({x,{-1,i}}) ;
         st.push_back({y,{1,i}});
     }

     for(int i = 0 ; i < n;  i++ )
     {
        x=i+1;
        st.push_back({x,{0, i}});
     }

     sweep(n,n);

 

 return 0;
}

Measured memory_bytes: 8432
#include<iostream>
#include<vector>
#include<string>
using namespace std;

bool prime(int a) {
	if (a == 3)return true;
	for (int b = 3;; b+=2) {
		if (a%b == 0)return false;
		if ((b + 1)*(b + 1) > a)return true;
	}
}
int main() {
	while (1) {
		int s = 0;
		int a;
		cin >> a;
		if (a == 0)break;
		for (int b = 3; b < a / 2 + 1; b += 2) {
			if (prime(b) && prime(a - b))s++;
		}
		cout << s << endl;
	}
}

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

using namespace std;

int main(void){
  int N;
  cin>>N;
  vector<string> W(N);
  for (int i=0;i<N;i++){
    cin>>W[i];
  }

  bool ans=true;
  for (int i=0;i<N&&ans;i++){
    if (i==0) continue;
    if (W[i-1].back()!=W[i].front()) ans=false;

    for (int j=0;j<N;j++){
      if (i!=j&&W[i]==W[j]) ans=false;
    }
  }
  if (ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  int n, k;
  cin >> n >> k;

  int res = 1;

  rep(i, n) {
    res = min(res * 2, res + k);
  }
  cout << res << endl;

  return 0;
}

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

int main(){
    map<int,int> f;
    LL ok = 1;
    for(int z = 0; z < 2; z++){
        int n;
        cin >> n;
        for(int i = 0; i < n; i++){
            int a;
            cin >> a;
            if(z == 0){
                f[a]++;
            } else {
                f[a]--;
            }
            if(f[a] < 0) ok = 0;
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
}


Measured memory_bytes: 9600