akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
	using namespace std;
const int N=100010;
const int MO=1e9+7;
int n;
int x[N];
int c[N];
long long ans=1;
long long calc(int p){
	if (p==1) return 1;
	else return p*calc(p-1)%MO;
}
int last=0;
int main(){
	cin>>n;
	x[0]=-1;
	for (int i=1;i<=n;i++)  {
		cin>>x[i];
		x[i]=min(x[i-1]+2,x[i]);
	}
	for (int i=1;i<=n;i++) {
	//	cout<<x[i]<<' ';
		ans=ans*((x[i-1]+1)/2+1)%MO;
	}
//	cout<<2*calc(12)<<endl;
	cout<<ans<<endl;
	return 0;
}

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

// --------------------------------------------------------------------------------
#define fast_IO	ios_base::sync_with_stio(false),cin.tie(NULL),cout.tie(NULL);
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------


void solve()
{
	ll a,b,c,k;cin>>a>>b>>c>>k;
	ll ans = 0;
	ans+=(min(a,k));
	k-=min(a,k);
	k-=min(b,k);
	ans-=min(c,k);
	cout<<ans<<"\n";
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    	freopen("/home/suryakant/input.txt","r",stdin);
 //        freopen("/home/suryakant/output.txt","w",stdout);
 //    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
    transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
    transform(s3.begin(), s3.end(), s3.begin(), ::toupper);
    cout << s1.at(0) << s2.at(0) << s3.at(0) << endl;
}

Measured memory_bytes: 256
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = []
ans, cnt = 0, 0
for i in range(N):
    A.append(list(map(int, input().split())))
for v in A:
    for i, w in enumerate(v):
        ans += w * B[i]
    if ans + C > 0:
        cnt += 1
    ans = 0
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#define ll long long int
using namespace std;

int main(){
  ll k,a,b;
  cin>>k>>a>>b;
  ll ans=(k-a+1)/2*(b-a)+a+(k-a+1)%2;
  cout<<max(k+1,ans)<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define N 52
#define M 262150
using namespace std;
int a[N],p1[N],p2[N];
long long C[N][N],choose[N];
long long ans;
bool need[N],bo[N];
int n,m,s1,s2;
int get(int x,int y)
{
	int ps=x/(1<<(y-1));
	return ps%2;
}
void dfs(int k,int xi)
{
	if (k>18)
	{
		if (!bo[1])
		{
			k++;k--;
		}
		for (int i=1;i<=n;i++)
		{
			if (!need[i]) continue;
			int ands=0,ors=0;
			for (int j=1;j<=18;j++)
			{
				ors=(ors+(1<<(j-1)));
				if (bo[j]) continue;
				int sp=get(a[i],j);
				ands=(ands+(1<<(j-1)));
				if (sp==1) ors=(ors-(1<<(j-1)));
				if (sp==1) ands=(ands-(1<<(j-1)));
			}
			int num=1;
			for (int j=i+1;j<=n;j++)
			{
				if (!need[j]) continue;
				int ps1=a[j]&ands;
				int ps2=a[j]|ors;
				if (ps1!=0||ps2!=((1ll<<18)-1)) continue;
				num++;
			}
			ans=(ans+xi*(choose[num-1]));
		}
		return ;
	}
	if (p1[k]==0&&p2[k]==1)
	{	
		bo[k]=true;
		dfs(k+1,xi);
		bo[k]=false;
		dfs(k+1,-xi);
		return;
	}
	if (p1[k]==1)
		for (int i=1;i<=n;i++)
			if (get(a[i],k)!=1)
				need[i]=false;
	if (p2[k]==0)
		for (int i=1;i<=n;i++)
			if (get(a[i],k)!=0)
				need[i]=false;
	dfs(k+1,xi);
}
int main()
{
	scanf("%d%d%d%d",&n,&m,&s1,&s2);
	for (int i=0;i<=n;i++) C[i][0]=1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=i;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1]);
	choose[0]=1;
	for (int i=1;i<=n;i++)
		for (int j=0;j<m;j++)
			choose[i]=choose[i]+C[i][j];
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=18;i++)
	{
		p1[i]=get(s1,i);
		p2[i]=get(s2,i);
		if (p1[i]==1&&p2[i]==0)
		{
			printf("0\n");
			return 0;
		}
	}
	memset(bo,true,sizeof(bo));
	memset(need,true,sizeof(need));
	dfs(1,1);
	printf("%lld\n",ans);
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int main(){
    int n; cin >> n;
    ll a[n];
    REP(i,n){
        cin >> a[i];
    }
    ll ans = 0;
    ll tmp = 0;
    REP(i,n){
        if(a[i]!=0){
            tmp+= a[i];
        }else{
            ans += tmp/2;
            tmp = 0;
        }
    }
    if(tmp!=0){
        ans += tmp/2;
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
#include<stdio.h>

int A[300];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &A[i]);
	for (int i = 1; i <= n; i++)
	{
		printf("node %d: key = %d, ", i, A[i]);
		if (i / 2 != 0)
			printf("parent key = %d, ", A[i / 2]);
		if (i * 2 <= n)
			printf("left key = %d, ", A[i * 2]);
		if (i * 2 + 1 <= n)
			printf("right key = %d, ", A[i * 2 + 1]);
		printf("\n");
	}
}


