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

using namespace std;


void solve() {
    vector<int> prime;
    auto sieve = [&](int _n = 45000){
        vector<bool> is(_n+1, true);
        is[0] = is[1] = false;
        for (int p = 2; p*p <= _n; p++) {
            if (is[p]) {
                for (int i = p*p; i <= _n; i += p) {
                    is[i] = false;
                }
            }
        }
        for (int i = 2; i <= _n; i++) {
            if (is[i])
                prime.emplace_back(i);
        }
    };
    sieve();
    vector<int> candi;
    for (int p: prime){
        if (p%5==1)candi.emplace_back(p);
    }
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        cout << candi[i] << ' ';
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

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

const int INF = 1000000007;

int main(void){
	int n; cin>>n;
	int a[n] = {0};
	for(int i=0;i<n;i++) cin>>a[i];

	int b[n] = {0};
	for(int i=0;i<n;i++) b[i] = a[i] - (i + 1);

	sort(b, b+n);

	ll ans = 0;
	int med;
	if(n % 2 == 1) {
		med = b[(n - 1) / 2];
	}
	else {
		med = (b[n/2 - 1] + b[n/2]) / 2;
	}
	for(int i=0;i<n;i++) ans += abs(a[i] - (med + (i+1)));

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

Measured memory_bytes: 1792
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

int n, k;
vector<vector<int>> g;

const int mod = 1e9 + 7;

int ans = 1;

void dfs(int v, int p, int d, int cur) {
    if (cur < 0) ans = 0;
    ans *= cur;
    ans %= mod;
    int kek = k - 2;
    if (d == 0) kek = k - 1;
    for (auto u : g[v]) {
        if (u == p) continue;
        dfs(u, v, d + 1, kek);
        kek--;
    }
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    cin >> n >> k;
    g.resize(n);
    int u, v;
    for (int i = 0; i < n - 1; i++) {
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(0, 0, 0, k);
    cout << ans;
}
/*

*/


Measured memory_bytes: 10368
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N, M, C;
	scanf("%d %d %d", &N, &M, &C);
	
	vector<int> B;
	int input;
	while (B.size() < M) {
		cin >> input;
		B.push_back(input);
	}

	int passing_cnt = 0;
	int n_loop_cnt = 0;
	while (n_loop_cnt < N) {
		int point_sum = 0;
		int m_loop_cnt = 0;
		while (m_loop_cnt < M) {
			cin >> input;
			point_sum += B[m_loop_cnt] * input;
			m_loop_cnt++;
		}
		point_sum += C;
		if (point_sum > 0) passing_cnt++;
		n_loop_cnt++;
	}

	printf("%d", passing_cnt);

	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int ans;
  if(S=="SUN") ans=7;
  if(S=="MON") ans=6;
  if(S=="TUE") ans=5;
  if(S=="WED") ans=4;
  if(S=="THU") ans=3;
  if(S=="FRI") ans=2;
  if(S=="SAT") ans=1;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=100005,M=200005;
struct node{
	int u,v,nxt;
}edge[M];
int head[N],mcnt;
void add_edge(int u,int v){
    mcnt++;
    edge[mcnt].u=u;
    edge[mcnt].v=v;
    edge[mcnt].nxt=head[u];
    head[u]=mcnt;
}
int id[N],idcnt;
int mincost[N],minid[N];
struct mode{
	int val;
	bool used;
}in[N];
bool operator <(mode a,mode b){
    if(a.used)
        return 0;
	if(b.used)
		return 1;
    return a.val<b.val;
}
void dfs(int u,int color){
	id[u]=color;
    if(mincost[color]==0||in[u].val<mincost[color]){
        mincost[color]=in[u].val;
        in[minid[color]].used=false;
        minid[color]=u;
        in[u].used=true;
    }
    for(int i=head[u];i;i=edge[i].nxt){
        int v=edge[i].v;
        if(id[v])
			continue ;
        dfs(v,color);
    }
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d",&in[i].val);
    for(int i=1;i<=m;i++){
        int u,v;
		scanf("%d%d",&u,&v);
		u++,v++;
		add_edge(u,v);
		add_edge(v,u);
    }
    for(int i=1;i<=n;i++){
		if(!id[i]){
			idcnt++;
			dfs(i,idcnt);
		}
    }
    if(idcnt==1){
        printf("0\n");
        return 0;
    }
    sort(in+1,in+n+1);
    long long ans=0;
    for(int i=1;i<=idcnt;i++)
		ans+=1ll*mincost[i];
    int k=idcnt-2;
    for(int i=1;i<=k;i++){
		if(in[i].used){
            printf("Impossible\n");
            return 0;
		}
		ans+=1ll*in[i].val;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 4224
#include <stdio.h>
#include <string.h>

int main(void) {
	/* [z][y][x] */
	char nowstatus[7][7][7]={0};
	char nextstatus[7][7][7]={0};
	char a[27];
	char b[27];
	int N;
	int M;
	int i,j,k,l,m,n;
	int day,count;
	int case_count;
	for(case_count=1;scanf("%d",&N)==1 && N>0;case_count++) {
		for(i=1;i<=5;i++) {
			for(j=1;j<=5;j++) {
				scanf("%s",&nowstatus[i][j][1]);
			}
		}
		for(i=0;i<27;i++)a[i]=b[i]=0;
		scanf("%d",&M);
		for(i=0;i<M;i++) {
			scanf("%d",&count);
			a[count]=1;
		}
		scanf("%d",&M);
		for(i=0;i<M;i++) {
			scanf("%d",&count);
			b[count]=1;
		}

		for(day=0;day<N;day++) {
			for(i=1;i<=5;i++) {
				for(j=1;j<=5;j++) {
					for(k=1;k<=5;k++) {
						count=0;
						for(l=-1;l<=1;l++) {
							for(m=-1;m<=1;m++) {
								for(n=-1;n<=1;n++) {
									if((l|m|n)==0)continue;
									if(nowstatus[i+l][j+m][k+n]=='1')count++;
								}
							}
						}
						if(nowstatus[i][j][k]=='1') {
							nextstatus[i][j][k]=(b[count]?'1':'0');
						} else {
							nextstatus[i][j][k]=(a[count]?'1':'0');
						}
					}
				}
			}
			memcpy(nowstatus,nextstatus,sizeof(nowstatus));
		}

		if(case_count>1)putchar('\n');
		printf("Case %d:\n",case_count);
		for(i=1;i<=5;i++) {
			for(j=1;j<=5;j++) {
				puts(&nowstatus[i][j][1]);
			}
			if(i<5)putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[100010];
    int sum = 0;
    int cnt = 0;
    while(sum < N) {
        a[cnt] = cnt + 1;
        sum += cnt + 1;
        cnt++;
    }
    //cnt--;
    int i = 0;
    while(N > 0) {
        a[i] = min(N, cnt);
        N -= min(N, cnt);
        cnt--;
        i++;
        //cerr << N << " " << cnt << endl;
    }
    rep(k, i) {
        cout << a[k] << endl;
    }

    return 0;
}


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

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

  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    n, m, x = list(map(int, input().split()))
    
    c = []
    a = []
    
    def calc_price(bit):
        price_total = 0
        learn_total = [0] * m #理解度
        
        for i in range(n):
            if (bit >> i) & 1:
                price_total += c[i]
                learn = a[i]
                for j, la in enumerate(learn):
                    learn_total[j] += la
        
        if check(learn_total):
            return price_total
        else:
            return INF
        
    def check(learn_total):
        for i in range(m):
            if learn_total[i] < x:
                return False
        return True
    
    for i in range(n):
        c_temp, *a_temp = list(map(int, input().split()))
        c.append(c_temp)
        a.append(a_temp)
        
    INF = float("inf")
    ans = INF
    
    for bit in range(1 << n):
        price = calc_price(bit)
        ans = min(ans, price)
    
    if ans == INF:
        print(-1)
    else:
        print(ans)

Measured memory_bytes: 9144
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define chmax(a,b) a=max(a,b)
#define N 3010
#define M 5010
ll a[M],b[M],c[M];
ll d[N],e[N];
ll n,m,p;
int main(){
  cin>>n>>m>>p;
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i]>>c[i];
    c[i]-=p;
  }
  for(int i=1;i<=n;i++)d[i]=-1e17; d[1]=0;
  ll bef;
  for(int k=0;k<20000;k++){
    //for(int i=1;i<=n;i++)e[i]=d[i];
    for(int i=0;i<m;i++){
      if(d[a[i]]==-1e17)continue;
      chmax(d[b[i]],d[a[i]]+c[i]);
    }
    //for(int i=1;i<=n;i++)d[i]=e[i];
    if(k==9998)bef=d[n];
    if(k==19999){
      if(bef!=d[n]){
	cout<<-1<<endl;
	return 0;
      }
    }
  }
  cout<<max(0LL,d[n])<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define print(x) cout << (x) << '\n'

inline vector<string> split(const string &str, char sep) {
  vector<string> v;
  auto beg = str.begin();
  while(beg != str.end()) {
    auto end = beg;
    while(end != str.end() && *end != sep) ++end;
    v.push_back(string(beg, end));
    if(end != str.end()) ++end;
    beg = end;
  }
  return v;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  string s; cin >> s;

  int ans = 1e3;

  for (auto x : s){
    string t = s;
    vector<string> v = split(t, x);
    int m = -1;
    for (int i = 0; i < (int) v.size(); ++i){
      m = max(m, (int) v[i].size());
    }
    ans = min(ans, m);
  }
  print(ans);
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	int noh = 0;
	int res = 0;
	for (int i = 0; i < N; ++i) {
		int H;
		cin >> H;
		if (H >= noh) {
			++res;
			noh = H;
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll //9223372036854775807
#define pi acos(-1.0)
#define ms(a,b) memset(a,b,sizeof(a))
#define nl "\n"
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = 998244353;
ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
//ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
ll inve(ll x){return x==1?1:(mod-mod/x)*inve(mod%x)%mod;}

int n, a[105];
int x, y;

int main()
{
    FAST_IO;
    cin>>n;
    cin>>x>>y;
    for(int i=1;i<=n;i++)cin>>a[i];

    int n1=0,n2=0,n3=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<=x) n1++;
        else if(a[i]>y) n3++;
        else n2++;
    }

    cout<<(min(n1,min(n2,n3)))<<nl;

    return 0;
}


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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

const double EPS = 1e-10;

int h, w;

int main() {
  int i, j;
  int rh, rw;
  while (1) {
    scanf("%d%d ", &h, &w); 
    if (!h && !w) break;

    rh = rw = 200;
    int min_diag = rh*rh + rw*rw;
    for (i=1; i<=150; i++)
      for (j=i+1; j<=150; j++) {
        int diag = i*i + j*j; 
        if ((diag <= h*h + w*w) && (diag != (h*h + w*w) || i<=h)) continue;
        if ((diag < min_diag) || (diag = min_diag && i < rh)) {
          rh = i;
          rw = j; 
          min_diag = diag;
        }
      }
    printf("%d %d\n", rh, rw);
  }
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

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

using namespace std;

int main(){
    int N;
    cin >> N;
    int d[N],count=0;
    rep(i,N) cin >> d[i];
    sort(d, d+N);
    

    cout << d[N/2]-d[N/2-1] << endl;
}

Measured memory_bytes: 640
gets
nums=gets.chomp.split(" ").map(&:to_i)
counter = 0
while true
  is_all_even = true
  nums.each do |num|
    if num.odd?
      is_all_even = false
      break
    end
  end
  break unless is_all_even
  nums = nums.map {|num| num.even? ? num / 2 : num }
  counter += 1
end
puts counter

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

int main() {
  int n;
  cin >> n;
  int i=0, x[n-1], L=0, R=0;
  while (cin >> x[i]) {
    L = min(L, x[i]);
    R = max(R, x[i]);
    i++;
  }
  int ans=1000000000, p, sum;
  for (p=L; p<=R; p++) {
    sum = 0;
    for (i=0; i<n; i++) {
      sum += (x[i] - p) * (x[i] - p);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    res = [0]*n
    for _ in range(k):
        d = int(input())
        a = list(map(int, input().split()))
        for i in a:
            res[i-1] += 1
    ans = 0
    for i in res:
        if i == 0:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68024
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N, M;
        N = sc.nextInt();
        M = sc.nextInt();

        //箱を作る
        int[] box = new int[N+M];
        //箱の中にNとMを入れる
        for (int i =0; i < N; i++) {
            box[i] = 2;
        }
        for (int i = N; i < box.length; i++) {
            box[i] = 1;
        }

        int count = 0;
        for (int i = 0; i < box.length; i++) {
            for (int j = i+1; j < box.length; j++) {
                if ((box[i]+box[j]) % 2 == 0)
                    count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35756
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */
ll cnt[10][10];
int main() {
    int N;
    cin >> N;
    int digit = 1;
    for(int i = 1; i <= N; ++i) {
        if(i / digit >= 10) digit *= 10;
        if(i % 10 == 0)continue;
        cnt[i / digit][i % 10]++;
    }
    ll ans = 0;
    for(int i = 1;i < 10; ++i) {
        for(int j = i; j < 10; ++j) {
            if(i == j) {
                ans += cnt[i][i] + cnt[i][i] * (cnt[i][i] - 1);
            }else {
                ans += 2 * cnt[i][j] * cnt[j][i];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
s=['.'*(w+2)]
for i in range(h):
    s.append('.'+input()+'.')
s+=['.'*(w+2)]
for i in range(h):
    for j in range(w):
        if s[i+1][j+1]=='#':
            if (s[i][j+1]+s[i+1][j]+s[i+1][j+2]+s[i+2][j+1]).count('.')==4:
                print('No')
                quit()
print('Yes')

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mn = 105;
int a[mn];
int main()
{
	int n, i, l = 1 << 30, r = -(1 << 30);
	scanf("%d", &n);
	for(i = 1; i <= n; i++)
		scanf("%d", &a[i]), l = min(l, a[i]), r = max(r, a[i]);
	int ans = 1 << 30, sum;
	for(int j = l; j <= r; j++)
	{
		sum = 0;
		for(i = 1; i <= n; i++)
			sum += (a[i] - j) * (a[i] - j);
		ans = min(ans, sum);
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 128
var
  a,b:longint;
begin
  readln(a,b);
  if (a>0) or ((abs(b)-abs(a)) mod 2<>0) then writeln('Positive')
    else if (a=0) or (b=0) or ((a<0) and (b>0)) then writeln('Zero')
           else writeln('Negative');
end.

Measured memory_bytes: 256
#!/usr/bin/env python3
h, w = map(int, input().split())

cnt = 0

if h == 1 or w == 1:
    print(1)
    exit()

cnt = (w * 2 // 2) * (h // 2)
if h % 2 == 1:
    if w % 2 == 1:
        cnt += w // 2 + 1
    else:
        cnt += w // 2

print(cnt)


Measured memory_bytes: 9028
#include<stdio.h>
int main(){
	int A[100], n, i, j, f, g, h, k = 0, minj;
	scanf("%d", &n);
	for (i = 0;i < n; i++) {
		scanf("%d", &A[i]);
	}
	for (i = 0; i < n - 1; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (A[j] < A[minj]) {
				minj = j;
			}
		}
		g = A[minj];
		h = A[i];
		A[i] = A[minj];
		A[minj] = h;
		if (g != h) {
			k++;
		}
	}
	for (i = 0; i < n; i++) {
		if (i == 0) {
			printf("%d", A[i]);
		}
		if (i != 0) {
			printf(" %d", A[i]);
		}
	}
	putchar('\n');
	printf("%d\n", k);
	return 0;
}

	


Measured memory_bytes: 2148
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		var A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));

		if (isPairwise(A)) {
			System.out.println("pairwise coprime");
			return;
		}

		if (isSetwise(A)) {
			System.out.println("setwise coprime");
			return;
		}

		System.out.println("not coprime");
	}

	int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	boolean isPairwise(int[] A) {
		int[] count = new int[1000000 + 1];
		for (int n : A) {
			for (int div = 2; (long) div * div <= (long) n; div++) {
				if (n % div == 0) {
					if (count[div] > 0 || count[n / div] > 0) {
						return false;
					}
					count[div]++;
					if (div != n / div) count[n / div]++;
				}
			}
			if (n != 1) {
				if (count[n] > 0) return false;
				count[n]++;
			}
		}
		return true;
	}

	boolean isSetwise(int[] A){
		int gcd = A[0];
		for (int i = 1; i < A.length; i++) {
			gcd = gcd(gcd, A[i]);
		}
		return gcd == 1;
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 77792
#include<stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i=0; i<n; i++){
        int x;
        scanf("%d", &x);
        x--;
        a[x] = i+1;
    }
    for(int i=0; i<n; i++){
        printf("%d", a[i]);
        if(i<n-1){
            printf(" ");
        }
    }

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int X,Y,Z; cin >> X >> Y >> Z;
    int t = X/(Y+Z);
    if(X-t*(Y+Z)<Z){
        cout << t-1 << endl;
    }else{
        cout << t << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
import java.util.*;
import java.util.stream.*;
import java.io.*;

public class Main {
  
  static int x, y, a, b, c;
  static long ans = 0L;
  static long[] p, q, r;

  static long max(long a, long b, long c){
    return Math.max(Math.max(a, b), c);
  }

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    String[] in;
    in = br.readLine().split(" ");
    x = Integer.parseInt(in[0]);
    y = Integer.parseInt(in[1]);
    a = Integer.parseInt(in[2]);
    b = Integer.parseInt(in[3]);
    c = Integer.parseInt(in[4]);

    in = br.readLine().split(" ");
    p = Stream.of(in).mapToLong(Long::parseLong).toArray();
    in = br.readLine().split(" ");
    q = Stream.of(in).mapToLong(Long::parseLong).toArray();
    in = br.readLine().split(" ");
    r = Stream.of(in).mapToLong(Long::parseLong).toArray();

    br.close();

    Arrays.sort(p);
    Arrays.sort(q);
    Arrays.sort(r);
    long[] all = new long[x + y + c];
    
    for(int i = 0; i < x; i++){
      all[i] = p[a - i - 1];
    }
    for(int i = 0; i < y; i++){
      all[x + i] = q[b - i - 1];
    }
    for(int i = 0; i < c; i++){
      all[x + y + i] = r[c - i - 1];
    }

    Arrays.sort(all);

    for(int i = 0; i < x + y; i++){
      ans += all[x + y + c - i - 1];
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 66604
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 11
#define INF 9999999

int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];

int dijkstra(int s){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
    
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = 0 ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
        
        if(mini == INF) break;
        visit[mn] = true;
        
        for(int i = 0; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            v[i] = min(v[i],t);
        }
    }
    
    int sum = 0;
    for(int i = minnum ; i <= maxnum ; i++) sum += v[i];
    
    return sum;
}


int main(){
    int a,b,c;
    
    while(cin >> n,n){
        for(int i = 0 ; i < MAX ; i++)
            for(int j = 0 ; j < MAX ; j++)
                r[i][j] = INF;
        
        maxnum = 0; minnum = INF;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = r[b][a] = c;
            maxnum = max(maxnum,max(a,b));
            minnum = min(minnum,min(a,b));
        }
        
        int ans = INF, e;
        for(int i = 0; i <= maxnum ; i++){
            if(dijkstra(i) < ans){
                ans = dijkstra(i);
                e = i;
            }
        }
        cout << e << ' ' << ans << endl;
    }
    
    return 0;
}

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

using namespace std;

int main(void)
{
    int x;
    cin >> x;
    int a, b;
    int ok = false;
    for(int i = 120; i >= 0 ; i--){
        for(int j = i - 1; j >= -64; j--){
            if(pow(i, 5) - pow(j, 5) == x){
                a = i, b = j;
                ok = true;
                break;
            }
            if(pow(i, 5) - pow(j, 5) > 1000000000)  break;
        }
        if(ok)  break;
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 4028
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();

		//出力用
    int s = a * b;

		// 文字列の入力
		if ((1 <= a && a <= 9) && (1 <= b && b <= 9) ){
				//何もしない
		}
		else{
			s = -1;
		}
		// 出力
		System.out.println(s);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <stack>
#include <queue>
#include <list>
#include <map>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define MIN(x, y) ( (x) < (y) ? (x) : (y) )
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define IVFOR(p,a) for(vector<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ILFOR(p,a) for(list<int>::iterator p = (a).begin(); p!=(a).end(); p++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define CHECK(x)  cout << #x << " = " << (x) << endl
#define FINA(y) cout << (y) << endl

int main(){

  int N;
  cin >> N;
  int A[N];
  int count = 0;
  REP(i,N){
    cin >> A[i];
    if(A[i]%2 != 0){
      count++;
    }
  }
  if(count%2 == 0)
    FINA("YES");
  else
    FINA("NO");
  
 return 0;
}


Measured memory_bytes: 640
#!/usr/bin/ruby
n,k=gets.split.map(&:to_i)
s=gets.chomp.chars
f=false
i=0
while i<n&&k>0
	if (s[i]=='A')^f
		s[i]=f ? 'A' : 'B'
	else
		f^=true
		s[n+i]=f ? 'B' : 'A'
		i+=1
	end
	k-=1
end
if 0<k
	if n%2>0
		print (s[i]=='A')^f^(k%2==0) ? 'B' : 'A'
	end
	(n/2).times{print 'BA'}
	puts
else
	if f
		puts n.times.map{|j|s[i+j]=='A' ? 'B' : 'A'}*''
	else
		puts s[i,n]*''
	end
end

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

using namespace std;

int num, sum, m;

void ans(long long n)
{
    num = 0;
    sum = 0;
    while(n > 0)
    {
        if(n < 10)
            m = n;
        num++;
        sum += n % 10;
        n /= 10;
    }
}

int main()
{
    long long n;
    scanf("%lld", &n);
    ans(n);
    int a = m + 9 * (num - 1);
    if(a != sum)
        a--;
    printf("%d\n", a);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define INFTY 1000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
int prim();
int n,M[100][100];
int main(void){
  int i,j,e;
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1) ? INFTY :e;
    }
  }
  printf("%d\n",prim());
  return 0;
}
int prim(){
  int u,minv,i;
  int d[100],p[100],color[100];
 
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
 
  d[0]=0;
 
  while(1){
    minv=INFTY;
    u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
    u=i;
    minv=d[i];
      }
     }
    if(u==-1)
      break;
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK&&M[u][v]!=INFTY){
    if(d[v]>M[u][v]){
      d[v]=M[u][v];
      p[v]=u;
      color[v]=GRAY;
    }
      }
    }
  }
  int sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1)
      sum+=M[i][p[i]];
  }
  return sum;
}


Measured memory_bytes: 2112
#include<stdio.h>
int main(void)
{
  int n,i,ans = 0,new_ans = 0;
  int true_i = 1,memo_i;
  
   scanf("%d", &n);
  
  for(i = 1; i <= n; i++){
   ans = 0;
   memo_i = i;
    while((memo_i % 2) == 0){
      ans++; 
      memo_i /= 2; 
    }
    if(ans > new_ans){ 
     new_ans = ans;
     true_i = i; 
    }
  }
    printf("%d", true_i);
  
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

template<class T> inline void chmax(T &a, T b) { if(b > a) a = b; }

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

	int n, m;
	cin >> n >> m;

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

	vector<vector<int> > dp(m + 1, vector<int>(9, INT_MIN));
	dp[m][0] = 0;

	for(int i = 0; i < n; ++i) {
		vector<vector<int> > tmp(m + 1, vector<int>(9, INT_MIN));

		for(int j = 0; j <= m; ++j) {
			for(int k = 0; k <= 8; ++k) {
				if(dp[j][k] == INT_MIN)
					continue;

				for(int l = 0; l <= min(j, 8); ++l) {
					chmax(tmp[j - l][l], dp[j][k] + c[i]);

					for(int one = 0; one <= k; ++one)
						for(int two = 0; two <= l; ++two)
							if(1 <= one + two && one + two <= 8)
								chmax(tmp[j - l][l], dp[j][k] + two * a[i] + one * b[i]);
				}
			}
		}

		dp.swap(tmp);
	}
	
	int ans = INT_MIN;
	for(int i = 0; i <= m; ++i)
		for(int j = 0; j <= 8; ++j)
			chmax(ans, dp[i][j]);

	cout << ans << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int x[301][301];
P y[100000];
signed main(){
	int a,b,c,z=1;
	cin>>a>>b>>c;
	f(i,a){
		f(j,b){
			char ch;
			cin>>ch;
			if(ch=='#'){
				y[z].F=i,y[z].S=j;
				z++;
			}
		}
	}
	y[0]=P(-1,-1);
	sort(y,y+c);
	z=0;
	f(i,c){
		if(y[i+1].F==y[c].F) y[i+1].F=a-1;
		if(y[i+1].F!=y[i].F){
			if(i){
				for(int j=z;j<=y[i].F;j++){
					for(int k=y[i].S+1;k<b;k++){
						x[j][k]=i;
					}
				}
			}
			z=y[i].F+1;
			i++;
			for(int j=z;j<=y[i].F;j++){
				f(k,y[i].S+1){
					x[j][k]=i;
				}
			}
			i--;
		}
		else{
			i++;
			for(int j=z;j<=y[i].F;j++){
				for(int k=y[i-1].S+1;k<=y[i].S;k++){
					x[j][k]=i;
				}
			}
			i--;
		}
	}
	for(int j=z;j<=y[c].F;j++){
		for(int k=y[c].S+1;k<b;k++){
			x[j][k]=c;
		}
	}
	f(i,a){
		f(j,b){
			if(j)cout<<" ";
			cout<<x[i][j];
		}
		cout<<endl;
	}
}


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

int main(){
  string o, e;
  cin >> o >> e;
  int lo = o.length();
  int le = e.length();
  string ans = "";
  rep(i,le) {
    ans += o[i];
    ans += e[i];
  }
  if(lo > le) ans += o[le];
  cout << ans << endl;
  return 0;
}


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

int n;
int is_sheep[100000];   //-1: not sure, 0:wolve, 1: sheep
char answer[100000];
bool check_kind(int pos)
{
    int front_pos = (pos - 1 + n) % n;
    int back_pos = (pos + 1) % n;
    if(is_sheep[pos])
    {
        if(answer[pos] == 'o')
            return is_sheep[front_pos] == is_sheep[back_pos];
        else
            return is_sheep[front_pos] != is_sheep[back_pos];
    }
    else
    {
        if(answer[pos] == 'o')
            return is_sheep[front_pos] != is_sheep[back_pos];
        else
            return is_sheep[front_pos] == is_sheep[back_pos];
    }
}
bool is_valid()
{
    for(int i = 2; i < n; ++i)
    {
        if(answer[i - 1] == 'o')
        {
            if(is_sheep[i - 1])
                is_sheep[i] = is_sheep[i - 2];
            else
                is_sheep[i] = is_sheep[i - 2] ^ 1;
        }
        else
        {
            if(is_sheep[i - 1])
                is_sheep[i] = is_sheep[i - 2] ^ 1;
            else
                is_sheep[i] = is_sheep[i - 2];
        }
    }
    if(!check_kind(0) || !check_kind(n - 1))
        return false;
    return true;
}
void print_kind()
{
    for(int i = 0; i < n; ++i)
    {
        if(is_sheep[i])
            cout << 'S';
        else
            cout << 'W';
    }
    cout << endl;
}
int main()
{
    cin >> n;
    cin >> answer;
    for(int first_kind = 0;first_kind <= 1;++first_kind)
    {
        for(int second_kind = 0;second_kind <= 1;++second_kind)
        {
            is_sheep[0] = first_kind;
            is_sheep[1] = second_kind;
            if(is_valid())
            {
                print_kind();
                exit(0);
            }
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 768
n,x = map(int,input().split())
a = list(map(int,input().split()))
new_lst=[abs(i-x) for i in a]

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

ans=new_lst[0]
for i in range(1,n):
	ans =gcd(new_lst[i],ans)

print(ans)

Measured memory_bytes: 14224
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define P pair<int, int>

char board[1001][1001];
int d[1001][1001];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
    std::ios::sync_with_stdio(false);
    int h, w, n, sx, sy;
    cin >> h >> w >> n;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> board[i][j];
            if (board[i][j] == 'S') sx = i, sy = j;
        }
    }
    int tar = 1, sum = 0;
    while (tar <= n) {
        queue<P> que;
        que.push(P(sx, sy));
        memset(d, -1, sizeof(d));
        d[sx][sy] = 0;
        while (!que.empty()) {
            P p = que.front();
            if (board[p.first][p.second] == '0' + tar) {
                sx = p.first, sy = p.second;
                sum += d[p.first][p.second];
                //printf("%d %d %d %d\n",p.first,p.second,d[p.first][p.second],sum);
                break;
            }
            que.pop();
            for (int i = 0; i < 4; i++) {
                int nx = p.first + dx[i], ny = p.second + dy[i];
                if (1 <= nx && nx <= h && 1 <= ny && ny <= w &&
                    board[nx][ny] != 'X' && d[nx][ny] == -1) {
                    d[nx][ny] = d[p.first][p.second] + 1;
                    que.push(P(nx, ny));
                }
            }
        }
        tar++;
    }
    printf("%d\n", sum);
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 998244353
using namespace std;


int main(){
    int left[10]={};
    int right[10]={};
    for(int i=0; i<10; i++){
        left[i]=-1;
        right[i]=-1;
    }
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    for(int i=0; i<N; i++){
        int temp=S[i]-'0';
        if(left[temp]==-1){
            left[temp]=i;
        }
    }
    for(int i=N-1; i>=0; i--){
        int temp=S[i]-'0';
        if(right[temp]==-1){
            right[temp]=i;
        }
    }
    
    int ans[10][10][10]={};
    for(int l=0; l<10; l++){
        for(int r=0; r<10; r++){
            
            if(left[l]==-1 || right[r]==-1){
                continue;
            }
            
            for(int m=left[l]+1; m<right[r]; m++){
                ans[l][S[m]-'0'][r]=1;
            }
        }
    }
    
    int sum=0;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            for(int k=0; k<10; k++){
                sum += ans[i][j][k];
            }
        }
    }
    
    cout<<sum<<endl;
    return 0;
    
}


Measured memory_bytes: 256
#!/usr/bin/python

while True:
	m,a,b = map(int, raw_input().split(' '))
	if m == 0:
		break
	P = [int(raw_input()) for i in range(0,m)]
	x,ans = -1,0
	for i in range(a,b+1):
		sub = P[i-1] - P[i]
		if x < sub:
			x = sub
		if x == sub:
			ans = i
	print ans

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

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

  ll n,m,s; cin>>n>>m>>s;
  struct Train {
    ll s, c, d;
    Train(ll s,ll c,ll d):s(s),c(c),d(d){}
    bool operator>(const Train& x) const {return d>x.d;}
  };
  vector<Train> graph[n];
  for (int i = 0; i < m; i++) {
    ll u,v,a,b; cin>>u>>v>>a>>b; u--; v--;
    graph[u].emplace_back(v,a,b);
    graph[v].emplace_back(u,a,b);
  }
  for (int i = 0; i < n; i++) {
    int c,d; cin>>c>>d;
    graph[i].emplace_back(i,-c,d);
  }
  constexpr ll MAX = 200;
  constexpr ll INF = 1e18;
  vector<array<ll, MAX+1>> dp(n);
  for (auto& arr:dp) arr.fill(INF);
  dp[0][min(s,MAX)] = 0;
  priority_queue<Train, vector<Train>, greater<>> qs;
  qs.emplace(0,s,0);
  while (not qs.empty()) {
    auto [s,c,d] = qs.top(); qs.pop();
    if (d > dp[s][min(c,MAX)]) continue;
    for (auto t:graph[s]) {
      if (c-t.c<0) continue;
      if (d+t.d >= dp[t.s][min(c-t.c,MAX)]) continue;
      dp[t.s][min(c-t.c,MAX)] = d+t.d;
      qs.emplace(t.s, c-t.c, d+t.d);
    }
  }
  for (int i = 1; i < n; i++) {
    cout << *min_element(dp[i].begin(), dp[i].end()) << '\n';
  }

  return 0;
}


Measured memory_bytes: 3868
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n;
    while(cin >> n,n){
        int a[1000];
        rep(i,n) cin >> a[i];

        int ans = INF;
        rep(i,n){
            rep(j,n){
                if(i == j) continue;
                ans = min(ans, abs(a[i] - a[j]));
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3084
#include<stdio.h>
#include<string.h>
int main(void)
{
    int n,sum=0,i,a[22]={0},b[22]={0},c[22]={0};
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=1;i<=n;i++)
    {
        scanf("%d",&b[i]);
    }
    for(i=1;i<n;i++)
        scanf("%d",&c[i]);
    for(i=0;i<n;i++)
    {
        sum+=b[a[i]];
        if(a[i]+1==a[i+1])
        sum += c[a[i]];
    }
    printf("%d\n",sum);
 return 0;
}


Measured memory_bytes: 128
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
def do():
    a = INT()
    b = INT()
    h = INT()
    print(int((a+b)*h/2))
if __name__ == '__main__':
    do()

Measured memory_bytes: 2940
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define N 100009

struct Num{
    long a;
    long b;
};

int cmp(const void * n1, const void * n2)
{
	if (((Num*)n1)->b > ((Num *)n2)->b)
	{
		return 1;
	}
	else if (((Num*)n1)->b < ((Num*)n2)->b)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}


int main(){
    long n,m;
    cin>>n>>m;
    struct Num num[n];
    for (int i=0; i<n; i++){
        long p,q;
        cin>>p>>q;
        num[i].a=q;
        num[i].b=p;
    }
    
    long p = sizeof num / sizeof( Num );
    qsort(num,p,sizeof(Num),cmp);
    
    long k=0;
    long sum=0;
    long ans=0;
    while (true){
        if (num[k].a+sum<m){
            ans+=num[k].a*num[k].b;
            sum+=num[k].a;
        }
        else{
            long h=m-sum;
            ans+=num[k].b*h;
            break;
        }
        k++;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 3324
#include <stdio.h>
#include <string.h>
//#include<iostream.h>
int main(){
long	long int n,t,i,len,j,l,c=0;
	
	

		scanf("%lld",&n);
		long long int ar[n+3];
		ar[0]=-222;
		ar[n+1]=678868;
		for(i=1;i<=n;i++){
			scanf("%lld",&ar[i]);
		
		if(ar[i]!=i){
			c++;
		}}
			if(c<3)
		printf("YES\n");
		else
		printf("NO\n");
	
	}

Measured memory_bytes: 128
N=list(input())

l=0
r=len(N)-1

c=0
while(True):
    if(r<=l):
        print(c)
        exit()
    
    if(N[l]==N[r]):
        l+=1
        r-=1
    elif(N[l]=="x" and N[r]!="x"):
        l+=1
        c+=1
    elif(N[l]!="x" and N[r]=="x"):
        r-=1
        c+=1
    else:
        print(-1)
        exit()

Measured memory_bytes: 49520
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    cout << n / 3 << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<vi> vii;
typedef map<int, int> mp;
typedef multiset<int> mset;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int64> vi64;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define form(i,j,k,l) for(int i=j;i<int(k);i+=l)
#define rform(i,j,k,l) for(int i=int(j);i>int(l);i-=l)
#define rep(i, j) for(int i=0;i<int(j);i++)
#define rrep(i, j) for(int i=int(j);i>=0;i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define forc(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define INF (int)1e9
#define INF64 (int64)1e18
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define F first
#define S  second
const double pie = acos(-1.0);
template <typename T>
T Max(T x, T y)
{
  return (x > y) ? x : y;
}
template <typename T>
T Min(T x, T y)
{
  return (x > y) ? y : x;
}
int gcd(int n1, int n2)
{
  if (n2 != 0) return gcd(n2, n1 % n2);
  else return n1;
}
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
clock_t time_p = clock();
void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)1000 * (time_p) / CLOCKS_PER_SEC << "\n";}
int main()
{ fast;
  int n;
  cin >> n;
  int arr[n];
  int count[100001] = {0};
  int max = 0;
  rep(i, n)
  { cin >> arr[i];
    count[arr[i]]++;
    if (arr[i] > max)
      max = arr[i];
  }
  int count2 = 0, count1 = 0;
  form(i, 1, max + 1, 1)
  {
    if (count[i] > 0 && count[i] % 2 == 0)
      count2++;
    if (count[i] > 0)
      count1++;
  }
  if (count2 % 2 == 0)
    cout << count1;
  else
    cout << count1 - 1;
}

Measured memory_bytes: 4384
def Replacing():

    n = int(input())
    A = list(map(int,input().split()))
    q = int(input())
    
    total = sum(A) # これを基に各queryに対応(加算、減算)する
    
    l = [0 for i in range(10**5+1)] # 配列のインデックスを各valueとみなす
    for _ in A: # 各インデックスに各keyを加算
        l[_] += 1
    
    for i in range(q):
        b, c = map(int,input().split())
        total += c * l[b] # totalの調整のみ
        total -= b * l[b] # 同上
        print(total)
        l[c] += l[b] # ここでリストの更新
        l[b] = 0 # 同上

Replacing()

Measured memory_bytes: 20832
/**
 *	Author: houtaru
 *	Create: 08.02.2018 23:38:01
 */

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

int x, y;

int main() {
    cin >> x >> y;
    if (x % y == 0) {
        puts("-1");
        return 0;
    }
    printf("%lld\n", 1ll * x * (y - 1));
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
  string S, T;
  cin >> S >> T;
  for (size_t i = 0; i < S.size(); ++i) {
    if (S.substr(i) + S.substr(0, i) == T) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,N,K,P;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d %d",&K,&P);
		if(K % P != 0)
			printf("%d\n",K%P);
		else
			printf("%d\n",P);
	}
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for( int i= 0; i<n ; i++ ) {
			a[i] = sc.nextInt();
		}
		
		int pmax = a[0];
		long s = 0;
		for( int i= 1; i<n ; i++ ) {
			int d = pmax - a[i];
			if( d >= 0 ) {
				s += d;
			}else {
				pmax = a[i];
			}
			
		}
		
		System.out.println(s);
	}
}



Measured memory_bytes: 59760
#include<bits/stdc++.h>
using namespace std;
inline void ChMax(int& a, int b){ a = max(a, b); }

const int dy[] = {-1, 0, 0, 1}, dx[] = {0, -1, 1, 0};
const int bitMask = (1 << 12) - 1;
int H, W, K;
char S[50][50];
int dp[4][50][50][1 << 12];
bool Visited[1 << 12];



int main()
{
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < (1 << 12); i++) {
    int nx = 0, ny = 0, bit = i;
    for(int j = 0; j < 6; j++, bit >>= 2) {
      nx -= dx[bit & 3], ny -= dy[bit & 3];
      if (nx == 0 && ny == 0) Visited[i] = true;
    }
  }

  cin >> H >> W >> K;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }

  dp[K][0][0][bitMask] = 0;

  for(int m = K; m >= 0; m--) {
    int notnext = m == 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        for (int k = 0; k < (1 << 12); k++) {
          if (dp[m][i][j][k] == -1) continue;
          int Get = 0;
          if (isdigit(S[i][j]) && !Visited[k]) Get += S[i][j] - '0';
          for (int l = notnext << 1; l < 4; l++) {
            int ny = i + dy[l], nx = j + dx[l];
            if (ny < 0 || nx < 0 || ny >= H || nx >= W) continue;
            if (S[ny][nx] == '#')                       continue;
            ChMax(dp[m - (l < 2)][ny][nx][((k << 2) | l) & bitMask], dp[m][i][j][k] + Get);
          }
        }
      }
    }
  }
  cout << *max_element(dp[0][H - 1][W - 1], dp[0][H - 1][W]) << endl;
}

Measured memory_bytes: 161176