akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sp <<" "<<
bool isprime(ll n){
    if (n <= 1)return false;ll g=sqrt(n);
    for (ll i = 2; i <= g; i++)if (n % i == 0)return false;
    return true;
}
ll MOD=LLONG_MAX;
ll power(ll base, ll exp)
{
    if(exp==1)return base;
    else{if(exp%2==0){ll base1=(pow(power(base, exp/2),2));return base1%MOD;}
        else{ll ans=(base*pow(power(base,(exp-1)/2),2));return ans%MOD;}}
}
ll temp,temp1,temp2;
int main()
{
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d)
        cout<<"Yes";
    else
    {
        cout<<"No";
    }
    

    return 0;
}


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

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

void solve(void) {
  long long N, M, X; cin >> N >> M >> X;

  vector<long long> price(N, 0);
  vector<vector<long long>> textbook(N, vector<long long>(M, 0));
  for(long long i = 0; i < N; ++i) {
    cin >> price[i];
    for(long long j = 0; j < M; ++j) cin >> textbook[i][j];
  }

  long long res = 10000000;
  for(long long bit = 0; bit < (1 << N); ++bit) {

    long long cost = 0;
    vector<long long> exp(M, 0);
    long long count = 0;
    for(long long i = 0; i < N; ++i) {
      if(bit & (1 << i)) {
        cost += price[i];
        for(long long j = 0; j < M; ++j) exp[j] += textbook[i][j];
      }
    } 
    for(long long mi = 0; mi < M; ++mi) {
      if (exp[mi] >= X) count++;
    }
    if(count == M) res = min(res, cost); 
  }


  if (res != 10000000) cout << res << endl;
  else cout << "-1" << endl;
}