Measured memory_bytes: 2052
import sys
input = sys.stdin.readline
n = int(input())
a = [int(input()) for _ in range(n)]
l1 = [0] * (n + 1)
l2 = [0] * (n + 1)
for i in range(n):
    l1[i + 1] = max(l1[i], a[i])
    l2[n - i - 1] = max(l2[n - i], a[n - i - 1])
for i in range(n):
    print(max(l1[i], l2[i + 1]))

Measured memory_bytes: 15636
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	var tmp = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);

  var groups = [
    [1, 3, 5, 7, 8, 10, 12],
    [4, 6, 9, 11],
    [2],
  ];

  var getGroupIndex = function(v) {
    var index;
    groups.find(function(group, i) {
      var findValue = group.find(function(value) {
        return value === v;
      });
      if (findValue) index = i;
      return !!findValue;
    });

    return index;
  };

  var aIndex = getGroupIndex(a);
  var bIndex = getGroupIndex(b);

  var validate = aIndex === bIndex;

  //出力
	console.log('%s', validate ? 'Yes' : 'No');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
n,c=map(int,input().split())
d=[list(map(int,input().split())) for _ in range(c)]
g0=[0]*c
g1=[0]*c
g2=[0]*c
for i in range(n):
    col=list(map(int,input().split()))
    for j in range(n):
        col[j]-=1
        if (i+j)%3==0:
            g0[col[j]]+=1
        elif (i+j)%3==1:
            g1[col[j]]+=1
        else:
            g2[col[j]]+=1
ans=10**18
for i in range(c):
    for j in range(c):
        for k in range(c):
            if i==j or j==k or i==k:
                continue
            s=0
            for l in range(c):
                s+=d[l][i]*g0[l]+d[l][j]*g1[l]+d[l][k]*g2[l]
            ans=min(ans,s)
print(ans)

Measured memory_bytes: 3064
from collections import Counter
n = int(input())
a = Counter(map(int,input().split()))
four = []
two = []
for k,v in a.items():
  if v  >= 4 :
    four.append(k)
  if v >= 2:
    two.append(k)
f,t = 0,0
if four:
  f = max(four)**2
if len(two) > 1:
  two.sort()
  t = two.pop() * two.pop()
print(max(f,t,0))

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N,A,B;

