akhauriyash/Code-Regression huggingface dataset:
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1], C = ip[2];
	if(B < A) {
		auto i = B;
		B = A;
		A = i;
	}
	if(A < C && C < B) writeln("Yes");
	else writeln("No");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { ll A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << max(A * B, C * D) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	int h, w;
	cin >> h >> w;
	if(h == 1 || w == 1) cout << 1 << endl;
	else cout << mod(h * w, 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#ifndef ONLINE_JUDGE
#define line cout<<"here - "<<__LINE__<<"\n";
#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
#else
#define line
#define dbg(a)
#endif
using namespace std;
main()
{
    //fast
    int tc=1,i,j,k;
    while(tc--)
    {
       int a;
       cin>>a;
       int x=__gcd(a,360);
       x=a/x;
       x*=360;
       cout<<x/a<<endl;
    }
}




Measured memory_bytes: 3628
N,M = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]

INF = float('inf')
ds = [[INF]*N for _ in range(N)]
for i in range(N):
    ds[i][i] = 0
for a,b,c in ABC:
    a,b = a-1,b-1
    ds[a][b] = ds[b][a] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            ds[i][j] = min(ds[i][j], ds[i][k]+ds[k][j])

ans = 0
for a,b,c in ABC:
    a,b = a-1,b-1
    if ds[a][b] < c:
        ans += 1
print(ans)

Measured memory_bytes: 9348
import math
import sys


sys.setrecursionlimit(10**7)

N = int(input())
words = [input() for _ in range(N)]
patterns = sorted([''.join(sorted(list(word))) for word in words])

def count_list_duplicates(arr):
    dup, prev, c = [], '', 0
    for l in arr:
        if prev == l:
            c += 1
        else:
            dup.append(c)
            c = 1
        prev = l
    else:
        dup.append(c)

    return dup

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

res = 0
for d in count_list_duplicates(patterns):
    if d >= 2:
        res += combinations_count(d, 2)
        
print(res)

Measured memory_bytes: 18652
n, k = map(int, input().split())
MOD = 1000000007

ans = 0
for i in range(k, n+2):
    maxNum = i * (2 * n - (i - 1)) / 2
    minNum = i * (i - 1) / 2
    ans += (maxNum - minNum + 1) % MOD
print(int(ans) % MOD)


Measured memory_bytes: 9072
from collections import deque

K = int(input())
que = deque()
for i in range(1, 10):
    que.append(i)
count = 0
while 1:
    count += 1
    x = que.popleft()
    for i in range(-1, 2):
        d = x % 10 + i
        if (d < 0 or 9 < d):
            continue
        que.append(x * 10 + d)
    if (count == K):
        print(x)
        break

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)

using P   = pair<int, int>;
using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    string s = "No";
    int n;cin >> n;
    if(n%10 == 9 || n/10 == 9) s = "Yes";
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  long long int n,x;
  cin>>n>>x;
  vector<long long int> candies(n);
  long long int ans=0;
  for(int i = 0;i<n;i++){
    cin>>candies[i];
  }
  for(int i=1;i<n-1;i++){
    while(candies[i-1]+candies[i]>x){
      if(candies[i]>0){
        long long int tmp=min(candies[i-1]+candies[i]-x,candies[i]);
        candies[i]-=tmp;
        ans+=tmp;
      }
      else{
        long long int tmp=min(candies[i-1]+candies[i]-x,candies[i-1]);
        candies[i-1]-=tmp;
        ans+=tmp;
      }
    }
  } 
  if(candies[n-2]+candies[n-1]>x)
    ans+=(candies[n-2]+candies[n-1])-x;
  cout<<ans<<"\n";  
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll a,b,c,d;
int main(){
  cin>>a>>b>>c>>d;
  ll ans=max(max(a*c,a*d),max(b*c,b*d));
  cout<<ans<<endl;
  return 0;
}

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