int main(void) {
  solve();
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

ll p(ll a){
	return a*a*a*a*a;
}

int main() {
	ll x; cin >> x;
	REP(i,1001){
		for(int j=i;j<1001;j++){
			if(x==p(i)+p(j)){
				cout << i << ' ' << -j << endl;
				return 0;
			}
		}
		for(int j=1;j<i;j++){
			if(x==p(i)-p(j)){
				cout << i << ' ' << j << endl;
				return 0;
			}
		}
	}
	return 0;
}

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

ll calc(int x,int y,int m){
  ll res=1;
  rep(i,y){
    res=res*x%m;
  }
  return res%m;
}

int main(){
  int const mod=1e9+7;
  int n;
  cin>>n;
  ll ten=calc(10,n,mod);
  ll nine=calc(9,n,mod);
  ll eight=calc(8,n,mod);
  ll ans=(ten-nine)%mod;
  ans=(ans-nine)%mod;
  ans=(ans+eight)%mod;
  ans=(ans+mod)%mod;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3612
N, Y = map(int, input().split())
out_x = out_y = out_z = -1
for x in range(N+1):
  for y in range(N+1):
    price = x * 10000 + y * 5000
    if price > Y:
      break
    price = price + (N-x-y) * 1000
    if price == Y:
      out_x = x
      out_y = y
      out_z = N-x-y
      break
  if out_x != -1:
    break
print("{0} {1} {2}".format(out_x, out_y, out_z))

Measured memory_bytes: 3064
import java.util.*;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        Long n=sc.nextLong();
        Long k=(long)Math.sqrt(n)+1;
        long min=n;
        for(int i=1;i<=k;i++){
            if(n%i==0){
                if(min>i+n/i-2){
                    min=i+n/i-2;
                }
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

vector<int> edge[110000];
vector<int> dp(110000, -1);

int rec(int v){
    if(dp[v] != -1) return dp[v];
    int ret = 0;
    for(auto to: edge[v]){
        ret = max(ret, rec(to) + 1);
    }
    return dp[v] = ret;
}

int main(){
    int n, m, x, y;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        edge[x-1].push_back(y-1);
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans = max(ans, rec(i));
    }
    cout << ans << endl;
}

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

#define MOD 1000000007
#define MAX_N 210
#define MAX_W 10100
int dp[2][MAX_N][MAX_W];
int N, W, x[MAX_N];
int main() {
	cin >> N >> W;
	for (int i = 1; i <= N; i++) {
		cin >> x[i];
	}
	x[N + 1] = W + 1;
	sort(x + 1, x + N + 1);
	dp[1][1][0] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= W; k++) {
				dp[0][j][k] = dp[1][j][k];
				dp[1][j][k] = 0;
			}
		}
		int w = x[i];
		int y = 0, z = 0;
		for (int j = 1; j <= i; j++) {
			y = j; z = j;
			if (y == i) { y += 1; }
			for (int k = 0; k <= W; k++) {
				if (k + w <= W) {
					dp[1][y][k + w] += dp[0][j][k];
					dp[1][y][k + w] %= MOD;
				}
				dp[1][z][k] += dp[0][j][k];
				dp[1][z][k] %= MOD;
			}
		}
	}
	int res = 0, v = 0;
	for (int i = 1; i <= N + 1; i++) {
		v = max(0, W - x[i] + 1);
		for (int j = v; j <= W; j++) {
			res += dp[1][i][j];
			res %= MOD;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 17536
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <stdio.h>
//end of libraries ;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define INF 3999999999999999999
#define N 3000003
#define PI 3.14159265359
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int main(){
fcin;
int a , b ,c ,d , ans = 1;
cin>>a>>b>>c>>d;
bool ok = 1;
while(true){
	if(c <= 0) {ans = 1; break;}
	if(a <= 0) {ans = 0; break;}
	if(ok){
		c -= b; 
		 ok = 0;
	}
	else{
		a -= d;
		ok = 1;
	}
}
if(ans) cout<<"Yes\n";
else cout<<"No\n";
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 200010;

inline int in() {int x; scanf("%d",&x); return x;}
inline ll lin() {ll x; scanf("%lld",&x); return x;}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

int n, k, l;

int seen[N];
int Have[N];
int Rail[N];
int kunt[N];

int X[N];

vector < int > G[N], V[N], STT[N];

void dfs(int u, int cnt){
    seen[u] = 1;
    STT[cnt].pb(u);
    for(int i = 0;i < G[u].size(); i++){
        int v = G[u][i];
        if(seen[v] == 0){
            dfs(v,cnt);
        }
    }
}

void go(int u, int cnt){
    Have[u] = 1;
    Rail[u] = cnt;
    for(int i = 0;i < V[u].size(); i++){
        int v = V[u][i];
        if(Have[v] == 0){
            go(v,cnt);
        }
    }
}

int main(){
    n = in(); k = in(); l = in();
    for(int i = 1;i <= k; i++){
        int u = in(), v = in();
        G[u].pb(v); G[v].pb(u);
    }
    for(int i = 1;i <= l; i++){
        int u = in(), v = in();
        V[u].pb(v); V[v].pb(u);
    }

    memset(Have, 0, sizeof Have);

    int no = 1;
    for(int i = 1;i <= n; i++){
        if(Have[i] == 0){
            go(i,no);
            no++;
        }
    }

    memset(seen, 0, sizeof seen);

    for(int i = 1;i <= n; i++){
        X[i] = 1;
    }

    int cnt = 1;
    for(int i = 1;i <= n; i++){
        if(seen[i] == 0){
            dfs(i,cnt);

            for(int j = 0;j < STT[cnt].size(); j++){
                int v = STT[cnt][j];

                kunt[Rail[v]]++;
            }

            for(int j = 0;j < STT[cnt].size(); j++){
                int v = STT[cnt][j];

                X[v] = kunt[Rail[v]];
            }

            for(int j = 0;j < STT[cnt].size(); j++){
                int v = STT[cnt][j];

                kunt[Rail[v]] = 0;
            }
            cnt++;
        }
    }

    for(int i = 1;i <= n; i++){
        printf("%d%c",X[i],(i == n ? '\n' : ' '));
    }
}


Measured memory_bytes: 28280
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
         53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109]

d = {}
for i in range(26):
    d[chr(ord('a')+i)] = prime[i]

N = int(input())
L = []
nums = [input()[:-1] for _ in range(N)]
for n in nums:
    tmp = 1
    for c in n:
        tmp *= d[c]
    L.append(tmp)

L = Counter(L)

ans = 0
for k, v in L.items():
    ans += (v*(v-1))//2
print(ans)


Measured memory_bytes: 24596
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	int n,ans=1000000,min=101,max=-101;
  long sum;
	int a[101];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(min>a[i]) min=a[i];
		if(max<a[i]) max=a[i];
	}
	for(int i=min;i<=max;i++){
      sum=0;
		for(int j=0;j<n;j++){
			sum+=pow((a[j]-i),2);
		}
      if(ans>sum) ans=sum;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4352
#include<stdio.h>

int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while( A[i] != key ) i++;
  return i != n;
}

int main() {
  int i ,n ,A[10000+1], q, key, sum = 0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++) scanf("%d", &A[i]);

  scanf("%d", &q);
  for ( i = 0; i < q; i++) {
    scanf("%d", &key);
    if ( search(A, n , key)) sum++;
  }
  printf("%d\n", sum);

  return 0;
}



Measured memory_bytes: 2104
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read();bool bk=true;
    for(int i=1;i<=n;i++)
    {
    	int uf=read();
    	if(uf%2==0)
    	{
    		if(uf%3!=0 && uf%5!=0){bk=false;}
    	}
    }
    if(bk==true)puts("APPROVED");
    else puts("DENIED");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

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

struct Frac {
  ll a, b;
  void normalize() {
    ll g = gcd(a, b);
    a /= g;
    b /= g;
  }
  Frac(ll _a, ll _b) {
    a = _a;
    b = _b;
    normalize();
  }
  bool operator <(const Frac &other) const {
    return (__int128)a * other.b < (__int128)b * other.a;
  }
};

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> a(n), b(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  Frac ans(0, 1);
  {
    vector <int> p(n);
    iota(p.begin(), p.end(), 0);
    sort(p.begin(), p.end(), [&] (int i, int j) {
      return b[i] < b[j];
    });
    vector <int> na(n), nb(n);
    for (int i = 0; i < n; ++i) {
      na[i] = a[p[i]];
      nb[i] = b[p[i]];
    }
    a = na;
    b = nb;
  }
  vector <ll> can_suf(n);
  for (int i = n - 2; i >= 0; --i) {
    can_suf[i] = can_suf[i + 1] + max(0, b[i + 1] - a[i + 1]);
  }   
  auto check = [&] (int m) {
    multiset <int> best;
    ll sum_a = 0;
    bool fl = false;
    for (int i = 0; i < n; ++i) {
      if (i > 0) {
        best.insert(a[i - 1]);
        sum_a += a[i - 1];
        if ((int)best.size() == m + 1) {
          sum_a -= *best.rbegin();
          best.erase(--best.end());
        }
      }
      if (best.size() == m) {
        ll need = max(0LL, (sum_a + a[i]) - can_suf[i]);
        if (b[i] >= need) {
          fl = true;
          ll good = b[i] - need;
          Frac cur = Frac((ll)b[i] * m + good, (ll)b[i] * n);
          if (ans < cur) ans = cur;
        }
      }
    }
    return fl;
  };
  int l = 0, r = n;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (check(m)) l = m;
    else r = m;
  }
  check(l);
  cout << ans.a << ' ' << ans.b << '\n';
}