int main()
{
	scanf("%lld%lld%lld",&N,&A,&B);

	ll ans = max(0ll,(B * (N - 1) + A + 1) - (A * (N - 1) + B));
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include <math.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
int main(){
	int n,m,k[11],s[11][11]={0},p[11],ans=0,all[11];
	scanf("%d%d",&n,&m);
	rep(i,m){
		scanf("%d",&k[i]);
		rep(j,k[i])scanf("%d",&s[i][j]);
	}
	rep(i,m)scanf("%d",&p[i]);
	rep(i,pow(2,n)){	//2進数全探索
		all[1]=i%2;
		Rep(j,2,n+1)all[j]=(i%(int)pow(2,j))/(int)pow(2,j-1);
		int flag=0;
		rep(j,m){
			int P=0;
			rep(l,k[j])if(all[s[j][l]])P++;
			if(P%2==p[j])flag++;
		}
		if(flag==m)ans++;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main (){
string s,t;
cin >>s>>t;
int x = stoi(s+t);
for(int i=1;i <=1000;i++){
if(i*i == x){
cout<<"Yes"<<endl;
return  0;
}
}
cout<<"No"<<endl;
}
        

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

typedef long long int ll;
#define    mod      1000000007
#define    speed    ios_base::sync_with_stdio(false);
#define    up       cin.tie(NULL);
#define    pb       push_back
#define    mp       make_pair
#define    T        int t; cin >> t; while(t--)

int main(){
  speed up
  int a , b;
  cin >> a >> b;
  if(a <= 5){
      cout << "0\n";
  }
  else if(a >= 13){
      cout << b << '\n';
  }
  else{
      cout << b/2 << '\n';
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>

using namespace std;

int main(){
  int H,W,n=0;
  int ans=0;
  cin>>H>>W;
  char c[40][40];
  int xa[30*30],ya[30*30];

  for(int y=0;y<H;y++){
    for(int x=0;x<W;x++){
      cin>>c[y][x];
      if(c[y][x] == 'B'){
        xa[n]=x;
        ya[n]=y;
        n++;
      }
    }
  }

  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      ans = max(ans,abs(xa[i]-xa[j])+abs(ya[i]-ya[j]));
    }
  }

  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 3116
#include<iostream>
#include<cstdlib>
#include<numeric>
using namespace std;
int main(){
int n;
  cin >> n;
  // w array
  int w[n];
  for (int i = 0; i < n; i++)
    cin >> w[i];
  int sum = accumulate(w,w+n, 0);
  int res = w[0];
  int ans = abs(sum - res*2);
  for (int i = 1; i < n; i++){
  	res += w[i];
    int temp =abs(sum - res*2) ;
    (temp < ans)? ans = temp : ans += 0;
  }
  cout << ans<<'\n';
 
	return 0;
}

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

int main() {
  int n,k;
  cin>>n>>k;
  int ans=1;
  for(int i=0;i<n;i++){
    if(ans*2<ans+k){
      ans*=2;
    }
    else{
      ans+=k;
    }
  }
    cout<<ans<<endl;
  }

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

bool isPrime(int n) {
  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) return false;
  }
  return true;
}

int main() {
  fast();
  cin >> n;
  int i = n;
  while (!isPrime(i)) ++i;
  cout << i;
  return 0;
}



Measured memory_bytes: 3708
n,W=map(int, input().split())
a=[]
for _ in range(n):
    w,v=map(int, input().split())
    a.append((w,v))
dp=[[0 for j in range(W+1)] for i in range(n+1)] # dp[n][w] = max value using up to n-th items and weigh = w

for i in range(1,n+1):
    w,v=a.pop()
    for j in range(W+1):
        if j-w>=0:
            dp[i][j]=max(
                dp[i-1][j-w]+v # use j-th item (w,v)
                ,dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]

print(max(dp[n]))

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    int ans = 0;
    REP(i,N){
        int a; cin >> a;
        if(i%2==0 && a%2==1) ans ++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
abcd = input()
ans_word = []

for i in range(2**3):
    ans = int(abcd[0])
    for j in range(3):
        #print(str(i) + ' ' + str(j))
        if((i>>j)&1 == 1):
            ans += int(abcd[j+1])
        else:
            ans -= int(abcd[j+1])
    #print(ans)
    if(ans == 7):
        for k in range(4):
            ans_word.append(abcd[k])
            if((i>>k)&1 == 1):
                ans_word.append('+')
            else:
                if(k < 3):
                    ans_word.append('-')
        ans_word.append("=7")
        print("".join(ans_word))
        break


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	int x, n;
	cin >> x >> n;
	vector<int> p(n);
	rep(i, n)cin>>p[i];

	map<int,bool> mp;
	rep(i,n){
		mp[p[i]] = true;
	}

	rep(i,100000){
		// iはxとの差の値
		if(mp[x-i] == false){
			cout << x - i << endl;
			return 0;
		}
		if(mp[x+i] == false){
			cout << x + i << endl;
			return 0;
		}


	}

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int mlog = 18;
int n,a,b;
vector<int> way1[maxn], way2[maxn];
int depA[maxn], depB[maxn];
int par[maxn][20];
int good[maxn];
int loop, ans;
void build(int u, int last) {
    par[u][0] = last;
    for(int i=1;i<=mlog;i++) par[u][i] = par[par[u][i-1]][i-1];
    for(auto v : way2[u]) {
        if(v==last) continue;
        depB[v] = depB[u] + 1;
        build(v, u);
    }
}
void dfs(int u, int last) {
    if(depB[u]<=depA[u]) return ;
    if(good[u]) loop = 1;
    else ans = max(ans, depB[u]*2);
    for(auto v : way1[u]) {
        if(v==last) continue;
        depA[v] = depA[u] + 1;
        dfs(v, u);
    }
}
int lca(int u, int v) {
    int res = 0;
    if(depB[u]<depB[v]) swap(u,v);
    for(int i=mlog;i>=0;i--) {
        if(par[u][i] && depB[par[u][i]]>=depB[v]) {
            u = par[u][i];
            res += (1<<i);
        }
    }
    if(u==v) return res;
    for(int i=mlog;i>=0;i--) {
        if(par[u][i]!=par[v][i]) {
            u = par[u][i]; v = par[v][i];
            res += (1<<i)*2;
        }
    }
    return res+2;
}
int main() {
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n-1;i++) {
        int u,v; scanf("%d%d",&u,&v);
        way1[u].push_back(v);
        way1[v].push_back(u);
    }
    for(int i=1;i<=n-1;i++) {
        int u,v; scanf("%d%d",&u,&v);
        way2[u].push_back(v);
        way2[v].push_back(u);
    }
    build(b,0);
    for(int u=1;u<=n;u++) {
        for(auto v : way1[u]) {
            if(lca(u,v)>=3) {
                good[u] = good[v] = 1;
            }
        }
    }
//    for(int u=1;u<=n;u++) printf("%d : %d\n",u,good[u]);
    dfs(a,0);
    if(loop) printf("-1");
    else printf("%d",ans);
}


Measured memory_bytes: 48636
S = input()
y = int(S[:4])
m = int(S[5:7])
d = int(S[8:10])

if y < 2019:
    print("Heisei")
elif y == 2019:
    if m < 4:
        print("Heisei")
    elif m == 4 and d <= 30:
        print("Heisei")
    else:
        print("TBD")


Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		
		DisjointSet dj = new DisjointSet(n);
		
		int a[] = new int[m];
		int b[] = new int[m];
		for(int i = 0; i < m; i++) {
			int tmpA = sc.nextInt();
			int tmpB = sc.nextInt();
			
			a[m - i - 1] = tmpA;
			b[m - i - 1] = tmpB;
		}
		//橋を0本から1本ずつ足していくという考え方で解く
		//最初の不便度はMAX
		long pattern = (long)n*(n - 1)/2;
		long result[] = new long[m + 1];
		result[m] = pattern;
		//aとbを繋いだ場合
		//(1)aとbが同じグループなら不便度変化無し
		//(2)異なるグループならAのグループの要素数とBのグループの要素数の積だけ不便度が減る
		for(int i = 0; i < m; i++) {
			if(!dj.isSameSet(a[i], b[i])) {
				pattern -= (long)dj.amountOfOwnGroup(a[i])*dj.amountOfOwnGroup(b[i]);
				dj.union(a[i], b[i]);
			}
			result[m - i - 1] = pattern;
		}
		
		for(int i = 1; i < m + 1; i++) {
			System.out.println(result[i]);
		}
	}

}
//各グループの要素数をまあまあ高速で取得できるよう改造
class DisjointSet {
	private int n;
	private int[] p;
	private int[] rank;
	//各グループの要素数を管理する
	private int[] num;