int main() {
   int r;
   cin >> r;

   if (r < 1200) {
       cout << "ABC" << endl;
   } else if(r < 2800) {
       cout << "ARC" << endl;
   } else {
       cout << "AGC" << endl;
   }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define min(q,w) ((q)>(w)?(w):(q))
#define max(q,w) ((q)<(w)?(w):(q))
using namespace std;
typedef long long LL;
const int N=100500;
const LL INF=1e17;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,n1;
LL a[N],ans;
bool az[N];
int L[N],R[N];
struct Data
{
	int l,r;
	LL v,la;
}b[N*100];
int root,b0;
void doit(int l,int r,int e,int K=1)
{
	if(!e||b[e].la<0)return;
	b[e].v=b[e].la;
	if(l!=r)
	{
		if(b[e].l||K)b[b[e].l?b[e].l:(b[e].l=++b0)].la=b[e].la;
		if(b[e].r||K)b[b[e].r?b[e].r:(b[e].r=++b0)].la=b[e].la;
	}
	b[e].la=-1;
}
void change(int l,int r,int &e,int l1,int r1,LL l2)
{
	if(l>r||l1>r1)return;
	if(!e)e=++b0;
	if(l1<=l&&r<=r1)
	{
		b[e].la=l2;
		doit(l,r,e);
		return;
	}
	int t=(l+r)>>1;
	doit(l,t,b[e].l),doit(t+1,r,b[e].r);
	if(l1<=t)change(l,t,b[e].l,l1,r1,l2);
	if(t<r1)change(t+1,r,b[e].r,l1,r1,l2);
	b[e].v=min(b[b[e].l].v-(LL)t+r,b[b[e].r].v);
}
LL find(int l,int r,int e,int l1,int r1)
{
	if(!e||r<l||l1>r1)return INF;
	doit(l,r,e);
	if(l1<=l&&r<=r1)return b[e].v-(LL)r+r1;
	int t=(l+r)>>1;
	LL ans=INF,ans1=INF;
	if(l1<=t)ans=find(l,t,b[e].l,l1,r1);
	if(t<r1)ans1=find(t+1,r,b[e].r,l1,r1);
	return min(ans,ans1);
}
LL findS(int l,int r,int e)
{
	if(!e)return INF;
	doit(l,r,e,0);
	if(l==r)return b[e].v;
	int t=(l+r)>>1;
	LL ans=INF,ans1=INF;
	ans=findS(l,t,b[e].l);
	ans1=findS(t+1,r,b[e].r);
	return min(ans,ans1);
}
int main()
{
	int q,w;
	read(n),read(n1);
	fo(i,1,n)
	{
		a[i]=a[i-1]+(LL)read(q);az[i]=read(w)-1;
		if(q*2>n1&&w==1)return printf("-1\n"),0;
		if(w==1)L[i]=(n1-2LL*a[i]%n1+1)%n1,R[i]=(n1-2LL*a[i-1]%n1-1)%n1;
	}
	b0=1;b[0].v=INF,b[1].v=0;
	b[0].la=-1,b[1].la=0;
	root=1;
	fo(i,1,n)if(!az[i])
	{
		if(L[i]<=(R[i]+1)%n1) 
		{
			LL t=find(0,n1-1,root,L[i],(R[i]+1)%n1);
			change(0,n1-1,root,L[i],R[i],INF);
			change(0,n1-1,root,(R[i]+1)%n1,(R[i]+1)%n1,t);
		}
		else
		{
			LL t=find(0,n1-1,root,L[i],n1-1)+(R[i]+1LL)%n1+1LL;
			change(0,n1-1,root,L[i],n1-1,INF);
			LL t1=find(0,n1-1,root,0,(R[i]+1)%n1);
			change(0,n1-1,root,0,(R[i]+1)%n1,INF);
			change(0,n1-1,root,(R[i]+1)%n1,(R[i]+1)%n1,min(t,t1));
		}
	}
	ans=findS(0,n1-1,root)+a[n]*2LL;
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define all(c) begin(c),end(c)
const int INF = 1e9;
int N, Ma, Mb;
int A[40], B[40], C[40];
int dp[41][401][401];

int main() {
	cin.sync_with_stdio(false);
	cin >> N >> Ma >> Mb;
	rep(i, N)cin >> A[i] >> B[i] >> C[i];

	rep(i, N+1) {
		rep(j, 401) {
			rep(k, 401)dp[i][j][k] = INF;
		}
	}
	dp[0][0][0] = 0;
	
	rep(i, N) {
		rep(j, 401) {
			rep(k, 401) {
				if (dp[i][j][k] == INF)continue;
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
				dp[i + 1][j + A[i]][k + B[i]] = min(dp[i + 1][j + A[i]][k + B[i]], dp[i][j][k] + C[i]);
			}
		}
	}
	int ans = INF;
	reps(i,1, 401) {
		reps(j,1, 401) {
			if (i*Mb == j*Ma)ans = min(ans, dp[N][i][j]);
		}
	}
	if (ans == INF)ans = -1;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 25984
N = int(input())
D = []
for i in range(N):
    a, b = map(int, input().split())
    D.append((a + b, a, b))
D.sort(reverse=True)
res = 0
for i, (_, a, b) in enumerate(D):
    if i % 2 == 0:
        res += a
    else:
        res -= b
print(res)


Measured memory_bytes: 20988
#include<iostream>
#include <cstring>

using namespace std;

char S[10];
char T[10];

int main()
{
	cin >> S >> T;
	int a = strlen(S);
	
	if (strncmp(S, T, a) == 0 )	cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

const int LIM1 = 500, LIM2 = 250000;
int h, w, a[LIM1][LIM1];

int main() {
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> a[i][j];
    bool has = false;
    if (a[0][0] % 2 == 1) {
        has = true;
    }
    int x = 1, y = 0; // current position
    int ox = 0, oy = 0; // odd position
    int ax[LIM2], ay[LIM2], adx[LIM2], ady[LIM2], i = 0; // ans

    while(true) {
        if (x >= w) {
            x = w-1;
            y++;
        } else if (x < 0) {
            x = 0;
            y++;
        }
        if (y >= h) break;

        if (has) {
            ax[i] = ox; ay[i] = oy;
            adx[i] = x; ady[i] = y;
            ox = x; oy = y;
            a[y][x]++; i++;
            if (a[y][x] % 2 == 0) {
                has = false;
            }
        } else if (a[y][x] % 2 == 1) {
            oy = y; ox = x;
            has = true;
        }

        if (y % 2 == 0) x++;
        else x--;
    }

    cout << i << endl;
    rep(j, i) {
        printf("%d %d %d %d\n", ay[j]+1, ax[j]+1, ady[j]+1, adx[j]+1);
    }
    return 0;
}

Measured memory_bytes: 6144
#include<iostream>

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

struct Pole{
	int left, right;
	Pole *red, *blue, *rred, *rblue;
};

// 中和をとった時の重さを返す
int trace(Pole pole){
	int red_w, blue_w;
	if(pole.red == nullptr && pole.blue == nullptr){
		red_w = pole.right;
		blue_w = pole.left;
	}else if(pole.red != nullptr && pole.blue != nullptr){
		red_w = trace(*pole.red);
		blue_w = trace(*pole.blue);

		int g = gcd(pole.left * red_w, pole.right * blue_w),
			_red_w = red_w;
		red_w = pole.right * blue_w / g * _red_w;
		blue_w = pole.left * _red_w / g * blue_w;
	}else{
		if(pole.red == nullptr){
			std::swap(pole.red, pole.blue);
			std::swap(pole.left, pole.right);
		}

		int _red_w = trace(*pole.red),
			g = gcd(pole.left * _red_w, pole.right);
			
		red_w = pole.right / g * _red_w;
		blue_w = pole.left * _red_w / g;
	}

	return red_w + blue_w;
}

int main(){
	int n;
	while(std::cin >> n, n){
		Pole ps[100];

		for(int i=0;i<100;i++){
			ps[i].red = nullptr;
			ps[i].blue = nullptr;
			ps[i].rred = nullptr;
			ps[i].rblue = nullptr;
			ps[i].left = 0;
			ps[i].right = 0;
		}

		for(int i=0;i<n;i++){
			int p, q, r, b;
			std::cin >> p >> q >> r >> b;
			r--;b--;

			int g = gcd(p, q);
			ps[i].left = p / g;
			ps[i].right = q / g;

			if(r != -1){
				ps[i].red = &ps[r];
				ps[r].rred = &ps[i];
			}
		
			if(b != -1){
				ps[i].blue = &ps[b];
				ps[b].rblue = &ps[i];
			}
		}
	
		int parent = 0;
		{
			Pole *p = &ps[0];
			while(p->rred != nullptr || p->rblue != nullptr){
				if(p->rred != nullptr){//実は一意(普通)
					p = p->rred;
				}else{
					p = p->rblue;
				}
			}

			parent = p - &ps[0];
		}

		std::cout << trace(ps[parent]) << std::endl;
	}
}

Measured memory_bytes: 1168
import sys
from collections import Counter

input = sys.stdin.readline

N, M = map(int, input().split())

A = [0] * (N + 1)
for _ in range(M):
    L, R = map(int, input().split())
    A[L - 1] += 1
    A[R] += -1

for i in range(1, N):
    A[i] += A[i - 1]

c = Counter(A)
print(c[M])

Measured memory_bytes: 12020
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[3] = {};
    for(int i = 0;i < n;i++)
    {
        long long int x;
        cin >> x;
        int count = 0;
        while(x % 2 == 0 && count < 2)
        {
            x = x / 2;
            count++;
        }
        a[count]++;
    }
    if(a[0] == 0)
    {
        cout << "Yes";
    }
    else if(n % 2 == 0 && a[0] <= a[2] || n % 2 == 1 && a[0] <= a[2] + 1)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    string w;
    cin>>w;
    bool flag = true;
    rep(i,0,w.size()-1){
        if((i+1)%2==1){
            if(w[i]=='L'){
                flag = false;
                break;
            }
        }
        else{
            if(w[i]=='R'){
                flag = false;
                break;
            }
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main()
{
  int n, x, y, t;
  bool flag = false;
  cin >> n;
  t = x = y = 0;

  for (int i = 0; i < n; i++)
  {
    int t1, x1, y1, t2, x2, y2;
    cin >> t1 >> x1 >> y1;
    t2 = abs(t1 - t);
    x2 = abs(x1 - x);
    y2 = abs(y1 - y);
    if ((x1 + y1) % 2 == t1 % 2 && t2 >= x2 + y2)
    {
      flag = true;
      t = t1;
      x = x1;
      y = y1;
    }
    else
    {
      flag = false;
      break;
    }
  }
  if (flag)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3672
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

		Integer N = Integer.parseInt(scanner.next());
		Integer M = Integer.parseInt(scanner.next());

		List<Integer> HList = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			HList.add(Integer.parseInt(scanner.next()));
		}

		Map<Integer, Set<Integer>> map = new HashMap<>();
		for (int i = 1; i <= N; i++) {
			map.put(i, new HashSet<>());
		}

		for (int i = 0; i < M; i++) {
			Integer A = Integer.parseInt(scanner.next());
			Integer B = Integer.parseInt(scanner.next());

			map.get(A).add(B);
			map.get(B).add(A);
		}

		int cnt = 0;
		for (int i = 1; i <= N; i++) {
			Integer height = HList.get(i-1);
			boolean flg = true;
			for (Integer j : map.get(i)) {
				if (height <= HList.get(j-1)) {
					flg = false;
					break;
				}
			}
			if (flg) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}

}

Measured memory_bytes: 90944
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll a[n];
    ll sum = 0;
    rep(i, n){
        cin >> a[i];
        sum += a[i];
    }
    ll sum_ = sum;
    ll midium = 0;
    ll sum__ = sum;
    rep(i, n) {
        sum_ -= a[i];
        if (sum_ <= sum / 2) {
            midium = i;
            break;
        }
    }
    rep(i, n) {
        sum__ -= a[n - 1 - i];
        if (sum__ <= sum / 2) {
            midium = i;
            break;
        }
    }

    cout << min(abs(2*sum__-sum), abs(2 * sum_ - sum)) << endl;

}

Measured memory_bytes: 1792
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
//処理
int H=sc.nextInt();
int W=sc.nextInt();
int[][] a=new int[H][W];
for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
        a[i][j]=sc.nextInt();
    }
}
String[] s=new String[W*H*2];
int c=0;
for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
        if(a[i][j]%2!=0){
            if(i!=H-1){
                s[c+1]=String.valueOf(i+1)+" "+String.valueOf(j+1)+" "+String.valueOf(i+2)+" "+String.valueOf(j+1);
                c++;
                a[i][j]--;
                a[i+1][j]++;
            }else if(j!=W-1){
                s[c+1]=String.valueOf(i+1)+" "+String.valueOf(j+1)+" "+String.valueOf(i+1)+" "+String.valueOf(j+2);
                c++;
                a[i][j]--;
                a[i][j+1]++;
            }
        }
    }
}
s[0]=String.valueOf(c);
for (int j = 0; j <= c; j++) {
    out.println(s[j]);
}
}
//階乗
static long fact(long a){
    long b=1;
    for (long i = 1; i <= a; i++) {
        b*=i;
    }
    return b;
}
//最大公約数
static int gcd (int a, int b) {
    int temp;
    while((temp = a%b)!=0) {
        a = b;
        b = temp;
    }
    return b;
}
//※最小公倍数はa*b/gcd(a,b)である
//二項係数
static long combi (long a, long b) {
    b=min(a-b,b);
    return permu(a,b)/fact(b);
}
//順列
static long permu(long a,long b){
    long temp=1;
    for (long i =a ; i > a-b; i--) {
        temp*=i;
    }
    return temp;
}
}