Measured memory_bytes: 9308
#入力
n = int(input())
elements = [int(n) for n in input().split()]
print(' '.join(map(str, elements)))

#未ソート部分の先頭を取り出す
for i in range(1,n):
    v = elements[i]
    j = i - 1
    #ソート部分から挿入場所を決定する。
    while j >= 0 and elements[j] > v :
        elements[j+1] = elements[j]
        j -= 1
    elements[j+1] = v
    print(' '.join(map(str, elements)))


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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  double r1, r2;
  cin >> r1 >> r2;
  cout << 1 / (1 / r1 + 1 / r2) << endl;
}


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

#define IO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define m(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
typedef pair<string,int> p;
const int MAXN=1e5+10;

int main(){
	IO;
	string s;
	cin>>s;
	int cnt=0;
	for(int i=0;i<s.size();i++)
		if (s[i]=='o')
			cnt++;
	cout<<700+cnt*100<<endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
l = s.split()
sx = int(l[0])
sy = int(l[1])
tx = int(l[2])
ty = int(l[3])
for i in range(tx - sx):
    print("R", end="")
for i in range(ty - sy):
    print("U", end="")
for i in range(tx - sx):
    print("L", end="")
for i in range(ty - sy):
    print("D", end="")
print("D", end="")
for i in range(tx - sx + 1):
    print("R", end="")
for i in range(ty - sy + 1):
    print("U", end="")
print("L", end="")
print("U", end="")
for i in range(tx - sx + 1):
    print("L", end="")
for i in range(ty - sy + 1):
    print("D", end="")
print("R", end="")

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << "\n";
}


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