	public DisjointSet(int n){
		this.n = n;

		p = new int[n + 1];
		rank = new int[n + 1];

		num = new int[n + 1];
		
		Arrays.fill(num, 1);
		
		for(int i = 1; i <= n; i++){
			makeSet(i);
		}
	}

	private void makeSet(int x){
		p[x] = x;
		rank[x] = 0;
	}

	public void union(int x, int y){
		int p1 = findSet(x), p2 = findSet(y);
		int num1 = num[p1];
		int num2 = num[p2];
		link (findSet(x), findSet(y));
		
		if(p1 != p2) {
			num[p1] = num[p2] = num1 + num2;
		}
		
	}
	
	public int amountOfOwnGroup(int x) {
		return num[findSet(x)];
	}

	private int findSet(int x){
		if(x != p[x]){
			p[x] = findSet( p[x]);
		}
		return p[x];
	}

	public boolean isSameSet(int x, int y){
		return findSet(x) == findSet(y);
	}

	private void link(int x, int y){
		if(rank[x] > rank[y]){
			p[y] = x;
		}
		else {
			p[x] = y;
			if(rank[x] == rank[y]){
				rank[y]++;
			}
		}
	}
}


Measured memory_bytes: 62220
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 100005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 + c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int H,W,N;
int a[100005],c[105][105],g[105];
void Solve() {
    read(H);read(W);
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(a[i]);
    int f = 0;
    int t = 1;
    for(int i = 1 ; i <= N ; ++i) {
        if(g[t] + a[i] < W) {
            if(!f) {
                for(int j = g[t] + 1 ; j <= g[t] + a[i] ; ++j) c[t][j] = i;
            }
            else {
                for(int j = W - g[t] ; j >= W - g[t] - a[i] + 1 ; --j) c[t][j] = i;
            }
            g[t] += a[i];
        }
        else {
            for(int j = 1 ; j <= W ; ++j) {
                if(!c[t][j]) c[t][j] = i;
            }
            a[i] -= W - g[t];
            if(c[t][W] == i) f = 1;
            else f = 0;
            ++t;
            while(a[i]) {
                if(!f) c[t][g[t] + 1] = i;
                else c[t][W - g[t]] = i;
                ++g[t];--a[i];
                if(g[t] == W) ++t;
            }
        }
    }
    for(int i = 1 ; i <= H ; ++i) {
        for(int j = 1 ; j <= W ; ++j) {
            out(c[i][j]);space;
        }
        enter;
    }
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
    Solve();
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n, d1, d2;
	cin >> n;
	int cnt=0, ok=0;
	REP(i,n){
		cin >> d1 >> d2;
		if(d1==d2) cnt++;
		else cnt=0;
		if(cnt==3) ok=1;
	}
	if(ok) OUT("Yes");
	else OUT("No");
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
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; }

