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

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

using namespace std;

typedef long long ll;
const int MAX_N = 100100;
int a[MAX_N],sum[MAX_N],N,Q;

inline void _25(){
  long long cnt = 0, cost = 0;
  for(int i=N-1;i>=0;i--){
    if( a[i] % Q == 0 ) cost++;
    if( a[i] ) cnt += cost;
  }
  cout << cnt << endl;
}

inline void compute(){
  if( Q == 2 || Q == 5 ) {
    _25();
    return;
  }
  sum[N-1] = sum[N] = 0;
  int ten = 1;
  map<int,ll> mp;
  mp[0]++;
  for(int i=N-1;i>=0;i--){
    sum[i] = ( sum[i+1] + ( a[i] * ten ) % Q ) % Q;
    ( ten *= 10 ) %= Q;
    mp[sum[i]]++;
  }
  ll cnt = 0;

  rep(i,N){
    --mp[sum[i]];
    if( a[i] ) cnt += mp[sum[i]];
  }
  cout << cnt << endl;
}

int main(){

  int S,W;
  while( cin >> N >> S >> W >> Q, N|S|W|Q ){
    int g = S;    
    rep(i,N) { 
      a[i] = ( g / 7 ) % 10;
      if( g % 2 == 0 ) g = ( g / 2 );
      else             g = ( g / 2 ) ^ W;
    }
    //rep(i,N) cout << a[i]; cout << endl;
    compute();
  }
  return 0;
}

Measured memory_bytes: 7596
/*#include<stdio.h>
#include<string.h>
int dp[50][2001][3001];
int main(){
    memset(dp,0,sizeof(dp));
    for(int i=0;i<=2000;i++)dp[0][i][0]=1;
    for(int i=1;i<=2000;i++){
        for(int j=1;j<=49;j++){
            for(int k=0;k<=3000;k++){
                dp[j][i][k]+=dp[j][i-1][k];
                if(k-i>=0) dp[j][i][k]+=dp[j-1][i-1][k-i];
                dp[j][i][k]%=100000;
            }
        }
    }
    while(1){
        int n,m,s;
        scanf("%d %d %d",&n,&m,&s);
        if(n==0&&m==0&&s==0) return 0;
        printf("%d\n",dp[n*n][m][s]);
    }
}*/
#include<stdio.h>
#include<string.h>
int dp[50][3001];
int main(){
    memset(dp,0,sizeof(dp));
    while(1){
        int n,m,s;
        scanf("%d %d %d",&n,&m,&s);
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(int i=1;i<=m;i++){
        for(int j=49;j>=1;j--){
            for(int k=3000;k>=0;k--){
                if(k-i>=0) dp[j][k]+=dp[j-1][k-i];
                dp[j][k]%=100000;
            }
        }
        }
        if(n==0&&m==0&&s==0) return 0;
        printf("%d\n",dp[n*n][s]);
    }
}