int main(){
  string s,s_copy;
  cin >> s;
  long long answer=0,now=0;
  int length = s.size();
  
  for(int i=0; i< (1<<length-1); i++){
    now = s.at(0) - '0';
    
    for(int j=0; j < length-1; j++){
      if((i>>j)&1){
        answer += now;
        now = s.at(j+1) - '0';
      }else{
        now *= 10;
        now += s.at(j+1) - '0';
      }
    }
    answer += now;
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
N,K,S=map(int,input().split())
if S==10**9:
    for i in range(K):
        print(S,"",end="")
    for i in range(K,N):
        print(1,"",end="")
    print()
else:
    for i in range(K):
        print(S,"",end="")
    for i in range(K,N):
        print(S+1,"",end="")
    print()


Measured memory_bytes: 4644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
#define MAXN 100000
#define MAXM 400000
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
int first[MAXN+5], con[MAXN+5], book[MAXN+5], sz[MAXN+5], N, M, I, B, G, tot; bool unbi[MAXN+5];
struct Edge{int to,nex; Edge(){} Edge(int _to, int _nex):to(_to),nex(_nex){}}e[MAXM+5];
inline void Add(int a, int b){e[tot] = Edge(b,first[a]), first[a] = tot++, e[tot] = Edge(a,first[b]), first[b] = tot++;}
void DFS(int p, int w){book[p] = w, ++sz[G]; for(rint u = first[p], v; ~u; u = e[u].nex) if(!book[v=e[u].to]) DFS(v,w^1); else if(book[v] == w) B -= !unbi[G], unbi[G] = true;}
int main()
{
	N = read(), M = read(), memset(first+1,-1,N<<2); for(rint i = 1; i <= M; Add(read(),read()), i++);
	for(rint i = 1; i <= N; book[i] ?: (DFS(con[++G]=i,2),I+=sz[G]==1), i++); B = G-I+B, G = G-I-B;
	printf("%lld\n",2ll*I*N-1ll*I*I+1ll*G*G+2ll*G*B+2ll*B*B); return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;
public class Main {
static private Scanner s = new Scanner(System.in);
static Node root = null;
static StringBuilder sb = new StringBuilder();
public static void main(String[] args) {
	int n = s.nextInt();

	 for(int i = 0;i < n;i++) {
		 if(s.next().equals("insert")) {
		 Insert(s.nextInt());
		 }else {
			 inorder(root);
			 sb.append("\n");
			 preorder(root);
			 sb.append("\n");
		 }
	 }
	 System.out.print(sb);
}

Node mins(int n,Node[] a) {
	Node min = a[0];
	for(int i = 1;i < n;i++) {
		if(min.key > a[i].key) {

		}
	}
	return min;
}

static void Insert(int k) {
	Node y = null;
	Node x = root;
	Node z = new Node();

	z.key = k;
	z.l = null;
	z.r = null;
	while(x != null) {
		y = x;
		if(z.key < x.key) {
			x = x.l;
		}else {
			x = x.r;
		}
	}
	z.parent = y;
	if(y == null) {
		root = z;
	}else if(z.key < y.key) {
		y.l = z;
	}else {
		y.r = z;
	}
}

static void preorder(Node a) {
		if(a ==null)return;
		sb.append(" " + a.key);
		preorder(a.l);
		preorder(a.r);
}

static void inorder(Node a) {
		if(a == null) return;
		inorder(a.l);
		sb.append(" " + a.key);
		inorder(a.r);
}
}

class Node{
	int key;
	Node l = null;
	Node r = null;
	Node parent;


	Node(){
	}
}




Measured memory_bytes: 221536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  string a;
  cin>>a;
  int b=(a.size()-1)/2;
  bool k=1;
  rep(i,b){
    if(a[i]!=a[a.size()-1-i])
      k=0;
    }
  bool k1=1,k2=1;
  rep(i,ceil((b+1)/2)){
  if(a[i]!=a[b-i-1])
    k1=0;
  }
  rep(i,ceil((b+1)/2)){
  if(a[b+1+i]!=a[a.size()-1-i])
    k2=0;
  }
  if(k&&k1&&k2)
    cout<<"Yes"<<endl;
  else
    cout<<"No";
}

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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

int main() {
	int N;
	cin >> N;
	int ans[9] = { 0 };

	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;

		if (1 <= a && a <= 399) {
			ans[0]++;
		}
		else if (400 <= a && a <= 799) {
			ans[1]++;
		}
		else if (800 <= a && a <= 1199) {
			ans[2]++;
		}
		else if (1200 <= a && a <= 1599) {
			ans[3]++;
		}
		else if (1600 <= a && a <= 1999) {
			ans[4]++;
		}
		else if (2000 <= a && a <= 2399) {
			ans[5]++;
		}
		else if (2400 <= a && a <= 2799) {
			ans[6]++;
		}
		else if (2800 <= a && a <= 3199) {
			ans[7]++;
		}
		else if (3200 <= a){
			ans[8]++;
		}
	}

	int cnt = 0;
	for (int i = 0; i < 8; ++i) {
		if (ans[i] > 0) {
			cnt++;
		}
	}

	int maxval = cnt + ans[8];
	int minval = cnt;
	if (cnt == 0) {
		minval = 1;
	}

	cout << minval << " " << maxval << endl;
	return 0;
}


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

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


int main() {
    int N; cin >> N;
    vector<ll> dp(100,0);
    dp[0]=2;
    dp[1]=1;
    REP(i,N){
        dp[i+2] = dp[i+1] + dp[i];
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 3560
import heapq
import math
n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)
for i in range(m):
    heapq.heappush(a,math.ceil(heapq.heappop(a)/2))
   
    
    
print(-1*sum(a))    

Measured memory_bytes: 14532
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define itn int
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long double ld;
const int mod=1e9+7;
const int inf=2e9;

map<int,int> pfmp; //各素因数の冪指数の総和を格納
vector<int> pfv(0); //異なる素因数を昇順に格納

bool f1;
void pf(int N){
  int n=N;
  if(n<=0) return;
  if(n%2==0){
    if(pfmp[2]==0) pfv.push_back(2);
    else f1=0;
    while(n%2==0){
      n/=2;
      pfmp[2]++;
    }
  }
  if(n==1) return;
  for(int i=3;i<=sqrt(N);i+=2){
    if(n%i==0){
      if(pfmp[i]==0) pfv.push_back(i);
      else f1=0;
      while(n%i==0){
        n/=i;
        pfmp[i]++;
      }
    }
  }
  if(n!=1){
    if(pfmp[n]==0) pfv.push_back(n);
    else f1=0;
    pfmp[n]++;
  } 
  //sort(all(pfv));
}

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

int main(){
  itn n; cin >> n;
  f1=1;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) pf(a[i]);
  if(f1){
    cout << "pairwise coprime" << endl;
    return 0;
  }
  int GCD=a[0];
  rep(i,n-1){
    GCD=gcd(GCD,a[i+1]);
  }
  if(GCD==1){
    cout << "setwise coprime" << endl;
    return 0;
  }
  cout << "not coprime" << endl;
}

Measured memory_bytes: 10916
//By : BebekJK
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//Declare -> ordered_set NAMA;
//Nth smallest integer -> find_by_order(N-1)
//Number of elements less than N -> order_of_key(N)
//Delete N from the set -> erase(N)

#define endl '\n'
#define MOD 1000000007
#define PI 3.141592653
#define fi first
#define sc second
#define pb push_back
#define pbb pop_back

//#pragma GCC optimize("Ofast")
//#pragma GCC target ("string"...)
//#pragma GCC push_options
//#pragma GCC pop_options
//#pragma GCC reset_options
//#pragma GCC optimize ("O3")

typedef long long ll;
typedef long double ld;
typedef pair<int , int> pii;
typedef pair<long long , long long> pll;

void BOOST(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
}
void fcin(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c=='-'){
		neg = true;
		c = getchar();
	}
	for(;(c>47 && c<58);c=getchar())x = (x<<1)+(x<<3)+c-48;
	if(neg)x*=-1;
}
ll pmod(ll a , ll b){
	if(b==0)return 1;
	ll temp = pmod(a , b/2);
	if(b%2==0)return(temp*temp)%MOD;
	return (((temp*temp)%MOD)*a)%MOD;
}
int main(){
//	BOOST();
	int a , b;
	cin>>a>>b;
	if(a*2 > b)cout<<"No"<<endl;
	else if(a*4 < b)cout<<"No"<<endl;
	else if(b%2!=0)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}







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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cout << #x << " : " << x << '\n'