// 最大公約数(ユークリッドの互除法)
// O(log max(a, b))
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main(){
    int n, ans = 0;
    cin >> n;
    n = 100000;
    vector<int> a(n);
    vector<int> front_gcd(n), back_gcd(n);
    rep(i, n) {
        cin >> a[i];
    }
    if(n == 1) {
        cout << a[0] << endl;
        return 0;
    }
    front_gcd[0] = a[0];
    rep2(i, 1, n) {
        front_gcd[i] = gcd(a[i], front_gcd[i-1]);
    }
    back_gcd[n-1] = a[n-1];
    for (int i = n-2; i >= 0; i--) {
        back_gcd[i] = gcd(a[i], back_gcd[i+1]);
    }
    ans = front_gcd[n-1];
    rep(i, n) {
        int res;
        if(i == 0) {
            res = back_gcd[1];
        }
        else if(i == n-1) {
            res = front_gcd[max(n-2, 0)];
        }
        else if(i+1 <= n-1 && i-1 >= 0){
            res = gcd(back_gcd[i+1], front_gcd[i-1]);
        }
        chmax(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4548
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

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

    int a, b, c;

    cin >> a >> b >> c;

    if (a <= c && c <= b) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
#define vi vector<int>
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      
    x = x % p;  
    while (y > 0) {  
        if (y & 1) 
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;       
    while (y > 0) {    
        if (y & 1) 
            res = (res*x) ;  
        y = y>>1; 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
int dp[6010];
pii A[3100];
void solve(){
    int n,t;cin>>n>>t;
    fr(i,0,n-1)cin>>A[i].first>>A[i].second;
    sort(A,A+n);
    fr(i,0,t+3000)dp[i]=0;
    fr(i,0,n-1){
        frr(j,t-1,0)dp[j+A[i].first]=max(dp[j+A[i].first],dp[j]+A[i].second);
    }
    int ans=0;
    fr(i,0,t+3000)ans=max(ans,dp[i]);
    cout<<ans<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}

Measured memory_bytes: 3672
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	long p;
	P ans;
	P point;
	final int offset = 10000000;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			HashSet< Long > stars = new HashSet<Long>();
			HashSet< Long > cons = new HashSet<Long>();
			int m = sc.nextInt();
			if(m == 0) break;
			p = getL(sc.nextInt(), sc.nextInt());
			point = new P(p);
			cons.add(p);
			for(int i=1;i<m;i++) {
				cons.add(getL(sc.nextInt(), sc.nextInt()));
			}
			int n = sc.nextInt();
			for(int i=0;i<n;i++) {
				stars.add(getL(sc.nextInt(), sc.nextInt()));
			}
//			debug(stars);
//			debug(cons);
			for(long l: stars) {
				boolean flg = true;
				P p = getP(l);
//				debug("  ", p.x, p.y);
				for(long dl: cons) {
					P dp = getP(dl);
					dp.x = point.x-dp.x;
					dp.y = point.y-dp.y;
//					debug("   ",dp.x, dp.y, p.x-dp.x, p.y-dp.y);
//					debug("    ",l, dl, getL(p.x-dp.x, p.y-dp.y), stars.contains( getL( p.x-dp.x, p.y-dp.y )));
					if(!stars.contains( getL( p.x-dp.x, p.y-dp.y ) )) {
						flg = false;
						break;
					}
				}
				if( flg ) {
					ans = new P(p.x-point.x, p.y-point.y);
					break;
				}
			}
			System.out.println(ans.x + " " + ans.y);
		}
	}
	
	P getP(long l) {
		int x = (int)((l - l%offset)/offset);
		int y = (int)(l - x*offset);
		return new P(x, y);
	}
	
	long getL(int x, int y) {
		return (long)x * offset + y;
	}
	
	class P {
		int x, y;
		P(int x, int y) {
			this.x = x;
			this.y = y;
		}
		
		P (long l) {
			x = (int)((l - l%offset)/offset);
			y = (int)(l - x*offset);
		}
		
		@Override
		public boolean equals(Object o) {
			if( o instanceof P ) {
				P p = (P) o;
				return x == p.x && y == p.y;
			}
			return false;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int d1, d2, d3, d4;
  d1 = N/1000;
  d2 = (N - d1*1000)/100;
  d3 = (N - d1*1000 - d2*100)/10;
  d4 = N - d1*1000 - d2*100 - d3*10;
  if ((d1 == d2 && d2 == d3)||(d2 == d3 && d3 == d4)) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    static int[] g;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        g = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            int a = sc.nextInt();
            g[i] = a;
        }
        Set<Integer> s = new HashSet<>();
        int current = 1;
        while (!s.contains(current)) {
            s.add(current);
            if (!s.contains(g[current])) {
                if (g[current] == 2) {
                    s.add(2);
                } else {
                    current = g[current];
                }
            }
        }

        if (s.contains(2)) {
            System.out.println(s.size() - 1);
        } else {
            System.out.println(-1);
        }
    }
}

Measured memory_bytes: 51576
# coding: utf-8
# 89
import re

while True:
    n,t = input().split()
    if t == 'X':
        break
    if '_' in n:
        N=n.split('_')
        #print(N)
    else:
        i = n[0].upper()
        #print(i)
        k = n[1:]
        K = i +k
        #print(K)
        #N = re.split('[A-Z]',n)
        N = re.findall('[A-Z][^A-Z]*',K)
        #print(N)
    if t=='U':
        for i in range(len(N)):
            if i == len(N)-1:
                print(N[i].capitalize())
            else:
                print(N[i].capitalize(),end='')
    elif t=='L':
        for j in range(len(N)):
            if j == 0:
                if j==len(N)-1:
                    print(N[j].lower())
                else:
                    print(N[j].lower(),end='')
            elif j == len(N)-1:
                print(N[j].capitalize())
            else:
                print(N[j].capitalize(),end='')
        
    elif t=='D':
        for z in range(len(N)):
            if z == len(N)-1:
                print(N[z].lower())
            else:
                print(N[z].lower(),end='')
                print('_',end='')
        



Measured memory_bytes: 6544
#include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int a, b, c, d, e, ans;
	scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
	if (a < 0)
		ans = b*e +( -1) * a*c + d;
	else if (a == 0)
		ans = b*e + d;
	else
		ans = (b - a)*e;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3220
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;


public class AtCoder
{
    static int N, K, X, Y;
    static void Main() {
        N = int.Parse(Console.ReadLine());
        K = int.Parse(Console.ReadLine());
        X = int.Parse(Console.ReadLine());
        Y = int.Parse(Console.ReadLine());
        int cnt=0;
        if (N <= K) {
            cnt += X * N;
        }
        else {
            cnt += X * K;
            cnt += (N - K) * Y;
        }
        Console.WriteLine(cnt);
    }
}



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

using namespace std;

#define ll long long;

const int N=1e6+5;

vector<int> v;

int n,ans,tc,q,m,a[N],k;

char s1[N],s2[N];

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

            ans=max(ans,curr);

            curr = 1;
        }
    } 
    ans=max(ans,curr);
    printf("%d\n",ans-1);
}