Measured memory_bytes: 108504
//#include <bits/stdc++.h>
//#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>

using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using intpv=vector<intpair>;
using llpair=pair<ll,ll>;
using llpv=vector<llpair>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;
using pairmat=vector<llpv>;

template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())
#define matin(mat,H,W) for(int i__=0; i__<H; i__++)for(int j__=0; j__<W; j__++) cin>>mat[i__][j__]
#define out(n) cout<<n<<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;
}

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a__: v) cin>>a__;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a__: v) cin>>a__;
}

template<class N> void resiz(N n) {} // empty
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll GCD(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}

ll Fact(ll x, ll p) { //階乗
	ll f=1;
	for(ll i=2; i<=x; i++) {
		f*=i;
		f%=p;
	}
	return f;
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll div=1LL;
	while(n/div) {
		digit++;
		div*=10;
	}
	return digit;
}


intvec X(5);

void input() {
	init(X);
}

void solve() {
	for(int i=0; i<5; i++) {
		if(X[i]==0) {
			cout<<i+1<<endl;
			return;
		}
	}
}

int main() {
	while(1) {
		input();
		solve();
		break;
	}
}


Measured memory_bytes: 3584
import java.util.Scanner;
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Map<Integer, List<Pair>> map = new HashMap<>();
        for (int i = 0; i < m; i++) {
            int pre = sc.nextInt();
            int year = sc.nextInt();
            if (!map.containsKey(pre)) {
                List<Pair> pairs = new ArrayList<>();
                map.put(pre, pairs);
            }
            Pair p = new Pair(i, year);
            map.get(pre).add(p);
        }
        for (Map.Entry<Integer, List<Pair>> entry : map.entrySet()) {
            Collections.sort(entry.getValue(), new PairComparator());
        }
        String[] ans = new String[m];
        for (Map.Entry<Integer, List<Pair>> entry : map.entrySet()) {
            int order = 0;
            for (Pair p : entry.getValue()) {
                order++;
                ans[p.city] = String.format("%06d%06d", entry.getKey(), order);
            }
        }

        PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        for (String s : ans) {
            writer.println(s);
        }
        writer.flush();
    }
}
class Pair {
    int city;
    int year;
    public Pair(int city, int year) {
        this.city = city;
        this.year = year;
    }
    public int compareTo(Pair p) {
        return this.year - p.year;
    }
    public String toString() {
        return String.format("city : %d year: %d %n", this.city, this.year);
    }
}
class PairComparator implements Comparator<Pair> {
    public int compare(Pair p1, Pair p2) {
        return p1.year - p2.year;
    }
}