const int INF = 1e9;

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

  int ans = 0;
  int N;
  cin >> N;

  vector<string> s(N);
  FOR(i, 0, N) { cin >> s[i]; }

  int countA = 0;
  int countB = 0;
  int countBA = 0;
  FOR(i, 0, N) {
    int size = s[i].size();

    if (s[i][0] != 'B' && s[i][size - 1] == 'A') {
      countA++;
    }
    if (s[i][0] == 'B' && s[i][size - 1] != 'A') {
      countB++;
    }
    if (s[i][0] == 'B' && s[i][size - 1] == 'A') {
      countBA++;
    }
  }

  if (countBA) {
    if (countB + countA) {
      ans = countBA + min(countA, countB);
    } else {
      ans = countBA - 1;
    }
  } else {
    ans = min(countA, countB);
  }

  regex pattern("AB");
  smatch match;

  FOR(i, 0, N) {
    while (regex_search(s[i], match, pattern)) {
      ans++;
      s[i] = match.suffix();
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main()
{
  long long n, i;
  scanf("%lld", &n);
  long long a[n];
  long long sum = 0;
  for(i = 0; i <= n; i++){
    scanf("%lld", &a[i]);
    sum = sum + a[i];
  }
  long long int eda = 1, result = 1;
  if(n == 0 && a[0] == 1){
    printf("1\n");
    return 0;
  }
  if(a[0] != 0){
    printf("-1\n");
    return 0;
  }else{
    for(i = 1; i <= n; i++){
      if(eda*2 < sum){
        if(eda*2 < a[i]){
          printf("-1\n");
          return 0;
        }
        eda = eda*2 - a[i];
      }else{
        eda = sum - a[i];
      }
      result = result + eda + a[i];
      sum = sum - a[i];
    }
    printf("%lld\n", result);
    return 0;
  }
}

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

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

  int even;
  if(K%2==0) even=K/2;
  else even=(K-1)/2;

  cout << even*(K-even) << endl;
}

Measured memory_bytes: 256
from itertools import accumulate
n,k = map(int, input().split())
a = list(map(int, input().split()))
a = [0] + a
a2 = list(accumulate(a))

sa = dict()
ans = 0
l = 0
for i in range(n+1):
    saadd = (i-a2[i]) % k
    try:
        sa[saadd] += 1
    except:
        sa[saadd] = 1
    l += 1
    if l < k:
        continue
    nowidx = i-k+1
    now = (nowidx-a2[nowidx])% k
    try:
        ans += sa[now]-1
    except:
        pass
    sa[now] -= 1
    l -= 1




for val,cnt in sa.items():
    ans += cnt*(cnt-1)//2


print(ans)

Measured memory_bytes: 113868
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define N 200200
pair <long long, long long> v[N];
queue <pair<long long, long long> > q;
long long damage, D, A, curr, ans;
int i, n;
int main()
{
    cin >> n >> D >> A;
    for (i = 0; i < n; ++i)
        cin >> v[i].first >> v[i].second;
    sort (v, v + n);
    for (i = 0; i < n; ++i){
        while (!q.empty() && v[i].first > q.front().first){
            damage -= q.front().second;
            q.pop();
        }
        if (v[i].second - damage > 0){
            curr = (v[i].second - damage) / A;
            if (curr * A < v[i].second - damage)
                ++curr;
            damage += curr * A;
            ans += curr;
            q.push(make_pair(2 * D + v[i].first, curr * A));
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5120
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String complete = sc.nextLine();
        String part = sc.nextLine();
        System.out.println(solve(complete, part));
    }

    public static int solve(String complete, String part) {
        if (part.length() > complete.length()) {
            return -1;
        }
        int count = 0;
        for(int i = 0; i < (complete.length() - part.length())+ 1; i++) {
            String substr = complete.substring(i, i + part.length());
            int value = calc(substr, part);
            if(value > count){
                count = value;
            }
        }
        return (part.length() - count);
    }

    public static int calc(String substr, String part) {
        int similar = 0;
        for(int i = 0; i < substr.length(); i++) {
            char ch1 = substr.charAt(i);
            char ch2 = part.charAt(i);
            if(ch1 == ch2) {
                similar++;
            }
        }
        return similar;
    }
}


Measured memory_bytes: 35804
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node {
	int p, l, r, key; 
};
struct Node T[MAX];

int n, S[MAX], DG[MAX], H[MAX], D[MAX];

int getDepth(int p) {
	int i = 0, n = p;
	while (1) {
		n = T[n].p;
		if (n == NIL)break;
		i++;
	}
	return i;
}


int getHeight(int v) {
	int L = 0, R = 0;
	if (T[v].r == NIL && T[v].l == NIL) return 0;
	if (T[v].l != NIL) {
		L = getHeight(T[v].l) + 1;
	}
	if (T[v].r != NIL) {
		R = getHeight(T[v].r) + 1;
	}
	if (L > R) return L;

	else return R;
}


int getDegree(int v) {
	int n = v;
	if (T[v].l != NIL && T[v].r != NIL)return 2;
	else if (T[v].l != NIL || T[v].r != NIL)return 1;
	else return 0;
}

int getSibling(int u, int x) {
	int i;
	for (i = 0; i < x; i++) {
		if (T[u].p == T[i].p && i != u)return i;
	}
	return NIL;
}

void print(int u) {
	int n = u;
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d,", u, T[u].p, S[u], DG[u], D[u], H[u]);
	n = T[n].l;

	if (T[u].p == NIL)printf(" root\n");
	else if (DG[u] >= 1 && DG[u] <= 2)printf(" internal node\n");
	else printf(" leaf\n");

}
int main() {
	int i, v, l, r;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		T[i].p = T[i].l = T[i].r = NIL;
	}

	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &v, &l, &r);
		T[v].l = l;
		T[v].r = r;
		if (l != NIL)T[l].p = v;
		if (r != NIL)T[r].p = v;
	}

	for (i = 0; i < n; i++) {
		S[i] = getSibling(i, n);
	}

	for (i = 0; i < n; i++) {
		DG[i] = getDegree(i);
	}
	for (i = 0; i < n; i++) {
		D[i] = getDepth(i);
	}

	for (i = 0; i < n; i++) {
		H[i] = getHeight(i);
	}

	for (i = 0; i < n; i++) print(i);
	return 0;

}


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