Measured memory_bytes: 2432
x = int(input())
for a in range(1000000):
    b = round(abs(a ** 5 - x) ** (1 / 5))
    if x in [a ** 5 + b ** 5, a ** 5 - b ** 5]:
        if a ** 5 < x: b *= -1
        print(a, b)
        break
    

Measured memory_bytes: 9304
#include<iostream>
using namespace std;
int main(){
    int n,k;
    int count = 0;
    cin >> n >> k;
    int h[n];
    for(int i=0; i<n ; i++){
        cin >> h[i];
    }

    for(int i=0; i<n ; i++){
        if(k <= h[i])count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 640
n=int(input())
cnt_a=0
cnt_b=0
cnt_ab=0
cnt_bxa=0
for i in range(n):
  s=input()
  if s[0]=='B' and s[-1]!='A':
    cnt_b+=1
  if s[-1]=='A' and s[0]!='B':
    cnt_a+=1
  if s[0]=='B' and s[-1]=='A':
    cnt_bxa+=1
  for i in range(len(s)-1):
    if s[i:i+2]=='AB':
      cnt_ab+=1
ans=cnt_ab
if cnt_a==0 and cnt_b==0 and cnt_bxa==0:
  print(ans)
elif cnt_a==0 and cnt_b==0 and cnt_bxa!=0:
  print(ans+cnt_bxa-1)
elif cnt_a==0 and cnt_b!=0 and cnt_bxa==0:
  print(ans)
elif cnt_a!=0 and cnt_b==0 and cnt_bxa==0:
  print(ans)
elif cnt_a==0 and cnt_b!=0 and cnt_bxa!=0:
  print(ans+cnt_bxa)
elif cnt_a!=0 and cnt_b==0 and cnt_bxa!=0:
  print(ans+cnt_bxa)
elif cnt_a!=0 and cnt_b!=0 and cnt_bxa==0:
  print(ans+min(cnt_a,cnt_b))
else:
  print(ans+min(cnt_a,cnt_b)+cnt_bxa)

Measured memory_bytes: 3064
import math
x,a,b = input().split()
x = int(x,10)
a = int(a,10)
b = int(b,10)
alpha = a - x
beta = b - x
alpha = math.fabs(alpha)
beta = math.fabs(beta)
if alpha > beta:
    print('B')
else:
    print('A')

Measured memory_bytes: 3060
s = input()

if ("RRS" == s) or ("SRR" == s) :
    print(2)
elif ("RSS" == s) or ("SRS" == s) or ("SSR" == s) or ("RSR" == s):
    print(1)
elif ("SSS" == s):
    print(0)
elif ("RRR" == s):
    print(3)

Measured memory_bytes: 9116
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] d = new Integer[n];
        for (int i = 0; i < n; i++) {
            d[i] = Integer.parseInt(sc.next());
        }

        long result = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                result += d[i] * d[j];
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 21844
import java.util.*;

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

	//ツエツδ可トツスツテツネツスツづ古「ツソツ　
	int max = 300000;
	int[] list = new int[max];
	int a = 6;
	int b = 8;
	for(int i=6; i<list.length; i+=7){list[i] = 1;}
	for(int i=8; i<list.length; i+=7){list[i] = 1;}
	for(int i=6; i<Math.sqrt(max)+1; i+=7){
	    for(int j=i*2; j<max; j+=i){
		list[j] = 0;
	    }
	}
	for(int i=8; i<Math.sqrt(max)+1; i+=7){
	    for(int j=i*2; j<max; j+=i){
		list[j] = 0;
	    }
	}
	
	int monday = sc.nextInt();
	
	while(monday!=1){
	    List<Integer> mylist = new ArrayList<Integer>();
	    boolean hantei = false;
	    for(int i=0; i<max; i++){
		if(list[i]>=monday){break;}
		if(list[i]==1 && monday%i==0 && !mylist.contains(i)){
		    mylist.add(i);
		}
	    }
	    
	    if(mylist.size()==0){mylist.add(monday);}

	    String ans = "";
	    for(int i=0; i<mylist.size(); i++){
		ans += " "+mylist.get(i);
	    }

	    System.out.println(monday+":"+ans);

	    monday = sc.nextInt();
	}
    }
}

Measured memory_bytes: 0
### subroutines