Measured memory_bytes: 170480
import sys


for line in sys.stdin:
    waight = ["1", "2", "4", "8", "16", "32", "64", "128", "256", "512"]
    ans = []
    n = bin(int(line))[2:].zfill(10)
    for i, x in enumerate(n[::-1]):
        if x == "1":
            ans.append(waight[i])
    print(" ".join(ans))

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

int main(){
    int N;
    cin >> N;
    map<string, int> cards;
    for(int i = 0; i < N; i++){
        string tmp;
        cin >> tmp;
        if(cards.count(tmp))
            cards[tmp] += 1;
        else
            cards[tmp] = 1;
        
    }

    int M;
    cin >> M;
    for(int i = 0; i < M; i++){
        string tmp;
        cin >> tmp;
        if(cards.count(tmp))
            cards[tmp] -= 1;
        else
            cards[tmp] = -1;
        
    }

    int max = 0;
    for(auto i:cards){
        if(max < i.second) max = i.second;
    }
    cout << max << endl;
}

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

int main(void){
	int n, k, f;
	cin >> n >> k;
	vector<ll> a(n, 0);
	queue<ll> que;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < k; i++) que.push(a[i]);
	for(int i = k; i < n; i++){
		f = que.front();
		que.pop();
		// cout << f << " " << a[i] << endl;
		if(f < a[i]) cout << "Yes" << endl;
		else cout << "No" << endl;
		que.push(a[i]);
	}
	return 0;
}