int main(){
  int N;
  cin >> N;
  int a,b,count;
  count = 0;
  bool judge = 0;
  for(int i= 0;i < N; i++){
    cin >> a >> b;
    if(a == b)count++;
    if(a != b)count = 0;
    if(count == 3){
      judge = 1;
      break;
    }
  }
  if(judge){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
 
}

Measured memory_bytes: 3592
#include <iostream>

using namespace std;

int main()
{
    int n,h=0;
    cin >> n;
    while (n>=5){
        if (n-500>=0){
            h+=1000;
            n-=500;
        }
        else if (n-5>=0){
            h+=5;
            n-=5;
        }
    }
    cout << h;
    return 0;
}


Measured memory_bytes: 256
w,h,n = map(int, input().split())

o,p,q,r = 0,0,0,0
for _ in range(n):
  x,y,a = map(int, input().split())
  if a == 1:
    o = max(o, x)
  elif a == 2:
    p = max(p, w-x)
  elif a == 3:
    q = max(q, y)
  elif a == 4:
    r = max(r, h-y)

w -= o+p
h -= q+r
if w <= 0 or h <= 0:
  print(0)
else:
  print(w*h)

Measured memory_bytes: 9068
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        if ("ABC".equals(str[0])) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }

    }
}


Measured memory_bytes: 32400
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define rep(i, x, y) for (int i = (x); i <= (y); i ++)
#define travel(x, i) for (int i = fir[x]; i; i = e[i].nxt)
using namespace std;

const int N = 1e5 + 10;

struct edge {
  int nxt, to;
} e[N];
int fir[N], cnt = 0;
int n, k, ans = 0;
int mst[N], dep[N];

inline void addedge(int x, int y) {
  e[++ cnt] = (edge){fir[x], y};
  fir[x] = cnt;
}

inline void dfs(int x) {
  travel(x, i) {
    dep[e[i].to] = dep[x] + 1;
    dfs(e[i].to);
    mst[x] = max(mst[x], mst[e[i].to] + 1);
  }
  if (x != 1 && mst[x] == k - 1 && dep[x] != 1) ans ++, mst[x] = -1;
}

int main() {
  scanf("%d%d", &n, &k);
  int x;
  scanf("%d", &x);
  if (x != 1) ans = 1;
  rep(i, 2, n) {
    scanf("%d", &x);
    addedge(x, i);
  }
  dfs(1);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 4480
#include <cstdio>
#include <set>
#include <stdint.h>
#include <cassert>

const int L=100000;
bool isprime[L];

int64_t as[1005];
int64_t bs[1005];
int64_t mat[1005][1005];

std::set<int64_t> used;

int main(){
  int N;
  scanf("%d",&N);
  for(int i=2;i<L;i++){
    isprime[i]=true;
  }
  int a_max=0,b_max=0;
  for(int i=2;i<L;i++){
    if(isprime[i]){
      for(int k=i*2;k<L;k+=i){
	isprime[k]=false;
      }
      if(a_max<=N){
	as[a_max++]=i;
      }else if(b_max<=N){
	bs[b_max++]=i;
      }
    }
  }
  assert(a_max>N&&b_max>N);
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if((i+j)%2==0){
	mat[i][j]=as[(i+j)/2]*bs[(j-i+N)/2];
	used.insert(mat[i][j]);
      }else{
	int64_t base=as[(i+j+1)/2]*as[(i+j-1)/2]*
	  bs[(j-i+1+N)/2]*bs[(j-i-1+N)/2];
	int64_t k=1;
	while(used.count(base*k+1)){
	  k++;
	}
	mat[i][j]=base*k+1;
	used.insert(mat[i][j]);
      }
    }
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(j) printf(" ");
      printf("%ld",mat[i][j]);
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 19072
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[210000];
int main(){
	long long a;scanf("%lld",&a);
	if(a%2){
		printf("0\n");return 0;
	}
	a/=2;
	long long ret=0;
	while(a){
		ret+=a/5;
		a/=5;
	}
	printf("%lld\n",ret);
}

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

int n, h, w;

void input() {
	cin >> n >> h >> w;
}

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

	input();

    cout << (n - h + 1) * (n - w + 1) << "\n";

	return 0;
}

Measured memory_bytes: 256
def bisect(bi, x, target, left, right):
    if left + 1 == right:
        return right
    half = (right + left) // 2
    if bi[half] * x < target:
        half = bisect(bi, x, target, half, right)
    else:
        half = bisect(bi, x, target, left, half)
    return half
N,K = map(int, input().split())
bi = []
i = 1
while i <= 10**5:
    bi.append(i)
    i *= 2
bi.append(i)

ans = 0
for i in range(1,N+1):
    if i >= K:
        ans += 1
    else:
        j = bisect(bi, i, K, 0, len(bi))
        ans += 0.5**j
print('{:.10f}'.format(ans / N))