Measured memory_bytes: 1620
#include<cstdio>
#include<queue>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
using namespace std;
int main(){
	int n,m,p,a,b;
	while(scanf("%d%d%d%d%d",&n,&m,&p,&a,&b),n){
		a--,b--;
		int t[n],d[m][m];
		rep(i,n)scanf("%d",t+i); rep(i,m)rep(j,m)d[i][j]=0;
		rep(i,p){
			int x,y,z; scanf("%d%d%d",&x,&y,&z);
			x--,y--;
			d[x][y]=d[y][x]=z;
		}
		double cost[1<<n][m],ans=INF; rep(i,1<<n)rep(j,m)cost[i][j]=INF;
		queue<pair<int,int> > F; cost[(1<<n)-1][a]=0;
		F.push(make_pair((1<<n)-1,a));
		while(!F.empty()){
			int cs=F.front().first,cn=F.front().second,ns; F.pop();
			rep(i,m)rep(j,n)if((cs&(1<<j))&&d[cn][i]){
				ns=cs^(1<<j);
				if(cost[ns][i]>cost[cs][cn]+d[cn][i]*1./t[j]){
					cost[ns][i]=cost[cs][cn]+d[cn][i]*1./t[j];
					if(i==b&&cost[ns][i]<ans)ans=cost[ns][i];
					F.push(make_pair(ns,i));
				}
			}
		}
		if(ans==INF)printf("Impossible\n");
		else printf("%.5f\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1020
M,D = map(int, input().split())


def seki(n):
    s = str(n)
    i1,i2 = int(s[0]), int(s[1])
    if i1>=2 and i2>=2:
        return i1*i2
    else:
        return -1

res = 0
for m in range(1,M+1):
    for d in range(11,D+1):
        if m==seki(d):
            res += 1
print(res)



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/
vector<vector<string>> v(27);

vector<pair<int, int>> vp;
int main(void)
{
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        int a, b;
        cin >> a >> b;
        vp.push_back({a, b});
    }
    sort(vp.begin(), vp.end());

    ll ans = vp[vp.size() - 1].first + vp[vp.size() - 1].second;
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	int n, m, k; scanf("%d %d %d", &n, &m, &k);
	vector<ll> una(n), panga(m);
	for (int i = 0; i < n; ++i) scanf("%lld", &una[i]);
	for (int i = 0; i < m; ++i) scanf("%lld", &panga[i]);
	vector<ll> psu(n + 1), psp(m + 1);
	for (int i = 0; i < n; ++i) psu[i+1] = psu[i] + una[i];
	for (int i = 0; i < m; ++i) psp[i+1] = psp[i] + panga[i];
	int ans = 0;
	for (int i = 0; i <= n; ++i) {
		if (psu[i] > k) continue;
		ans = max(ans, i + (int)distance(begin(psp), upper_bound(begin(psp), end(psp), k - psu[i])));
	}
	printf("%d\n", ans - 1);
	return 0;
}


Measured memory_bytes: 9600
mod = 1000000007
n = int(input())

if n == 1:
  print(0)
elif n == 2:
  print(2)
else:
  a = pow(10,n) % mod
  b = pow(9,n) % mod
  c = pow(9,n) % mod
  d = pow(8,n) % mod
  print((a-b-c+d)%mod)


Measured memory_bytes: 10668
while True:
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
    else:
        count=0
        for i in range(1,n-1):
            for j in range(i+1,n):
                for k in range(j+1,n+1):
                    if i+j+k==x:
                        count=count+1
    print(count)


Measured memory_bytes: 5592
n = int(input())
# a,b = map(int, input().split())
# A = list(map(int, input().split()))
# AA = list(map(int, input().split()) for i in range(n))

res=0

for i in range(n+1):  
    if max(n,2**i)<=n:
        res=2**i
print(res)

Measured memory_bytes: 2940
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <array>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void) {

	string s;
	std::cin >> s;
	int res = 100;

	for (char targ = 'a'; targ <= 'z'; targ++) {
		if (s.find(targ) == std::string::npos) continue;
		string temps(s);
		int count = 0;
		while (1) {
			bool clear = true;
			for (auto c : temps) {
				if (c != targ) {
					clear = false;
					break;
				}
			}
			if (clear) break;
			
			for (int i = 0; i < temps.size() - 1; i++) {
				if (temps[i] == targ) continue;
				if (temps[i + 1] == targ) {
					temps[i] = targ;
				}
			}
			count++;
			temps.resize(temps.size() - 1);
		}
		res = min(res, count);
	}
	std::cout << res << std::endl;

	return 0;
}

Measured memory_bytes: 256
/*
Author : Xinyuan
*/
#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 INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

template <class T>
void max_self(T &a, T b) {
    a = max(a, b);
}

bool first_row_or_column(pair<int, int> p) {
    return p.first == 0 || p.second == 0;
}
int main() {
    string a, b;
    cin >> a >> b;
    vector<vector<pair<int, PII>>> dp(a.length() + 1, vector<pair<int, PII>>(b.length() + 1, {-INF, {0, 0}}));
    // dp[i][j] = the max
    dp[0][0] = {0, {0, 0}};
    REP(i, a.length()) {
        REP(j, b.length()) {
            if (a[i] == b[j]) {
                max_self(dp[i + 1][j + 1], make_pair(dp[i][j].first + 1, make_pair(i, j)));
            }
            max_self(dp[i + 1][j], make_pair(dp[i][j].first, make_pair(i, j)));
            max_self(dp[i][j + 1], make_pair(dp[i][j].first, make_pair(i, j)));
        }
    }
    pair<int, PII> cur = {0, {0, 0}};
    REP(i, (int)a.length() + 1)
    REP(j, (int)b.length() + 1)
    max_self(cur, make_pair(dp[i][j].first, make_pair(i, j)));
    // int ans = 0;
    string ans = "";
    PII answer = cur.second;
    while (!first_row_or_column(answer)) {
        int i = answer.first, j = answer.second;
        PII previous = dp[i][j].second;  // a cell which we came to  (i, j)

        if (previous == make_pair(i - 1, j - 1)) {
            ans += a[i - 1];
        }
        answer = previous;
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 105984
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue

def main():
    # N = int(input())

    N, M = [int(s) for s in input().split()]
    print(N*M)

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 9156
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll n, k;
bool check(ll x, vector<ll> &a){
    ll res = 0;
    for(int i = 0; i < n; i++){
        if(a[i] >= 0){
            ll ok = -1;
            ll ng = (ll)a.size();
            while(abs(ok - ng) > 1){
                ll mid = (ok + ng) / 2;
                //cout << "cnc " << i << " " << mid  << " " << a[i] << " " << va[mid] << endl;
                //cout << "comp " << a[i] * va[mid] << endl;
                if(a[i] * a[mid] < x){
                    ok = mid; 
                } else {
                    ng = mid;
                }
            }
            res += ok + 1;
            //cout << i << " " << ok + 1 << endl;
            if(a[i] * a[i] < x) res--;
        } else {
            ll ng = -1;
            ll ok = (ll)a.size();
            while(abs(ok - ng) > 1){
                ll mid = (ok + ng) / 2;
                //cout << "cnc " << i << " " << mid  << " " << a[i] << " " << va[mid] << endl;
                //cout << "comp " << a[i] * va[mid] << endl;
                if(a[i] * a[mid] < x){
                    ok = mid; 
                } else {
                    ng = mid;
                }
            }
            res += a.size() - ok;
            //cout << i << " " << ok + 1 << endl;
            if(a[i] * a[i] < x) res--;
        }
    }
    res /= 2;
    //cout << res << endl;
    return res < k;
}

int main(void){

    cin >> n >> k;

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

    sort(a.begin(), a.end());

    ll ok = -INF;
    ll ng = INF;

    // cout << check(0, a) << endl;
    // return 0;

    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;

        //cout << mid << endl;

        if(check(mid, a)){
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok << endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, X: "List[int]"):
    X.sort()
    
    ans = INF
    for p in range(101):
        ans = min(ans, sum([abs(X[i]-p)**2 for i in range(N)]))

    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n,k=map(int,input().split())
inf=10**18
sushi=[[-inf] for _ in range(n)]
for i in range(n):
  t,d=map(int,input().split())
  sushi[t-1].append(d)
for i in range(n):
  sushi[i].sort(reverse=True)
sushi.sort(key=lambda x:x[0],reverse=True)
q=[]
res=0
for i in range(k):
  res+=sushi[i][0]
  for j in sushi[i][1:]:
    q.append(j)
q.sort()
cur=res
res+=k**2
for var in range(1,k)[::-1]:
  a=q.pop()
  b=sushi[var][0]
  cur+=a-b
  res=max(res,cur+var**2)
print(res)

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


int main(){
    string s, ans = "No";
    int k = 0;
    cin >> s;

    int n = s.length();
    for (int i = 0; i < n; i++){
        int j = s.at(i) - '0';
        k = (k + j) % 9;
    }

    if(k == 0)ans = "Yes";

    cout << ans << endl;

}

Measured memory_bytes: 3748
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

int n,m,k,cnt,num[100010],val[100010];
vector<int> v[100010],g[100010];
bool vis[100010];

inline void dfs(int x)
{
	vis[x]=1;
	num[x]=cnt;
	val[cnt]++;
	for(int i=0;i<v[x].size();i++){
		int u=v[x][i];
		if(!vis[u]) dfs(u);
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>k;
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for(int i=1;i<=n;i++) if(!vis[i]){
		cnt++;
		dfs(i);
	}
	for(int i=1;i<=k;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++){
		int ans=val[num[i]]-1;
		for(int j=0;j<v[i].size();j++) if(num[i]==num[v[i][j]]) ans--;
		for(int j=0;j<g[i].size();j++) if(num[i]==num[g[i][j]]) ans--;
		cout<<ans<<" ";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 12288
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll x, a, b;
    cin >> x >> a >> b;
    ll y = x - a;
    cout << y % b << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int m,r,d[15],k[10];
int f(int de,int s){//printf("%d %d\n",de,s);
  int i,p,c=0;
  if(de==r)return s%10?0:1; 
  for(i=0;i<m;i++){
    p=d[i]*k[de];
    if(p>9)p-=9;
    c+=f(de+1,s+p);
  }
  return c;
}
int main(){
  int n,s=0,i,j;
  char c;
  scanf("%d",&n);
  for(i=r=0;i<n;i++){
    scanf(" %c",&c);
    if(c=='*')k[r++]=2-((n-i)%2);
    else{
      s+=c-'0';
      if((n-i-1)%2){
	s+=c-'0';
	if(c>'4')s-=9;
      }
    }
  }//printf("%d\n",s);
  scanf("%d",&m);
  for(i=0;i<m;i++)scanf("%d",&d[i]);
  printf("%d\n",f(0,s));
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
 
int main(){
int n;
cin>>n;
int h[n];
int i;
for(i=0;i<n;i++){
	cin>>h[i];
	
}
long long int c=0;
long long int curc=0;
for(i=0;i<n-1;i++){
	if(h[i] < h[i+1]){
		curc = 0;
		
	}
	else{
		curc++;
	}
	
		if(curc>c){
			c=curc;
		}
	
}
cout<<c<<"\n";

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i=0;i<e;i++)
#define all(a) (a).begin(),(a).end()
using LL=long long;

int main() {
  int n;
  cin>>n;
  vector<int> l(n);
  rep(i,n) cin>>l[i];
  if(accumulate(all(l),0) -  *max_element(all(l))*2 > 0) puts("Yes");
  else puts("No");
 
}

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

int main()
{
    int n;
    cin >> n;
    char s[n];
    cin >> s;
    int arr[26]={0};
    if(n&1)
    cout << "No" << endl;
    else
    {
    for(int i=0;i<n;i++)
    {
        arr[s[i]-'a']++;
    }
    int f=0;
    for(int i=0;i<26;i++)
    {
        if(arr[i]%2)
        f=1;
    }
    if(f==0)
    cout << "Yes" << endl;
    else
    cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import math

def main():
    n,k = list(map(int, input().split()))

    ans = 0
    for i in range(n):
        if i+1 == k:
            ans += (n-(i+1)+1)/n
            break
        num = math.ceil(math.log(k/(i+1),2))
        ans += (1/2)**num/n
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import math
import bisect

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)

def XX(A, M):
  if M <= 0 or A[0]<1:
    return
  A[0] = A[0]/2
  M -= 1
  for i in range(1, len(A)):
    if A[i] > A[0] and M > 0:
      A[i] = A[i]/2
      M -= 1
    else:
      break
  A.sort(reverse = True)
  XX(A, M)
  
XX(A, M)
A = list(map(math.floor, A))
print(sum(A))
  
           

Measured memory_bytes: 14156
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define rn return
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



int main(){
    int N,K; cin >> N >> K;
    int ans = 0;
    rep(i,N){
        int a;
        cin >> a;
        if (a>=K) ans ++;
    }
    cout << ans;
    rn 0;
}

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

bool check(int n, int* A){
	sort(A, A+n);
	if (n%2){
		if (A[0] != 0) return false;
		for(int i=0; i<n/2; i++){
			if (A[2*i+1] != 2*(i+1)) return false;
		}
		for(int i=0; i<n/2; i++){
			if (A[2*i+2] != 2*(i+1)) return false;
		}
	}else{
		for(int i=0; i<n/2; i++){
			if (A[2*i] != 2*i+1) return false;
		}
		for(int i=0; i<n/2; i++){
			if (A[2*i+1] != 2*i+1) return false;
		}
	}
	return true;
}

int main() {
	// your code goes here
	int n; cin>>n;
	int *A = new int[n];
	for(int i=0;i<n;i++) cin>>A[i];
	if (!check(n,A)) cout<<0<<endl;
	else{
		long long res = 1;
		for(int i=0; i<n/2; i++) res = (res*2)%1000000007;
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back

#define y0 pmt
#define y1 pmtpmt
#define x0 pmtQAQ
#define x1 pmtQwQ

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int > vi;
typedef pair<int ,int > pii;
typedef vector<pii> vii;
const int inf=0x3f3f3f3f, maxn=100007, mod=1e9+7;
const ll linf=0x3f3f3f3f3f3f3f3fLL;
const ll P=19260817;
ll get(ll x){
	if(x%4==1){
		return 1;
	}
	if(x%4==2){
		return  x+1;
	}
	if(x%4==3){
		return 0;
	}
	if(x%4==0){
		return x;
	}
}
int main(){
	ll a,b;
	scanf("%lld%lld",&a,&b);
	a--;
	printf("%lld",get(a)^get(b));
    return 0;
}


Measured memory_bytes: 256
/*
ID: Nipun Paul
LANG: C++
PROB: God knows
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int a,b[25],c[3]={0},sum=0,l=0;
    cin>>a;
    for(int i=0; i<a; i++)
    {
        cin>>b[i];
    }
    for(int i=0; i<a-2; i++)
    {
        for(int j=i; j<i+3; j++)
        {
            c[l]=b[j];
            //cout<<c[l]<<endl;
            l++;
        }
        sort(c,c+l);
        if(c[1]==b[i+1])
        {
            sum++;
        }
        l=0;
        c[3]={0};
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int[] r = new int[200000];
		int kai = -1000000000;
		
		int n = scan.nextInt();
		
		for(int i=0; i<n; i++){
			r[i] = scan.nextInt();
		}
		int min = r[0];
		int max = -1000000000;
		
		for(int j=1; j<n; j++){
			if(max < r[j]-min){
				max = r[j] - min;
			}
			if(min > r[j]){
				min = r[j];
			}
		}
		
		System.out.println(max);
	}
}


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


int main()
{	
		int a[3];
		int c =0;
		cin>>a[0]>>a[1]>>a[2];
		for(int b = a[0];b<a[1]+1;b++)
			if(a[2]%b==0)
				c++;
		cout<<c<<endl;
		return 0;
}

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

int main(){
  int n; cin >> n;
  ll k, sum = 0; cin >> k;
  vector<ll> a(n);
  rep(i, n){
    cin >> a[i];
  }

  ll l = 0, r = 1e9;
  while(l + 1 < r){
    ll m = (l + r) / 2;
    auto f = [&](ll x){
      ll cnt = 0;
      rep(i, n){
        cnt += (a[i] - 1) / x;
      }
      return cnt <= k;
    };

    if(f(m)) r = m;
    else l = m;
  }
  cout << r << endl;

  return 0;
}


Measured memory_bytes: 4716
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 199

int top,S[MAX];
void initialize(void);
void push(int);
int pop(void);
int isEmpty(void);
int isFull(void);

int main(){

  int a,b,i;
  char s[MAX];
  
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else push(atoi(s));
  }
  printf("%d\n",pop());
  return 0;
}




 
void initialize(void){
  top=0;
}

int isEmpty(void){
  return top==0;
}

int isFull(void){
  return top>=MAX-1;
}

void push(int x){
  if(isFull())
    printf("overflow\n");
  top++;
  S[top]=x;
}


int pop(void){
  if(isEmpty())
    printf("underflow\n");
  top--;
  return S[top+1];
}

Measured memory_bytes: 980
#include <stdio.h>

int main () {
    int n,a,b,soma=0;
    int cadeiras[112345];

    scanf("%d", &n);

    while (n--) {
        scanf("%d%d", &a,&b);
        soma += (b-a)+1;
    }
    printf("%d\n", soma);



 return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int n = Integer.valueOf(arr01[0]);
        String s = mylist.get(1);

        int cnt = 0;

        int sposi = 0;

        while (sposi < n - 2) {

            String stemp = s.substring(sposi, sposi + 3);
            if (stemp.equals("ABC")) {
                cnt += 1;
                sposi += 3;
            } else {
                sposi += 1;
            }

        }

        System.out.println(cnt);

    }

}

Measured memory_bytes: 22228
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(void) {

  char s[11];
  scanf("%s", s);
  long sum_of_sum = 0;
  int length = strlen(s);
  int bit[length-1];
  for (int i = 0; i < length-1; i++) {
    bit[i] = 0;
  }
  bit[0] = -1;
  long sum,tmp;
  for (int i = 0; i < pow(2,length-1); i++) {
    bit[0]++;
    for (int i = 1; i < length-1; i++) {
      bit[i] += bit[i-1]/2;
      bit[i-1] %= 2;
    }
    sum = 0;
    tmp = 0;
    for (int i = 0; i < length-1; i++) {
      tmp += s[i]-'0';
      if (bit[i] == 0) {
        tmp *= 10;
      } else {
        sum += tmp;
        tmp = 0;
      }
    }
    tmp += s[length-1]-'0';
    sum += tmp;
    sum_of_sum += sum;
  }
  printf("%ld\n", sum_of_sum);

  return 0;
}

Measured memory_bytes: 128
s = str(input())
 
q = int(input())
 
d_list=[]
for i in range(q):
  s2 = ''
   
  d = list(map(str, input().split()))
  if d[0] == 'print':
    print( s[ int(d[1]): int(d[2])+1 ] )
     
  elif d[0] == 'reverse':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = reversed(S[int(d[1]):int(d[2])+1])
    for i in S:
      s2 += i
    s = s2
    
  elif d[0] == 'replace':
    S = list(s)
    S[int(d[1]):int(d[2])+1] = list(d[3])
    for i in S:
      s2 += i
    s = s2


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

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

const int MOD = int(1e9+7);
const int oo  = int(1e9 + 20);
const ll lloo  = (ll)(1e18 + 10);


template <typename T, class F = function<T(const T&, const T&)>>
class SegmentTree {
    int NEUTRAL;
    int n;
    vector<int> tree;
    F func;
public:
    
    SegmentTree(vector<int> values, int neutral, const F& f) : func(f) {
        NEUTRAL = neutral;
        
        n = values.size();
        tree.resize(n*2);
        // Build
        for (int i=0; i < n; i++){
            tree[n+i] = values[i];
        }
        for (int i = n - 1; i > 0; --i) {
            tree[i] = func(tree[i*2], tree[i*2+1]);
        }
    }
    
    void update(int index, int value) {
        tree[index+n] = value;
        index = index + n;
        for (int i = index; i > 1; i >>= 1){
            tree[i/2] = func(tree[i], tree[i^1]);
        }
    }
    
    int query(int l, int r) {
        int ans = NEUTRAL;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if (l&1) {
                ans = func(ans, tree[l++]);
            }
            if (r&1) {
                ans = func(ans, tree[--r]);
            }
        }
        return ans;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    n++;
    vector<int> val(n);
    for(int i = 1; i < n; ++i) {
        cin >> val[i];
    }
    
    SegmentTree<int> st(val, -oo, [&](int x, int y) -> int {return max(x, y);});
    
    vector<bool> visited(n, false);
    int colors = 0;
    int last;
    for(int i = 1; i < n; ++i) {
        if(!visited[i]) {
            colors++;
            last = val[i];
            visited[i] = true;
            st.update(i, -oo);
            
            if(st.query(i+1, n) <= last) continue;
            
            for(int j = i + 1; j < n; ++j) {
                if(!visited[j] && last < val[j]) {
                    last = val[j];
                    visited[j] = true;
                    st.update(j, -oo);
                    if(st.query(j+1, n) <= last) break;
                }
            }
        }
    }
    cout << colors << endl;

    return 0;
}


Measured memory_bytes: 4756
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long LL;
typedef pair<int, string> pii;

const int N = 200000 + 5;

int n, a[N], b[N];
vector<int> v;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = n; i >= 1; i--)
    {
        int sum = 0;
        for (int j = i; j <= n; j += i) sum += b[j];
        sum %= 2;
        if (a[i] == sum) b[i] = 0;
        else b[i] = 1, v.push_back(i);
    }
    printf("%d\n", v.size());
    for (int i = v.size() - 1; i >= 0; i--) printf("%d ", v[i]);
    return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
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; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n; cin >> n;
  vll a(n), b(n), c(n);
  FOR(i,n){ cin >> a[i]; }
  FOR(i,n){ cin >> b[i]; }
  FOR(i,n){ cin >> c[i]; }
  
  //main
  ll ans = 0;
  sort(all(a)); sort(all(b)); sort(all(c));
  for(int i=0; i<n; i++){
    ll tmp = 1;
    tmp *= (lower_bound(all(a), b[i])-a.begin());
    tmp *= (c.end()-(upper_bound(all(c), b[i])));
    ans += tmp;
  }
  
  // output
  cout << ans << endl;

  return 0;
}

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

int main() {
    int n,k; scanf("%d %d", &n, &k);

    priority_queue<int> pq;
    while (!pq.empty()) pq.pop();

    for (int i=1; i<=n; i++) {
        int a; scanf("%d", &a);
        pq.push(a);
    }

    for (int i=1; i<=k && !pq.empty(); i++) {
        pq.pop();
    }

    long long res = (long long)0;
    while (!pq.empty()) {
        res += (long long)pq.top();
        pq.pop();
    }

    printf("%lld\n", res);
    return 0;
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const ll MOD = 998244353;

vi graph[100007];
int d1[100007];
int d2[100007];
bitset<100007> vis;

void bfs(int i, int n){
	queue<int> q;
	q.push(i);
	FOR(j, n) d1[j] = 1e9+7;
	d1[i] = 0;
	while(!q.empty()){
		int atual = q.front();
		q.pop();
		if(vis[atual]) continue;
		vis[atual] = 1;
		for(auto& v : graph[atual]){
			if(vis[v] == 0){
				q.push(v);
				d1[v] = min(d1[v], d1[atual]+1);
			}
		}
	}
}

void dfs(int i, int p=-1){
	vis[i] = 1;
	for(auto& v : graph[i]){
		if(v != p){
			d2[v] = d2[i]+1;
			dfs(v, i);
		}
	}
}

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

	int n, u, v; cin >> n >> u >> v;
	u--; v--;
	FOR(i, n-1){
		int a, b; cin >> a >> b;
		a--; b--;
		graph[a].PB(b);
		graph[b].PB(a);
	}

	vis.reset();
	bfs(v, n);

	vis.reset();

	memset(d2, -1, sizeof d2);
	d2[u] = 0;
	dfs(u);

	int ans = 0;
	FOR(i, n){
		if(graph[i].size() == 1 && d2[i] < d1[i]){
			ans = max(ans, d1[i]-1);
		}
	}
	cout << ans << '\n';

 	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
long x;
long f(long z){
    if(z>=0)
        return z/x + 1;
    else
        return 0;
}
int main(){
    long a,b;
    cin>>a>>b>>x;
    cout<<f(b)-f(a-1);
}

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

int main() {
	int x,a,b,c,ans=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0; i<=a; ++i)
		for(int j=0; j<=b; ++j)
			for(int k=0; k<=c; ++k) {
				int tot=i*500+j*100+k*50;
				if(tot==x)
					ans++;
				if(tot>x)
					break;
			}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> C(N),S(N),F(N);
    for(int i = 0;i < N-1;i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    for(int i = 0;i < N;i++){
        int time = 0;
        for(int j = i;j < N-1;j++){
            //timeより大きくもっとも近い電車にのる
            if(time < S[j]){
                time = S[j];
            }else{
                time = (time + F[j]-1) / F[j] * F[j];
            }
            time += C[j];
        }
        cout << time << endl;
    }
}

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

#define X first
#define Y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for (unsigned i = (a); i <= (b); ++i)
#define per(i, a, b) for (unsigned i = (a); i >= (b); --i)

using namespace std;

using I = int;
using L = long;
using F = float;
using S = string;
using LL = long long;
using VI = vector<int>;
using VL = vector<long>;
using VF = vector<float>;
using VS = vector<string>;
using PLL = pair<long, long>;
using PLF = pair<long, float>;
using PLS = pair<long, string>;
using PSL = pair<string, long>;
using PSF = pair<string, float>;
using PSS = pair<string, string>;
using MLL = map<long, long>;
using MLF = map<long, float>;
using MLS = map<long, string>;
using MSL = map<string, long>;
using MSF = map<string, float>;
using MSS = map<string, string>;

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

int main(int argc, char const *argv[]) {
  while (1) {
    L n;
    L ans1 = 0;
    L ans2 = 0;
    scanf("%ld", &n);
    if (n == 0) { break; }
    for (unsigned i = 0; i < n; i++) {
      L a, b;
      cin >> a >> b;
      if (a > b) {
        ans1 += a + b;
      } else if (a < b) {
        ans2 += a + b;
      } else {
        ans1 += a;
        ans2 += b;
      }
    }
    printf("%ld %ld\n", ans1, ans2);
  }

  return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int h,w,n;
    scanf("%d%d%d",&h,&w,&n);
    int r,c;
    scanf("%d%d",&r,&c);
    --r;--c;
    string s,t;
    cin >> s >> t;
    bool out = false;
    int y=r,x=c;
    rep(j,4){
        rep(i,n){
            if(s[i]=='R') ++x;
            else if(s[i]=='U') --y;

            if(y<0||x>=w) out=true;

            if(t[i]=='L'&&x>0) --x;
            else if(t[i]=='D'&&y<h-1) ++y;
        }
        rep(i,n){
            if(s[i]=='R') s[i]='D';
            else if(s[i]=='D') s[i]='L';
            else if(s[i]=='L') s[i]='U';
            else if(s[i]=='U') s[i]='R';

            if(t[i]=='R') t[i]='D';
            else if(t[i]=='D') t[i]='L';
            else if(t[i]=='L') t[i]='U';
            else if(t[i]=='U') t[i]='R';
        }
        int tmp=r;
        r=c;
        c=h-1-tmp;
        swap(h,w);
        y=r;
        x=c;
        //cout << r << " " << c << endl;
    }
    cout << (out?"NO":"YES") << endl;
    return 0;
}

Measured memory_bytes: 3984
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (h,w) = get!(usize, usize);
    let n = get!(usize);
    let a = get!([usize]);

    let mut c = vec![VecDeque::new(); h];
    let mut row = 0;
    for i in 0..n {
        for _j in 0..a[i] {
            if c[row].len() >= w {
                row += 1;
            }
            if row % 2 == 0 {
                c[row].push_back(i);
            } else {
                c[row].push_front(i);
            }
        }
    }
    for i in 0..h {
        for j in 0..w {
            print!("{} ", c[i][j]+1);
        }
        println!("");
    }
}


Measured memory_bytes: 8572
X = gets.to_i
arr = Array.new

ans = 1
b = 2
p = 2
while b <= Math.sqrt(X)
  n = b**p
  if n <= X
    ans = [ans, n].max
    arr += [n]
    p += 1
  else
    b += 1
    while arr.include?(b)
      b += 1
    end
    p = 2
  end
end

puts ans


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

using namespace std;

int main(){
	long long ans = 0;
	string S;
	cin >> S;

	for (int i = 0; i < (1 << (S.size() - 1)); ++i){
		long long tmp = 0, prev = 0;
		for (int b = 0; b < S.size() - 1; ++b){
			tmp += S[b] - '0';
			if (i >> b & 1){
				ans += tmp;
				tmp = 0;
			}
			else{
				tmp *= 10;
			}
		}
		tmp += atoi(&S[S.size() - 1]);
		ans += tmp;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    for (int i = -k + 1; i < k; i++) {
        cout << x + i << " \n"[i == k - 1];
    }

    return 0;
}

Measured memory_bytes: 256
while 1:
    N=int(input())
    if N==0:break
    tile=[[0,0]]
    xma,xmi,yma,ymi=0,0,0,0
    for i in range(N-1):
        n,d=map(int,input().split())
        if d==0:
            tile.append([tile[n][0]-1,tile[n][1]])
            xmi=min(xmi,tile[n][0]-1)
        elif d==1:
            tile.append([tile[n][0],tile[n][1]-1])
            ymi=min(ymi,tile[n][1]-1)
        elif d==2:
            tile.append([tile[n][0]+1,tile[n][1]])
            xma=max(xma,tile[n][0]+1)
        elif d==3:
            tile.append([tile[n][0],tile[n][1]+1])
            yma=max(yma,tile[n][1]+1)
    print(xma-xmi+1,yma-ymi+1)


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

int main() {
	int N;
	cin >> N;
  
  	vector<pair<double, string>> p(N);
    for(int i = 0; i < N ; i++){
      double a;
      string b;
      cin >> a >> b;
      p.at(i) = make_pair(a, b);
    }

  	double total = 0;
  	for(int i = 0; i < N ; i++){
      double a;
      string b;
      tie(a, b) = p.at(i);
      if(b == "JPY") total += a;
      else total += 380000*a;
    }
  
  cout << fixed << setprecision(5);
  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  S.at(K - 1) += 'a' - 'A';
  cout << S << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        // Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int[] a = new int[n+2];
        for(int i=0; i<n; i++) a[i+1] =  Integer.parseInt(st.nextToken());
        a[0] = 0;
        a[n+1] = 0;
        long total = 0;
        for(int i=1; i<n+2; i++) total += Math.abs(a[i] - a[i-1]);
        for(int i=1; i<n+1; i++) {
          long new_val = total - Math.abs(a[i] - a[i-1]) - Math.abs(a[i] - a[i+1]) + Math.abs(a[i-1] - a[i+1]);
          out.println(new_val);
        }



        out.close(); System.exit(0);
    }


}


Measured memory_bytes: 49516
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

vector<int> fac(MX);
vector<int> ifac(MX);

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}

int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}

int P(int a, int b) {
    int res = comb(a,b);
    res *= fac[b];
    return res % mod;
}

int ans, k;
vector<int> to[100005];
void dfs(int v, int p=-1) {
    for(int u: to[v]) {
        if(u == p) continue;
        dfs(u, v);
    }
    int nk = (p==-1) ? k : k-2;
    int c = (p==-1) ? to[v].size()+1 : to[v].size()-1;
    ans *= P(nk, c);
    ans %= mod;
}

char a[1002][1002];
signed main(){
    int h, w;
    cin >> h >> w;

    queue<pair<int, pair<int, int>>> q;
    FOR(i, 1, h+1) {
        string str;
        cin >> str;
        FOR(j, 1, w+1) {
            a[i][j] = str[j-1];
            //cout << a[i][j] << endl;
            if(a[i][j]=='#') q.push(make_pair(0, make_pair(i,j)));
        }
    }

    int cnt = 0;
    while(q.size()>0) {
        int i = q.front().second.first;
        int j = q.front().second.second;
        int depth = q.front().first;
        //cout << depth <<" " << i <<" " << j << endl;
        cnt = depth;
        q.pop();

        if(a[i-1][j]=='.') {
            a[i-1][j] = '#';
            q.push(make_pair(depth+1, make_pair(i-1,j)));
        }if(a[i][j-1]=='.') {
            a[i][j-1] = '#';
            q.push(make_pair(depth+1, make_pair(i,j-1)));
        }if(a[i+1][j]=='.') {
            a[i+1][j] = '#';
            q.push(make_pair(depth+1, make_pair(i+1,j)));
        }if(a[i][j+1]=='.'){
            a[i][j+1] = '#';
            q.push(make_pair(depth+1, make_pair(i,j+1)));
        }

    }
    cout << cnt << endl;


    return 0;
}


Measured memory_bytes: 43444
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

ll N,K;
ll a[100005];

int main(){
  while(scanf("%lld%lld", &N,&K) && N||K){
    for(int i=0;i<N;i++) scanf("%lld", &a[i]);
    ll sum = 0, res;
    for(ll i=0;i<K;i++) sum += a[i];
    res = sum;
    for(ll i=K;i<N;i++){
      sum -= a[i-K];
      sum += a[i];
      res = max(res, sum);
    }
    printf("%lld\n", res);
  }
  return 0;
}

Measured memory_bytes: 1808
#include <stdio.h>
#include <string.h>
//#define DEBUG
#define MAX 20

#ifdef DEBUG
#define DBGPRINTF(...) printf(__VA_ARGS__)
#else
#define DBGPRINTF(...)
#endif

int main( int argc, char *argv[] )
{
    int i, j, tmp, m[3], loopcount = 0, datanum, flag;
    char s[MAX];

    scanf( "%d", &datanum );

    if ( datanum > 1000 ) datanum = 1000;

    DBGPRINTF( "datanum: %d\n", datanum );

    while( ( fgets( s, MAX, stdin ) != NULL ) && ( loopcount < datanum ) )
    {
        DBGPRINTF( "%s", s );

        if ( sscanf( s, "%d %d %d", &m[0], &m[1], &m[2] ) == 3 )
        {

            DBGPRINTF( "m[0]: %d, m[1]: %d, m[2]: %d\n", m[0], m[1], m[2] );

            flag = 0;

            if ( ( m[0] >= m[1] ) && ( m[0] >= m[2] ) )
            {
                /* m[0]???????????§?????? */
                if ( m[0] * m[0] == m[1] * m[1] + m[2] * m[2] ) flag = 1;
                
            }
            else if ( ( m[1] >= m[0] ) && ( m[1] >= m[2] ) )
            {
                /* m[1]???????????§?????? */
                if ( m[1] * m[1] == m[0] * m[0] + m[2] * m[2] ) flag = 1;
            }
            else if ( ( m[2] >= m[0] ) && ( m[2] >= m[1] ) )
            {
                /* m[2]???????????§?????? */
                if ( m[2] * m[2] == m[0] * m[0] + m[1] * m[1] ) flag = 1;
            }
            else
            {
                /* nanikore */
            }

            if ( flag > 0 ) 
            {
                printf( "YES\n" );
            }
            else 
            {
                printf( "NO\n" );
            }

            memset( s, 0, sizeof(s) );
        }
    }

    return 0;

}

Measured memory_bytes: 596