Measured memory_bytes: 6372
#include<bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define lson k<<1
#define rson k<<1|1
#define R register
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
const ll INF64=1e18;
const double eps=1e-8;
int n,m;
int dp[100005];
int w[100005],v[100005];
int ans;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	memset(dp,0x3f3f3f3f,sizeof(dp));
	dp[0]=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>w[i]>>v[i];
	for(int i=1;i<=n;i++){
		for(int j=100000;j>=v[i];j--){
			dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
		    if(dp[j]<=m) ans=max(ans,j);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));

class UnionFind {
public:
	vector<int> Parent;

	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0)return A;
		return Parent[A] = root(Parent[A]);
	}

	int size(int A) {
		return -Parent[root(A)];
	}

	bool connect(int A, int B) {
		A = root(A);
		B = root(B);
		if (A == B)
			return false;

		if (size(A) < size(B))
			swap(A, B);

		Parent[A] += Parent[B];
		Parent[B] = A;

		return true;
	}
};
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int N,K,L;
	cin >> N >> K >> L;
	VI P(K);
	VI Q(K);
	VI R(L);
	VI S(L);
	UnionFind douro(N);
	UnionFind train(N);

	REP(i, K) {
		cin >> P[i] >> Q[i];
		P[i]--;
		Q[i]--;
		douro.connect(P[i], Q[i]);
	}
	REP(i, L) {
		cin >> R[i] >> S[i];
		R[i]--;
		S[i]--;
		train.connect(R[i], S[i]);
	}
	map<pair<int, int>, int> cnt;
	REP(i, N) {
		cnt[make_pair(douro.root(i), train.root(i))]++;
	}
	cout << cnt[make_pair(douro.root(0), train.root(0))];
	FOR(i,1, N) {
		cout <<" "<< cnt[make_pair(douro.root(i), train.root(i))];
	}
	return 0;
}



Measured memory_bytes: 18048
a,b,k=map(int,input().split())
for i in range(k):
  if i%2:  # あおき
    if b%2:
      b -=1
    a += b//2
    b = b//2
  else:  # たかはし
    if a%2:
      a -=1
    b += a//2
    a = a//2
print(a,b)
    

Measured memory_bytes: 9092
import java.io.*;

public class Main{
	public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        try {
            while(true){
                String x = reader.readLine();
                if(x.equals("0")) break;

                int sum = 0;
                for(int i = 0; i < x.length(); i++){
                    sum += x.charAt(i) - '0';
                }

                System.out.println(sum);
            } 
        }catch (IOException e){
            System.out.println(e);
        }
    }
}


Measured memory_bytes: 24280
N=int(input())
S=[]
T=[]
for i in range(N):
  s,t=map(str,input().split())
  t=int(t)
  S.append(s)
  T.append(t)
X=input()
num=None
for i in range(N):
  if S[i]==X:
    num=i
    break
print(sum(T[(num+1):]))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>

using namespace std;

const int INF = (1 << 30);