def count_rt(x0, y0)
  return 1 if y0 >= $y
  return $rtcache[y0][x0] if ! $rtcache[y0][x0].nil?

  count = 0
  y1 = y0 + 1

  if $flds[y0][x0] == 0
    count += count_rt(x0 - 1, y1) if x0 > 0 && $flds[y1][x0 - 1] == 0
    count += count_rt(x0, y1)
    count += count_rt(x0 + 1, y1) if x0 < $x - 1 && $flds[y1][x0 + 1] == 0
  else
    count += count_rt(x0, y0 + 2)
  end

  $rtcache[y0][x0] = count
end

### main

while true
  $x, $y = gets.strip.split(' ').map{|s| s.to_i}
  break if $x == 0 && $y == 0

  $flds = []
  $y.times.each do
    hl = gets.strip.split(' ').map{|s| s.to_i}
    $flds << hl
  end

  $rtcache = $y.times.map{[nil] * $x}
  $rtcache << [1] * $x

  for y0 in (0...$y)
    for x0 in (0...$x)
      if $flds[y0][x0] == 1
        $rtcache[y0][x0] = 0
      elsif y0 == $y - 1
        $rtcache[y0][x0] = 1
      end
    end
  end

  count = 0
  for x0 in (0...$x)
    count += count_rt(x0, 0)
  end
  puts count
end

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

deque<char> S;
int Q; 
int main(){
  string moji;
  cin >> moji;
  for(char c : moji) {
    S.push_back(c);
  }
  cin>>Q;
  int count = 0;
  rep(i,Q) {
    int T;
    cin>>T;
    if(T==1){
      count++;
    }else{
      int F;
      char C;
      cin>>F>>C;
      if(F==1) {
        if(count%2==0) {
          S.push_front(C);
        }else{
          S.push_back(C);
        }
      }else{
        if(count%2==0) {
          S.push_back(C);
        }else{
          S.push_front(C);
        }
      }
    }
  }
  if(count%2==1)reverse(begin(S), end(S));
  for(char c:S) {
    cout<<c;
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,s,t;
vector<int>G[100001];
int vis[100001][3];
struct node {
	int pos,times,val;
} now,nxt;
queue<node>Q;
int bfs() {
	vis[s][0]=1;
	Q.push((node)<%s,0,0%>);
	while(!Q.empty()) {
		now=Q.front();
		Q.pop();
	//	printf("now %d %d\n",now.pos,now.times);
		if(now.pos==t&&now.times==0)return now.val;
		for(unsigned i=0; i<G[now.pos].size(); i++) {
			nxt.pos=G[now.pos][i],nxt.times=(now.times+1)%3,nxt.val=now.val;
			if(now.times==0)nxt.val++;
			if(vis[nxt.pos][nxt.times])continue;
			Q.push(nxt);
			vis[nxt.pos][nxt.times]=1;
		}
	}
	return -1;
}
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1; i<=m; i++) {
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
	}
	scanf("%d%d",&s,&t);
	printf("%d",bfs());
}

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

using namespace std;

int main(){
    char b;
    cin >> b;

    map<char, char> map;

    map['A'] = 'T';
    map['C'] = 'G';
    map['T'] = 'A';
    map['G'] = 'C';

    cout << map[b] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(T x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
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;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    ll res=gcd(a[0],a[1]);
    rep2(i,2,n)res=gcd(res,(ll)a[i]);
    cout<<res<<endl;
    return 0;
}




Measured memory_bytes: 640
//It is made by Awson on 2018.1.28
    #include <set>
    #include <map>
    #include <cmath>
    #include <ctime>
    #include <queue>
    #include <stack>
    #include <cstdio>
    #include <string>
    #include <vector>
    #include <complex>
    #include <cstdlib>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #define LL long long
    #define dob complex<double>
    #define Abs(a) ((a) < 0 ? (-(a)) : (a))
    #define Max(a, b) ((a) > (b) ? (a) : (b))
    #define Min(a, b) ((a) < (b) ? (a) : (b))
    #define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
    #define writeln(x) (write(x), putchar('\n'))
    #define lowbit(x) ((x)&(-(x)))
    using namespace std;
    const int N = 100000;
    const int M = 200000;
    void read(int &x) {
        char ch; bool flag = 0;
        for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
        for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
        x *= 1-2*flag;
    }
    void write(int x) {
        if (x > 9) write(x/10);
        putchar(x%10+48);
    }
     
    int n, m, path[N+5], tot, u, v, c, flag;
    int dist[N+5], vis[N+5];
    struct tt {int to, cost, next; }edge[(M<<1)+5];
    void add(int u, int v, int c) {edge[++tot].to = v, edge[tot].cost = c, edge[tot].next = path[u], path[u] = tot; }
     
    bool dfs(int o) {
        vis[o] = 1;
        for (int i = path[o]; i; i = edge[i].next)
    	if (dist[edge[i].to] > dist[o]+edge[i].cost) {
    	    if (vis[edge[i].to]) return true;
    	    dist[edge[i].to] = dist[o]+edge[i].cost;
    	    if (dfs(edge[i].to)) return true;
    	}
        vis[o] = 0; return false;
    }
    void work() {
        read(n), read(m);
        for (int i = 1; i <= m; i++) {read(u), read(v), read(c); add(u, v, c), add(v, u, -c); }
        for (int i = 1; i <= n; i++) if (dfs(i)) {flag = 1; break; }
        if (flag) puts("No");
        else puts("Yes");
    }
    int main() {
        work(); return 0;
    }

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

int n;
int a[10000];


int main() {
    cin >> n;
    int m = 1000000;
    int M = -1000000;
    long int sum = 0;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        m = min(m, a[i]);
        M = max(M, a[i]);
        sum += a[i];
    }
    cout << m << " " << M << " " << sum << endl;

}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
#include<atcoder/all>

