akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    ll n, m; cin >> n >> m;
    vector<ll> b(n+1);
    for (int i = 1; i <= n; i++)
    {
        int a; cin >> a;
        b[i] = (b[i-1]+a)%m;
        // cout << b[i] << endl;
    }

    ll ans = 0;
    map<ll, ll> p;
    for (int i = 0; i <= n; i++) {
        ans += p[b[i]];
        p[b[i]]++;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 4992
# -*- coding: utf-8 -*-
N, M = map(int, input().split(' '))

road_count_from_city = [0 for i in range(N)]

for i in range(M):
    a, b = map(int, input().split(' '))
    road_count_from_city[a - 1] = road_count_from_city[a - 1] + 1
    road_count_from_city[b - 1] = road_count_from_city[b - 1] + 1

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


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

#define int long long
//#define ll int long long
#define REP(i,n) for(int i=0;i<n;i++)
//#define ALL(vec) (vec).begin(),(vec).end()
//#print_double(d) printf("%.9f\n", d)
/*
int par[100002];
int rnk[100002];
void init(int n){REP(i,n){par[i]=i;rnk[i]=0;}}
int find(int x){if(par[x]==x){return x;}else{return par[x]=find(par[x]);}}
void unite(int x,int y){x=find(x);y=find(y);if(x==y)return;if(rnk[x]<rnk[y]){par[x]=y;}else{par[y]=x;if(rnk[x]==rnk[y])rnk[x]++;}}
bool same(int x,int y){return find(x)==find(y);}
*/

//const int INF = numeric_limits<int>::max();
const int INF = 1e17;
struct edge {int to,cost;};
typedef pair<int,int> P;
vector<int> dijkstra(int s,vector<vector<edge>>&G){
    vector<int> d(G.size(),INF);
    priority_queue<P,vector<P>,greater<P>> que;
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(edge e : G[v]){
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    return d;
}


signed main(){
    int n,m,s,t;
    cin>>n>>m>>s>>t;
    s--;t--;
    vector<vector<edge>> G(n),H(n);
    REP(i,m){
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        u--;v--;
        G[u].push_back({v,a});
        G[v].push_back({u,a});
        H[u].push_back({v,b});
        H[v].push_back({u,b});
    }
    auto D=dijkstra(s,G);
    auto E=dijkstra(t,H);
    vector<int> ans(n+1,INF);
    for(int i=n;i--;)ans[i]=min(D[i]+E[i],ans[i+1]);
    int ken=1e15;
    REP(i,n){
        cout<<(ken-ans[i])<<endl;
    }
}


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

int main(){
	int n; cin >> n;
	ll ans = 0;
	ll c, s = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", &c);
		if(!c){
			ans += s / 2;
			s = 0;
		}
		else s += c;
	} ans += s / 2;
	cout << ans << '\n';
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V) \
    for (auto v : (V)) cout << v << ' ';
#define PRINT_ENTER() cout << endl;

int main() {
    /* code */
    int n;
    cin >> n;
    vector<long long> a(n);
    int bit{};
    REP(i, n) {
        cin >> a[i];
        bit = (a[i] | bit);
    }
    int counter{};
    while ((bit & 1) == 0) {
        bit = bit >> 1;
        counter++;
    }
    PRINT(counter);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string S,T;
    cin >> S >> T;
    bool ok = true;
    map<char,char> ma, ima;
    for (int i = 0; i < S.size(); ++i) {
        char s = S[i], t = T[i];
        if (ma.count(s)) if (ma[s] != t) ok = false;
        if (ima.count(t)) if (ima[t] != s) ok = false;
        ma[s] = t; ima[t] = s;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    /*
    // 嘘解法
    vector<int> Smoji(26),Tmoji(26);
    rep(i,S.size()){
        Smoji[S[i]-'a']++;
        Tmoji[T[i]-'a']++;
    }
    sort(Smoji.begin(),Smoji.end());
    sort(Tmoji.begin(),Tmoji.end());
    rep(i,26){
        if(Smoji[i]!=Tmoji[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    */
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int main() {
    int H, W, D;
    cin >> H >> W >> D;
    vector<vector<lint>> G(H, vector<lint>(W));
    map<int, pair<int, int>> mp;
    rep(i, H) rep(j, W) {
        cin >> G[i][j];
        G[i][j]--;
        mp[G[i][j]] = {i, j};
    };
    // ddump(G);

    vector<vector<lint>> L(D, vector<lint>((H * W + D - 1) / D, 0));
    rep(k, D) {
        for (int i = 0; k + D * (i + 1) <= H * W; i++) {
            int Ai = k + D * i;
            int Aj = k + D * (i + 1);
            int cx = mp[Ai].first, cy = mp[Ai].second;
            int nx = mp[Aj].first, ny = mp[Aj].second;
            L[k][i + 1] = L[k][i] + abs(nx - cx) + abs(ny - cy);
        }
    }
    // ddump(L);

    int Q;
    cin >> Q;
    rep(q, Q) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        cout << L[l % D][r / D] - L[l % D][l / D] << endl;
    }

    return 0;
}

Measured memory_bytes: 14484
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 && W ==0){
                break;
            }
            for(int i=0;i<H;i++){
               for(int j=0;j<W;j++){
                  if(i%2==0){
                      if(j%2==0){
                          System.out.printf("#");
                      }else{
                        System.out.printf(".");
                      }
                  } else{
                    if(j%2==0){
                        System.out.printf(".");
                    }else{
                      System.out.printf("#");
                    }
                  }
               }
               System.out.printf("\n"); 
            }
            System.out.printf("\n"); 
        }
    }
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> L(N);
  for (int i = 0; i < N; i++)
  {
    cin >> L[i];
  }
  int ans = 0;
  sort(L.begin(), L.end());
  for (int i = 0; i < N; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      for (int k = j + 1; k < N; k++)
      {
        if (L[i] < L[j] + L[k] && L[j] < L[i] + L[k] && L[k] < L[i] + L[j])
          ans++;
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
    int n;
    char s[100], t[100];
    cin >> n;
    for (size_t i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    for (size_t i = 0; i < n; i++)
    {
        cin >> t[i];
    }
    for (size_t i = 0; i < n; i++)
    {
        cout << s[i] << t[i];
    }
    cout << endl;
    return 0;
}

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


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n, k;
	cin >> n >> k;
	vector<int> p(n);
	for (int i = 0; i < n;i++) {
		cin >> p[i];		
	}

	int sum = 0;
	for (int i = 0; i < k;i++) {
		sum += p[i];
	}

	int mSum = sum;
	for (int i = k;i < n;i++) {
		sum = sum + p[i] - p[i - k];
		mSum = max(mSum, sum);
	}

	double ans = (mSum + k) / 2.0;
	cout << setprecision(10) << ans << endl;



}





Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
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 n, m;
vector<int> a(1000100, 0);
int main() {
    cin >> n >> m;
    long long sum = 0;
    for(int i = 0; i < m; ++i) {
        cin >> a.at(i);
        sum += a.at(i);
    }

    if(sum > n) {
        cout << -1 << endl;
    }else {
        cout << n-sum << endl;
    }
}

Measured memory_bytes: 7032
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,inv2=(mod+1)/2;
inline long long sqr(long long x){return x*x%mod;}
inline long long power(long long x,int n){return !n?1:power(sqr(x),n/2)*(n&1?x:1)%mod;}
inline long long inv(long long x){return power(x,mod-2);}
int b,w;
long long fac[500001],invf[500001],p[500001],q[500001];
inline long long C(int n,int m){return n<m?0:fac[n]*invf[m]%mod*invf[n-m]%mod;}
int main()
{
	fac[0]=1;
	for(int i=1;i<500001;i++)fac[i]=fac[i-1]*i%mod;
	invf[500000]=inv(fac[500000]);
	for(int i=499999;i>=0;i--)invf[i]=invf[i+1]*(i+1)%mod;
	cin>>b>>w;
	cout<<inv2<<'\n';
	for(int i=1;i<b+w;i++)
	{
		p[i]=(p[i-1]+C(i-1,b-1)*power(inv2,i))%mod;
		q[i]=(q[i-1]+C(i-1,w-1)*power(inv2,i))%mod;
		cout<<(1-p[i]+q[i]+mod)*inv2%mod<<'\n';
	}
}


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


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}


