akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, d, a;
	cin >> n >> d >> a;
	d *= 2;
	
	set <pi> c;
	map <int, int> mp;
	
	FOR (i, 1, n)
	{
	    int x, y;
	    cin >> x >> y;
	    c.insert({x, y});
	}
	
	auto it = c.begin();
	FOR (i, 1, n) mp[(*(it++)).fi] = i;
	
	int sum = 0, pre[n + 100] = {}, i = 0, ans = 0;
	for (pi j: c)
	{
	    int h = j.se, x = j.fi;
	    sum -= pre[++i];
	    h -= sum;
	    
	    if (h > 0)
	    {
	        int meow = (h+a-1)/a, nxt;
	        ans += meow;
	        sum += meow*a;
	        if (mp.upper_bound(x + d) != mp.end()) nxt = (*mp.upper_bound(x + d)).se;
	        else nxt = n + 1;
	        pre[nxt] += meow*a;
	    }
	}
	
	cout << ans;
}

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

int main() {
    int n;
    string s;
    cin>>n>>s;

    if(n%2==1) {
        cout<<"No"<<endl;
        return 0;
    }
    else {
        int z = 1;
        for(int i=0; i<n/2; i++) {
            if(s.at(i)!=s.at(i+n/2)) z--;
        }
        if(z==1) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
a = input().split()

n = int(a[0])
m = int(a[1])

a1 = m - (n - 1)
a2 = m + (n)

max = 1000000
min = -1000000

if a1 < min:
    a1 = min
if a2 > max:
    a2 = max

l = map(str, range(a1, a2))
print(' '.join(l))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> cnt(100001,0);
  for(int i=0; i<n; i++){
    int a, b;
    cin >> a >> b;
    cnt[a] += b;
  }
  for(int i=1; i<100001; i++){
    if(k<=cnt[i]){
      cout << i << endl;
      break;
    }
    k -= cnt[i];
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  int N;
  cin >> N;

  vector<string> S(N);
  REP(i, N) cin >> S[i];
  
  ll B[5] = {0};
  REP(i,N){
    if(S.at(i).at(0)=='M'){
      B[0]++;
    }else if(S.at(i).at(0)=='A'){
      B[1]++;
    }else if(S.at(i).at(0)=='R'){
      B[2]++;
    }else if(S.at(i).at(0)=='C'){
      B[3]++;
    }else if(S.at(i).at(0)=='H'){
      B[4]++;
    }
  }
  ll x = B[0]*B[1]*B[2]+
  B[0]*B[1]*B[3]+
  B[0]*B[1]*B[4]+
  B[0]*B[2]*B[3]+
  B[0]*B[2]*B[4]+
  B[0]*B[3]*B[4]+
  B[1]*B[2]*B[3]+
  B[1]*B[2]*B[4]+
  B[1]*B[3]*B[4]+
  B[2]*B[3]*B[4];
  cout << x << endl;
  
}

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

int main() {
    string S;
    cin >> S;
    map<long long,long long> mp;
    mp[0] = 1;
    long long now = 0, ten = 1;    
    for(int i = S.size()-1; i >= 0;i--){
        now = (now + ( S[i] - '0') * ten) % 2019;
        ten *= 10;
        ten %= 2019;
        mp[now]++;
    }
    long long ans = 0;
    for(auto m:mp){
        ans += m.second*(m.second-1)/2;
    }
    cout << ans << endl;
    
    
}


Measured memory_bytes: 3804
//
//  main.cpp
//  ABC174E
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
vector<int>a;
int n,k;
bool cc(int m){
    ll now=0;
    rep(i,n) now+=((a.at(i)-1)/m); // 答えをmとした時の、それぞれの丸太を切る回数の合計
    if(now<=k){
        return true;
    }else{
    return false;
    }
}
int main(int argc, const char * argv[]) {
    cin>>n>>k;
    a.resize(n);
    rep(i,n) cin >> a.at(i);
    int l=0;
    int r=1e9;
    while(r-l > 1){
        int m=(l+r)/2;
        if(cc(m)==true){
            r=m;
        }else{
            l=m;
        }
    }
    cout<<r<<endl; // 答えは切り上げなので右側を採用する
    return 0;
}


Measured memory_bytes: 3544
N, M, K = map(int, input().split())
mod = int(1e9) + 7
fact = [1 for _ in range(N*M+1)]
invf = [1 for _ in range(N*M+1)]
def inved(a):
  x, y, u, v, k, l = 1, 0, 0, 1, a, mod
  while l != 0:
    x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
    k, l = l, k % l
  return x % mod
for i in range(N*M):
  fact[i+1] = (fact[i] * (i + 1)) % mod
invf[-1] = inved(fact[-1])
for i in range(N*M, 0, -1):
  invf[i-1] = (invf[i] * i) % mod
Z = (fact[M*N-2] * invf[K-2] * invf[M*N-K]) % mod
X = M * (N + 1) * (N - 1)
X %= mod
Y = N * (M + 1) * (M - 1)
Y %= mod
XY = (inved(6) * M * N * (X + Y)) % mod
print((XY * Z) % mod)

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

int main()
{
    int m, f, r;

    while (1)
    {
        scanf("%d %d %d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1)
            break;
        int p = m + f;
        if (m == -1 || f == -1)
            printf("F\n");
        else if (p >= 80)
            printf("A\n");
        else if (p >= 65)
            printf("B\n");
        else if (p >= 50)
            printf("C\n");
        else if (p >= 30)
        {
            if (r >= 50)
                printf("C\n");
            else
                printf("D\n");
        }
        else
            printf("F\n");
    }
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#include <string.h>
#include <cmath>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define max3(A,B,C) max((A),max((B),(C)))
#define popcount(X) __builtin_popcount(X)
#define popcountl(X) __builtin_popcountl(X)
#define getbit(x,i) (1&((x)>>(i)))
#define setbit(x,i,bit) ((x)|=((bit)<<(i)))
#define getbitl(x,i) (1&((x)>>((ll)i)))
#define setbitl(x,i,bit) ((x)|=((bit)<<((ll)i)))
#define log2(x) (32 - __builtin_clz(x))
#define log2l(x) (32 - __builtin_clzl(x))

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

const int INF = 0x3f3f3f3f;
const long long int INFL = 0x3f3f3f3f3f3f3f3f;
const double pi = atan(1.0)*4.0;
const int N = 3e5 + 500;

int dist[N], mrc[N];
vii v[N];
set<ii> st;

void Dijkstra(int o) {
	memset(dist,INF,sizeof(dist));
	dist[o] = 0;
	st.clear();
	st.insert(mp(0,o));
	memset(mrc,0,sizeof(mrc));
	while(!st.empty()) {
		set<ii>::iterator it = st.begin();
		if(mrc[it->s] == 0) {
			mrc[it->s] = 1;
			dist[it->s] = it->f;
			for(int i = 0; i < v[it->s].size(); i++) {
				st.insert(mp(dist[it->s] + v[it->s][i].s,v[it->s][i].f));
			}
		}
		st.erase(it);
	}
}

int main(void) {
	int n;
	
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++) {
		int u, k;
		scanf("%d %d", &u, &k);
		for(int j = 0; j < k; j++) {
			int vt, c;
			scanf("%d %d", &vt, &c);
			v[u].pb(mp(vt,c));
		}
	}
	Dijkstra(0);
	for(int i = 0; i < n; i++) {
		printf("%d %d\n", i, dist[i]);
	}
	
	return 0;
}


Measured memory_bytes: 12624
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>
using namespace std;
typedef long long ll;

int main(){
    ll N,K;
    cin >> N >> K;
    ll a,b;
    a = llabs(N - (ll)(N/K)*K);
    b = llabs(a - K);
    if(a > b){
        cout << b;
    }else{
        cout << a;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int w,a,b;
  cin >> w >> a >> b;
  if(a<b){
    cout << max(0,b-(a+w)) << endl;
  }
  else if(b<a){
    cout << max(0,a-(b+w)) << endl;
  }
  else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
*A, = map(int, input().split())

dp1 = [A[0]]
dp2 = [-A[0]]
for i in range(1, N-1):
    dp1.append(max(dp1[i-1] + A[i], dp2[i-1] - A[i]))
    dp2.append(max(dp1[i-1] - A[i], dp2[i-1] + A[i]))
dp1.append(dp1[-1] + A[N-1])
dp2.append(dp2[-1] - A[N-1])


print(max(dp1[-1], dp2[-1]))

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(ll, n, k);
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  rep(i, k) {
    vector<ll> na(n);
    rep(j, n) na[j] = 1;
    {
      priority_queue<ll, vector<ll>, greater<ll>> que;
      rep(j, n) {
        while (!que.empty() && que.top() < j) que.pop();
        na[j] += que.size();
        que.push(j + a[j]);
      }
    }
    {
      priority_queue<ll> que;
      for (ll j = n - 1; j >= 0; --j) {
        while (!que.empty() && que.top() > j) que.pop();
        na[j] += que.size();
        que.push(j - a[j]);
      }
    }
    bool changed = false;
    rep(j, n) if (na[j] != a[j]) changed = true;
    if (!changed) break;
    swap(a, na);
  }
  rep(i, n) {
    cout << a[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 10020
#include <iostream>
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,m,n) for(int (i)=(m);(i)<(n); i++)
#define REP(i, n) for(int (i)=0;(i)<(n);(i)++)
//------
#define R2(i,in,j,jn) REP(i,in)REP(j,jn)

using namespace std;


int main(void){
	int I;
	cin>>I;
	int z;
	z=(I/1.08);//zeinuki
//	cout <<(I/1.08)<<" : "<<z;
	int Z=z*1.08;//zeikomi
	if(Z==I)Z=I;
	else if(int((z+1)*1.08)==I){
		z=z+1;
		Z=int(z*1.08);
	}else{
		cout << ":(";
		return 0;
	}
	cout << to_string(z);
	return 0;
}//422

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, q = map(int, input().split())
edges = [[]for _ in range(n)]
for _ in range(n-1):
    a, b = list(map(lambda x: int(x)-1, input().split()))
    edges[a].append(b)
    edges[b].append(a)

counts = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    counts[p-1] += x


def dfs(v, parent):
    for v2 in edges[v]:
        if v2 == parent:
            continue
        counts[v2] += counts[v]
        dfs(v2, v)


dfs(0, -1)
print(*counts)

Measured memory_bytes: 237360
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 10010
#define llg long long 
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,mid,ans,x;
int main()
{
//	yyj("A");
	cin>>x;
	llg l=1,r=1e9;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if ((llg)mid*(mid+1)/2>=x) {r=mid-1,ans=mid;} else l=mid+1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
h,w,k=map(int,input().split())
a=[]
b=[]
f=[]
g=[]
for i in range(h):
    a.append(input())
for i in range(h):
    c=0
    for j in range(w):
        if a[i][j]=='#':
            c=1
    b.append(c)
k=0
while True:
    if b[k]==0:
        k+=1
    else:
        break
d=0
for i in range(h):
    if b[i]==1:
        if a[i][0]=='.':
            e=-1
        for j in range(w):       
            if a[i][j]=='#':
                d+=1
                e=0
            f.append(d-e)
        g.append(f)
        f=[]
for i in range(k):
    g.insert(0,g[0])
while k<h:
    if b[k]==0:
        n=1
        while True:
            if b[k-n]==1:
                g.insert(k,g[k-n])
                break
            n+=1
    k+=1
for i in range(h):
    for j in range(w):
        print(g[i][j],end=' ')
    print('')

Measured memory_bytes: 7592
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
#define F(i,L,R) for(int i=L;i<R;++i)
#define FE(i,L,R) for(int i=L;i<=R;++i)
#define getI(a) scanf("%lld",&a)
#define getII(a,b) scanf("%lld%lld",&a,&b)
#define getIII(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define VgetI(n) int (n); scanf("%lld",&(n))
#define VgetII(n,m) int (n),(m); scanf("%lld%lld",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define qq cout<<"QQ\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define INF 2000000000
int a[200005],MOD=1000000007;
main(){
	int n;
	while(~getI(n)){
		F(i,0,n) getI(a[i]);
		int sum=0,ans=0,sumNow=0;
		F(i,0,n) sum+=a[i];
		F(i,0,n){
			sumNow+=a[i];
			ans+=a[i]*((sum-sumNow)%MOD);
			assert((sum-sumNow)>=0);
			ans%=MOD;
		}
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 5372
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<cstring>
#include<climits>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
inline int read() {
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c==EOF)exit(0);if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 200000
#define INF 0x3f3f3f3f
map<int,int> Map;
int main(){
	int n=read();
	for(int i=1;i<=n;i++){
		int x=read();
		if(Map[x])
			puts("NO"),exit(0);
		Map[x]++;
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 9600
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func solve(L, R int) int {
	if L == 0 {
		return 0
	}
	l := (L - 1) / 2019
	r := R / 2019

	if r-l >= 1 {
		return 0
	}

	ret := 2019
	for i := L; i < R; i++ {
		for j := i + 1; j <= R; j++ {
			ret = min(ret, (i*j)%2019)
		}
	}
	return ret
}

func ref(L, R int) (int, int, int) {
	ret := 2019
	l := L
	r := R
	for i := L; i < R; i++ {
		for j := i + 1; j <= R; j++ {
			if i*j%2019 < ret {
				l = i
				r = j
				ret = min(ret, (i*j)%2019)
			}
		}
	}
	return ret, l, r
}

// Pfs :　素因数分解し、スライスを作成
func Pfs(n int) (pfs []int) {
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}
func main() {
	sc.Split(bufio.ScanWords)
	L, R := getInt(), getInt()
	out(solve(L, R))
}


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

#define ll long long
#define ull unsigned long long
#define openfiles ifstream cin("input10.txt"); ofstream cout("output10.txt");

using namespace std;

ll dp[200000];
ll a[200];

int main()
{
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    for(int i = 0; i < a[0]; i++)
        dp[i] = 1;
    for(int i = a[0]; i <= k; i++)
    {
        dp[i] = 1;
        for(int j = 0; j < n; j++)
        {
            if(i >= a[j] && dp[i - a[j]] == 1)
                dp[i] = 2;
        }
    }
    if(dp[k] == 1)
        cout<<"Second";
    else
        cout<<"First";

}


Measured memory_bytes: 1024
#include <stdio.h>
int main(){
  int i,j,k,l;
  scanf("%d %d",&i,&j);
  if(i<j){
    k=i;
    i=j;
    j=k;
  }
  //ユークリッド互除法
  l=i%j;
  while(l!=0){
    i=j;
    j=l;
    l=i%j;
  }
  printf("%d\n",j);
  return 0;
}



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

bool overflow(unsigned long long a, unsigned long long b) {
	const unsigned long long c = a * b;
	return !(c / a == b);
}

int main() {
	int n, m;
	cin >> n >> m;

	vector<unsigned long long> a(n), b(m);
	for(auto &e : a) cin >> e;
	for(auto &e : b) cin >> e;

	unsigned long long g = a[0];
	for(int i = 1; i < n; ++i) {
		g = __gcd(g, a[i]);
	}

	unsigned long long l = b[0];
	for(int i = 1; i < m; ++i) {
		l /= __gcd(l, b[i]);

		if(overflow(l, b[i])) {
			cout << 0 << endl;
			return 0;
		}

		l *= b[i];
	}

	int ans = 0;
	for(unsigned long long i = 1; i * i <= g; ++i) {
		if(g % i == 0) {
			if(i % l == 0) ++ans;
			if(i * i != g && (g / i) % l == 0) ++ans;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1204
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
a = list(set(readInts()))

if len(a)==1:
  print(a[0])
  exit()

odd = []
even = []


from math import gcd


d = a[0]
for i in a:
  d = gcd(i,d)
print(d)

Measured memory_bytes: 20572
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define YESNO OUT(three(solve(),YES,NO))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr ,greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,0 }, dy[] = { 1,0,-1,0,0 };
const int SIZE1 =3e5 + 1000;
const int SIZE2 = 5010;
const int SIZE3 = 22;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
ut N, M, K, X, L, Y,H,W,Q;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], nums[SIZE], maps[SIZE3][SIZE3], answer = zero;
LL A[SIZE], B[SIZE];
bool isBigger[SIZE];
LL solve() {
	cin >> N >> M;
	Vpr v;
	REP(i, N) {
		cin >> A[i];
		v.pb(A[i],i);
	}
	Vpr vb[2];
	sort(ALL(v), greater<pr>());
	REP(i, N) {
		if (v[i].first > i) isBigger[v[i].second] = true;
		LL potential = v[i].second;
		if (isBigger[v[i].second]) potential *= -1;
		if ((v[i].first > i) ^ (v[i].first > v[i].second)) {
			potential += abs(v[i].first - v[i].second);
		}
		vb[isBigger[v[i].second]].pb(potential,v[i].second);
	}
	//outputVI(vb[0]);
	//outputVI(vb[1]);
	sort(ALL(vb[0]));
	sort(ALL(vb[1]));
	LL ans = 0;
	REP(i, N) ans += abs(A[i] - i);
	LL maxim = ans;
	MN(M, min<LL>(vb[1].size(), vb[0].size()));
	REP(i, M) {
		LL a = vb[0][i].second;
		LL b = vb[1][i].second;
		ans -= abs(a - A[a]) + abs(b - A[b]);
		swap(vb[0][i], vb[1][i]);
		ans += abs(a - A[b]) + abs(b - A[a]);
		MX(maxim, ans);
	}
	cout << maxim << endl;
	return 0;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	solve();
//	cin >> N;
	return 0;
}


Measured memory_bytes: 15012
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    n,k = cin()
    ans = 0
    for i in range(n+1):
      for j in range(n+1):
        if k-i-j>=0 and k-i-j<=(n):
          ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  int d=0,e=0,f=99999999;
  for(int i=0;i<n;i++){
    cin >> a[i];
    d+=a[i];
  }
  for(int i=0;i<n;i++){
    e+=a[i];
    d-=a[i];
    if(f>abs(d-e))f=abs(d-e);
  }
  cout << f;
}

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

using namespace std;

using ll = long long;

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

#define INF 1e9

int main(void)
{
    int n, s[100005] = {}, q, t, i, c = 0;

    cin >> n;
    for(i = 0; i < n; i++){
        cin >> s[i];
    }
    cin >> q;
    for(i = 0; i < q; i++){
        cin >> t;
        if(binary_search(s, s + n, t))c++;
    }

    cout << c << endl;
}

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

using namespace std;

int main()
{
    vector<int> W(26, 0);

    string s = "";
    string s0;
    while(cin >> s0){
        s += s0;
    }

    for(int i = 0; i < s.size(); i++){
        char c = s.at(i);
        if('A' <= c && c <= 'Z'){
            c = c - 'A' + 'a';
        }
        if('a' <= c && c <= 'z'){
            W.at(c-'a') += 1;
        }
    }
    for(int i = 0; i < W.size(); i++){
        cout << (char)('a' + i) << " : " << W.at(i) << endl;
    }

}


Measured memory_bytes: 3188
#include <stdio.h>

int main() {
	int n = 0;
	int x = 0;

	while (1) {
		scanf("%d %d", &n, &x);
		if (n == 0 && x == 0) { break; }

		int count = 0;
		for (int a = 1; a <= n - 2; a++) {
			for (int b = a + 1; b <= n - 1; b++) {
				for (int c = b + 1; c <= n; c++) {
					if (a + b + c == x) { count++; }
				}
			}
		}
		printf("%d\n", count);
	}

	return 0;
}

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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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;
}

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 100005;

ll N, K, Q;
int cnt[MX];

void solve() {
    cin >> N >> K >> Q;
    vector<int> a(Q);
    for (auto& i : a) {
		cin >> i;
		cnt[i]++;
	}
	for (int i = 1; i <= N; i++) {
		K - Q + cnt[i] > 0 ? cout << "Yes\n" : cout << "No\n";
	}
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; //cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 1408
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def conv(s):
    num = 3
    if s == 'A':
        num = 0
    elif s == 'B':
        num = 1
    elif s == 'AB':
        num = 2
    return num

N = get_input()

K = [0,0,0,0]

for i in N:
    gomi, ketsu = [x for x in i.split(',')]
    K[conv(ketsu)] += 1

for i in K:
    print(i)



Measured memory_bytes: 5648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC146B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            string a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int l = S.Length;
            string[] ans = new string[l];
            for (int i = 0; i < l; i++)
            {
                int j = a.IndexOf(S[i]);
                int k = (j + N) % 26;
                ans[i] = a[k].ToString();
            }
            Console.WriteLine(string.Join("", ans));
        }
    }
}


Measured memory_bytes: 27792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll dp[3001][7001];
int prev_w[3001][7001];

int main(){
    int n, t;
    cin >> n >> t;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    set<int> use;

    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= t; ++w) {
            if(w >= a[i]){
                if (dp[i+1][w] < dp[i][w-a[i]] + b[i]) {
                    dp[i+1][w] = dp[i][w-a[i]] + b[i];
                    prev_w[i+1][w] = w - a[i];
                }
            }

            if (dp[i+1][w] < dp[i][w]) {
                dp[i+1][w] = dp[i][w];
                prev_w[i+1][w] = w;
            }
        }
    }

    int cur_w = t-1;
    for (int i = n-1; i >= 0; --i) {
        // 選んでいた場合
        if (prev_w[i+1][cur_w] == cur_w - a[i]) {
            //cout << i << " th item (weight = " << a[i] << ", value = " << b[i] << ")" << endl;
            use.insert(i);
        }

        // 復元テーブルをたどる
        cur_w = prev_w[i+1][cur_w];
    }

    int add = 0;
    rep(i, n){
        if(use.find(i) == use.end()) chmax(add, b[i]);
    }

    ll ans = dp[n][t];
    chmax(ans, dp[n][t-1]+add);

    cout << ans << endl;
}

Measured memory_bytes: 245632
#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}


int32_t main(int32_t argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
    vs args(argv, argv+argc);
    string sample = make_sample(args, "sample-1");
    ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#endif


    int N; cin >> N;

    int sum = 0;
    FOR(i,1, N+1) {
        if (i%3==0 or i%5 == 0) {
            continue;
        }
        sum += i;
    }

    int ans = sum;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>

int main(){
	int n=0,m=0,ans=0;
	int A_g[100][100];
	int B_g[100];
	scanf("%d %d",&n,&m);
	for(int i=0; i<n; i++){
		for(int t=0; t<m; t++){
			scanf("%d",&A_g[i][t]);
		}
	}
	for(int i=0; i<m; i++){
		scanf("%d",&B_g[i]);
	}
	for(int i=0; i<n; i++){
		ans=0;
		for(int t=0; t<m; t++){
			ans+=A_g[i][t]*B_g[t];
		}
		printf("%d\n",ans);
	}
}



Measured memory_bytes: 2768
#include<stdio.h>

int main(){
	int h,x,n;
	scanf("%d%d%d",&h,&x,&n);
	if(h>=n || x>=n) printf("1\n");
	else if(h>x){
		if(n % h == 0) printf("%d\n",n/h);
		else printf("%d\n",n/h+1);	
		
	}
	else{
		if(n % x == 0) printf("%d\n",n/x);
		else printf("%d\n",n/x+1);	
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1712
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

/////////////////////////////////////////////////////////////////////

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

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

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

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e5 + 7;
const int MAXN = (int)3e3 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e17;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

/////////////////////////////////////////////////////////////////////

void solve() {
	int n;
	cin >> n;
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 && i % 5)
			ans += i;
	}
	cout << ans;
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}

#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

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

int main() {
  long long N, D;
  cin >> N >> D;
  
  vector<long long> X(N);
  vector<long long> Y(N);
  
  int count = 0;
  
  for (int i=0; i<N ;i++){
    cin >> X.at(i) >> Y.at(i) ;
    if(X.at(i)*X.at(i)+Y.at(i)*Y.at(i)<=D*D){
      count = count + 1;
    }
  }
  cout << count << endl;
  
}

Measured memory_bytes: 6424
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
typedef long long LL;

int main() {
    int x, y;
    cin >> x >> y;
    cout << x + y /2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}

//cin.tie(0);ios::sync_with_stdio(false);
//cout<<fixed<<setprecision(20);

ll dp[3005][6005]={};

signed main(){
  int n,t;cin>>n>>t;
  vector<PL> v(n);
  rep(i,0,n)cin>>v[i].fs>>v[i].sc;
  sort(all(v));

  rep(i,0,n){
    rep(j,0,t){
      chmax(dp[i+1][j+v[i].fs],dp[i][j]+v[i].sc);
      chmax(dp[i+1][j],dp[i][j]);
    }
    rep(j,t,6005){
      chmax(dp[i+1][j],dp[i][j]);
    }
  }
  ll ans=0;
  rep(j,0,6005){
    ans=max(ans,dp[n][j]);
  }
  cout<<ans<<endl;

}


//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,output_format?

Measured memory_bytes: 139648
#include <stdio.h>
int main(void){
	int n;
	scanf("%d",&n);
	char a[n][12];
	for(int i=0;i<n;i++){
		for(int j=0;j<12;j++){
			a[i][j]='0';		}
	}
	for(int i=0;i<n;i++){
		scanf("%s",a[i]);
	}
	int b=1;
	int x;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			x=0;
			for(int k=0;k<12;k++){
				if(a[i][k]==a[j][k])x++;
			}
			if(x==12&&i!=j)b=0;
		}
	}
	for(int i=0;i<n-1;i++){
		x=0;
		while(a[i][x]!='0')x++;
		x-=2;
		if(a[i][x]!=a[i+1][0])b=0;
	}
	if(b)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int n,m,i,t,r,a,q[100010];
  int ta[100010],to[100010],nt[100010],c[100010]={};
  int d[100010]={};
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)ta[i+1]=-1;
  for(i=0;i<m;i++){
    scanf("%d %d",&a,&to[i]);
    nt[i]=ta[a];
    ta[a]=i;
    c[to[i]]++;
  }
  for(i=r=0;i<n;i++){
    if(c[i+1]==0)q[r++]=i+1;
  }
  for(t=a=0;r-t;t++){//printf("!%d %d\n",q[t],d[q[t]]);
    a=MAX(d[q[t]],a);
    for(i=ta[q[t]];i+1;i=nt[i]){
      d[to[i]]=MAX(d[to[i]],d[q[t]]+1);
      c[to[i]]--;
      if(c[to[i]]==0)q[r++]=to[i];
    }
  }
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 2560
/***
	chauhan176's code

	DO WHATEVER IT TAKES!!!
	Nothing happens , nothing happens and then everything happens.
	But the thing is nothing happens in air:)-
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define maxn 300005
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define stringio cin.ignore(256, '\n')  //to take string input after taking integer inputs
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

typedef pair<int,int>pi;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const ll mx = 1000000000000;
#define PI 3.14159265
vector<pi>af;
ll k;
ll n , a[maxn] , f[maxn];
bool check(ll t)
{
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        ll dif = a[i]*f[i]*1LL - t;
        if(dif<=0)continue;
        cnt+= dif/f[i];
        if(dif%f[i]!=0)
            cnt+=1;
    }
    if(cnt>k)
        return false;
    return true;
}
int main()
{
    fastio;
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>f[i];

    sort(a,a+n);sort(f,f+n);
    reverse(f,f+n);
    ll ti=-1;
    for(ll j=mx;j>=1;j/=2)
    {
        while(ti+j<=inf)
        {
            bool f = check(ti+j);
            if(!f)
                ti+=j;
            else break;
        }
    }
    cout<<ti+1<<endl;
    return 0;
}


Measured memory_bytes: 3840
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<set>

const int maxn=1e5+5;

using namespace std;

int n,m,a,b,c,d,k;
int sum[maxn],ans[maxn],father[maxn];

int find(int x)
{
    int t=father[x];
    if(t!=x)
    {
        father[x]=find(t);
    }
    return father[x];
}

int unionn(int a,int b)
{
    int sa=find(a);
    int sb=find(b);
    if(sa!=sb)
    {
        father[sa]=sb;
        sum[sb]+=sum[sa];
    }
}

int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
    {
        father[i]=i;
        sum[i]=1;
    }
    while(m--)
    {
        scanf("%d%d",&a,&b);
        ans[a]++,ans[b]++;
        unionn(a,b);
    }
    while(k--)
    {
        scanf("%d%d",&c,&d);
        if(find(c)==find(d))
            ans[c]++,ans[d]++;
    }
    int f1=find(1);
    printf("%d",sum[f1]-ans[1]-1);
    for(int i=2;i<=n;i++)
    {
        int fi=find(i);
        printf(" %d",sum[fi]-ans[i]-1);
    }
    printf("\n");
}

Measured memory_bytes: 2560
#include <iostream>
#include <cmath>


using namespace std;

int main(){
   int N, K, X, Y, result;
   cin>>N;
   cin>>K;
   cin>>X;
   cin>>Y;
    if(N>K){
        cout<< X*K + Y*(N-K);
    }else{
        cout<< X*N;
    }
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long x[] = new long[N];
		long y[] = new long[N];
		long h[] = new long[N];
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextLong();
			y[i] = sc.nextLong();
			h[i] = sc.nextLong();
		}
		for (int X = 0; X <= 100; X++) {
			for (int Y = 0; Y <= 100; Y++) {
				long temp = 0;
				boolean b = true;
				for (int i = 0; i < N; i++) {
					long t = Math.abs((long)X - x[i]) + Math.abs((long)Y - y[i]) + h[i];
					if (h[i] > 0) {
						if (temp == 0) {
							temp = t;
						} else {
							if (t != temp) {
								b = false;
								break;
							}
						}
					}
				}
				if (b == true) {
					for (int i = 0; i < N; i++) {
						long t = Math.abs((long)X - x[i]) + Math.abs((long)Y - y[i]) ;
						if (h[i] == 0 &&temp-t>0) {
							b = false;
							break;
						}
					}

				}
				if (b == true) {
					System.out.println(X + " " + Y + " " + temp);
					return;
				}
			}
		}

	}
}

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


// 常に貪欲に選択する

vector<vector<int>> s(400,vector<int>(27));
vector<int> c(27);
int D;

int cal_score(vector<int> t){
  int p(0);
  vector<int> l(27,0);
  for(int i(1);i<=D;i++){
    p += s[i][t[i]];
    l[t[i]] = i;
    for(int j(1);j<=26;j++){
      p -= c[j]*(i-l[j]);
    }
  }
  return p;
}

void input(){
  cin>>D;
  for(int i(1);i<27;i++){
    cin>>c[i];
  }
  for(int i(1);i<=D;i++){
    for(int j(1);j<=26;j++){
      cin>>s[i][j];
    }
  }
}

vector<int> cal_greedy(){
  vector<int> t(D+1);
  int nowp(0);
  vector<int> l(D,0);
  for(int i(1);i<=D;i++){
    int maxj(0),maxp(-1e9);
    for(int j(1);j<=26;j++){
      //i日目がj番目の場合
      int tmp(nowp);
      tmp += s[i][j];
      for(int k(1);k<=26;k++){ //ここ一度和を計算しておけば、何回も引くものを計算しなくても良い
        if(k == j) continue;
        tmp -= c[k]*(i - l[k]);
      }
      if(maxp < tmp) {
        maxj = j;
        maxp = tmp;
      }
    }
    t[i] = maxj;
    // 貪欲的にmaxj番目と決める
    nowp += s[i][maxj];
    l[maxj] = i;
    for(int j(1);j<=26;j++){
      nowp -= c[j]*(i - l[j]);
    }
  }
  return t;
}

int main(){
  clock_t start = clock(); 
  input();
  vector<int> t = cal_greedy();

  double time;
  int cnt(0);
  int nowp = cal_score(t);
  while(time < 1800){
    int d = max(rand()%(D+1),1);
    int q = max(rand()%27+1,1);
    int old = t[d];
    t[d] = q;
    int next_score = cal_score(t);
    if(nowp >= next_score){
      t[d] = old;
    }else{
      nowp = next_score;
    }
    cnt++;
    clock_t now = clock();
    time = static_cast<double>(now - start) / CLOCKS_PER_SEC * 1000.0;
    //cout << "point:" << max(1000000+nowp,0) << " " << "row_point:" << nowp << endl;
  }
  // cout << "ランダムに変更回数:" << cnt << endl;
  // printf("time %lf[ms]\n", time);

  for(int i(1);i<=D;i++){
    cout << t[i] << endl;
  }
  return 0;
}


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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int t , n , x;
string s;

int main()
{
    _FastIO;
    string s;
    cin >> s;
    int k = 0;
    for(int i = 0; i < s.size(); i++){
        int p = int(s[i]) - 48;
        k += p;
    }
    if(k % 9 == 0){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3780
def solve():
    def max2(x, y): return x if x >= y else y
    def min2(x, y): return x if x <= y else y

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

    if N%2 == 1:
        dp = [A for A in As]
    else:
        dp = [-A for A in As]

    for W in range(2, N+1):
        dp2 = [0] * (N-W+1)
        if (N-W)%2 == 0:
            for L in range(N-W+1):
                R = L+W-1
                dp2[L] = max2(As[L]+dp[L+1], As[R]+dp[L])
        else:
            for L in range(N-W+1):
                R = L+W-1
                dp2[L] = min2(-As[L]+dp[L+1], -As[R]+dp[L])
        dp = dp2

    print(dp[0])


solve()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int a,b;
  cin>>a>>b;
  int Ans=0;
  rep(i,2){
    if(a>b) {
      Ans+=a;
      a--;
    }
    else{
     Ans+=b;
      b--;
    }
    
  }
  cout<<Ans<<endl;
}






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

int main() {
  char s[11], t[12];
  scanf("%s %s", &s, &t);
  for(int i=0;i<strlen(s);i++){
    if(s[i] == t[i]) continue;
    else {
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 2152