typedef long long ll;

using namespace std;

ll ans;
ll n;
auto check(ll x){
    ll y = 2*n/x;
    auto [a, b] = atcoder::crt({0, y-1}, {x, y});
    if (b == 0)return;
    ans = min(ans, a);
}

int main(){
    cin >> n;
    ans = 2*n - 1;
    for(int x = 2, stop = sqrt(2*n); x <= stop; ++x){
        if((2*n)%x == 0){
            check(x);
            check(2*n/x);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
// ProblemURL : https://atcoder.jp/contests/abc104/tasks/abc104_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var r int
	fmt.Scan(&r)
	if r < 1200 {
		fmt.Println("ABC")
	} else if r < 2800 {
		fmt.Println("ARC")
	} else {
		fmt.Println("AGC")
	}
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define sz(s) (int) s.size()
#define pb push_back
#define rc(x) return cout<<x<<"\n",0

using namespace std;
    void solve()
    {
     int n, m;
     cin >> n >> m;
     int max = m * 2 + 1;
     if (max>=n)
      cout << 1;
     else
      if (n % max == 0)
        cout << n / max;
      else
        cout << n / max + 1;
 }
               
    int main()
    {
        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        int t=1;
      // cin>>t;
        while(t--)
        {
            solve();
        }
    }

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
typedef long long LL;
const int maxn=55;

int n;
int a[maxn],b[maxn],maxi;
LL state;
int s[maxn][maxn];
vector<int> ava;

bool trans(int p,int q)
{
	if (p<q) return false;
	if (p==q) return true;
	if (s[p][q]>=0) return s[p][q];
	for(int i=0;i<ava.size();i++)
	{
		if (ava[i]>p) continue;
		if (trans(p%ava[i],q)) return s[p][q]=1;
 	}
 	return s[p][q]=0;
}

bool judge(LL p)
{
	for(int i=maxi;i>=0;i--)
		for(int j=i-1;j>=0;j--)
			s[i][j]=-1;
	ava.clear();
	for(int i=maxi;i>=1;i--)
		if (p&(1ll<<(i-1))) ava.push_back(i);
	
	
	for(int i=1;i<=n;i++)
		if (!trans(a[i],b[i])) return false;
	return true;
}

int main()
{
	scanf("%d",&n);
	maxi=0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),maxi=max(maxi,a[i]);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		if (b[i]>a[i])
		{
			puts("-1");
			return 0;
		}
	}
	
	state=(1ll<<maxi)-1;
	if (!judge(state))
	{
		puts("-1");
		return 0;
	}
	for(int i=maxi;i>=1;i--)
	{
		state^=(1ll<<(i-1));
		if (!judge(state)) state^=(1ll<<(i-1));
	}
	printf("%lld\n",state<<1);
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val L = nextDouble()
    val l = L / 3.0
    println(l * l * l)
}

Measured memory_bytes: 33692
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>

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

using namespace std;
//        tmp = stoi(S.substr(i,3));
int main(){

    string S;
    string T;

    string res;

    cin >> S >> T;

    res = "No";
    REP(i,S.size())
    {
        if(S.compare(T) == 0){
            res = "Yes";
            break;
        }
        S = S[S.size() -1] + S;
        //末尾を削除
        S.pop_back();
    }


    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		Long a[] = new Long[n];

		String str[] = br.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]);
		}

		long ans = Long.MAX_VALUE;
		for (int i = 0; i <= 100; i++) {
			long cost = 0;

			for (int j = 0; j < n; j++) {
				cost += Math.pow(a[j] - i, 2);
			}
			ans = Math.min(ans, cost);
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 32544
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

string f(int i){ 
	string h; 
	cout << i << endl; 
	cin>>h; 
	if ( h == "Vacant" ) exit(0); 
	return h; 
} 

inline void solve(){
    int  n, c=0; cin >> n ; 
    string  L = f(0); 
    int  l=0, r=n-1, m ; 
    while (l<=r){ 
    	string h = f(m = (l+r)/2) ; 
    	if ( ((m-l) % 2 ==0 and h != L) or ( (m-l) % 2 == 1 and h==L) )  r = m ; 
    	else  l = m ,L = h; 
    	if (r-l<=2){
    		for (int i=l;i<=r;i++){
    			f(i);
    		}
    	}
    } 
    // 1 0 1 0 _ 1 0
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

int main(){
  int a,b,c;
  scanf("%d %d %d", &a, &b,&c);
  if(b - a == c - b){//beautiful
    printf("YES\n");
  }else{//not beautiful
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128