int main(){
    ll n;
  cin >>n;
  unsigned long long ans=0;
    //vector <int> res;
  for(ll i=1;i<n;i++){

    const auto &pf = prime_factorize(i);
  	long long res = 1;
    for (auto p : pf) res *= p.second + 1;
    ans += res;
    //cout << ans << endl;
  }
  
  
  
  /*for (int i = 0; i < (int)res.size(); ++i) //cout << res[i] << " ";
    cout << endl;*/


cout << ans << endl;
}



Measured memory_bytes: 3624
import math
n,m =map(int,input().split())
 
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(int(n))
  return table
 
a =prime_decomposition(m)

def combination(n,r):
    r = min(r,n-r)
    result = 1
    for i in range(n-r+1,n+1):
        result *= i
    for i in range(1,r+1):
        result //= i
    return result

ans=1
count = 1
if not a:
  print(ans)
  exit()

for i in range(1,len(a)):
  if a[i-1]== a[i]:
    count +=1
  else:
    ans *= combination(count+n-1,count)
    ans %=1000000007
    count = 1
    
ans *= combination(count+n-1,count)
ans %=1000000007
print(ans)
  

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#define lli long long int
#include<climits>
#include<unordered_map>
#include<algorithm>
#include<bitset>
#include<map>
#define pb push_back
using namespace std;


