akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define int long long

typedef struct {
	int *array;
	int N;
}stack;

stack *make_stack(int maxN){
	stack *s = (stack *)malloc(sizeof(stack));
	s->array = (int *)malloc(sizeof(int) * maxN);
	s->N = 0;
	return s;
}

int element_num_stack(stack *s){
	return s->N;
}

void add_data_stack(int val, stack *s){
	s->array[s->N] = val;
	s->N++;
}

int take_data_stack(stack *s){
	if(s->N == 0){
		printf("no data in the stack\n");
	}
	s->N--;
	return s->array[s->N];
}

int look_data_stack(stack *s){
	if(s->N == 0){
		printf("no data in the stack\n");
	}
	else{
		return s->array[s->N - 1];
	}
}

void flush_stack(stack *s){
	s->N = 0;
}

int max(int a, int b){
	return a >= b ? a : b;
}

signed main(){
	int N, i, j, ans = 0, garbage;
	scanf("%lld", &N);
	int *a = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &a[i]);
	}
	int *L = (int *)malloc(sizeof(int) * N);
	int *R = (int *)malloc(sizeof(int) * N);
	stack *sL = make_stack(N);
	stack *sR = make_stack(N);
	for(j = 0; j < N; j++){
		while(1){
			if(element_num_stack(sL) == 0){
				L[j] = 0;
				break;
			}
			else if(a[j] > a[look_data_stack(sL)]){
				L[j] = look_data_stack(sL) + 1;
				break;
			}
			garbage = take_data_stack(sL);
		}
		add_data_stack(j, sL);
	}
	flush_stack(sL);
	for(j = N - 1; j >= 0; j--){
		while(1){
			if(element_num_stack(sR) == 0){
				R[j] = N - 1;
				break;
			}
			else if(a[j] > a[look_data_stack(sR)]){
				R[j] = look_data_stack(sR) - 1;
				break;
			}
			garbage = take_data_stack(sR);
		}
		add_data_stack(j, sR);
	}
	flush_stack(sR);
	for(j = 0; j < N; j++){
		ans += a[j] * (j - L[j] + 1) * (R[j] - j + 1);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6400
#include<iostream>
using namespace std;
int main(){
	int mon,day,week;
	while(1){
		cin>>mon>>day;
		if(mon==0)break;
		switch(mon){
			case 1:
			mon=0;
			break;
			case 2:
			mon=31;
			break;
			case 3:
			mon=60;
			break;
			case 4:
			mon=91;
			break;
			case 5:
			mon=121;
			break;
			case 6:
			mon=152;
			break;
			case 7:
			mon=182;
			break;
			case 8:
			mon=213;
			break;
			case 9:
			mon=244;
			break;
			case 10:
			mon=274;
			break;
			case 11:
			mon=305;
			break;
			case 12:
			mon=335;
			break;
		}
		week=(mon+day)%7;
		switch(week){
		    case 1:
			cout<<"Thursday"<<endl;
			break;
			 case 2:
			cout<<"Friday"<<endl;
			break;
			 case 3:
			cout<<"Saturday"<<endl;
			break;
			 case 4:
			cout<<"Sunday"<<endl;
			break;
			 case 5:
			cout<<"Monday"<<endl;
			break;
			 case 6:
			cout<<"Tuesday"<<endl;
			break;
			 case 0:
			cout<<"Wednesday"<<endl;
			break;
		}
	}
	return 0;
}

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

int main() {
string S,S1,S2;
cin>>S;
string Ans="Yes";
int N=S.size();
  for(int i=0;i<(N-1)/2;i++){S1+=S.at(i);}
  for(int i=(N+1)/2;i<N;i++){S2+=S.at(i);}
  
  for(int i=0;i<N;i++){if(S.at(i)!=S.at(N-1-i)){Ans="No";break;}}
  N=S1.size();
  for(int i=0;i<N;i++){if(S1.at(i)!=S1.at(N-1-i)){Ans="No";break;}}
  N=S2.size();
  for(int i=0;i<N;i++){if(S2.at(i)!=S2.at(N-1-i)){Ans="No";break;}}
  
  cout<<Ans<<endl;
}

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

using namespace std;

struct node
{
    int x,e;
}h[1200];

bool cmp(node a,node b)
{
    if(a.e > b.e) return true;
    else return false;
}

int main()
{
   int n,i,t,a,num;
   double m,k = 1e9;
   cin >> n;
   cin >> t >> a;
   for(i = 0; i < n; i ++)
   {
       cin >> h[i].e;
       h[i].x = i + 1;
   }
   sort(h,h+n,cmp);
   for(i = 0; i < n; i ++)
   {
       m = abs(t - h[i].e * 0.006 - a);
       if(k > m)
       {
           k = m;
           num = h[i].x;
       }
   }
   cout << num << endl;
}

Measured memory_bytes: 256
N = int(input())

def digit_sum(num):
  digit_sum = 0
  while(num > 0):
    digit_sum += num % 10
    num = int(num / 10)
  return digit_sum

min_num = 100000
for A in range(1, N):
  B = N - A
  digit_num = digit_sum(A)
  digit_num += digit_sum(B)
  if digit_num < min_num:
    min_num = digit_num

print(min_num)

Measured memory_bytes: 9124
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n;
  cin>>n;
  int a[n];
  rep(i,n) cin>>a[i];
  map<int, int> m;
  rep(i,n) {
    m[a[i]]++;
  }
  int ans = 0;
  rep(i,n) {
    if(m[a[i]] < a[i]) {
      ans += m[a[i]];
      m[a[i]] = 0;
    } else if(m[a[i]] > a[i]) {
      ans += m[a[i]] - a[i];
      m[a[i]] = a[i];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5120
import numpy as np
n = int(input())
a = list(map(int,input().split()))+[10**7]
a.sort()
e = np.zeros(10**6+1)
ans = 0
for i in range(n):
    if e[a[i]] == 0:
        e[::a[i]] = 1
        if a[i] != a[i+1]:
            ans += 1
print(ans)

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

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int c=0;
  int d=0;
  int e=0;
  for(int i=0;i<n;i++){
 		int f;
    cin >> f;
    if(f<=a){
      c++;
    }  
    else if (f > a && f <= b){
      d++;
    }  
    else if(f > b){
      e++;
    }  
  }  
  cout << min (c,min(d,e)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};

int main(){
  int n,ans=0;
  cin >> n;
  rep(i,n){
    rep(j,n){
      rep(k,n){
        ans+=gcd(gcd(i+1,j+1),gcd(j+1,k+1));
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int[] heap = new int[h + 1];
		for (int i = 1; i <= h; i++)
			heap[i] = scan.nextInt();
		for (int i = 1; i <= h; i++) {
			System.out.print("node " + i + ": ");
			System.out.print("key = " + heap[i] + ", ");
			if (i / 2 > 0)
				System.out.print("parent key = " + heap[i / 2] + ", ");
			if (2 * i <= h)
				System.out.print("left key = " + heap[2 * i] + ", ");
			if (2 * i + 1 <= h)
				System.out.print("right key = " + heap[2 * i + 1] + ", ");
			System.out.println();
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 27528
//{{{
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
const int MOD = 1e9+7;
//}}}

typedef pair<int,int> PII;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
queue<PII> q;
int H, W;
char s[51][51];
int dist[51][51];

void f(int x, int y, int num){
	if(x < 0 || W <= x) return;
	if(y < 0 || H <= y) return;
	if(s[y][x] == '.' && dist[y][x] == 0){
		dist[y][x] = num + 1;
		q.emplace(x, y);
	}
}

int main(void){
	cin >> H >> W;
	rep(i, H) cin >> s[i];
	int total = 0;
	rep(i, H){
		rep(j, W){
			if(s[i][j] == '.') total++;
		}
	}

	q.emplace(0, 0);
	dist[0][0] = 1;
	while(!q.empty()){
		PII pos = q.front();
		q.pop();
		int x = pos.first;
		int y = pos.second;
		int num = dist[y][x];
		rep(i, 4) f(x + dx[i], y + dy[i], num);
	}
	if(dist[H - 1][W - 1] == 0){
		puts("-1");
	}else{
		printf("%d\n", total - dist[H - 1][W - 1]);
	}
	return 0;
}


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

int A, B, C, n;
vector<int> l;
int rec(int a, int b, int c, int cur){
  if(cur == n){
    if(a <= 0 || b <= 0 || c <= 0) return 100000000;
    return abs(a - A) + abs(b - B) + abs(c - C);
  }
  int res = INT_MAX;
  res = min(res, rec(a + l[cur], b, c, cur + 1) + 10);
  res = min(res, rec(a, b + l[cur], c, cur + 1) + 10);
  res = min(res, rec(a, b, c + l[cur], cur + 1) + 10);
  res = min(res, rec(a, b, c, cur + 1));
  return res;
}

int main(){
  cin >> n >> A >> B >> C;
  l.resize(n);
  rep(i, n) cin >> l[i];
  int ans = rec(0, 0, 0, 0);
  cout << ans - 30 << endl;
  
}

Measured memory_bytes: 256
a = sorted(list(map(int, input().split(" "))))
count = 0
a[0] += a[2] - a[1]
count += a[2] - a[1]

if (a[2] - a[0]) % 2 == 0:
  print(count +  ((a[2] - a[0]) // 2))
else:
  print(count +  ((a[2] - a[0]) // 2) + 2)

Measured memory_bytes: 9044
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string o, e;
	cin >> o >> e;
	rep(i,e.size()){
		cout << o[i] << e[i];
	}
	if(o.size() > e.size()) cout << o[o.size()-1];
	cout << endl;
	return 0;
}

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

#define SIZE 5010

long long int d[SIZE], pfx[SIZE];
int pfx1[SIZE];

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

    int len, qNum;
    cin >> len >> qNum;
    for (int i = 0; i < len; i++)
        cin >> d[i];

    while (qNum--) {
        long long int num, fst, mod;
        cin >> num >> fst >> mod;
        fst %= mod;
        
        pfx[0] = d[0] % mod;
        pfx1[0] = (d[0] % mod == 0); 
        for (int i = 1; i < len; i++) {
            pfx[i] = pfx[i - 1] + (d[i] % mod);
            pfx1[i] = pfx1[i - 1] + (d[i] % mod == 0);
        }
        
        long long int cyc = max(0ll, (num - 1) / len);
        long long int ans = cyc * pfx1[len - 1] + ((num - 1) % len == 0 ? 0 : pfx1[(num - 2 + len) % len]);
        long long int last = fst + cyc * pfx[len - 1] + ((num - 1) % len == 0 ? 0 : pfx[(num - 2 + len) % len]);
        ans += last / mod - fst / mod;
        cout << num - ans - 1 << '\n';
    }
    
    return 0;
}

Measured memory_bytes: 512
n = int(raw_input())
d1 = raw_input()
d2 = raw_input()

ans = 3
flag = 0
for i in range(n):
    if flag == -1:
        flag = 1
        continue
    if i < n-1 and d1[i] == d1[i+1]:
        if flag == 1:
            ans *= 3
        elif flag in [0, 2]:
            ans *= 2
        flag = -1
    elif d1[i] == d2[i]:
        if flag in [0, 1]:
            ans *= 1
        else:
            ans *= 2
        flag = 2
    else:
        'error'
print ans % 1000000007

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

#define inf 9023372036854775807
/* Who reading it is a gay*/

using namespace std;

long long dp[2005][2005];

long long b[2 * 2005][2 * 2005];
long long ib[2 * 2005];
long long ich[2 * 2005];
long long ch[2 * 2005][2 * 2005];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    long long n;
    cin >> n;

    long long a[n * 2];

    bool c[n * 2];

    char __u_u_u_u_u_u_fkmwefnwehufevyfg___gwfjwekfniwe___fijekflmrjkghsdjdfewbjjdjwefnjewknnjwcbhbcbwnu3nj3nunu3nu3n3fonejwce43y89tuyg4uifhw7r8fuiheyrgu;
    for (long long i = 0; i < n * 2; ++i) {
        cin >> __u_u_u_u_u_u_fkmwefnwehufevyfg___gwfjwekfniwe___fijekflmrjkghsdjdfewbjjdjwefnjewknnjwcbhbcbwnu3nj3nunu3nu3n3fonejwce43y89tuyg4uifhw7r8fuiheyrgu;
        if (__u_u_u_u_u_u_fkmwefnwehufevyfg___gwfjwekfniwe___fijekflmrjkghsdjdfewbjjdjwefnjewknnjwcbhbcbwnu3nj3nunu3nu3n3fonejwce43y89tuyg4uifhw7r8fuiheyrgu == 'W') {
            c[i] = false;
        } else {
            c[i] = true;
        }

        cin >> a[i];
    }

    long long bb = 0, chh = 0;


    for (long long i = 0; i < n * 2; ++i) {
        long long h = 0, l = 0;
        vector <long long> hb;
        vector <long long> hch;
        for (long long j = i; j >= 0; --j) {
            if (c[j]) {
                hch.push_back(a[j]);
            }
            if (!c[j]) {
                hb.push_back(a[j]);
            }
        }

        sort(hch.begin(), hch.end());
        sort(hb.begin(), hb.end());

        for (long long j = 0; j <= n; ++j) {
            b[i][j] = hb.end() - upper_bound(hb.begin(), hb.end(), j);
            ch[i][j] = hch.end() - upper_bound(hch.begin(), hch.end(), j);
        }

        if (c[i]) {
            ich[a[i]] = i;
        } else {
            ib[a[i]] = i;
        }
    }


    dp[0][1] = ib[1];
    dp[1][0] = ich[1];
    for (long long i = 0; i <= n; ++i) {
        for (long long j = 0; j <= n; ++j) {
            if (!i && !j) {
                continue;
            }

            if (!i && j == 1) {
                continue;
            }

            if (i == 1 && !j) {
                continue;
            }
            long long jj = inf, jjj = inf;
            if (i) {
                jj = dp[i - 1][j] + ch[ich[i]][i] + b[ich[i]][j];
            }
            if (j) {
                jjj = dp[i][j - 1] + ch[ib[j]][i] + b[ib[j]][j];
            }
            dp[i][j] = min(jj, jjj);
        }
    }

    cout << dp[n][n] << '\n';








    return 0;
}

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

constexpr int INF = 1 << 30;

struct Info {
    int h;
    int w;
    int dist;
};

int main()
{
    while (true) {
        int w, h;
        cin >> w >> h;
        if (w == 0 and h == 0) {
            break;
        }
        vector<vector<bool>> yoko(h, vector<bool>(w - 1, true));  // (h,w)->(h,w+1)
        vector<vector<bool>> tate(h - 1, vector<bool>(w, true));  // (h,w)->(h+1, w)
        for (int i = 0; i < 2 * h - 1; i++) {
            if (i % 2 == 0) {
                for (int j = 0; j < w - 1; j++) {
                    int c;
                    cin >> c;
                    yoko[i / 2][j] = (c == 0);
                }
            } else {
                for (int j = 0; j < w; j++) {
                    int c;
                    cin >> c;
                    tate[i / 2][j] = (c == 0);
                }
            }
        }
        vector<vector<bool>> visited(h, vector<bool>(w, false));
        queue<Info> q;
        q.push(Info{0, 0, 1});
        visited[0][0] = true;
        int distance = INF;
        while (not q.empty()) {
            const Info p = q.front();
            q.pop();
            if (p.h == h - 1 and p.w == w - 1) {
                distance = p.dist;
                break;
            }
            if (p.dist > h * w) {
                break;
            }
            if (p.h != h - 1 and tate[p.h][p.w] and (not visited[p.h + 1][p.w])) {
                visited[p.h + 1][p.w] = true;
                q.push(Info{p.h + 1, p.w, p.dist + 1});
            }
            if (p.h != 0 and tate[p.h - 1][p.w] and (not visited[p.h - 1][p.w])) {
                visited[p.h - 1][p.w] = true;
                q.push(Info{p.h - 1, p.w, p.dist + 1});
            }
            if (p.w != w - 1 and yoko[p.h][p.w] and (not visited[p.h][p.w + 1])) {
                visited[p.h][p.w + 1] = true;
                q.push(Info{p.h, p.w + 1, p.dist + 1});
            }
            if (p.w != 0 and yoko[p.h][p.w - 1] and (not visited[p.h][p.w - 1])) {
                visited[p.h][p.w - 1] = true;
                q.push(Info{p.h, p.w - 1, p.dist + 1});
            }
        }

        if (distance != INF) {
            cout << distance << endl;
        } else {
            cout << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3168
#include<iostream>

using namespace std;

int main(){
    int N; 
    cin >> N;
    int A1[N], A2[N];

    int below = 0;
    for(int i = 0; i < N; i++) cin >> A1[i];

    for(int i = 0; i < N; i++){
        cin >> A2[i];
        below += A2[i];
    }
    int ans = 0;
    int high = 0;
    for(int i = 0; i < N; i++){
        high += A1[i];
        int tmp = high + below;
        if(tmp >= ans)ans = tmp;
        below -= A2[i];
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
using namespace std;
vector<int> dp(1e6);
vector<int> dp2(1e6);
int num[200];
void solve(){
    for(int i=1;i<200;i++){
        for(int j=0;j<1e6;j++){
            if(j>=num[i]){
                dp[j]=min(dp[j-num[i]]+1,dp[j]);
            }
        }
    }
    for(int i=1;i<200;i++){
        if(num[i]%2==0) continue;
        for(int j=0;j<1e6;j++){
            if(j>=num[i]){
                dp2[j]=min(dp2[j-num[i]]+1,dp2[j]);
            }
        }
    }
}
int main(){
    fill(dp.begin(),dp.end(),INF);
    fill(dp2.begin(),dp2.end(),INF);
    dp[0]=0;
    dp2[0]=0;
    for(int i=1;i<200;i++){
        num[i]=i*(i+1)*(i+2)/6;
    }
    int n;
    solve();
    while(cin>>n,n){
        cout<<dp[n]<<" "<<dp2[n]<<endl;
    }
    
    return 0;
}



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

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      mp[a]++;
    }
  }

  int ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    if (itr -> second == n) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#define int long long int
int mod=1e9+7;
#define p_b push_back
#define p_f push_front
#define P_f pop_front
#define P_b pop_back
#define len() length()
#define sz() size()
#define u_b upper_bound
#define l_b lower_bound
#define ins insert
#define str string 
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define ld long double
#define db double
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define F first
#define S second
#define T third
#define endl "\n"
using namespace std;
typedef map<int,int> Map;
typedef pair<int,int> pr;
typedef vector<int> vec;
const int INF = 1e18;
const int MAX =1e6;
int power(int a,int b)
{   
    if(b==0)
    return 1;
    int num=1;
    int m=mod;
    while(b!=1)
    { 
        if(b%2==0)
        { 
            a*=a;
            a%=m;
            b/=2;
        }
        else
        { 
            num*=a;
            num%=m;
            b--;
        }
        
    }
    return (a*num)%m;
}
void solve()
{
    int n;
    cin>>n;
    Map mp;
    for(int i=1;i<=200;i++)
    {
        for(int j=1;j<=200;j++)
        {
            for(int k=1;k<=200;k++)
            {
                 int temp=i*i+j*j+k*k+i*j+j*k+k*i;
                 if(temp<=10000)
                 mp[temp]++;

            }
        }
    }
    for(int i=1;i<=n;i++)
    cout<<mp[i]<<endl;
}
int32_t main()
{    
    fio;
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {   
        solve();
    }
    return 0;
}

Measured memory_bytes: 4196
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <stdlib.h>
#include <queue>
#include <set>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
  ll n;
  cin >> n;
  vector<ll> base = {};
  vector<ll> ps = {};
  vector<ll> qs = {};

  for (auto i = 1; i <= n; i++)
  {
    ll p;
    cin >> p;
    ps.push_back(p);
  }

  for (auto i = 1; i <= n; i++)
  {
    ll q;
    cin >> q;
    qs.push_back(q);
  }

  for (auto i = 1; i <= n; i++)
  {
    base.push_back(i);
  }

  int p_pos, q_pos;
  int cycle = 1;

  do
  {
    if (equal(base.begin(), base.end(), ps.begin()))
    {
      p_pos = cycle;
    }

    if (equal(base.begin(), base.end(), qs.begin()))
    {
      q_pos = cycle;
    }
    cycle++;
  } while (next_permutation(base.begin(), base.end()));

  cout << abs(p_pos - q_pos) << endl;
  return 0;
}


Measured memory_bytes: 256
#create date: 2020-04-12 21:02

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n = ni()
    nsum = n * (n +1) // 2
    div3 = (3 + (n//3)*3) * (n // 3) //2
    div5 = (5 + (n//5)*5) * (n// 5) //2
    div15 = (15 + (n//15)*15) * (n // 15) //2
    print(nsum - div3 - div5 + div15)

if __name__ == "__main__":
    main()

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


using namespace std;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    const int modder = 1e9 + 7;
    char grid[1005][1005];
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; ++i){
        cin >> grid[i];
    }
    vector<vector<int>> dp(H, vector<int> (W));
    dp[0][0] = 1;
    for(int row = 0; row < H; ++row){
        for(int col = 0; col < W; ++col){
            for(int row2 = row; row2 <= row + 1; ++row2){
                int col2 = col;
                if (row2 == row){
                    ++col2;
                }
                if (row2 < H && col2 < W && grid[row2][col2] == '.'){
                    dp[row2][col2]  = (dp[row][col] + dp[row2][col2]) % modder;
                }
            }
        }
    }
    cout << dp[H-1][W-1] << "\n";


}


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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define rep(i, n)   for (int i = 0; i < (n); i++)
#define sz(x)       (int)(x).size()
#define pb          push_back
#define eb          emplace_back
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int n, k;
    cin >> n >> k;
    vt<int> p(n), c(n);
    for (int& i : p) cin >> i, i--;
    for (int& i : c) cin >> i;

    vt<bool> vis(n);
    vt<vt<int>> v;
    rep(i, n) {
        if (vis[i]) continue;
        v.pb({c[i]});
        int cur = p[i];
        vis[i] = true;
        while (cur != i) {
            vis[cur] = true;
            v.back().pb(c[cur]);
            cur = p[cur];
        }
    }

    ll mx = -(1 << 30);
    for (auto& i : v) {
        ll sum = accumulate(all(i), 0ll);
        i.resize(sz(i) * 2);
        copy(i.begin(), i.begin() + sz(i) / 2, i.begin() + sz(i) / 2);
        for (int j = 1; j <= min(sz(i) / 2, k); j++) {
            int l = 0, r = 0;
            ll cur = 0;
            while (r < j) {
                cur += i[r++];
            }
            mx = max({cur, cur + (k - j) / (sz(i) / 2) * sum, mx});
            while (r != sz(i)) {
                cur -= i[l++];
                cur += i[r++];
                mx = max({cur, cur + (k - j) / (sz(i) / 2) * sum, mx});
            }
        }
    }

    cout << mx;
}


Measured memory_bytes: 3792
#include<stdio.h>
int ha(int a){
  switch(a){
    case 1:
    case 3:
    case 5:
    case 7:
    case 8:
    case 10:
    case 12:
        return 0;
        break;
    case 4:
    case 6:
    case 9:
        return 1;
        break;
    default:
        return 2;
        break;
  }
}

int main(){
  int x,y;
  scanf("%d %d",&x,&y);
  if(ha(x) == ha(y)){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,-1,0,1},dy={1,0,-1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n),b(n),c(n);
	rep(i,n){
		cin >> a.at(i);
		a.at(i)--;
	}
	rep(i,n) cin >> b.at(i);
	rep(i,n-1) cin >> c.at(i);
	int ans = b.at(a.at(0)), k = a.at(0);
	rep(i,n-1){
		ans += b.at(a.at(i+1));
		if(k == a.at(i+1) - 1) ans += c.at(k);
		k = a.at(i+1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

"""
左端の順番を固定して考えた.(A,B,Cの順とする)
n : Aの長さ, m : Bの長さ, l : Cの長さ
AB : Aを固定した時のBが一致する先頭位置
    ⇒ Aの先頭からAの末尾+1の位置までn+1箇所考える
AC : Aを固定した時のCが一致する先頭位置
    ⇒ Aの先頭からAの末尾+1の位置までn+1箇所考える
BC : Bを固定した時のCが一致する先頭位置
　　⇒ Bの先頭からBの末尾+1の位置までm+1箇所考える + nがmより大きい場合はBとCが離れているかもしれないので, Aの末尾+1まで考える
　　⇒ Bの先頭からmax(n,m)+1の位置まで考える
"""

def compare(a, b):
    return a == '?' or b == '?' or a == b

def solve(A, B, C):
    n, m, l = len(A), len(B), len(C)
    AB, AC, BC = [True]*(n+1), [True]*(n+1), []
    for i in range(n):
        for j in range(m):
            if i + j >= n:
                continue
            if not compare(A[i + j], B[j]):
                AB[i] = False
                break
    
    for i in range(n):
        for j in range(l):
            if i + j >= n:
                continue
            if not compare(A[i + j], C[j]):
                AC[i] = False
                break

    for i in range(max(n,m)+1):
        for j in range(l):
            if i + j >= m:
                continue
            if compare(B[i + j], C[j]):
                continue
            break
        else:
            BC.append(i)

    res = n + m + l
    for i in range(n+1):
        if AB[i]:
            for j in BC:
                if i + j >= n:
                    res = min(res, max(n, i + m, i + j + l))
                elif AC[i + j]:
                    res = min(res, max(n, i + m, i + j + l))
    return res

def main():
    a = input()
    b = input()
    c = input()
    ans = min(solve(a,b,c),solve(a,c,b),solve(b,a,c),solve(b,c,a),solve(c,a,b),solve(c,b,a))
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49776
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct UnionFind
{
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<int> childN;
	ll r = 0;

	UnionFind(int N) : par(N), childN(N)
	{ 
		//最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) 
			par[i] = i, childN[i] = 1;
	}

	int root(int x) 
	{ 
		// データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) 
	{
		// xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		r -= childN[rx] * (childN[rx] - 1) / 2;
		r -= childN[ry] * (childN[ry] - 1) / 2;
		childN[ry] += childN[rx];
		childN[rx] = 0;
		r += childN[ry] * (childN[ry] - 1) / 2;
	}

	bool same(int x, int y)
	{
		// 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//	for priority queue
//	priority_queue<ipair, vector<ipair>, greater<ipair>>
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };

using xpair = pair<int, int>;
bool operator>(const xpair &a, const xpair &b) { return a.second > b.second || (a.second == b.second && a.first > b.first); };
bool operator<(const xpair &a, const xpair &b) { return a.second < b.second || (a.second == b.second && a.first > b.first); };
bool operator==(const xpair &a, const xpair &b) { return a.first== b.first; };

int main()
{
	char c;
	cin >> c;
	if (c >= 'a' && c <= 'z')
		printf("a");
	else
		printf("A");

	return 0;
}


Measured memory_bytes: 3024
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	LL pos[5];
	rep(i, 0, 5)	pos[i] = scanLong();
	sll(k);
	rep(i, 0, 5) {
		rep(j, 0, 5) {
			if(abs(pos[i]-pos[j]) > k) {
				puts(":(");
				return 0;
			}
		}
	}
	puts("Yay!");
}


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

#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
using namespace std;
typedef long long ll;


string s;
int mx, c;

int main() {
	cin >> s;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'A' || s[i] == 'G' || s[i] == 'T' || s[i] == 'C') {
			++c;
			mx = max(mx, c);
		}
		else
			c = 0;
	}
	cout << mx << endl;
	return 0;
}

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

const int INF = INT_MAX;

int main() {

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

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

    vector<int> dp(n, INF);

    dp[0] = 0;
    dp[1] = abs(step[0] - step[1]);


    for(int i = 2; i < n; ++i) {

        for(int j = 1; j <= k; ++j) {

            if(j > i)
                break;

            int a = dp[i - j] + abs(step[i] - step[i - j]);
            dp[i] = min(dp[i], a);


        }
    }
    
    cout << dp[n - 1] << endl;

    return 0;

}

Measured memory_bytes: 1024
import sys
input=sys.stdin.buffer.readline
inputs=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
n=int(input())
a=tuple(map(int,input().split() ))
from itertools import accumulate
b=[0]+list(accumulate(a))
xor=[0]
ar=0
for i in a:ar^=i;xor.append(ar)
right=0
ub=-1
ans=0
for left in range(n):
    while right<n and xor[right+1]^xor[left]==b[right+1]-b[left]:
        right+=1
    #出来上がるのは半開区間[left,right)
    if xor[right]^xor[left]==b[right]-b[left]:
        ans+=(right-left)*(right-left-1)//2
        if ub>left:
            ans-=(ub-left)*(ub-left-1)//2
        ub=right
    if right==left:right+=1
    
print(ans+n)

Measured memory_bytes: 113256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cout<<#x<<" = "<<(x)<<endl;
#define debug2(x,y) cout<<"("<<#x<<","<<#y<<") = ("<<(x)<<","<<(y)<<")\n"

#define LIMIT 1000000007 //10^9+7

namespace /* combination.cpp */{
  namespace /* modinv.cpp */{
    namespace /* extGCD.cpp */{
      //ax + by = gcd(a, b)を満たすx, yを参照渡しから入れる
      long long extGCD(long long a, long long b, long long &x, long long &y) {
          if (b == 0) {
              x = 1;
              y = 0;
              return a;
          }
          long long d = extGCD(b, a%b, y, x);
          y -= a/b * x;
          return d;
      }
    }

    /*
    mod pでの a の逆元 x
    ax = 1 mod p
    ax-1がpで割り切れるので
    ax + py = 1 の解 x をとる
    aとpは互いに素であること
    */
    long long modinv(long long a, long long p){
      long long x, y;
      extGCD(a, p, x, y);
      return (x>0? x: x+p);
    }
  }

  long long l_fac(long long n){
    if(n<0) return -1;
    long long ans = 1;
    for(long long i=1; i<=n; i++){
      ans *= i;
      ans %= LIMIT;
    }
    return ans;
  }

  long long l_nPr(long long n, long long r){
    long long ans = 1;
    for(long long i=0; i<r; i++){
      ans *= (n-i);
      ans %= LIMIT;
    }
    return ans;
  }

  long long l_nCr(long long n, long long r){
    if(r > n/2) r = n-r;
    return l_nPr(n, r) * modinv(l_fac(r), LIMIT) % LIMIT;
  }
}

namespace /* COMfast.cpp */{
  #define COMMAX 510000
  long long fac[COMMAX], finv[COMMAX], inv[COMMAX];
  // テーブルを作る前処理
  void COMinit() {
      fac[0] = fac[1] = 1;
      finv[0] = finv[1] = 1;
      inv[1] = 1;
      for (int i = 2; i < COMMAX; i++){
          fac[i] = fac[i - 1] * i % LIMIT;
          inv[i] = LIMIT - inv[LIMIT%i] * (LIMIT / i) % LIMIT;
          finv[i] = finv[i - 1] * inv[i] % LIMIT;
      }
  }

  // 二項係数計算
  long long COM(int n, int k){
      if (n < k) return 0;
      if (n < 0 || k < 0) return 0;
      return fac[n] * (finv[k] * finv[n - k] % LIMIT) % LIMIT;
  }
}


//(sx,sy)から(gx,gy)へいく組み合わせ
ll ways(ll sx, ll sy, ll gx, ll gy){
  ll X = abs(gx - sx);
  ll Y = abs(gy - sy);
  return COM(X+Y, X);
}

//中継点(cx,cy)を通る組み合わせ
ll ways_by_checkpoint(ll sx, ll sy, ll cx, ll cy, ll gx, ll gy){
  ll w1 = ways(sx,sy,cx,cy);
  ll w2 = ways(cx,cy,gx,gy);
  //debug2(w1,w2);
  return w1 * w2;
}

int main(){
  COMinit();
  int H,W,A,B;
  cin>>H>>W>>A>>B;
  ll ans = 0;
  int CH = H - A;
  int CW = B + 1;
  //debug2(CH,CW);
  while(CH>=1 && CW<=W){
    ll plus = ways_by_checkpoint(1,1,CH,CW,H,W);
    ans += plus;
    ans %= LIMIT;
    CH--;CW++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 12160
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("2100 2500 2700 2700");
            //2 2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("1100 1900 2800 3200 3200");
            //3 5
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("20");
            WillReturn.Add("800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990");
            //1 1
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        var CntDict = new Dictionary<int, int>();
        foreach (int EachA in AArr) {
            int TruncRate = DeriveTruncRate(EachA);
            if (CntDict.ContainsKey(TruncRate)) {
                CntDict[TruncRate]++;
            }
            else CntDict[TruncRate] = 1;
        }

        int Cnt1 = CntDict.Where(X => X.Key <= 2800).Count();

        int Cnt2;
        var Query = CntDict.Where(X => X.Key == 3200);
        if (Query.Any()) Cnt2 = Query.Sum(X => X.Value);
        else Cnt2 = 0;

        //色の種類数の最小値
        int MinCnt;
        if (Cnt1 > 0) MinCnt = Cnt1;
        else MinCnt = 1;

        //色の種類数の最大値
        int MaxCnt = Cnt1 + Cnt2;

        Console.WriteLine("{0} {1}", MinCnt, MaxCnt);
    }

    //切り捨てたレートを返す
    static int DeriveTruncRate(int pRate)
    {
        if (pRate <= 399) return 1;
        if (pRate <= 799) return 400;
        if (pRate <= 1199) return 800;
        if (pRate <= 1599) return 1200;
        if (pRate <= 1999) return 1600;
        if (pRate <= 2399) return 2000;
        if (pRate <= 2799) return 2400;
        if (pRate <= 3199) return 2800;
        return 3200;
    }
}


Measured memory_bytes: 13524
N = int(input())
A = [int(input()) for _ in range(N)]

ans = 0
for i in range(N-1):
    if A[i] % 2 == 0 or A[i+1] == 0:
        continue
    A[i] -= 1
    A[i+1] -= 1
    ans += 1

for i in A:
    ans += i // 2

print(ans)    
        

Measured memory_bytes: 7072
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            checked
            {
                var A = cin.ReadInt;
                var B = cin.ReadInt;
                var X = cin.ReadInt;

                if (A > X || A + B < X) WriteLine("NO");
                else WriteLine("YES");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; }}
        public void ReadIntArrays(long N, out int[] A, out int[] B, out int[] C) { A = new int[N]; B = new int[N]; C = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; C[i] = ReadInt; }}
        public void ReadLongArrays(long N, out long[] A, out long[] B) { A = new long[N]; B = new long[N]; for (long i = 0; i < N; ++i) { A[i] = ReadLong; B[i] = ReadLong; }}
    }
}


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

int main()
{
	int n, p[101], dp[101][101];
	cin >> n;
	for (int i = 1; i <= n; ++i)cin >> p[i - 1] >> p[i];
	for (int i = 1; i <= n; ++i)dp[i][i] = 0;
	
	for (int l = 2; l <= n; ++l)
	{
		for (int i = 1; i <= n - l + 1; ++i)
		{
			int j = i + l - 1;
			dp[i][j] = (1 << 21);
			for (int k = i; k < j; ++k){
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << dp[1][n] << endl;
	return 0;
}


Measured memory_bytes: 3124
package main

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

func solve() {
	n, q := getInt(), getInt()
	graph := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := getInt()-1, getInt()-1
		graph[a] = append(graph[a], b)
		graph[b] = append(graph[b], a)
	}

	operations := make([]int, n)
	for i := 0; i < q; i++ {
		p, x := getInt()-1, getInt()
		operations[p] += x
	}

	ans := make([]int, n)
	var dfs func(int, int, int)
	dfs = func(prev, now, sum int) {
		sum += operations[now]
		ans[now] += sum

		for _, next := range graph[now] {
			if next == prev {
				continue
			}

			dfs(now, next, sum)
		}
	}
	dfs(-1, 0, 0)

	for _, a := range ans {
		fmt.Fprintln(wr, a)
	}
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

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

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

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

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

int main(){
    int n;
    cin >> n;
    map<string,int> result;
    result["AC"]=0;
    result["WA"]=0;
    result["TLE"]=0;
    result["RE"]=0;
    
    rep(i,n){
        string tmp;
        cin >> tmp;
        ++result[tmp];
    }
    cout << "AC x " <<result["AC"] << "\n";
    cout << "WA x " <<result["WA"] << "\n";
    cout << "TLE x " <<result["TLE"] << "\n";
    cout << "RE x " <<result["RE"] << "\n";
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <vector>
#include <map>

using namespace std;

int main(){
  map<string,int> pls;
  map<string,int> sub;
  int N,M;
  int ans = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    string s;
    cin >> s;
    pls.count(s) != 0 ? pls[s]++ : pls[s] = 0;
  }
  cin >> M;
  for(int i = 0; i < M; i++){
    string s;
    cin >> s;
    sub.count(s) != 0 ? sub[s]++ : sub[s] = 0;
  }

  auto iter = pls.begin();
  while(iter != pls.end() ){
     int tmp;
     string key = iter -> first;
     if(sub.count(key) != 0) tmp = pls[key] + 1 - sub[key] - 1;
     else tmp = pls[key] + 1;
     ans = max(ans ,tmp);
     iter = next(iter, 1);
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	map<string, int> m;
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		string s;
		cin >> s;
		m[s]++;
	}
	cout << m.size();
	return 0;
}

Measured memory_bytes: 19244
#include <stdio.h>

int main(void) {
    int H;
    int W;
    int i;
    int n;
    while(1){
        scanf("%d%d",&H,&W);
        if(H==0 || W==0) break;
        for(i=1;i<=H;i++){
            for(n=1;n<=W;n++){
                if((i + n) % 2 == 1){
                    printf(".");
                }else{
                    printf("#");
                }
            }
                printf("\n");
        }
        printf("\n");
    }
   
	return 0;
}




Measured memory_bytes: 2100
N,K = map(int,input().split())
S = input()

A = [0]
B = [0]
for s in S:
  if s == '1':
    A[-1] += 1
  elif A[-1] != 0:
    A.append(0)
  if s == '0':
    B[-1] += 1
  elif B[-1] != 0:
    B.append(0)

ans = 0
c,d,e,f = 0,0,0,0

for i in range(min(len(A),len(B))):
  a = 0
  if i == 0:
    if S[0] == '1':
      c,d = sum(A[i:min(i + K + 1,len(A))]),sum(B[i:min(i + K,len(B))])
      a = c + d
    else:
      c,d = sum(A[i:min(i + K,len(A))]) , sum(B[i:min(i + K,len(B))])
      a = c + d
  else:
    if S[0] == '1':
      if i + K < len(A):
        c += A[min(i + K,len(A) - 1)] - A[i - 1]
        d += B[min(i + K - 1,len(B) - 1)] - B[i - 1]
        a = c + d
    else:
      if i + K <= len(A):
        c += A[min(i + K - 1,len(A) - 1)] - (0 if i == 1 else A[i - 2])
        d += B[min(i + K - 1,len(B) - 1)] - B[i - 1]
        a = c + d
  ans = max(ans,a)
print(ans)

Measured memory_bytes: 4528
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

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

  if (S.back() == 's') {
    S.push_back('e');
    S.push_back('s');
  }
  else {
    S.push_back('s');
  }

  cout << S << endl;

  return 0;
}


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

int main() {
	// your code goes here
	long long n,k,min=100000000,max=-100000000,sum=0;
	cin>>n;
	for(long long i=0;i<n;i++){
		cin>>k;
		if(k<min) min=k;
		if(k>max) max=k;
		sum=sum+k;
		
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1160
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        int total = int.Parse(ReadLine());
        int roop = total/4;
        int aaa = 0;
        for(int i=0;i<=roop;i++){
            for(int j=0;j<=roop;j++){
                int kei = (i*7) + (j*4);
                if(kei == total){
                    aaa++;
                    break;
                }
            }
        }
        if(aaa>0){
            WriteLine("Yes");
        }else{
            WriteLine("No");
        }
    }
}

Measured memory_bytes: 13140
import sys
from operator import itemgetter

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    AB = [None] * N
    for i in range(N):
        AB[i] = tuple(map(int, input().split()))

    AB.sort(key=itemgetter(0))
    ans = 0
    n_buy = 0
    for A, B in AB:
        if n_buy + B < M:
            n_buy += B
            ans += A * B
        else:
            ans += A * (M - n_buy)
            break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18072
#include <bits/stdc++.h>
using namespace std;
bool T=false;

int main(){
    int X,Y;cin>>X>>Y;
    for (int i = 0; i <= X; i++)
    {
        for (int j = 0; j <= X; j++)
        {
            if(i+j==X&&2*i+4*j==Y){
                T=true;
                break;
            }
        }
    }
    if(T)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3616