Measured memory_bytes: 3188
Printf.printf "%d\n" @@ Scanf.scanf "%d %d" @@ fun x y ->
  [x,y,0; -x,y,1; x,-y,1; -x,-y,2] |> List.fold_left (fun z (x,y,s) ->
    if x > y then z else min z (y-x+s)) 101010101010

Measured memory_bytes: 384
#include <bits/stdc++.h>
     
using namespace std;
     
#define FOR(i,a,b)		for(int i=(a),_b=(b);i<(_b);++i)
#define FORD(i,a,b)		for(int i=(a),_b=(b);i>(_b);--i)
#define pb			push_back
#define mp			make_pair
#define	all(c)			(c).begin(),(c).end()
#define	present(c,x)		((c).find(x) != (c).end())
#define	cpresent(c,x)		(find(all(c),x) != (c).end())
#define	endl			'\n'
     
typedef long long		ll;
typedef unsigned long long	ull;
typedef unsigned char	 	byte;
typedef vector<int>		vi;
typedef pair<int, int>		pii;
typedef pair<ll, ll>		pll;
typedef vector<pii>		vpii;
     
const int MX = 100005;

int memo[MX];
vi g[MX];

int dfs(int u)
{
	if (memo[u] != -1) return memo[u];
	int ret = 0;
	int n = g[u].size();
	FOR(i,0,n) {
		int v = g[u][i];
		ret = max(ret,dfs(v)+1);
	}
	return memo[u] = ret;
}