lli mgcd(lli a ,lli b)
{
    if(b==0)  return a;
    return mgcd(b,a%b);
}
int main()
{
   
    lli a,b;
    cin>>a>>b;
    lli mul = a*b;
    lli g = mgcd(a,b);
    cout<<mul/g<<endl;
    
    
}



Measured memory_bytes: 3544
// finish date: 2018/03/09

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N, x;
    cin >> N >> x;
    vi a(N);
    rep(i, N) cin >> a[i];
    vvi b(N, vi(N));
    ll ans = 0;
    rep(i, N) {
        b[0][i] = a[i];
        ans += a[i];
    }
    FOR (i, 1, N) {
        ll temp = 0;
        rep(j, N) {
            b[i][j] = min(b[i - 1][(j - 1 + N) % N], a[j]);
            temp += b[i][j];
        }
        ans = min(ans, temp + (ll) x * i);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16000
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <random>
#include <vector>
//#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
 
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(a) (a).begin(), (a).end()
 
int main()
{
	vi a(3);
	int k;
	rep(i,3){
		cin>>a.at(i);
	}
	cin>>k;
	sort(all(a));
	a.at(2)=a.at(2)*pow(2,k);
	cout<<a.at(0)+a.at(1)+a.at(2)<<endl;
	
	return 0;
}

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

vector<int> Input(const int n)
{
    vector<int> W;
    for(int i = 0; i < n; i++){
        int w;
        cin >> w;
        W.push_back(w);
    }
    return W;
}
 
bool IsAllLoaded(int P, vector<int> W, int k)
{
    int TrackIndex = 0;
    int CurrentSum = 0;
    int i = 0;
    for(i = 0; i < W.size(); i++){
        if(W[i] > P){
            return false;
        }
        if(CurrentSum + W[i] > P){
            TrackIndex++;
            if(TrackIndex == k){
                return false;
            }
            CurrentSum = 0;
        }
        CurrentSum += W[i];
    }
    return true;
}
 
int Calc(vector<int> W, int k)
{
    int Sum = accumulate(W.begin(), W.end(), 0 );
    int P = (Sum + k - 1) / k;
    while(!IsAllLoaded(P, W, k)){
        P++;
    }
    return P;
}
 
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> W = Input(n);
    int P = Calc(W, k);
    cout << P << endl;
    return 0;
}

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