int main(){
    string S;
    while(cin >> S){
        vector<int> dp(1<<26, INF);
        dp[0] = 0;
        int h = 0;
        int res = 0;
        for(auto c : S){
            h ^= 1 << (c - 'a');
            res = dp[h] + 1;
            for(int i=0;i<26;i++){
                int t = h^(1<<i);
                res = min(res, dp[t] + 1);
            }
            dp[h] = min(dp[h], res);
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 262660
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
#include<numeric>
#include<set>
#include<iterator>
#include<cstdio>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
#define ll long long

int main(){
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  if(n>=k){
    cout<<(n-k)*y+k*x<<endl;
  }
  else{
    cout<<n*x<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int n;
int a[100001];
string s;
int main(){
  cin >> s;
  for(int i=0;i<s.length()-8;i++)cout << s[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
def solve():
    H, N = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(N)]
    dp = [float('inf')]*(H+10**4)
    dp[0] = 0
    for h in range(1,H+10**4):
        for i in range(N):
            if A[i][0]<=h:
                dp[h] = min(dp[h],dp[h-A[i][0]]+A[i][1])
    ans = min(dp[H:])
    return ans
print(solve())

Measured memory_bytes: 74608
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	s = '0'+s;
	++n;
	vector<vector<int>> nxt(n+1,vector<int>(10));
	rep(i,10)nxt[n][i]=n;
	for(int i=n-1;i>=0;--i){
		rep(j,10)nxt[i][j]=nxt[i+1][j];
		if(i+1<n)nxt[i][s[i+1]-'0']=i+1;
	}
	int ans = 0;
	rep(i,10)rep(j,10)rep(k,10){
		if(nxt[nxt[nxt[0][i]][j]][k]<n)++ans;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX],n;
int ans[200000],ans2[200000];vector<int> hen[200000];bool used[200000];
// テーブルを作る前処理
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;
    }
}
int 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;
}
int dfs(int a){
     int t=0,k,p=1;used[a]=true;
     for(int i=0;i<hen[a].size();i++)if(!used[hen[a][i]]){
         p=(p* dfs(hen[a][i]))%MOD;
          t+=ans[hen[a][i]];
          p=(p*COM(t,ans[hen[a][i]]))%MOD;
     }
     ans[a]=t+1;
     return p;

}
void dfs2(int a){
     used[a]=true;
     for(int i=0;i<hen[a].size();i++)if(!used[hen[a][i]]){
          ans2[hen[a][i]]=(ans2[a]*ans[hen[a][i]]%MOD*inv[n-ans[hen[a][i]]])%MOD;
          dfs2(hen[a][i]);
     }
     return;
}
     signed main(){
          COMinit();
  
       cin>>n;
     int a,b;
     for(int i=0;i<n-1;i++){
          cin>>a>>b;a--;b--;
          hen[a].push_back(b);
          hen[b].push_back(a);
     }
     fill(used,used+n,0);
     ans2[0]=dfs(0);
     fill(used,used+n,0);
     dfs2(0);
     for(int i=0;i<n;i++)cout<<ans2[i]<<endl;


   }
         


        


Measured memory_bytes: 29936
import collections

N = int(input())
V = list(map(int, input().split()))

even = V[::2]
odd = V[1::2]

even_c = collections.Counter(even)
odd_c = collections.Counter(odd)

even_max1_num = 0
even_max1_cnt = 0
even_max2_num = 0
even_max2_cnt = 0
for k, v in even_c.items():
    if v > even_max1_cnt:
        even_max2_cnt = even_max1_cnt
        even_max2_num = even_max1_num
        even_max1_cnt = v
        even_max1_num = k
    elif v > even_max2_cnt:
        even_max2_cnt = v
        even_max2_num = k

odd_max1_num = 0
odd_max1_cnt = 0
odd_max2_num = 0
odd_max2_cnt = 0
for k, v in odd_c.items():
    if v > odd_max1_cnt:
        odd_max2_cnt = odd_max1_cnt
        odd_max2_num = odd_max1_num
        odd_max1_cnt = v
        odd_max1_num = k
    elif v > odd_max2_cnt:
        odd_max2_cnt = v
        odd_max2_num = k

ans = 0
if even_max1_num == odd_max1_num:
    if even_max1_cnt == odd_max1_cnt:
        if even_max2_cnt > odd_max2_cnt:
            ans = N-(even_max2_cnt+odd_max1_cnt)
        else:
            ans = N-(even_max1_cnt+odd_max2_cnt)
    elif even_max1_cnt > odd_max1_cnt:
        ans = N-(even_max1_cnt+odd_max2_cnt)
    else:
        ans = N-(even_max2_cnt+odd_max1_cnt)
else:
    ans = N-(even_max1_cnt+odd_max1_cnt)
print(ans)


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

int main(){
	int n; cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; ++i){
		long tmp; cin >> tmp;
		bool prime = true;
		if (tmp == 1) { prime = false; continue; }
		for (int j = 2; j*j <= tmp; ++j){
			if (tmp%j == 0) {
				prime = false; break;
			}
		}
		if (prime) ++cnt;
	}
	cout << cnt << '\n';
}

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

int mn[50005];

int main() {
  int n, m; cin >> n >> m;
  for (int i = 1; i < 50005; i++) mn[i] = 0x3f3f3f3f;
  for (int i = 0; i < m; i++) {
    int v; cin >> v;
    for (int j = v; j <= n; j++)
      mn[j] = min(mn[j], mn[j - v] + 1);
  }
  cout << mn[n] << endl;
}



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

int main() {
	long n,i,j,ans,zero=0;
	cin >> n;
	vector<long> a(n),p(n+1,0);
	for(i=0; i<n; i++){
		cin >> a[i];
		p[a[i]]++;
	}
	
	ans=0;
	for(j=1; j<=n; j++){
		ans+=p[j]*(p[j]-1)/2;
	}
	for(i=0; i<n; i++){
		cout << ans-max(zero,p[a[i]]-1) << endl;
	}
}

Measured memory_bytes: 5760
/**
 *   Author:  Wasi Ur Rahman
 *   FROM RMSTU
**/
#include <bits/stdc++.h>
#define ll                      long long
#define boost                   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ticktock                cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n"
#define min3(a,b,c)             min(a,min(b,c))
#define min4(a,b,c,d)           min(d,min3(a,b,c))
#define max3(a,b,c)             max(a,max(b,c))
#define max4(a,b,c,d)           max(d,max3(a,b,c))
#define all(v)                  v.begin(),v.end()
#define revall(v)               v.rbegin(),v.rend()
#define pb                  	push_back
#define eb                      emplace_back
#define mk                      make_pair
#define setbits(x)              __builtin_popcountll(x)
#define zrobits(x)              __builtin_ctzll(x)
#define si(x)               	scanf("%d", &x)
#define sii(x, y)           	scanf("%d %d", &x, &y)
#define siii(x, y, z)       	scanf("%d %d %d", &x, &y, &z)
#define siiii(p,x, y, z)    	scanf("%d %d %d %d",&p, &x, &y, &z)
#define sll(x, y)           	scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       	scanf("%lld %lld %lld", &x, &y, &z)
#define read                	freopen("input.txt","r",stdin)
#define write               	freopen("output.txt","w",stdout)
#define println()          		cout << endl
#define printi(x)           	printf("%d\n")
#define printii(x,y)        	printf("%d %d\n")
#define printiii(x,y,z)     	printf("%d %d %d\n")
#define printl(x)           	printf("%lld\n")
#define printll(x,y)        	printf("%lld %lld\n")
#define printlll(x,y,z)     	printf("%lld %lld %lld\n")
using namespace std;
/*************************************
*          A S S E M B L E           *
**************************************/
bool Prime(ll n){if(n <= 1)return false;for (ll i = 2; i<=sqrt(n); i++)if (n % i == 0)return false;return true;}
const int mod = 1e9+7;
inline int add(int a,int b){if((a+=b)>=mod)a-=mod;return a;}
inline int dec(int a,int b){if((a-=b)<0)a+=mod;return a;}
ll mult(ll a,ll b){long long t=1ll*a*b;if(t>=mod)t%=mod;return t;}
inline int power(int a,int b){int out=1;while(b){if(b&1)out=mult(out,a);a=mult(a,a);b>>=1;}return out;}
ll fact(ll n){ll res = 1;for(ll i = n;i>=1;i--) res = mult(res,i);return res;}
ll nCr(ll n,ll r){return (fact(n)/(fact(r)*fact(n-r)));}
ll nPr(ll n,ll r){return fact(n)/fact(n-r);}
ll modpow(ll a, ll n, ll mod){ll res=1;while(n>0){if(n&1) res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
bool com(pair<ll,ll> a,pair<ll,ll> b) {if(a.first != b.first)return a.first<b.first;else return (a.second > b.second);}
/*************************************
*  E N D    G A M E   S T A R T S    *
**************************************/
int main(){
    boost;
    string str;
    cin >> str;
    int cnt = 0;
    for(int i = 0;i<str.size();i++){
        if(str[i] == '+')
            cnt++;
        else cnt--;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

// グリッド上の縦横移動
constexpr std::array<std::pair<int, int>, 4> dxdy = {
    std::pair<int, int>( 1,  0),
    std::pair<int, int>(-1,  0),
    std::pair<int, int>( 0,  1),
    std::pair<int, int>( 0, -1)
};

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

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

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

inline bool isIn(int x, int y, int H, int W){
    return 0 <= x and x < H and 0 <= y and y < W;
}
inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}

// z-algorithm
template <class T> std::vector<int> z_algorithm(const T &str) {
    const int n = str.size();
    std::vector<int> resOfCP(n); resOfCP[0] = n;
    int i = 1, j = 0;
    while (i < n) {
        while (i + j < n and str[j] == str[i + j]) ++j;
        resOfCP[i] = j;
        if (j == 0) { ++i; continue;}
        int k = 1;
        while (i + k < n and k + resOfCP[k] < j) resOfCP[i + k] = resOfCP[k], ++k;
        i += k; j -= k;
    }
    return resOfCP;
}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


std::array<std::array<lli, 10>, 10> S;

int main(void){
    int n; scanf("%d", &n);
    for(int x = 1; x <= n; ++x){
        int s = x % 10;
        int t = x; while(t >= 10) t /= 10;
        S[s][t]++;
    }
    lli res = 0;
    for(int a = 1; a <= 9; ++a){
        for(int b = 1; b <= 9; ++b){
            res += S[a][b] * S[b][a];
        }
    }
    printf("%lld\n", res);

    
    
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int n,m;
bool ans;
map<int,int> c;
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		int x; scanf("%d",&x);
		c[x]++;
	}
	scanf("%d",&m);
	ans=1;
	for (int i=1;i<=m;i++) {
		int x; scanf("%d",&x);
		c[x]--;
		if (c[x]<0) {
			ans=0; break;
		}
	}
	if (ans) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 9600
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;

long a, b;

long gcd(long x, long y) {
  return y ? gcd(y, x % y) : x;
}

long countPrimes(long n) {
  // 1は必ず公約数になるので数える
  long ans = 1;
  for (long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans++;
      while (n % i == 0) {
        n /= i;
      }
    }
  }
  if (n != 1) {
    // 1以外の約数を見つけられなかった場合
    // n は素数なのでその数を数える
    ans++;
  }
  return ans;
}

int main() {
  cin >> a >> b;
  long d = gcd(a, b);
  cout << countPrimes(d) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

const int N=1e5+5;

int n,a[N];
long long ans;

int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	for(int i=1; i<=n; i++) {
		ans+=a[i]/2,a[i]%=2;
		if(i<n and a[i] and a[i+1])
			ans++,a[i]--,a[i+1]--;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
string sa[1005];
string sb[2];
int used[1005][1005][3];
int main(){
	int n,m;
	int i,j,k,l;
	int s=0,miss=0;
	int count=0;
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>sa[i];
	}
	for(i=0;i<2;i++){
		cin>>sb[i];
	}
	for(i=0;i<n-1;i++){
		for(j=0;j<m-1;j++){
			s=0;
			for(k=0;k<2;k++){for(l=0;l<2;l++){
				if(sa[i+k][j+l]==sb[k][l]){
					s++;
				}else{
					miss=k*2+l;
				}
			}}
			if(s==4)count++;
			if(s==3){
				k=miss/2,l=miss%2;
				if(sb[k][l]=='J')s=0;
				if(sb[k][l]=='O')s=1;
				if(sb[k][l]=='I')s=2;
				used[i+k][j+l][s]++;
			}
		}
	}
	for(s=0,i=0;i<n;i++){
		for(j=0;j<m;j++){
			for(k=0;k<3;k++){
				if(s<used[i][j][k])s=used[i][j][k];
			}
		}
	}
	count+=s;
	cout<<count<<endl;
	return 0;
}

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


public class Main {
	
	

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		double[] v = new double[n];
		for (int i=0;i<n;i++) {
			v[i]=sc.nextDouble();
		}
		Arrays.sort(v);
		double ans = v[0];
		for (int i=1;i<n;i++) {
			ans = (v[i]+ans)/2;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 24916
#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() {
  int n , k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  rep(ki, k) {
    vector<int> b(n+1);
    rep(i, n) {
      int l = max(0, i-a[i]);
      int r = min(i+a[i]+1, n);
      b[l]++;
      b[r]--;
    }
    rep(i, n) b[i+1] =  b[i] + b[i+1];
    b.pop_back();
    if (a == b) break;
    a = b;
  }
  rep(i,n) cout << a[i] << endl;
}


Measured memory_bytes: 4796
#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pld = pair<LD, LD>;
const int MAX_N = 1e5;
bitset<MAX_N + 1> ist_nicht_gut;


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

    int N, M;
    cin >> N >> M;
    vector<int> elev(N + 1);
    for (int i = 1; i <= N; ++i)
    {
        cin >> elev[i];
    }
    vector<vector<int>> adj(N + 1);
    while (M--)
    {
        int i, j;
        cin >> i >> j;

        adj[i].emplace_back(j);
        adj[j].emplace_back(i);
    }

    for (int obs = 1; obs <= N; ++obs)
    {
        for (const int adj_obs : adj[obs])
        {
            if (elev[adj_obs] >= elev[obs])
            {
                ist_nicht_gut[obs] = true;
                break;
            }
        }
    }

    cout << N - ist_nicht_gut.count();
}


Measured memory_bytes: 8732
#include <iostream>
#include <algorithm>
#define INF 1e+18
#define int long long
using namespace std;

typedef pair<int,int> P;

int n,d,a[30],b[30],now = 0,ma = 0;
P val[15000000];
int seg = 1,dat[35000000] = {};

void update(int i,int x){
	i += seg - 1;
	dat[i] = max(dat[i],x);
	while(i){
		i = (i - 1) / 2;
		dat[i] = max(dat[i * 2 + 1],dat[i * 2 + 2]);
	}
}

int get(int a,int b,int k,int l,int r){
	if(b <= l || r <= a) return -INF;
	if(a <= l && r <= b) return dat[k];
	return max(get(a,b,k * 2 + 1,l,(l + r) / 2),get(a,b,k * 2 + 2,(l + r) / 2,r));
}

void dfs(int k,int x,int y){
	if(k == n / 2){
		if(y > 0) val[now++] = P(x,y);
		return;
	}
	dfs(k + 1,x,y);
	dfs(k + 1,x + a[k],y + b[k]);
	dfs(k + 1,x - a[k],y - b[k]);
}

void dfs2(int k,int x,int y){
	if(k == (n + 1) / 2){
		if(y < 0) return;
		int low = lower_bound(val,val + now,P(-d - x,-INF)) - val;
		int up = upper_bound(val,val + now,P(d - x,INF)) - val - 1;
		if(up < low) return;
		ma = max(ma,y + get(low,up + 1,0,0,seg));
		return;
	}
	dfs2(k + 1,x,y);
	dfs2(k + 1,x + a[k + n / 2],y + b[k + n / 2]);
	dfs2(k + 1,x - a[k + n / 2],y - b[k + n / 2]);
}

signed main(){
	cin >> n >> d;
	for(int i = 0;i < n;i++) cin >> a[i] >> b[i];
	dfs(0,0,0);
	sort(val,val + now);
	while(seg < now) seg *= 2;
	for(int i = 0;i < seg * 2 - 1;i++) dat[i] = -INF;
	for(int i = 0;i < now;i++) update(i,val[i].second);
	dfs2(0,0,0);
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 368536
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 C = sc.nextInt();

    sc.close();

    String result = "NO";

    for (int i = 1; i <= A; i++) {
      int bx = B * i + C;
      if (bx % A == 0) {
        result = "YES";
        break;
      }
    }

    System.out.println(result);

  }

}

Measured memory_bytes: 21844