akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 2000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll a,b,c;

int main(void){
	scanf("%lld%lld%lld",&a,&b,&c);
	if(a%2LL==0 || b%2LL==0 || c%2LL==0){
		printf("0\n");
	}else{
		printf("%lld\n",min(min(a*b,b*c),a*c));
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n;
struct node
{
    int x,y;
    int id;
}town[maxn];
struct edge
{
    int st,ed;
    int cost;
}e[maxn*4];
int fa[maxn];
bool cmp1(const node &a,const node &b)
{
    return a.x<b.x;
}
bool cmp2(const node &a,const node &b)
{
    return a.y<b.y;
}
bool cmp3(const edge &a,const edge &b)
{
    return a.cost<b.cost;
}
int Find(int x)
{
    if(fa[x]!=x)
        fa[x]=Find(fa[x]);
    return fa[x];
}
int main()
{
	scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d %d",&town[i].x,&town[i].y);
        town[i].id=i;
    }
    int k=0;
    sort(town+1,town+1+n,cmp1);
    for(int i=1;i<=n-1;i++)
    {
        e[k].st=town[i].id;
        e[k].ed=town[i+1].id;
        e[k++].cost=abs(town[i].x-town[i+1].x);
    }
	sort(town+1,town+1+n,cmp2);
    for(int i=1;i<=n-1;i++)
    {
        e[k].st=town[i].id;
        e[k].ed=town[i+1].id;
        e[k++].cost=abs(town[i].y-town[i+1].y);
    }
    sort(e,e+k,cmp3);
    for(int i=1;i<=n;i++)
        fa[i]=i;
    int ans=0;
    for(int i=0;i<k;i++)
    {
        int a=Find(e[i].st),b=Find(e[i].ed);
        if(a!=b)
        {
            ans+=e[i].cost;
            fa[b]=a;
        }
    }
	printf("%d",ans);
    return 0;
}

Measured memory_bytes: 6528
#include<iostream>
using namespace std;
typedef long long ll;
ll solve(ll x,ll n)
{
    ll ans;
    if(n%x==0)
        return n*2-x;
    ans=n/x*x*2+solve(n%x,x);
    return ans;
}
int main()
{
    ll n,x;
    ll ans;
 
    scanf("%lld%lld",&n,&x);
    ans=solve(x,n-x)+n;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define MAX 100000
int n, G[MAX];

void simulate(){
    vector<pair<int, int> > S;
    S.push_back(make_pair(G[0], 1));

    for ( int i = 1; i < n; i++ ){
	if ( (i+1) % 2 ){
	    if ( G[i] == S.back().first ) S.back().second++;
	    else S.push_back(make_pair(G[i], 1));
	} else {
	    if ( G[i] == S.back().first ) S.back().second++;
	    else {
		S.back().first = G[i];
		S.back().second++;
	    }
	}
	
	while( S.size() >= 2 ){
	    if ( S[S.size()-2].first == S[S.size()-1].first ){
		S[S.size()-2].second += S[S.size()-1].second;
		S.resize(S.size()-1);
	    } else break;
	}
    }
    int cnt = 0;
    for ( int i = 0; i < S.size(); i++ ){
	if ( S[i].first == 0 ) cnt += S[i].second;
    }
    cout << cnt << endl;
}

main(){

    while( cin >> n && n ){
	for ( int i = 0; i < n; i++ ) cin >> G[i];
	simulate();
    }
}

Measured memory_bytes: 1184
N, K = map(int, input().split())
S = [tuple(map(int, input().split())) for i in range(K)]
MOD = 998244353

dp = [1]
acc = [0, 1]
for i in range(1, N):
    c = 0
    for lk, rk in S:
        if i - lk < 0:
            continue
        c += acc[i - lk + 1] - acc[max(i - rk, 0)]
    c %= MOD
    dp.append(c)
    acc.append((acc[-1] + dp[-1]) % MOD)
print(dp[N - 1])

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

const int maxn = 20;
int n, vis[maxn], cnt;
double sum;
struct node {
	int x, y;
}po[maxn];

double dis(int x1, int y1, int x2, int y2) {
	return sqrt( (x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2) );
}
void dfs(int now,int num, double tmp) {
	if (num == n) {
		++cnt;
		sum += tmp;
		return;
	}
	forn(i, n) {
		if (!vis[i]) {
			vis[i] = 1;
			dfs(i, num + 1, tmp + dis(po[now].x, po[now].y, po[i].x, po[i].y));
			vis[i] = 0;
		}
	}
}
void solve() {
	forn(i, n) {
		vis[i] = 1;
		dfs(i, 1, 0);
		vis[i] = 0;
	}
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif
	
	sum = 0;
	cnt = 0;
	memset(vis, 0, sizeof(vis));
	scanf("%d", &n);
	forn(i, n) {
		scanf("%d%d", &po[i].x, &po[i].y);
	}
	solve();
	double ans = sum / cnt;
//	ans /= 2;
	printf("%.12lf\n", ans);
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,p,a[60],cnt0,cnt1;
ll yh[60][60],ans;
int main() {
	scanf("%d %d",&n,&p);
	cnt0=cnt1=0;
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		a[i]%=2;
		if (a[i]==0)
			cnt0++;
		else cnt1++;
	}
	yh[0][0]=1;
	for (int i=1;i<=n;i++) {
		yh[i][0]=yh[i][i]=1;
		for (int j=1;j<i;j++)
			yh[i][j]=yh[i-1][j-1]+yh[i-1][j];
	}
	ans=0;
	for (int i=0;i<=cnt0;i++)
		for (int j=0;j<=cnt1;j++)
			if (j%2==p)
				ans+=yh[cnt0][i]*yh[cnt1][j];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

def main():
    n, k = map(int, input().split())
    s = input()
    z = [len(i) for i in s.split("1") if i]
    o = [0] * (s[0] == "0") + [len(i) for i in s.split("0") if i] + [0]
    az = [0] + list(accumulate(z))
    ao = [0] + list(accumulate(o))
    if k < len(z):
        print(max(ao[i + k + 1] - ao[i] + az[i + k] - az[i] for i in range(len(z) - k + 1)))
    else:
        print(n)

if __name__ == '__main__':
    main()

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

int main() {
  int a, b, c;
  cin >> a >> b;
  c = a * b;
  if (c % 2 == 0 ) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>

int K, N;

int main() {
	scanf("%d", &K);
	if (K == 1) return puts("1\n1"), 0;
	printf("%d\n", N = (K - 1) / 4 * 2 + 2);
	for (int i = 1; i <= N; ++i, puts(""))
		for (int j = 1, z; j <= N; ++j)
			z = (i + j - 2) % N + 1,
			printf("%d ", z + (N + z <= K && i & 1 ? N : 0));
	return 0;
}

Measured memory_bytes: 1152
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * M
C = [0] * M
for i in range(M):
    B[i], C[i] = map(int, input().split())

cb = sorted(zip(C, B), reverse=True)

exchange = []
for c, b in cb:
    exchange.extend([c] * b)
    if len(exchange) >= N:
        break

A.extend(exchange)

A.sort(reverse=True)

print(sum(A[:N]))

Measured memory_bytes: 27292
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
//#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef pair<int,int> pa;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
const int N=2e3+5,M=2e6+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int n,m,bin[30]={1};
int a[N],g[N][N],ind[N],vis[N];
vector<int>e[N];
il int gcd(int a,int b){return b?gcd(b,a%b):a;}
void dfs(int x){
	re(i,0,n)if(g[x][i]>1&&!vis[i]){
		vis[i]=1;e[x].pb(i);
		ind[i]++;
		dfs(i);
	}
}
int main(){
	read(n);re(i,0,n)read(a[i]);
	sort(a,a+n);
	re(i,0,n)re(j,0,n)g[i][j]=gcd(a[i],a[j]);
	re(i,0,n)if(!vis[i])vis[i]=1,dfs(i);
	priority_queue<int,vector<int> >pq;
	re(i,0,n)if(ind[i]==0)pq.push(i);
	while(!pq.empty()){
		int x=pq.top();pq.pop();
		printf("%d ",a[x]);
		re(i,0,e[x].size())if(--ind[e[x][i]]==0)pq.push(e[x][i]);
	}
}

Measured memory_bytes: 16128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

map<ll,ll> M;

int main(){
  ll C[5][5],T=0,sa;
  rep(i,3){
    rep(j,3){
      cin >> C[i][j];
    }
  }
  rep(i,2){
    rep(j,3){
      if(j==0){
        sa=C[i+1][j]-C[i][j];
      }
      else{
        if(sa!=C[i+1][j]-C[i][j]){
          T++;
        }
      }
    }
  }
  rep(i,2){
    rep(j,3){
      if(j==0){
        sa=C[j][i+1]-C[j][i];
      }
      else{
        if(sa!=C[j][i+1]-C[j][i]){
          T++;
        }
      }
    }
  }
  cout <<(T==0 ? "Yes" : "No") << endl;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
typedef long long int ll;
#define iceil(a,b) (x+y-1)/y
#define min(x,y)(x<y?x:y)
 
using namespace std;
typedef pair<long, int> P;

 
int main() {
	FAST;

	std::priority_queue<int> q;
	int tmp;
	int a[3];

	rep(i,3) {
		cin >> tmp;
		q.push(tmp);
	}

	rep(i,3) {
		a[i] = q.top(); q.pop();
	}

	int sum = 0;
	sum += (a[0] - a[1]) + (a[1] - a[2]);

	cout << sum << "\n";
	
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.sqrt
import kotlin.math.tan

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val d = readInteger()
    val cList = readLongList()
    val sPerDay = Array(d) { readLongList() }
    val tArray = Array(d) { 0 }

    // 貪欲
    for (i in 0 until d) {
        var maxT = 1
        var maxScore = Long.MIN_VALUE
        for (j in 0 until 26) {
            tArray[i] = j + 1
            val tmpScore = calcScore(i + 1, cList, sPerDay, tArray)

            if (tmpScore > maxScore) {
                maxT = j + 1
                maxScore = tmpScore
            }
        }

//        out.println("max score: $maxScore")
        tArray[i] = maxT
    }

    // 局所探索
    var currentScore = calcScore(d, cList, sPerDay, tArray)
    repeat(100000) {
        val toD = (1..d).random()
        val toQ = (1..26).random()

        val oldQ = tArray[toD - 1]
        tArray[toD - 1] = toQ

        val score = calcScore(d, cList, sPerDay, tArray)

        if (score > currentScore) {
            currentScore = score
        } else {
            tArray[toD - 1] = oldQ
        }
    }

    for (t in tArray) {
        out.println(t)
    }
}

fun calcScore(d: Int, cList: List<Long>, sPerDay: Array<List<Long>>, tArray: Array<Int>): Long {
    var score = 0L
    val last = IntArray(26)
    for (i in 0 until d) {
        val contestNo = tArray[i] - 1
        score += sPerDay[i][contestNo]

        last[contestNo] = i + 1

        for (j in 0 until 26) score -= cList[j] * ((i + 1) - last[j])
    }

    return score
}


fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 57080
#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)-1;i>=0;i--)

#define FOR(i,m,n) for(int i=(m);i<(n);i++)
#define int long long
#define ALL(x) (x).begin(),(x).end()
typedef pair<int, int> pii;

int dp[20020][400];//i番目までで、y[i]=jとしたときの誤差の二乗和の最小値

void solve() {
	int N, M; cin >> N >> M;
	if (N == 0)exit(0);
	vector<int>C(M);
	REP(i, M)cin >> C[i];
	vector<int>X(N);
	REP(i, N) {
		cin >> X[i];
	}
	REP(i, N + 1) {
		REP(j, 300)dp[i][j] = 1e18;
	}
	dp[0][128] = 0;
	REP(i, N) {
		REP(j, 256) {
			for (int c : C) {
				int nxt = j + c;
				if (nxt < 0)nxt = 0;
				if (nxt > 255)nxt = 255;
				int dif = X[i] - nxt;
				dif *= dif;
				dp[i + 1][nxt] = min(dp[i + 1][nxt], dp[i][j] + dif);
			}
		}
	}
	int ans = 1e18;
	REP(j, 256) {
		ans = min(ans, dp[N][j]);
	}
	cout << ans << endl;
}

signed main() {
	while(true)solve();
}



Measured memory_bytes: 65740
#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 f(int a, int hp) {
  return (hp+a-1)/a;
}

int main() {
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  if (f(b,c) <= f(d,a)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
  string s;
  cin>>s;
  bool ans=0;
  int n=s.size()-1;
  if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[5]=='c'&&s[0]=='e')ans=1;
  if(s[0]=='k'&&s[n-5]=='e'&&s[n-4]=='y'&&s[n-3]=='e'&&s[n-2]=='n'&&s[n-1]=='c'&&s[n]=='e')ans=1;
  if(s[0]=='k'&&s[1]=='e'&&s[n-4]=='y'&&s[n-3]=='e'&&s[n-2]=='n'&&s[n-1]=='c'&&s[n]=='e')ans=1;
  if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[n-3]=='e'&&s[n-2]=='n'&&s[n-1]=='c'&&s[n]=='e')ans=1;
  if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[n-2]=='n'&&s[n-1]=='c'&&s[n]=='e')ans=1;
  if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[n-1]=='c'&&s[n]=='e')ans=1;
  if(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[5]=='c'&&s[n]=='e')ans=1;
  if(s[n-6]=='k'&&s[n-5]=='e'&&s[n-4]=='y'&&s[n-3]=='e'&&s[n-2]=='n'&&s[n-1]=='c'&&s[n]=='e')ans=1;
  if(ans)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}



Measured memory_bytes: 3640
S = input()
mae = int(S[0:2])
ushiro = int(S[2:4])
flg = 3
 
if 1 <= mae <= 12 :
	flg -= 2
if 1 <= ushiro <= 12 :
	flg -= 1
if flg == 3:
	print('NA')
elif flg == 2:
	print('YYMM')
elif flg == 1:
	print('MMYY')
elif flg == 0:
	print('AMBIGUOUS')

Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>

int main(int argc, char const *argv[]) {
  unsigned long long A;
  double B;
  scanf("%llu %lf", &A, &B);

  unsigned long long Bx100;
  Bx100 = round(B * 100.0);

  printf("%llu\n", (A * Bx100) / 100);

  return 0;
}


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

int main()
{
  int64_t n, m;
  cin >> n >> m;
  vector<int64_t> v(n), d;
  vector<pair<int64_t, int64_t>> bc(m);

  for (auto&& e : v)
    cin >> e;

  for (auto&& e : bc)
    cin >> e.second >> e.first;

  sort(begin(bc), end(bc), greater<>());

  for (auto&& e : bc) {
    if (d.size() >= size_t(n)) break;
    for (int i = 0; i < e.second; i++) {
      d.push_back(e.first);
    }
  }

  v.insert(end(v), begin(d), end(d));
  sort(begin(v), end(v), greater<>());
  v.resize(n);

  int64_t ans(0);
  for (const auto& e : v) {
    ans += e;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5744
import java.util.Arrays;
import java.util.*;
class Main
{
	static ArrayList<Integer> adj[];
	static int dpi[],dpo[],vis[];
	static int ans;
	public static void main (String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int i;
		int n=sc.nextInt(); int m=sc.nextInt();
		dpi=new int[n]; dpo=new int[n];
		adj=new ArrayList[n]; ans=0;
		for(i=0;i<n;i++)
			adj[i]=new ArrayList();
		for(i=0;i<m;i++) 
		{
			int u=sc.nextInt()-1; int v=sc.nextInt()-1;
			adj[u].add(v); 
		}
		vis=new int[n];
		for(i=0;i<n;i++)
		{
			if(vis[i]==0)
				dfs(i,-1,0);
		}
		for(i=0;i<n;i++)
			if(dpi[i]+dpo[i]>ans)
				ans=dpi[i]+dpo[i];
		System.out.println(ans);
	}
	public static void dfs(int v,int p,int l)
	{
		vis[v]=1;
		dpi[v]=Math.max(dpi[v], l);
		if(p!=-1)
		{
			dpo[p]=Math.max(dpo[p], 1+dpo[v]);
			dpi[v]=Math.max(dpi[v], dpi[p]+1);
		}
		for(int node:adj[v])
		{
			if(vis[node]==0)
			{
				dfs(node,v,l+1);
				dpo[v]=Math.max(dpo[v], 1+dpo[node]);
			}
			else
			{
				dpi[node]=Math.max(dpi[node], dpi[v]+1);
				dpo[v]=Math.max(dpo[node]+1, dpo[v]);
			}
		}
		
	}
} 

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

vector<int > L(11);

int main(){
	int  N ;
	cin >> N ;
	for( int i = 0 ;i < N ; i++){
		cin >> L[i] ;
	}
	sort(L.begin(),L.begin()+N);
	int sum = 0 ; 
	for( int i = 0 ; i < N-1 ; i++ ){
		sum += L[i] ;
	}
	if(L[N-1] < sum ){
		puts("Yes");
	}
	else{
		puts("No");
	}

	return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 

  vector<int> a(3);
  cin>>a.at(0)>>a.at(1)>>a.at(2);

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

  int wk1 = a.at(2)-a.at(1);
  int wk2 = a.at(2)-(a.at(0)+wk1);
  int wk3 = ceil(wk2/2.0)+wk2%2;

  cout<<wk1+wk3<<endl;


	return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 ip;
    cin >> ip;
    int32 n = 0;
    vector<int32> s;
    while(ip > 0){
        s.pb(ip % 10);
        ip /= 10;
        n++;
    }
    int64 sum = 0;
    for(int32 mask = 0; mask < (1 << (n - 1)); mask++){
        // cout << bitset<10>(mask) << endl;
        int64 ans = s[0];
        int32 d = 0;
        FOR(i,1,n){
            if(mask >> (i-1) & 1){
                d = 0;
                ans += s[i];
            }else{
                d++;
                ans += s[i] * pow(10,d);
            }
        }
        // cout << ans << endl;
        sum += ans;
    }
    ANS(sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

template<typename T> T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    set<int> pb;

    int c = 0;
    int i = 0;
    while (c <= N) {
        i++;
        c += i;
        pb.insert(i);
    }

    int d = c - N;
    if (d > 0) {
        pb.erase(d);
    }

    for (auto&& i : pb) {
        cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
int h,w,i=0,i2=0,s=0,s2=0;
while(1){
	cin >>h >>w;
	if(h==0 && w==0) break;
	for(i=0; i<h; i++)
		{for(i2=0; i2<w; i2++)
			{			
			s=i;
			s2=i2;
			s%=2;
			s2%=2;
			if(s==s2) { cout<<"#";}
			else {cout<<".";};
			}
		cout<<"\n";
		}
	cout<<"\n";
	}
return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<map>

using namespace std;
using LLI = long long int;

int main(void) {
	LLI N, a, MIN = 1e9, MAX = 0,res = 0;
	cin >> N;
	map<LLI,LLI>M;
	for (int i = 0; i < N;i++) {
		cin >> a;
		MIN = min(MIN, a);
		MAX = max(MAX, a);
		M[a]++;
	}
	for (int i = MIN; i <= MAX;i++) {
		if (M[i] + M[i + 1] + M[i - 1] > res) {
			res = M[i] + M[i + 1] + M[i - 1];
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
int main()
{
	ios;
	ll n,d;
	cin>>n;
	while(n!=0)
	{
		d=n%10;
		if(d==7)
		{
			cout<<"Yes"<<endl;
			exit(0);
		}
		n=n/10;
	}
	cout<<"No"<<endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main(void){
  int number;
  cin >> number;

  vector<int> weight(number);
  for(int i = 0; i < number; i++) cin >> weight[i];

  vector<int> sums(number);
  sums[0] = weight[0];
  for(int i = 1; i < number; i++){
    sums[i] = sums[i - 1] + weight[i];
  }

  int sum = sums[number - 1];
  float half_weight = sum / 2;
  int half_point;

  for(half_point = 0; half_point < number; half_point++){
    if(sums[half_point] > half_weight) break;
  }

  int a = abs(sum - sums[half_point] * 2);
  int b = abs(sum - sums[half_point - 1] * 2);
  if(a > b)
    cout << b << endl;
  else
    cout << a << endl;

  return 0;
}

Measured memory_bytes: 256
//template code, C343, 2019
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;

	// adjacency list of edges
	public Graph() {
		totalVertex = 0;
	}

	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for (int i = 0; i < totalVertex; i++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			// System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for (int j = 0; j < degree; j++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}
			adjList.add(tmp);
		}
		in.close();

	}

	public void printAdjMatrix() {
		int[][] adjMatrix = new int[totalVertex][totalVertex];
		// complete the following
		int count = 0;
		for (LinkedList<Integer> neighbors : adjList) {
			for (Integer n : neighbors) {
				adjMatrix[count][n] = 1;
			}
			count++;
		}
		for (int i = 0; i < adjMatrix.length; i++) {
			for (int j = 0; j < adjMatrix[i].length; j++) {
				if (j == adjMatrix[i].length - 1) {
					System.out.print(adjMatrix[i][j]);
				} else {
					System.out.print(adjMatrix[i][j] + " ");
				}
			}
			System.out.println();
		}
//		
//		for (int i = 0; i< totalVertex; i++) {
//			if(adjList.get(i)!=null) {
//				adjMatrix
//			}
//		}

	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();

	}
}


Measured memory_bytes: 33304
#include<cstdio>
#include<string.h>
#include<stack>
#include<iostream>
#include<algorithm>
using namespace std;
char s1[100000+10];
char s2[100000+10];
int map[6010][6010];
stack<char> s;
int n,t,num,tot=1,t_t=0;
int main()
{
	ios::sync_with_stdio(false);
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	int len1=strlen(s1+1);
	int len2=strlen(s2+1);
/*	if(len1>len2)
	{
		swap(len1,len2);
		swap(s1,s2);
	}
*/	for(register int i=1;i<=len1;i++)
	{
		for(register int j=1;j<=len2;j++)
		{
			if(s1[i]==s2[j])
			{
				map[i][j]=map[i-1][j-1]+1;
			}
			else map[i][j]=max(map[i-1][j],map[i][j-1]);
		}
	}
/*	for(int i=1;i<=len1;i++)
	{
		for(int j=1;j<=len2;j++)
		{
			cout<<map[i][j]<<' ';
		}
		cout<<endl;
	}*/
//	cout<<map[len1][len2]<<'\n';
	int ans=map[len1][len2];
	int xx=len1,yy=len2;
	while(ans)
	{
		int t=ans-1;
		ans--;
		if(xx-1>=0)
		{
			while(map[xx-1][yy]!=t)
			{
				xx--;
			}
		}
		if(yy-1>=0)
		{
			while(map[xx][yy-1]!=t)
			{
				yy--;
			}
		}
		s.push(s2[yy]);
		yy--;
	}
	while(!s.empty())
	{
		cout<<s.top();
		s.pop();
	}
	if(map[len1][len2]==0) cout<<" ";
	return 0;
}
/*
ababab
bab
*/

/*
ababab
cbabcc
*/

Measured memory_bytes: 50848
#include<bits/stdc++.h>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
ll dp[maxn];
ll n,W;
ll v[maxn];
ll w[maxn];
int main()
{
    memset(dp,0x3f,sizeof(dp));
    gbtb;
    cin>>n>>W;
    repd(i,1,n)
    {
        cin>>w[i]>>v[i];
    }
    ll ans=0ll;
    dp[0]=0;
    repd(i,1,n)
    {
        for(int j=1e5;j>=v[i];--j)
        {
            {
                dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
                if(dp[j]<=W)
                    ans=max(ans,(ll)(j));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}


Measured memory_bytes: 11392
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		int[] t = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.next();
			t[i] = sc.nextInt();
		}
		String x = sc.next();
		sc.close();
		int ans = 0;
		boolean b = false;
		for (int i = 0; i < n; i++) {
			if (b) {
				ans += t[i];
			}
			if (s[i].equals(x)) {
				b = true;
			}
		}
		System.out.println(ans);
	}

	// 配列要素数が1だと前触れなくバグるので注意！！！REりたくなければ要素数を保証するか例外処理を入れろ！！！
	public static long gcd(final long[] param) {
		final int len = param.length;
		long g = gcd(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			g = gcd(g, param[i + 1]);
		}
		return g;
	}

	public static long gcd(long a, long b) {
		// a > b にする(swap)
		if (a < b) {
			a = a ^ b;
			b = a ^ b;
			a = a ^ b;
		}
		// ユークリッドの互除法
		long r = -1;
		while (r != 0) {
			r = a % b;
			a = b;
			b = r;
		}

		return a; // b には r=0 の値が入るため、a を返す
	}

	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	public static long lcm(final int[] param) {
		final int len = param.length;
		long l = lcm(param[0], param[1]);
		for (int i = 1; i < len - 1; i++) {
			l = lcm(l, param[i + 1]);
		}
		return l;
	}

	public static int arrayMax(int[] array) {
		int ans = Integer.MIN_VALUE;
		for (int i = 0; i < array.length; i++) {
			if (array[i] > ans)
				ans = array[i];
		}
		return ans;
	}

	public static int[] arrayInt(Scanner sc, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		return array;
	}

	public static long[] arrayLong(Scanner sc, int n) {
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextLong();
		}
		return array;
	}

	public static double[] arrayDouble(Scanner sc, int n) {
		double[] array = new double[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextDouble();
		}
		return array;
	}
}


Measured memory_bytes: 23124
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n;
	cin >> n;
	map<int, int> mp;
	REP(i,n){
		cin >> tmp;
		mp[tmp]++;
	}
	vector<int> v;
	int only = 0;
	bool zero = false;
	for(auto it = mp.begin(); it != mp.end(); it ++){
		if(it->second >= 3) zero = true;
		if(it->second == 2){
			v.push_back(-12 + it->first);
			v.push_back(12 - it->first);
		}
		if(it->second == 1) only += 1 << it->first;
	}
	vector<int> now;
	ans = 0;
	REP(i, 1 << 13){
		now.clear();
		now.push_back(-12);
		now.push_back(12);
		copy(v.begin(), v.end(), back_inserter(now));
		REP(j, 13){
			if(only & (1<<j)){
				if(i & (1<<j)) now.push_back(-12 + j);
				else now.push_back(12 - j);
			}
		}
		sort(now.begin(), now.end());
		tmp = 24;
		REP(i, now.size()-1) tmp = min(tmp, now[i+1] - now[i]);
		ans = max(ans, tmp);
	}
	if(zero) cout << 0 << endl;
	else cout << ans << endl;
}

Measured memory_bytes: 764
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

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

func main() {
	k, s := scanInt(), scanString()
	if len(s) <= k {
		fmt.Println(s)
	} else {
		fmt.Println(s[0:k] + "...")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  int A[N]; rep(i,N) cin >> A[i];
  map<int, ll> count; rep(i,N) count[A[i]]++;
  ll sum = 0; for (auto x: count) sum += x.second * (x.second-1) / 2;
  rep(i,N) {
    ll result = sum - (count[A[i]]-1);
    cout << result << endl;
  }
  return 0;
}

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

int main(){
  int n;cin>>n;
  long long sh=0,lo=0;
  map<long long, int> mp;
  REP(i,n){
    long long t;cin>>t;
    mp[t]++;
  }
  for(auto p:mp){
    if(p.second>=2&&p.second<4){
      sh=lo;
      lo=p.first;
    }else if(p.second>=4){
      sh=lo=p.first;
    }
  }
  
  cout<<sh*lo;
}

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

int main(){
	int a,b,c,d,count=0;
	cin>>a>>b;
	bool arr[a][b];
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			arr[i][j]=true;
		}
	}
	cin>>c>>d;
	for(int i=0;i<c;i++){
		for(int j=0;j<b;j++){
			arr[i][j]=false;
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<d;j++){
			arr[i][j]=false;
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(arr[i][j]==true){
				count++;
			}
		}
	}
	cout<<count<<endl;
}

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

struct Node {
  int p, l, r;
};

struct Node T[10000];
int n;

//先行順巡回
void preParse(int u) {
  if ( u == -1 ) return;
  cout << " " << u;
  preParse(T[u].l);
  preParse(T[u].r);  
}

//中間順巡回
void inParse(int u) {
  if ( u == -1 ) return;
  inParse(T[u].l);
  cout << " " << u;
  inParse(T[u].r);
}

//後行順巡回数
void postParse(int u) {
  if ( u == -1 ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  cout << " " << u;
}

int main() {
  int v, l, r, root;
  
  cin >> n;
  //初期化
  for ( int i = 0; i < n; i++ ) {
    T[i].p = -1;
  }
  
  //入力
  for ( int i = 0; i < n; i++ ) {
    cin >> v >> l >> r;
    T[v].l = l;
    T[v].r = r;
    if ( l != -1 ) T[l].p = v;
    if ( r != -1 ) T[r].p = v;    
  }

  for ( int i = 0; i < n; i++ ) if ( T[i].p == -1 ) root = i;
  
  cout << "Preorder" << endl;
  preParse(root);
  cout << endl;
  cout << "Inorder" << endl;
  inParse(root);
  cout << endl;
  cout << "Postorder" << endl;
  postParse(root);
  cout << endl;

  return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000001;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

ll gcd(ll x,ll y){
	if(y == 0)return x;
	return gcd(y,x%y);
}

int main(){
	static ll n;
	static ll a[100010];
	scanf("%lld",&n);
	rep(i,n)scanf("%lld",&a[i]);
	
	//if(n != 2){
		int cnt = 0;
		while(1){
			ll sum = 0;
			rep(i,n)sum += a[i];
			if(sum == n){
				if(cnt%2 == 0)puts("Second");
				else puts("First");
				return 0;
			}
			if((sum-n)%2 == 1){
				if(cnt%2 == 0)puts("First");
				else puts("Second");
				return 0;
			}
			int cnt_ = 0;
			rep(i,n){
				if(a[i]%2 == 1)cnt_ ++;
			}
			if(cnt_ > 1){
				if(cnt%2 == 0)puts("Second");
				else puts("First");
				return 0;
			}
			rep(i,n){
				if(a[i]%2 == 1){
					if(a[i] == 1){
						if(cnt%2 == 0)puts("Second");
						else puts("First");
						return 0;
					}
					else{
						a[i] -= 1;
						break;
					}
				}
			}
			ll g = 0;
			rep(i,n)g = gcd(g,a[i]);
			rep(i,n)a[i] /= g;
			cnt ++;
		}
	//}
}
	



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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> countA;
    REP(i, N)
    {
        cin >> A[i];
        countA[A[i]]++;
    }

    sort(ALL(A));
    ll aMax = A[N - 1];
    vector<bool> isCalced(aMax + 1, false), sieve(aMax + 1, true);
    ll ans = 0;
    REP(i, N)
    {
        if (isCalced[A[i]])
        {
            continue;
        }
        isCalced[A[i]] = true;
        if (sieve[A[i]])
        {
            if (countA[A[i]] == 1)
            {
                ans++;
            }
            ll k = 2;
            while(A[i] * k <= aMax)
            {
                sieve[A[i] * k] = false;
                k++;
            }
        }
    }

    cout << ans << endl;
}


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

int H, W;

int bfs(vector<string> s, int x, int y) {
  vector<vector<int>> dist(H, vector<int>(W, -1));
  dist.at(x).at(y) = 0;
  vector<int> mx(4), my(4);
  mx = {1, 0, -1, 0}, my = {0, 1, 0, -1};
  queue<pair<int,int>> Q;
  Q.push({x, y});

  int res = 0;
  while (Q.size()) {
    int x = Q.front().first, y = Q.front().second;
    res = max(res, dist.at(x).at(y));
    Q.pop();
    for (int i = 0; i < 4; i++) {
      int nx = x + mx.at(i), ny = y + my.at(i);
      if (nx < 0 || ny < 0 || nx >= H || ny >= W) continue;
      if (s.at(nx).at(ny) == '.' && dist.at(nx).at(ny) == -1) {
        dist.at(nx).at(ny) = dist.at(x).at(y) + 1;
        Q.push({nx, ny});
      }
    }
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) cin >> S.at(i);

  int ans = 0;
  for (int x = 0; x < H; x++) 
    for (int y = 0; y < W; y++)
      if (S.at(x).at(y) == '.') ans = max(ans, bfs(S, x, y));

  cout << ans << endl;
}

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

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int n;
    cin >> n;
    int a[n],b[n];
    for(int i=0;i<n;i++){
    	int x,y;
    	cin >> x >> y;
    	a[i]=x+y,b[i]=x-y;
    }
    sort(a,a+n),sort(b,b+n);
    cout << max(a[n-1]-a[0],b[n-1]-b[0]);
}

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

int main()
{
	int n[5];
	
	for(int i = 0; i < 5; i++){
		scanf("%d", &n[i]);
	}
	
	sort(n,n+5);
	reverse(n, n+5);
	
	for(int i = 0; i < 4; i++){
		printf("%d ", n[i]);
	}
	
	printf("%d\n", n[4]);
	
	return(0);
}

Measured memory_bytes: 1040
#include <stdio.h>
int main(void) {
	int n, m, i, a, b;
	scanf("%d%d", &n, &m);
	int ans[51] = {};
	for (i = 0; i < m; i++) {
		scanf("%d%d", &a, &b);
		ans[a]++;
		ans[b]++;
	}
	for (i = 1; i <= n; i++) {
		printf("%d\n",ans[i]);
	}

	return 0;
}

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

using namespace std;

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

	int h, w;
	cin >> h >> w;

	int n;
	cin >> n;

	int sr, sc;
	cin >> sr >> sc;

	string s;
	cin >> s;

	string t;
	cin >> t;

	map<char, int> id;
	id['L'] = 0;
	id['R'] = 1;
	id['U'] = 2;
	id['D'] = 3;

	vector<int> cnts(4);
	vector<int> cntt(4);
	for(int i = 0; i < n; ++i) {
		cnts[id[s[i]]] += 1;
		if(sr - cnts[2] + cntt[3] <= 0 || sr + cnts[3] - cntt[2] > h || sc - cnts[0] + cntt[1] <= 0 || sc + cnts[1] - cntt[0] > w) {
			cout << "NO" << '\n';
			exit(0);
		}
		if(cnts[id[t[i]] ^ 1] > 0) {
			cnts[id[t[i]] ^ 1] -= 1;
		} else {
			cntt[id[t[i]]] += 1;
		}
	}

	bool okw = false;
	for(int i = -cntt[0]; i <= cntt[1]; ++i) {
		int cur = sc + i;
		if(1 <= cur - cnts[0] && cur + cnts[1] <= w) {
			okw = true;
		}
	}

	bool okh = false;
	for(int i = -cntt[2]; i <= cntt[3]; ++i) {
		int cur = sr + i;
		if(1 <= cur - cnts[2] && cur + cnts[3] <= h) {
			okh = true;
		}
	}

	if(okw && okh) {
		cout << "YES" << '\n';
	} else {
		cout << "NO" << '\n';
	}

	return 0;
}


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

using namespace std;

int main()
{
  int N;
  string A, B, C;
  cin >> N >> A >> B >> C;
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    map<char, int> m;
    m[A[i]]++;
    m[B[i]]++;
    m[C[i]]++;
    ans += 3 - max({m[A[i]], m[B[i]], m[C[i]]});
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define bigrep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define reps(i, n, s) for (int i = s; i < (int)(n); i++)
#define twopo(k)  1 << k

typedef vector<int> vec1;
typedef vector<vector<int>> vec2;
typedef vector<vector<char>> cvec2;
typedef pair<int, int> pairi;
typedef map<int, int> mapii;

vec1 vecplus(const vec1 &first, const vec1 &second){
  int len = first.size();
  vec1 answer(len);
  rep(i,len){
    answer.at(i) = first.at(i) + second.at(i);
  }
  return answer;
}

vec2 listmake(const int &row, const int &col){
  vec2 list;
  rep(i,row){
    vec1 v(col);
    rep(j,col){
      cin >> v.at(j);
    }
    list.push_back(v);
  }
  return list;
}

int main(){
  int K;
  cin >> K;
  string S;
  cin >> S;
  int len = S.size();
  if(len <= K){
    cout << S << endl;
  }else{
    string ans = "";
    rep(i,K){
      ans += S.at(i);
    }
    ans += "..." ;
    cout << ans << endl;
  }
}



Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int r=0;
	if(a>c){
		r =a;
	}
	else{
		r = c;
	}
	int q;
	if(b>d){
		q = d;
	} 
	else{
		q = b;
	}

	int res;

	res = q-r;
	if(res>0){
	cout<<res;}
	else{
		cout<<"0";
	}
}

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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 1e5 + 5;

typedef long long ll;

int n, a[N], cnt[N];

int main(){
      cin >> n;

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

      sort(a + 1, a + n + 1);

      for(int i = 1; i <= n; i ++){
            cnt[a[i]] ++;
            if(a[i] < (a[n] + 1) / 2){
                  puts("Impossible");
                  return 0;
            }
      }

      for(int i = (a[n] + 1) / 2; i <= a[n]; i ++){
            if(!cnt[i]){
                  puts("Impossible");
                  return 0;
            }
            if(i != (a[n] + 1) / 2 && cnt[i] < 2){
                  puts("Impossible");
                  return 0;
            }
            if(i == (a[n] + 1) / 2 && a[n] % 2 == 0 && cnt[i] != 1){
                  puts("Impossible");
                  return 0;
            }
            if(i == (a[n] + 1) / 2 && a[n] % 2 && cnt[i] != 2){
                  puts("Impossible");
                  return 0;
            }
      }

      puts("Possible");
}


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

bool prime(ll x){
    if(x<=1)    return false;
    for(int i=2; i*i<=x; i++)
        if(x%i==0) return false;
    return true;
}

int main(){
    ll x;  cin >> x;
    
    while(!prime(x)) x += 1;
    
    cout << x << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<int> A(N);
    rep(n,0,N) cin>>A.at(n);

    map<int,int> mp;
    for(auto a:A) mp[a]++;

    string ans="No";
    if(mp.size()==1){
        if(mp.count(0)) ans="Yes";
    }else if(mp.size()==2){
        if(N%3==0){
            bool correct=true;
            for(auto m:mp){
                if(m.first==0){if(m.second!=N/3) correct=false;}
                else{if(m.second!=2*N/3) correct=false;}
            }
            if(correct) ans="Yes";
        }
    }else{
        if(N%3==0){
            bool correct=true;
            vector<int> v;
            for(auto m:mp){
                v.push_back(m.first);
                if(m.second!=N/3) correct=false;
            }
            if((v.at(0)^v.at(1))!=v.at(2) || (v.at(1)^v.at(2))!=v.at(0) || (v.at(2)^v.at(0))!=v.at(1)) correct=false;
            if(correct) ans="Yes";
        }
    }

    cout<<ans<<endl;
}

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

//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define-----------------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1 << 25
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cerr << #x << " = " << (x) << "\n";
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)

//typedef----------------------------------------------------------------------------------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
//const------------------------------------------------------------------------------------------------------------------------
const double EPS = 1e-10;
const double PI = acos( -1.0 );

//global-----------------------------------------------------------------------------------------------------------------------
int n, m, k;
VI a, b, c;
#define mod 1000000007
//function-------------------------------------------------------------------------------------------------------------------- 
int main() {
	scanf( "%d", &n );
	scanf( "%d", &m );
	rep( i, m ) {
		int x, y;
		scanf( "%d %d", &x, &y );
		printf( "%d\n", ( ( min( min( ( x - 1 ) % n, ( n - x ) % n ), min( ( y - 1 ) % n, (n - y ) % n ) ) )% 3 ) + 1 );
		
	}
	return 0;
}

Measured memory_bytes: 1188