int main()
{
	char ch;
	int count[26]={0};
	int i;
	
	while(cin >> ch){
		if(isupper(ch))
			ch=tolower(ch);
	
		count[ch-'a']++;
	}
	
	for(i=0;i<26;i++){
		cout << char('a'+i) << ' ' << ':' << ' ' << count[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1140
n, y = map(int, input().split())

a = 0
b = 0

for a in range(n+1):
    for b in range(n-a+1):
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(a, b, c)
            break
        elif a == n:
            print("-1 -1 -1")
    else:
        continue
    break


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define f(a,b) for(ll i = a; i < b; i++)
#define fr(a,b) for(ll j = a; j >= b; j--)
#define fi(a,b) for(ll j = a; j < b; j++)
#define fii(a,b) for(ll k = a; k < b; k++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pl pair<ll,ll>
#define vll vector<ll>
#define pll vector< pair<ll,ll> >
#define ld long double


void sieve(int n)
{

    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
              for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
ll modpow(ll a,ll b){
    ll rs=1;
    a%=mod;
    while(b>0){
        if(b&1)rs=(rs*a)%mod;

        b=b>>1;
        a=(a*a)%mod;
    }
    return rs;
}


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

int t=1;
//cin>>t;

while(t--){

   ll n,a,b;
   cin>>n;
   vector<  pair < ll ,ll > > vv;
   f(0,n){
   cin>>a>>b;
   vv.pb(mp((b),a));

   }
   sort(vv.begin(),vv.end());


      int ck=0,tot=vv[0].second;
      if(tot>vv[0].first)ck++;

      f(1,n){
        if( tot+vv[i].second > vv[i].first)ck++;
         tot+=vv[i].second;

      }
    if(ck)cout<<"No";
    else cout<<"Yes";



}

    return 0;
}


Measured memory_bytes: 6384
#include <stdio.h>
#include <string.h>
int main()
{
	int n,a =0,b=0,c=0,d=0;
	scanf("%d", &n);
	getchar();
	char ch[5];
	int i;
	for(i = 0; i < n; i++)
	{
		gets(ch);
		if(strcmp("AC", ch) == 0)
		{
			a++;
		}else if(strcmp("WA", ch) == 0)
		{
			b++;
		}else if(strcmp("TLE", ch) == 0)
		{
			c++;
		}else if(strcmp("RE", ch) == 0)
		{
			d++;
		}
	}
	printf("AC x %d\n", a);
	printf("WA x %d\n", b);
	printf("TLE x %d\n", c);
	printf("RE x %d\n", d);
	return 0;
}

Measured memory_bytes: 2216
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
using namespace std;
#define ll long long 
#define dd cout<<endl
const int mod=1e9+7;
const int inf=1e9+7;

const int maxn=2e5+10;

int sum[maxn];
vector<int>edge[maxn];

int n,m;
int x,y;

int book[maxn];

void dfs(int now,int mark)
{
	mark+=book[now];
		
	sum[now]+=mark;
	
	for(int i=0;i<edge[now].size();i++)
		dfs(edge[now][i],mark);
}

int main()
{
   	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    while(cin>>n>>m)
    {
    	memset(sum,0,sizeof(sum));
    	memset(book,0,sizeof(book));
    	for(int i=0;i<=n;i++)
    		edge[i].clear();
    		
		for(int i=0;i<n-1;i++)
		{
			cin>>x>>y;
			edge[x].push_back(y);
		}
		
		for(int i=0;i<m;i++)
		{
			cin>>x>>y;
			book[x]+=y;
		}
		
		dfs(1,0);
		
		for(int i=1;i<n;i++)
			cout<<sum[i]<<" ";
		cout<<sum[n]<<endl;
	}
    return 0;
}

Measured memory_bytes: 24320
#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 <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    string s;
    ll K;
    cin >> s;
    cin >> K;
    ll leng = s.size();
    ll ans = 0;
    /*
    ll dp[leng][K+1][2];

    REP(i, leng)REP(j, K+1)REP(k, 2) dp[i][j][k] = 0;
*/
    vector<vector<vector<ll>>> dp(leng, vector<vector<ll>> (K+1, vector<ll>(2, 0)));
    if(leng != K) dp[0][K][0] = 1;
    dp[0][K-1][0] = s[0] - '1';
    dp[0][K-1][1] = 1;
    rep(i, 1, leng)REP(j, K+1){
        dp[i][j][0] = dp[i-1][j][0];
        if (j < K) dp[i][j][0] += 9 * dp[i-1][j+1][0];
        if (j < K && s[i] != '0') dp[i][j][0] += dp[i-1][j+1][1] * (s[i] - '1') + dp[i-1][j][1];
        if (s[i] == '0') dp[i][j][1] = dp[i-1][j][1];
        else  if(j < K) dp[i][j][1] = dp[i-1][j+1][1];

    }

    cout << (dp[leng-1][0][0] + dp[leng-1][0][1]) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int a[60], b[60];
int main(void)
{
    while (1) {
        int n, p, k, i, res;
        scanf("%d%d", &n, &p);
        if (n==0 && p==0) break;
        for(i=0;i<n;++i) a[i]=b[i]=0;
        k=0;
        a[k]=p;
        while (1) {
            if (a[k]>0) {
                --a[k];
                ++b[k];
            }
            else {
                a[k]+=b[k];
                b[k]=0;
            }
            a[(k+1)%n]=a[k];
            a[k]=0;
            k=(k+1)%n;

            res=-1;
            for(i=0;i<n;++i) if (b[i]==p) res=i;
            if (res>=0) break;
        }
        printf("%d\n", res);
    }
    return 0;
}

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

int main(){
    
    int w;
    
    while(1){
        cin >> w;
        if(w == -1){
            break;
        }
        else{
            if(w <= 10){
               cout << 4280-1150 << endl; 
            }
            else if(w <= 20){
                cout << 4280 -(1150+(w-10)*125) << endl;
            }
            else if(w <= 30){
                cout << 4280 -(1150+1250+(w-20)*140) << endl;
            }
            else{
                cout << 4280 -(1150+1250+1400+(w-30)*160) << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3108
def solve():
    N, K, S = map(int, input().split())
    Ans = [0] * N
    for i in range(K):
        Ans[i] = S
    for i in range(K, N):
        Ans[i] = (S + 1 if S < 10 ** 9 else 1)

    print(" ".join(map(str, Ans)))
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 15012
#include<stdio.h>

int main() {
	int n,i,j,k,b,f,r,v,data[4][3][10] = {0};
	scanf("%d", &n);
	for(i = 0; i < n; i++) {
		scanf("%d %d %d %d", &b, &f, &r, &v);
		data[b-1][f-1][r-1] += v;
	}
	for(i = 0; i < 4; i++) {
		for(j = 0; j < 3; j++) {
			for(k = 0; k < 10; k++) {
				printf(" %d", data[i][j][k]);
			}
			printf("\n");
		}
		if(i != 3) {
			printf("####################\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <vector>

using namespace std;

vector<int> components;

// used_borderが3のとき0, 1, 2まで使用済み。
bool can_construct(int target, int used_border) {
  if(target == 0) {
    return true;
  }
  if(used_border > components.size()) {
    return false;
  }

  return can_construct(target - components[used_border - 1], used_border + 1) ||
    can_construct(target, used_border + 1);
}


int main() {
  int component_num;
  cin >> component_num;
  components.resize(component_num);

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

  int target_num;
  cin >> target_num;
  for(int i = 0; i < target_num; i++) {
    int target;
    cin >> target;
    bool constratable = can_construct(target, 1);

    if(constratable) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }
}



Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s; cin >> s;
    rep(i,s.size()) {
        if (s[i] == '1')
        {
            s[i] = '9';
        } else {
            s[i] = '1';
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
char a[14];
int flag=0;
int main()
{
    scanf("%s",a);
    int t=strlen(a);
    if(t%2!=0)
    return 0*printf("No");
    else
    {
     for(int i=0;i<t;i+=2)
     {
      if(a[i]!='h'||a[i+1]!='i')
      {
      flag=1;
      break;
  }
	 }
	 if(flag)
	 printf("No");
	 else
	 printf("Yes");
	}
} 

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


ll extgcd(ll a, ll b, ll &x, ll &y){
    ll d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x=1;
        y=0;
    }
    return d;
}

int main() {
    cin>>N>>A;
    ll ans = A;
    rep(i,N - 1){
        cin>>A;
        ll x, y;
        if(ans < A) swap(ans,A);
        ans *= A / extgcd(ans,A,x,y);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
A, B, C = map(int, raw_input().split())
[A, B, C] = sorted([A, B, C])

cnt = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    cnt += 1
    r = [(A + B) / 2, (A + C) / 2, (B + C) / 2]
    [A, B, C] = r;
    if A == C:
        cnt = -1
        break

print cnt


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

using namespace std;
typedef long long               ll;
typedef long double             ld;

#define min3(a, b, c)           min((a), min((b), (c)))
#define max3(a, b, c)           max((a), max((b), (c)))
#define lcm(a,b)                (a / __gcd(a,b) ) *b
#define gcd(a,b)                __gcd(a,b)
#define dist(x1,y1,x2,y2)       sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define distl(x1,y1,x2,y2)      sqrtl((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))
#define sqr(a)                  ((a)*(a))
#define FOR(a, b)               for(int i=a; i<b; i++)
#define fRead(x)                freopen(x,"r",stdin)
#define fWrite(x)               freopen (x,"w",stdout)
#define pb                      push_back
#define mk                      make_pair
#define ff                      first
#define ss                      second
#define lb                      lower_bound
#define ub                      upper_bound
#define all(a)                  a.begin(),a.end()
#define FASTIO                  ios_base::sync_with_stdio(0);cin.tie(NULL);
ll BMod(ll B,ll P,ll M)
{
    ll R=1;
    B=B%M;
    while(P)
    {
        if(P&1)
            R=(R*B)%M;
        P >>= 1;
        B=(B*B)%M;
    }
    return R;
}

ll invMOD(ll num,ll M)
{
    return BMod(num,M-2,M);
}


int main()
{
    FASTIO

    int n, k;
    vector<pair<int,int> > v;
    cin >> n >> k;

    FOR (0, n)
    {
        int x, y;
        cin >> x >> y;
        if (y <= k)
            v.push_back({x, y});
    }

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

    if (!v.empty())
        cout << v[0].ff;
    else
        cout << "TLE";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

vector<ll> ans;

void dfs(ll n){
  if (n > 3234566667) return;
  ans.pb(n);
  ll d = n % 10;
  if (d != 0) dfs(10 * n + (d - 1));
  if (d != 9) dfs(10 * n + (d + 1));
  dfs(10 * n + d);
}

int main(int argc, char const *argv[]) {
  int x;
  cin >> x;
  rep(i, 9) dfs(i+1);
  sort(all(ans));
  cout << ans[x-1] << endl;
  return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
 
void solve(){
 
 
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();

    ll x,y;cin>>x>>y;
    if(x==y||x-1==y||x==y-1) cout<<"Brown\n";
    else cout<<"Alice\n";

	return 0;
}
 



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
     
     
def gcd(m, n):
    return m if n == 0 else gcd(n, m % n)
     
     
def lcm(m, n):
    return m * n // gcd(m,n)
     
     
def main():
    n = int(input())
    t = []
    for i in range(n):
        tmp = int(input())
        t.append(tmp)
    ans = t[0]
    for i in t:
        ans = lcm(ans, i)
    print(ans)
     
     
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
#define llMAX 9223372036854775807
#define llMIN -9223372036854775808
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll l;

int main(){
  ll ans=0;
  double lda;
  cin >> lda;
  lda/=3.0;
  lda=lda*lda*lda;
  //小数点表記
cout << setprecision(16) << lda<<endl;
  return 0;
}


Measured memory_bytes: 256
H,W = list(map(int,input().split()))
M = []
for i in range(H):
    M.append(list(input()))

Bs = []
for i in range(H):
    for j in range(W):
        if M[i][j]=="#":
            Bs.append([i,j])

from collections import deque
memo = [[2000] * W for i in range(H)]
dy = [0, 1, 0, -1]
dx = [1, 0, -1, 0]
que = deque([])
que.append(Bs)
for Bi,Bj in Bs:
    memo[Bi][Bj] = 0

out = 0
while que:
    ps = que.popleft()
    next = []
    for p in ps:
        for i in range(4):
            ny = p[0] + dy[i]
            nx = p[1] + dx[i]
            if (0<=nx<W)and(0<=ny<H)and(memo[ny][nx]==2000):
                next.append((ny, nx))
                memo[ny][nx] = memo[p[0]][p[1]] + 1
                if memo[ny][nx]>out:
                    out=memo[ny][nx]
    if len(next)>0:
        que.append(next)

print(out)

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

int main(){
  ull N;
  cin >> N;
  set<ull> A;
  for (ull i = 0; i < N; i++) {
    ull tmp;
    cin >> tmp;
    A.insert(tmp);
  }
  
  if (A.size() == N) cout << "YES";
  else cout << "NO";
  
  return 0;
}



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

typedef long long ll;

ll N, K;

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

    if (K % 2 == 0) {
        // mod K が 0
        ll tmp1 = N / K;

        // mod K が K / 2
        ll tmp2 = N * 2 / K;
        // K の倍数を引く
        tmp2 -= tmp1;

        cout << tmp1 * tmp1 * tmp1 + tmp2 * tmp2 * tmp2 << endl;
    } else {
        ll tmp = N / K;
        cout << tmp * tmp * tmp << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

res = "APPROVED"

for i in range(N):
  # 偶数が3or5で割り切れるので、まずは偶数判定をする
  if(A[i] % 2 == 0):
    # 3でも5でも割り切れない = 余りが出たら、DENIED
    if(A[i] % 3 != 0 and A[i] % 5 != 0):
      res = "DENIED"
      break


print(res)


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    char n;cin >> n;
    if(n<'a'){
        cout << "A" << "\n";
    }else{
        cout << "a"
             << "\n";
    }
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

int main() {
    int a, b, c, x, y;
    scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);

    ll ans = a * x + b * y;
    for (int i = 0; i <= max(x, y); i++) {
        ll price = a * max(0, (x - i)) + b * max(0, (y - i)) + c * 2 * i;
        ans = min(ans, price);
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int n;

char s[200010];

int main () {
	scanf ("%s", s + 1), n = strlen (s + 1);
	long long ans = 0;
	int num = 0, xnum = 0;
	for (int i = n; i >= 1; --i) {
		if (s[i] == 'A') ans += num, xnum = 0;
		else if (s[i] == 'B' && s[i + 1] == 'C') num = xnum + 1, xnum = 0;
		else xnum = num, num = 0;
	}
	printf ("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int sosu[1000010]={1,1,0};
vvp nu;
vvi dp;
int main(){
	for(int i=2;i*i<1000010;i++)if(sosu[i]==0){
		for(int j=i+i;j<1000010;j+=i)sosu[j]=1;
	}
	nu=vvp(1100,vp(1100,pii(inf,0)));
	int x=550,y=550;
	int dx[]={0,-1,0,1};
	int dy[]={1,0,-1,0};
	int co=1,t=0,tt=1;;
	nu[x][y]=pii(1,0);
	while(1){
		rep(i,co){
			tt++;
			x+=dx[t];y+=dy[t];
			nu[x][y]=pii(tt,sosu[tt]^1);
			if(tt==1000010)break;
		}
		t++;
		if(t==4)t=0;
		if(t==0||t==2)co++;
		if(tt==1000010)break;
	}
	int n,m;
	while(cin>>m>>n,n+m){
		dp=vvi(1100,vi(1100,-1));
		rep(i,1100)rep(j,1100)if(nu[i][j].first==n)dp[i][j]=nu[i][j].second;
		loop(i,20,1080)loop(j,20,1080)if(dp[i][j]>=0&&nu[i][j].first<=m){
			if(nu[i+1][j+1].first<=m)dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+nu[i+1][j+1].second);
			if(nu[i+1][j].first<=m)dp[i+1][j]=max(dp[i+1][j],dp[i][j]+nu[i+1][j].second);
			if(nu[i+1][j-1].first<=m)dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]+nu[i+1][j-1].second);
		}
		int out=-1,q=0;
		rep(i,1090)rep(j,1090)if(out<=dp[i][j]&&nu[i][j].second){
			if(out==dp[i][j])q=max(q,nu[i][j].first);
			else q=nu[i][j].first;
			out=max(dp[i][j],out);
		}
		if(out<=0)cout<<0<<" "<<0<<endl;
		else cout<<out<<" "<<q<<endl;
	}
}

Measured memory_bytes: 23980
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define all(x) (x).begin(), (x).end()
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007LL

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15)

  ll x, k, d;
  cin >> x >> k >> d;
  if (((abs(x)-1)/d) + 1 <= k) {
    //0を超えられる
    if (x < 0) x *= -1;
    //x %= d;
    if (k % 2 == 0) {
      x %= 2*d;
      cout << min(x, 2*d - x) << endl;
      return 0;
    }
    else {
      x += d;
      x %= 2*d;
      cout << min(x, 2*d - x) << endl;
      return 0;
    }
    //cout << min(x, d-x) << endl;
    //return 0;
  }
  if (x >= 0) {
    cout << abs(abs(x) - k * d) << endl;
    return 0;
  }
  if (x < 0) {
    cout << abs(abs(x) - k * d) << endl;
  }
}


Measured memory_bytes: 3648
n_tree, n_choice = [int(data) for data in input().split()]
heights = []
for i in range(n_tree):
  heights.append(int(input()))

diff = float("inf")
heights = sorted(heights)
for i in range(n_tree - n_choice + 1):
  h_min = heights[i]
  h_max = heights[i + n_choice - 1]
  if (h_max - h_min < diff):
    diff = h_max - h_min

print(diff)

Measured memory_bytes: 8280
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> v(5);
    rep(i,5) cin >> v[i];
    int min = 1000;

    do {  
        int time = 0;
        for (int i = 0; i < v.size(); i++){
            if(time % 10 != 0){
                time += (10 - time % 10);
            }
            time += v[i];
        }
        if(min > time) min = time;
    } while (next_permutation(v.begin(), v.end()));

    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<fstream>
#include<queue>
using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}
int main()
{
	ll();

	int i = 0, j = 0;
	char arr[100][100];
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		
			cin>>arr[i][j];
		
	}
	while (i < 3 && j < 3)
	{
		cout<<arr[i++][j++];
	}
	cout << endl;
}

Measured memory_bytes: 3508
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e16;
const double EPS=1e-8;
const ll mod = 1000000007;


int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	for(ll i1=0;i1<n;i1++){
		ll temp;
		cin>>temp;
		a.push_back(temp);
	}
	ll *odd_sum=new ll[n];
	ll *even_sum=new ll[n];
	odd_sum[0]=0;
	even_sum[0]=a[0];
	for(ll i1=1;i1<n;i1++){
		if(i1%2==0){
			even_sum[i1]=even_sum[i1-1]+a[i1];
			odd_sum[i1]=odd_sum[i1-1];
		}else{
			even_sum[i1]=even_sum[i1-1];
			odd_sum[i1]=odd_sum[i1-1]+a[i1];
		}
	}

	if(n<=3){
		cout<<*max_element(a.begin(),a.end())<<endl;
		return 0;
	}
	if(n%2==0){
		ll ans=max(odd_sum[n-1],even_sum[n-2]);
		for(ll i1=0;i1<n-3;i1++){
			if(i1%2==0&&even_sum[i1]+odd_sum[n-1]-odd_sum[i1+2]>ans){
				ans=even_sum[i1]+odd_sum[n-1]-odd_sum[i1+2];
			}
		}
		cout<<ans<<endl;
	}else{
		//all even

		ll ans=-INF;
		for(ll i1=0;i1<n;i1++){
			if(i1%2==0){
				ll temp = even_sum[n-1]-a[i1];
				if(temp>ans){
					ans=temp;
				}
			}
		}
		ll *middle_sum=new ll[n];
		middle_sum[0]=0;
		for(ll i1=2;i1<n;i1++){
			if(i1%2==0){
				middle_sum[i1]=max(even_sum[i1-2]-odd_sum[i1],middle_sum[i1-2]);
			}
		}
		for(ll i1=2;i1<n-2;i1++){
			ll temp_ans;
			if(i1%2==1){
				temp_ans = middle_sum[i1-3]+odd_sum[i1]-even_sum[i1+2]+even_sum[n-1];
				if(temp_ans>ans){
					ans=temp_ans;
				}
			}

		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 9576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> v(n+1,0);
  int l,r;
  for(int i=0;i<m;i++){
    cin >> l >> r;
    v[--l]++;
    v[r]--;
  }
  for(int i=1;i<n;i++){
      v[i]+= v[i-1];
  }
  int ans = 0;
  for(int i=0;i<n;i++) ans += (v[i]==m?1:0);
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, m, k;
  cin >> n >> m;
  vector<bitset<10>> a(m);
  vector<int> c(m);
  rep(i,m)
  {
    cin >> k;
    int b;
    bitset<10> bs;
    rep(j,k)
    {
      cin >> b;
      bs.set(b-1);
    }
    a[i] = bs;
  }
  rep(i,m)
  {
    cin >> c[i];
  }
  int sum = 0;
  for (int bit = 0; bit < (1 << n); ++bit) {
    rep(i,m)
    {
      if (c[i] != (int) (a[i] & (bitset<10> ) bit).count() % 2) {
        sum--;
        break;
      }
    }
    sum++;
  }
  cout << sum;
}

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

int main() {
    string s;
    cin >> s;
    int ans;
    for (int i = s.size() - 2; i >= 1; i--) {
        if ((i + 1) % 2 != 0) {
            continue;
        }

        bool is_evenstr = true;
        for (int j = 0; j < (i + 1) / 2; j++) {
            if (s[j] != s[j + (i + 1) / 2]) {
                is_evenstr = false;
                break;
            }
        }
        if (is_evenstr == true) {
            ans = i + 1;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
  
int main() {
  int N;
  double p;
  cin >> N;

  if(N%2 == 0){
    p = (float)(N/2)/N;
  } else if(N%2 != 0) {
    p = (float)(N/2+1)/N;
  }
  cout << p;
 }

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define pw(x) (1LL << (x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    cout << max(A * B, C * D) << '\n';

    return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;



int main() {
    li n;
    cin >> n;
    li res = 0;
    repp(i, 1, n+1) {
        if (i % 3 > 0 && i % 5 > 0) {
            res += i;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int main() {
  int a, b, c=0;
  int N;
  cin >> N;
  vector<int> p(N), q(N), v(N);
  for(int i=0; i<N;i++){
    cin >> p[i];
    v[i] = i+1;
  }
  for(int i=0; i<N; i++) cin >> q[i];
  do{
    c++;
    if(p==v) a = c;
    if(q==v) b = c;
  }while(next_permutation(v.begin(), v.end()));
  cout << abs(a-b) << endl;
  return 0;
}

Measured memory_bytes: 3520
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	var n int
	fmt.Scan(&n)

	type point struct{ x, y int }
	rs := make(map[point]bool)
	for i := 0; i < n; i++ {
		x, y := scanInt(), scanInt()
		rs[point{x, y}] = true
	}

	bs := make([]point, n)
	for i := range bs {
		bs[i].x, bs[i].y = scanInt(), scanInt()
	}

	sort.Slice(bs, func(i, j int) bool { return bs[i].x < bs[j].x })
	ans := 0
	for _, b := range bs {
		ps := make([]point, 0, n)
		for r := range rs {
			if r.x < b.x && r.y < b.y {
				ps = append(ps, r)
			}
		}

		if len(ps) > 0 {
			sort.Slice(ps, func(i, j int) bool { return ps[i].y > ps[j].y })
			delete(rs, ps[0])
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2008
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int x, y;
int a[10000];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> x>>y;
    int a[7]={1,3,5,7,8,10,12};
    int b[4]={4,6,9,11};
    for(int i=0;i<7;i++){
        if(x==a[i]){
            for(int j=0;j<7;j++){
                if(y==a[j]){
                    yes;
                    return 0;
                }
            }
            no;
            return 0;
        }
    }
    for(int i=0;i<4;i++){
        if(x==b[i]){
            for(int j=0;j<4;j++){
                if(y==b[j]){
                    yes;
                    return 0;
                }
            }
            no;
            return 0;
        }
    }
    no;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;cin>>N;
    int A[2][110],sum[2][110];
    sum[0][0]=0;
    for(int i=1;i<=N;i++){
        cin>>A[0][i];
        sum[0][i]=sum[0][i-1]+A[0][i];
    }
    for(int i=1;i<=N;i++)
        cin>>A[1][i];
    sum[1][N+1]=0;
    for(int i=1;i<=N;i++)
        sum[1][N+1-i]=sum[1][N+2-i]+A[1][N+1-i];
    
    int ans=0;
    for(int i=1;i<=N;i++)
        ans=max(ans,sum[0][i]+sum[1][i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256