int main(int argc, char *argv[])
{
#ifdef	HTRINH_UNIT_TEST
	freopen(argv[1],"r",stdin);
	ifstream cin(argv[1]);
#endif
#if 0
	ofstream cout(argv[2]);
#endif
	ios :: sync_with_stdio(false);
	cin.tie(NULL);

	int n,m,u,v;
	cin >> n >> m;
	FOR(i,1,n+1) memo[i] = -1;
	FOR(i,0,m) {
		cin >> u >> v;
		g[u].pb(v);
	}
	int ans = 0;
	FOR(i,1,n+1) {
		if (memo[i] == -1) ans = max(ans, dfs(i));
	}
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int N;
vector<int> C, S, F;

int solve(int i){
    int t = 0;
    for(;i<N;i++){
        if(t < S[i]) t = S[i];
        t += t%F[i]==0 ? 0 : F[i]-t%F[i];
        t += C[i];
    }
    return t;
}

int main(void){
    cin >> N;
    C.resize(N); S.resize(N); F.resize(N);
    for(int i=0;i<N-1;i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    C[N-1] = S[N-1] = 0;
    F[N-1] = 1;

    for(int i=0;i<N;i++){
        int ans = solve(i);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
a = [int(input()) for _ in range(M)]
dp = [0]*(N+1)
j = 0
dp[0] = 1
mod = 10**9+7
for i in range(1, N+1):
    if j < M and i == a[j]:
        j += 1
    elif i == 1:
        dp[i] = 1
    else:
        dp[i] = (dp[i-1]+dp[i-2]) % mod
print(dp[N])

Measured memory_bytes: 7824
#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
typedef long long ll;
vector<pair<ll,ll> > g[100001];
ll visit[100001];
pair<ll,ll> p[100001],mi[100001];
void dfs(ll x,ll y,ll z){
    visit[x]=1;
    for(ll i=0;i<g[x].size();i++){
        if(z){
            if(p[g[x][i].first].second==0){
                p[g[x][i].first].first=g[x][i].second-mi[x].first;
                p[g[x][i].first].second=1;
            }
            else if(p[g[x][i].first].first!=g[x][i].second-mi[x].first){
                p[g[x][i].first].second=-1;
            }
        }
        else{
            if(mi[g[x][i].first].second==0){
                mi[g[x][i].first].first=g[x][i].second-p[x].first;
                mi[g[x][i].first].second=1;
            }
            else if(mi[g[x][i].first].first!=g[x][i].second-p[x].first){
                mi[g[x][i].first].second=-1;
            }
        }
    }
    for(ll i=0;i<g[x].size();i++){
        if(visit[g[x][i].first]==0){
            dfs(g[x][i].first,y,z^1);
        }
    }
}

int main(){
    ll n,m,u,v,s,f=1,l,r,x=0,y=0;
    scanf("%lld %lld",&n,&m);
    for(ll i=0;i<m;i++){
        scanf("%lld %lld %lld",&u,&v,&s);
        g[u].push_back(make_pair(v,s));
        g[v].push_back(make_pair(u,s));
    }
    dfs(1,0,0);
    for(ll i=1;i<=n;i++){
        if(p[i].second==-1||mi[i].second==-1){
            f=0;
        }
        if(p[i].second==1&&mi[i].second==1){
            if(y==1){
                if(x!=(mi[i].first-p[i].first)/2){
                    f=0;
                }
            }
            y=1;
            x=(mi[i].first-p[i].first)/2;
        }
    }
    if(!f){
        printf("0\n");
    }
    else if(y){
        for(int i=1;i<=n;i++){
            if(p[i].second){
                if(x+p[i].first<=0){
                    f=0;
                }
            }
            if(mi[i].second){
                if(mi[i].first-x<=0){
                    f=0;
                }
            }
        }
        printf("%lld\n",f);
    }
    else{
        l=1;
        r=1000000000;
        for(ll i=1;i<=n;i++){
            if(mi[i].second){
                r=min(r,mi[i].first-1);
            }
            if(p[i].second){
                l=max(l,-p[i].first+1);
            }
        }
        if(l>r){
            printf("0\n");
        }
        else{
            printf("%lld\n",r-l+1);
        }
    }
}


Measured memory_bytes: 18048
from time import time
from random import randrange, expovariate
from bisect import bisect_left
import sys
def input():
	return sys.stdin.buffer.readline()[:-1]
start = time()
d = int(input())
c = list(map(int, input().split()))
C = sum(c)
s = [list(map(int, input().split())) for _ in range(d)]
#t = [int(input()) for _ in range(d)]
t = []
day = [[0] for _ in range(26)]
order = []

def score(t):
	res = 0
	minus = 0
	last = [0 for _ in range(26)]
	for i, x in enumerate(t):
		minus += C - c[x-1] * (i - last[x-1] + 1)
		res -= minus
		res += s[i][x-1]
		last[x-1] = i+1
		#print(res)
	return res

def tri(n):
	return n * (n-1) // 2

def change(i, to):
	diff = 0
	fr = t[i]-1
	#print(day[fr])
	#print(day[to])
	if fr == to:
		return None
	fr_ind = bisect_left(day[fr], i+1)
	diff += (tri(day[fr][fr_ind] - day[fr][fr_ind-1]) + tri(day[fr][fr_ind+1] - day[fr][fr_ind])) * c[fr]
	diff -= (tri(day[fr][fr_ind+1] - day[fr][fr_ind-1])) * c[fr]
	diff -= s[i][fr]
	
	to_ind = bisect_left(day[to], i+1)
	diff += (tri(day[to][to_ind] - day[to][to_ind-1])) * c[to]
	diff -= (tri(day[to][to_ind] - (i+1)) + tri(i+1 - day[to][to_ind-1])) * c[to]
	diff += s[i][to]

	if diff > -1000:
		day[fr].pop(fr_ind)
		after = day[to][:to_ind] + [i+1] + day[to][to_ind:]
		day[to] = after
		t[i] = to+1
		#print("↓")
		#print(day[fr])
		#print(day[to])
		return diff
	else:
		return None

#score(t)
res = 0
minus = 0
last = [0 for _ in range(26)]
for i in range(d):
	minus += C
	li = sorted(list(range(26)), key=lambda x: - c[x] * (i - last[x] + 1) - s[i][x])
	order.append(li)
	M_ind = li[0]
	minus -= c[M_ind] * (i - last[M_ind] + 1)
	last[M_ind] = i+1
	res -= minus - s[i][M_ind]
	t.append(M_ind+1)
	day[M_ind].append(i+1)

for i in range(26):
	day[i].append(d+1)


#print(*t, sep="\n")
#print(score(t))
#print("↓")

priority = [0 for _ in range(d)]
while time() - start < 1.8:
	#i = min(d-1, int(expovariate(d//2)))
	i = randrange(d)
	pr = randrange(max(0, priority[i]-4), min(26, priority[i]+4))
	diff = change(i, order[i][pr])
	if diff is not None:
		res += diff
		priority[i] = pr

print(*t, sep="\n")
#print(score(t))

Measured memory_bytes: 96736
#include<iostream>

using namespace std;

int main(){
  int N,x=0,max=0; cin >> N;
  string s; cin >> s;

  for(int i=0; i<N; i++){

    if(s[i] == 'I')
      x += 1;
    else
      x -= 1;

    if(max < x)
      max = x;
  }
  cout << max << endl;
}


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

using namespace std;
const int maxn = 2005;

bool e[maxn][maxn];
int deg[maxn],n,a[maxn],usd[maxn];
int gcd(int n,int m) {return m?gcd(m,n%m):n;}

void dfs(int u)
{
	usd[u]=1;
	for (int j=1;j<=n;j++)
	if (e[u][j]) {
		if (!usd[j]) {
			e[j][u]=false;deg[j]++;dfs(j);
		}
		else {
			e[j][u]=e[u][j]=false;
		}
	}
}
int main()
{
	#ifdef Amberframe
		freopen("agc010e.in","r",stdin);
		freopen("agc010e.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	
	for (int i=1;i<=n;i++)
	for (int j=i+1;j<=n;j++)
		if (gcd(a[i],a[j])>1) e[i][j]=e[j][i]=true; 
	for (int i=1;i<=n;i++)
		if (!usd[i]) dfs(i);
	for (int i=1;i<=n;i++)
	{
		int pos=n;while (!usd[pos]||deg[pos]) --pos;
		printf("%d ",a[pos]);usd[pos]=0;
		for (int j=1;j<=n;j++)
			if (e[pos][j]) --deg[j];
	}
	return 0;
}

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

typedef long long ll;
using namespace std;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> w(n+1, 0);
    for(int i=1;i<=n;++i){
        cin >> w[i];
    }
    int ans = 1000000;
    for(int i=1;i<n;++i){
        int ansh = 0;
        int ansl = 0;
        for(int j=1;j<=i;++j){
            ansl += w[j];
        }
        for(int j=i+1;j<=n;++j){
            ansh += w[j];
        }
        ans = min(ans, abs(ansh-ansl));
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int n; cin >> n; vector<int>p(n,0); for(int i = 0; i < n; i++) cin >> p[i];
    sort(p.begin(), p.end());
    
    int ret = p.back() / 2; p.pop_back();
    for(auto v : p)
        ret += v;
    cout << ret << endl;
    
   
    return 0;
}


/*
 
 
 */


Measured memory_bytes: 256