akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int L, R;
int rem[2025];

int main() {
    cin >> L >> R;
    for (int i = L; i <= min(L+2019, R); ++i) {
        rem[i%2019]++;
    }
    int res = INF;
    rep(i, 2019) if (rem[i] > 1) chmin(res, (i*i)%2019);
    rep(i, 2019) rep(j, i) {
        if (rem[i] && rem[j]) {
            chmin(res, (i*j)%2019);
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3616
n, m, c = map(int, input().split())
lb = list(map(int, input().split()))
t = 0

for _ in range(n):
  la = list( map(int, input().split()) )
  s = c
  for i in range(m):
    s += la[i] * lb[i]
  if s > 0:
    t += 1

print(t)

Measured memory_bytes: 9120
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = sum(B)

for i in range(len(A)- 1):
    if A[i] + 1 == A[i + 1]:
        ans += C[A[i] - 1]

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define endl "\n"
#define loop(i,s,e) for(int i=s;i<e;i++)
#define int long long
#define mp make_pair
#define pii pair<int,int>
#define mset(a,f)  memset(a , f , sizeof(a))
#define pb push_back
const int N = 2e6 + 6;
const int M = 1e9 + 7;
int A[N];
int n;

void solve()
{
	int k ,n;
	cin >>  k >> n;

	loop(i,0,n)cin >> A[i];

	int ans =  INT_MAX;

	loop(i,0,n)
	{
		if(i == 0 )
		{
			ans = min(ans ,min(k-(A[0]+k-A[n-1]) , k-(A[i+1]-A[i])));
		}
		else if(i == n-1)
		{
			ans = min(ans ,min(k-(A[i]-A[i-1]) , k-(A[0]+k-A[n-1])));
		}
		else 
		{
			ans = min(ans , min(k-(A[i]-A[i-1]) , k - (A[i+1]-A[i])));
		}
	}

	cout << ans;
}
 
int32_t main()
{
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
    
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}


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

int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int ans =0;
  for(int i=0;i<A+1;i++){
    for(int j=0;j<B+1;j++){
      for(int k=0;k<C+1;k++){
        if(500*i+100*j+50*k==X){
          ans++;
        }
      }
    }
  }
  cout << ans;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<char>());
  //   int x = min(s.size(), t.size());
  //   for (int i = 0; i < x; i++) {
  //     if (t[i] - s[i] > 0) {
  //       judge = true;
  //       break;
  //     } else if (t[i] - s[i] == 0) {
  //       continue;
  //     } else {
  //       judge = false;
  //       break;
  //     }
  //   }
  cout << (s < t ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}

lint ll(char s){
    if(s=='A')return 1;
    if(s=='B')return 2;
    if(s=='C')return 3;
    if(s=='D')return 4;
    if(s=='E')return 5;
    if(s=='F')return 6;
    if(s=='G')return 7;
    if(s=='H')return 8;
    if(s=='I')return 9;
    if(s=='J')return 10;
    if(s=='K')return 11;
    if(s=='L')return 12; 
    if(s=='M')return 13;
    if(s=='N')return 14;
    if(s=='O')return 15;
    if(s=='P')return 16;
    if(s=='Q')return 17;
    if(s=='R')return 18;
    if(s=='S')return 19;
    if(s=='T')return 20;
    if(s=='U')return 21;
    if(s=='V')return 22;
    if(s=='W')return 23;
    if(s=='X')return 24;
     if(s=='Y')return 25;
    if(s=='Z')return 26;
    

}
int main(){
    lint N,W;
   string s;
   cin>>N>>s;

 rep(i,s.size()){
        if(N+ll(s[i])>26)s[i]-=(ll('Z')-N);
      else  s[i]+=N;}
        cout<<s;
       
}

Measured memory_bytes: 256
import heapq

n,l=map(int,raw_input().split())
a=[[0,0]]+[[0,i] for i in xrange(n)]+[[0,n+1]]
for i in xrange(n):
    en=int(raw_input())
    a[i]=[-en,i]
pq=[]
for i in xrange(n+2):
    heapq.heappush(pq,a[i])
ti=[0]*(n+2)
while 1:
    p,i=heapq.heappop(pq)
    p=-p
    if p==0:break
    ti[i]+=l-p
    a[i][0]=0
    if a[i-1][0]!=0:
        ti[i-1]=max(ti[i-1],ti[i])
    if a[i+1][0]!=0:
        ti[i+1]=max(ti[i+1],ti[i])
print(max(ti))

Measured memory_bytes: 23888
N=int(input())
S=input()

count=0
if(N%2==1):
    print("No")
else:
    flag=int(N/2)
    for i in range(0,flag):
        if(S[i]!=S[i+flag]):
            break
        else:
            count=count+1

    if(count==flag):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#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;

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

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define un(x)           x.erase(unique(all(x)), x.end())
#define xx              first
#define yy              second
#define pb              push_back
#define mp              make_pair
#define all(v)          v.begin(),v.end()
#define D(x)            cerr << #x " = " << x << '\n'
#define DBG             cerr << "Hi!" << '\n'

#define CLR(a)          memset(a,0,sizeof(a))
#define SET(a)          memset(a,-1,sizeof(a))

#define PI              acos(-1.0)

//inline int setBit(int n,int pos) { return n = n | (1 << pos); }
//inline int resetBit(int n,int pos) { return n = n & ~(1 << pos); }
//inline bool checkBit(int n,int pos) { return (bool)(n & (1 << pos)); }
//inline int countBit(ll n) { return __builtin_popcountll(n); }


//int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
//int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1}; //Four & Eight Direction

/******************************************************************************************/

const int MAX = 100010;
const int INF = 0x3f3f3f3f;
//const double inf = 1.0/0.0;
//const int MOD = 1000000007;

int n,k;
int ara[105];
int mn;
int dp[MAX];

int call(int coins) {
    if(coins<mn) return 0;
    if(dp[coins]!=-1) return dp[coins];
    int ret = 0;
    for(int i=1;i<=n;i++) if(coins-ara[i]>=0 and !call(coins-ara[i])) ret = 1;
    return dp[coins] = ret;
}

int main() {
//    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);


    sii(n,k);

    mn = 1000000;
    for(int i=1;i<=n;i++) {
        si(ara[i]);
        mn = min(mn,ara[i]);
    }

    SET(dp);
    if(call(k)) puts("First");
    else puts("Second");

    return 0;
}



Measured memory_bytes: 5376
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = sc.nextInt(), t = sc.nextInt(), a = sc.nextInt();
        int h[] = new int[n];
        int ans = 0;
        double min = Double.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            double tmpMin = Math.abs(a - (t - h[i] * 0.006));
            if (tmpMin < min) {
                min = tmpMin;
                ans = i;
            }
        }
        System.out.println(ans + 1);
    }
}

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

struct edge { long long to, cost;};
typedef pair<long long, long long> P_dij;

vector<long long> dijkstra(long long s, long long n, vector< vector<edge> > const &G){
    vector<long long> d = {};
    long long INF = 10000000000000000;
    d.resize(n);
    for(int i=0; i<n; i++){
        d[i] = INF;
    }
    priority_queue<P_dij, vector<P_dij>, greater<P_dij>> que;
    d[s] = 0;
    que.push(P_dij(0, s));
    while(!que.empty()){
        P_dij p = que.top();
        que.pop();
        long long v = p.second;
        if(d[v] < p.first)continue;
        for(int i=0;i<G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P_dij(d[e.to], e.to));
            }
        }
    }
    return d;
}

long long i, j, k;
vector< vector<edge> > edge_yen(200001);
vector< vector<edge> > edge_snu(200001);

int main(){
    long long n, m, s, t;
    cin >> n >> m >> s >> t;
    for(i=0; i<m; i++){
        long long u, v, a, b;
        cin >> u >> v >> a >> b;
        edge e1;
        e1.to = v, e1.cost = a;
        edge_yen[u].push_back(e1);
        edge e2;
        e2.to = u, e2.cost = a;
        edge_yen[v].push_back(e2);
        edge e3;
        e3.to = v, e3.cost = b;
        edge_snu[u].push_back(e3);
        edge e4;
        e4.to = u, e4.cost = b;
        edge_snu[v].push_back(e4);
    }

    vector<long long> dist_yen = dijkstra(s, n+1, edge_yen);
    vector<long long> dist_snu = dijkstra(t, n+1, edge_snu);

    long long ans[200001];
    long long Max = 0;
    long long FIRST = 1e15;
    for(i=n; i>=1; i--){
        long long val = FIRST - (dist_yen[i] + dist_snu[i]);
        Max = max(val, Max);
        ans[i] = Max;
    }
    for(i=1; i<=n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 23804
n,k,q = map(int,input().split())
a=[int(input()) for i in range(q)]

m = [k-q] * n
for i in range(q):
    m[a[i]-1] = m[a[i]-1] + 1
    
for j in range(n):
    if m[j] <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 10408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define All(x) (x).begin(),(x).end()
#define RAll(x) (x).rbegin(),(x).rend()


int main(){
	ll x;
	cin >> x;
	ll a = x / 500;
	ll b = (x - 500 * a) / 5;
	cout << a * 1000 + b * 5 << endl;
}

Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(int[]);
  auto a = rd[0], b = rd[1], c = rd[2], d = rd[3], e = rd[4], f = rd[5];

  auto ansW = 0, ansS = 0, ansK = real(0);

  foreach (i; 0..f/a+1)
    foreach (j; 0..f/b+1) {
      auto w = i*a + j*b;
      if (w*100 > f) continue;
      auto s = w*e;
      foreach (k; 0..s/c+1)
        foreach (l; 0..s/d+1) {
          auto t = k*c + l*d;
          if (t > s || t+w*100 > f) continue;
          auto m = t.to!real / (t+w*100);
          if (m >= ansK) {
            ansW = w;
            ansS = t;
            ansK = m;
          }
        }
    }

  writeln(ansW*100+ansS, " ", ansS);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();

		for(int i = 0; i < H; i++) {
			String receive = sc.next();
			System.out.println(receive);
			System.out.println(receive);
		}

		sc.close();
	}

}


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

#define MOD 1000000007

signed main() {
    int n;
    long long a[200000], ans, sum;
    
    cin >> n;
    sum = 0;
    for (int i=0 ;i<n ;i++ ) {
        cin >> a[i];
        sum += a[i];
        sum = sum % MOD;
    }
    
    ans = 0;
    for (int i=0 ;i<n ;i++ ) {
        sum -= a[i];
        if (sum < 0) {
            sum += MOD;
        }
        ans += a[i] * sum;
        ans = ans % MOD;
    }
    
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 5152
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[1500];
    for(int i =0 ; i < n; i++) cin >> a[i];
    int max = -1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(abs(a[i] - a[j] > max)) max = abs(a[i] - a[j]);
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<ios>
using namespace std;
char c='A',a,b;
main()
{
    while(~scanf("%c,%c\n",&a,&b))
    {
        if(a==c)c=b;
        else if(b==c)c=a;
    }
    printf("%c\n",c);
}



Measured memory_bytes: 3172
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int need = sc.nextInt();
		int max = (num - 1) * (num - 2) / 2;
		if(need > max) {
			System.out.println("-1"); return;
		}
		System.out.println(num - 1 + max - need);
		for(int i = 2; i <= num; i ++) {
			System.out.println("1 "+i);
		}
		int count = 0;
		for(int i = 2; i <= num; i ++) {
			for(int j = i + 1; j <= num; j ++) {
				if(count >= max - need) { break; }
				System.out.println(i+" "+j);
				count ++;
			}
		}
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

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

    cin>>n;
    n = n % 10;
    if(n==2||n==4||n==5||n==7||n==9){
        cout<<"hon"<<endl;
    }
    else if(n==0||n==1||n==6||n==8){
        cout<<"pon"<<endl;
    }
    else {
        cout<<"bon"<<endl;
    }
    

}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
using namespace std;
signed main() {
	int n,a,b;
	cin>>n>>a>>b;
	int x[n];
	rep(i,n) cin>>x[i];
	int cnt=0;
	rep(i,n-1) {
		cnt+=min(a*(x[i+1]-x[i]),b);
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

const int mod = 1000000007;
class mint {
  long long x;
  public:
  mint(long long x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const {
    return mint(-x);
  }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const  mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint& a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res/=a;
  }

  friend ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
  }
};

struct combination{
  vector<mint> fact,ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1;i <= n;i++) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1;i--) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n,int k){
    if(k < 0 || n < k) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

signed main(){
  int n,k;
  cin >> n >> k;
  k = min(k,n-1);
  combination c(n);
  mint ans;
  for(int i = 0;i <= k;i++){
    ans += c(n,i) * c((n-i-1) + i,i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
A = input()
B = input()
C = input()
X = input()
A = int(A)
B = int(B)
C = int(C)
X = int(X)

count = 0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if(500*i + 100*j + 50*k == X):
                count += 1

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <list>

const int MAX_N = 200000;

struct Node {
  int parent;
  std::list<int> *leaves;
};

int main(void) {
  int n = 0;
  struct Node *N[MAX_N];

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    struct Node *node = (struct Node *) std::malloc(sizeof(struct Node));

    node->parent = -1;
    node->leaves = new std::list<int>();
    
    N[i] = node;
  }

  for (int i = 0; i < n; i++) {
    int id = 0;
    int k = 0;

    std::cin >> id;
    std::cin >> k;
    
    for (int m = 0; m < k; m++) {
      int leaf = 0;
      
      std::cin >> leaf;
      
      N[id]->leaves->push_back(leaf);
      N[leaf]->parent = id;
    }
  }

  for (int i = 0; i < n; i++) {
    struct Node *node = N[i];
    
    std::cout << "node "<< i << ": ";
    std::cout << "parent = " << node->parent << ", ";

    int depth = 0;

    struct Node *p = node;

    while (p->parent >= 0) {
      p = N[p->parent];
      depth++;
    }
    
    std::cout << "depth = " << depth << ", ";

    if (node->parent < 0) {
      std::cout << "root";
    } else if ((node->parent >= 0) && (node->leaves->size() > 0)) {
      std::cout << "internal node";
    } else {
      std::cout << "leaf";
    }
    
    std::cout << ", [";
      
    for (std::list<int>::iterator iterator = node->leaves->begin(); iterator != node->leaves->end(); ++iterator) {
      std::cout << *iterator;

      ++iterator;

      if (iterator != node->leaves->end()) {
     	std::cout << ", ";
      }

      --iterator;
    }

    std::cout << "]" << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 11348
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,x) for(int i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    ll N, M;
    cin >> N >> M;
    ll n = 0;
    map<ll, ll> num;//n gyoushuturyoku
    rep(i, 2 * M) {
        cin >> n;
        num[n]++;
    }
    for (int i = 1; i <= N; i++) {
        cout << num[i] << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int func(int x, int y, int z){
    return x * x + y * y + z * z + x * y + y * z + z * x;
}

int main()
{
    int N;
    vector<int> res;
    cin >> N;
    res.resize(N + 1, 0);


    for (int x = 1; x <= N; x++){
        for (int y = x; y <= N; y++)
        {
            for (int z = y; z <= N; z++)
            {
                int val = func(x, y, z);
                if(val > N){
                    break;
                }
                if(x == y && y == z){
                    res[val] += 1;
                }else if((x != y) && (y != z) && (z != x)){
                    res[val] += 6;
                }else{
                    res[val] += 3;
                }
            }
        }
    }

    for (int i = 1; i <= N; i++){
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 3632
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)

int N;
int A[200000];
ll cnt[200000] ={};
ll ans = 0;

signed main(){
	cin >> N;
	rep(i, N){
		cin >> A[i];
		A[i]--;
		cnt[A[i]]++;
	}
	rep(i, N) ans += cnt[i]*(cnt[i]-1)/2;

	rep(i, N){
		cout << ans - cnt[A[i]]*(cnt[A[i]]-1)/2 + (cnt[A[i]]-1)*(cnt[A[i]]-2)/2 << endl;
	}
}

Measured memory_bytes: 3968
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**9)
from collections import defaultdict

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self,x):
        if(self.parents[x] < 0):
            return x
        self.parents[x] = self.find(self.parents[x])
        return self.parents[x]

    def size(self, x):
        return self.parents[ self.find(x) ] * -1

    def same(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)
        return (x_root == y_root)

    def union(self,x,y):
        x_root = self.find(x)
        y_root = self.find(y)
        if(x_root == y_root):
            return

        if( self.parents[x_root] <= self.parents[y_root] ):
            self.parents[x_root] += self.parents[y_root]
            self.parents[y_root] = x_root
        else:
            self.parents[y_root] += self.parents[x_root]
            self.parents[x_root] = y_root

    def members(self,x):
        root = self.find(x)
        ret = [ i for i in range(self.n) if self.find(i) == root ]
        return ret

    def roots(self):
        ret = [ i for i in range(self.n) if self.parents[i] < 0]
        return ret

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: set(self.members(r)) for r in self.roots()}

n,k,l = map(int,readline().split())
pqrs = list(map(int,read().split()))
pq = pqrs[:2*k]
rs = pqrs[2*k:]

uf_l = UnionFind(n+1)
uf_t = UnionFind(n+1)

for uf,link in zip([uf_l,uf_t],[pq,rs]):
    it = iter(link)
    for a,b in zip(it,it):
        uf.union(a,b)

d = defaultdict(lambda : set())
for i in range(n+1):
    root_l = uf_l.find(i)
    root_t = uf_t.find(i)
    d[root_l * 10**6 + root_t].add(i)

ans = [0] * (n+1)
for s in d.values():
    len_s = len(s)
    for i in s:
        ans[i] = len_s

print(' '.join(map(str,ans[1:])))

Measured memory_bytes: 186316
n = int(input())
a = [None]*n
b = [None]*n
c = [None]*n
for i in range(n):
    a[i],b[i],c[i] = list(map(int,input().split(' ')))

dp = [[0]*n for i in range(3)]
dp[0][0], dp[1][0], dp[2][0] = a[0],b[0],c[0]
for i in range(1,n):

    for j in range(3):
        if j==0:
            dp[j][i] = max(dp[1][i-1]+a[i], dp[2][i-1]+a[i])
        elif j==1:
            dp[j][i] = max(dp[0][i-1]+b[i], dp[2][i-1]+b[i])
        elif j==2:
            dp[j][i] = max(dp[0][i-1]+c[i], dp[1][i-1]+c[i])
print(max(dp[0][-1], dp[1][-1], dp[2][-1]))

Measured memory_bytes: 84696
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
ll mod = 1000000007;

class UnionFind {
  private:
    int num;
    vector<int> par;
    vector<int> sizes;
    vector<int> rank;

  public:
    UnionFind(int n) { init(n); }

    ~UnionFind() {}

    int init(int n) {
        num = n;
        par.resize(n);
        sizes.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            sizes[i] = 1;
            rank[i] = 0;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        if (rank[rx] < rank[ry]) {
            par[rx] = ry;
        } else {
            par[ry] = rx;
            if (rank[rx] == rank[ry]) {
                rank[rx]++;
            }
        }
        int temp = sizes[rx] + sizes[ry];
        sizes[rx] = temp;
        sizes[ry] = temp;
    }

    int get_size(int x) { return sizes[root(x)]; }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
source:
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind u(n + 1);
    int friends[n + 1] = {};
    rep(i, m) {
        int a, b;
        scanf("%d", &a);
        scanf("%d", &b);
        u.unite(a, b);
        friends[a]++;
        friends[b]++;
    }

    int c[k], d[k];
    rep(i, k) {
        scanf("%d", &c[i]);
        scanf("%d", &d[i]);
    }

    int ans[n + 1] = {};
    repd(i, 1, n + 1) { ans[i] = u.get_size(i) - 1; }

    rep(i, k) {
        bool same = u.same(c[i], d[i]);
        if (same) {
            ans[c[i]]--;
            ans[d[i]]--;
        }
    }

    repd(i, 1, n + 1) { printf("%d ", ans[i] - friends[i]); }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3584
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }

//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p%i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL a, b, c, d, e;
	string s1, s2, s3, s4;
	string ans = "";

	cin >> a;
	if (a < 1000) {
		O("ABC");
	}
	else {
		O("ABD");
	}

	return 0;
}

Measured memory_bytes: 256
a, b, h, m = gets.split(" ").map(&:to_i)
ca = h/12.0*2.0*Math::PI
ca = ca + (1/12.0)*(m/60.0)*2*Math::PI
cb = m/60.0*2*Math::PI
#p ca, cb
ax = a * Math.cos(ca)
ay = a * Math.sin(ca)
bx = b * Math.cos(cb)
by = b * Math.sin(cb)
#puts ax, ay, bx, by
puts Math.sqrt((bx-ax)**2 + (by-ay)**2)


Measured memory_bytes: 14684
f=lambda:map(int,input().split())
h,w,n=f()
d={}
while n:
 n-=1;x,y=f()
 for i in range(9):a=(x+i%3,y+i//3);d[a]=d.get(a,0)+(h>=a[0]>2<a[1]<=w)
c=[list(d.values()).count(i+1)for i in range(9)]
print((h-2)*(w-2)-sum(c),*c)

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

int main() {
  string s; cin >> s;
  int n; n=s.size();
  vector<char> command;
  
  for(int i=0; i < n; i++){
    if(s.at(i)=='0'){
      command.push_back('0');
    }
    else if(s.at(i)=='1'){
      command.push_back('1');
    }
    else if(s.at(i)=='B'){
      if(command.size() !=0){
        command.pop_back();
      }
    }
  }
  
  string t; 
  for(int i=0; i < command.size(); i++){
    t += command.at(i);
  }
  
  cout << t << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N;
LL S;

int main(){
	cin >> N >> S;
	vector<LL> X(N) , P(N);
	int c = -1;
	repp(i,0,N){
		cin >> X[i] >> P[i];
		X[i] -= S;
		if(c<0 && X[i] > 0) c = i;
	}
	if(c < 0) return cout << -X[0] << endl , 0;
	if(c == 0) return cout << X[N-1] << endl , 0;
	vector<LL> V;
	LL z;
	LL t[2] = {P[0],P[N-1]};
	LL a[2] = {0,N-1};
	if(P[0] < P[N-1]){
		V.PB(X[0]);
		V.PB(X[N-1]);
		z = N-1;
	} else {
		V.PB(X[N-1]);
		V.PB(X[0]);
		z = 0;
	}
	while(1){
		if(z < c){
			if(a[1] == c) break;
			--a[1];
			if(t[0]+t[1] < P[a[1]]){
				V.PB(X[a[1]]);
				z = a[1];
			}
			t[1] += P[a[1]];
		} else {
			if(a[0] == c-1) break;
			++a[0];
			if(t[0]+t[1] <= P[a[0]]){
				V.PB(X[a[0]]);
				z = a[0];
			}
			t[0] += P[a[0]];
		}
	}
	V.PB(0);
	LL ans = 0;
	repp(i,1,V.size()){
		ans += abs(V[i-1]-V[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

int read() {
	char ch;
	for(ch=getchar();ch<'0'||ch>'9';ch=getchar());
	int x=ch-'0';
	for(ch=getchar();ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int N=1e5+5;

int n,ord[N];
ll val[N],l[N],u[N],b[N],s[N],x;

bool cmp(int x,int y) {return val[x]>val[y];}

ll chk_mx(ll k) {
	ll mx=0;
	ll p=k/x,q=k%x;
	if (p==n) return s[n];
	fo(i,1,n) {
		int z=ord[i];
		ll tmp=(q<=b[z])?q*l[z]:b[z]*l[z]+(q-b[z])*u[z];
		tmp+=(i<=p)?s[p+1]-val[z]:s[p];
		mx=max(mx,tmp);
	}
	return mx;
}

int main() {
	n=read();x=read();
	fo(i,1,n) b[i]=read(),l[i]=read(),u[i]=read();
	fo(i,1,n) val[i]=l[i]*b[i]+(x-b[i])*u[i];
	fo(i,1,n) ord[i]=i;sort(ord+1,ord+n+1,cmp);
	fo(i,1,n) s[i]=s[i-1]+val[ord[i]];
	ll d=0;fo(i,1,n) d+=l[i]*b[i];
	ll L=0,R=0,ans=0;fo(i,1,n) R+=b[i];
	while (L<=R) {
		ll mid=L+R>>1;
		if (chk_mx(mid)>=d) ans=mid,R=mid-1;
		else L=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <string>

using namespace std;

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

	int n = s.length();

	if (s[0] != 'A')
	{
		cout << "WA" << endl;
		return 0;
	}

	int cnt = 0;
	for (int i = 2; i <= n - 2; i++)
	{
		if (s[i] == 'C')
		{
			cnt++;
		}
	}

	if (cnt != 1)
	{
		cout << "WA" << endl;
		return 0;
	}

	for (int i = 1; i < n; i++)
	{
		if (s[i] == 'C')
		{
			continue;
		}

		if (s[i] >= 'a' && s[i] <= 'z')
		{
			continue;
		}
		else
		{
			cout << "WA" << endl;
			return 0;
		}
	}

	cout << "AC" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    map<int,int> mp;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        mp[min(8,a/400)]++;
    }
    
    int mpn = mp.size();
    int mina = mpn;
    if (mpn > 1 && mp[8]) mina--;

    int maxa = mpn;
    if (mp[8]) maxa += mp[8] - 1;

    // for (auto p : mp) {
    //     cout << p.first << " " << p.second << endl;
    // }
    // cout << endl;    


    cout << mina << " " << maxa << endl;

}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u64,
    }
    println!("ABC{}", n);
}


Measured memory_bytes: 4352
#include <stdio.h>
int main(void){
 int d;
  scanf("%d",&d);
  switch(d){
    case 22:
      printf("Christmas Eve Eve Eve");
      break;
          case 23:
      printf("Christmas Eve Eve");
      break;
          case 24:
      printf("Christmas Eve");
      break;
          case 25:
      printf("Christmas");
      break;
  }
return 0;
}

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

int main() {
  ll X,Y;
  int A,B,C;
  cin >> A >> B >> C >> X >> Y;
  ll min_cost = 1.0e10;
  for(ll u=0;u<=max(X*2,Y*2);u=u+2){
    ll s,t;
    if(X-u/2 <= 0){
      s = 0;
    }else{
      s = X-u/2;
    }
    if(Y-u/2 <= 0){
      t = 0;
    }else{
      t = Y-u/2;
    }
    ll cost = A*s+B*t+C*u;
    //cout << cost << endl;
    //cout << s << " " << t << " " << u << endl;
    if(cost < min_cost){
      min_cost = cost;
    }
  }
      
  cout << min_cost << endl;
  return(0);
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int[] prime = new int[999999];
        prime[0] = 2;
        int num = 1;
        while(s.hasNext()){
            int n = s.nextInt();
            if (prime[num-1] > n){
                int out = 0;
                for(int i=0; ; i++){
                    if(prime[i] > n){
                        out = i;
                        break;
                    }
                }
                System.out.println(out);
            }else{
                for (int i=prime[num-1]+1 ; i<=n ; i++){
                    boolean flag = true;            
                    for (int j=0 ; prime[j]*prime[j] <= i ; j++){
                        if(i % prime[j] == 0){
                            flag = false;
                            break;
                        }
                    }
                    if(flag){
                        prime[num] = i;
                        num++;
                    }
                }        
            System.out.println(num);    
            }
        }
    }
}

Measured memory_bytes: 16000
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[10010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, N;
    cin >> H >> N;
    int A[1010], B[1010];
    rep(i, N) cin >> A[i] >> B[i];
    REP(i, 0, H) dp[i] = INF;
    dp[0] = 0;
    REP(i, 1, H) {
        rep(j, N) {
            dp[i] = min(dp[i], dp[max(0, i - A[j])] + B[j]);
        }
        //cout << i << " " << dp[i] << endl;
    }
    cout << dp[H] << endl;
    


    return 0;
}


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

#define INF 1e9

int a[41]={0}, b[41]={0}, c[41]={0};
int dp[41][402][402];

int main(){
    int n, ma, mb;
    cin >> n >> ma >> mb;
    for(int i=1;i<=n;++i){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i=0;i<=n;++i){
        for(int j=0;j<=400;++j){
            for(int k=0;k<=400;++k){
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;

    for(int i=1;i<=n;++i){
        for(int j=0;j<=400;++j){
            for(int k=0;k<=400;++k){
                dp[i][j][k] = min(dp[i][j][k], dp[i-1][j][k]);
                if(j >= a[i] && k >= b[i]){
                    dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-a[i]][k-b[i]] + c[i]);
                }
            }
        }
    }

    int ans = INF;
    for(int i=1;ma*i<=400&&mb*i<=400;++i){
        ans = min(ans, dp[n][ma*i][mb*i]);
    }

    if(ans == INF)cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 26112
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;

int main()
{

	ll i, j, k, l, m, flag, N, M, K, H, W, X,A,B,C;
	cin >> N >> A >> B;
	vector<int>P(N);
	int ans[3] = {};
	for (i = 0; i<N; i++) {
		cin >> P[i];
		if (P[i] <= A) {
			ans[0]++;
		}
		else if (P[i] <= B) {
			ans[1]++;
		}
		else {
			ans[2]++;
		}
	}
	sort(ans, ans + 3);
	output(ans[0]);


	return 0;
}





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

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    
    int start = 0, rank = 0, ans = 0;
    start = A <= B ? A : B;
        
    for(int i = start; i > 0; i--){
        if((A % i == 0) && (B % i == 0)){
            rank++;
            ans = i;
        }
        if(rank == K){
            break;
        }
    }    
    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = (int)1e9 + 7;
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
const int maxN = 2 * (int)1e7 + 100;
int fact[maxN], invfact[maxN], inv[maxN];
void init() {
    fact[0] = invfact[0] = fact[1] = invfact[1] = inv[1] = 1;
    for (int i = 2; i < maxN; i++) {
        inv[i] = mult(inv[mod % i], mod - (mod / i));
        invfact[i] = mult(invfact[i - 1], inv[i]);
        fact[i] = mult(fact[i - 1], i);
    }
}
int cnk(int a, int b) {
    if (b < 0 || a < 0 || a < b) return 0;
    return mult(fact[a], mult(invfact[a - b], invfact[b]));
}
int h, w, k;
int ans = 0;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    init();
    cin >> h >> w >> k;
    for (int s = 1; s <= k; s++) {
        int coef = mult(fact[s], mult(fact[k - s], cnk(h + w - s, k - s)));
        int cur = 0;
        cur = cnk(h + w, s);
        cur = sum(cur, mult(h + w, cnk(h + w - 1, s - 1)));
        cur = sum(cur, mult(mult(h, w), cnk(h + w - 2, s - 2)));
        //cout << s << " " << cur << endl;
        ans = sum(ans, mult(cur, coef));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 234752
class CompleteBinaryTree:
    def __init__(self, nodes):
        self.size = len(nodes)
        self.nodes = [None] + nodes
        
    
    def print_nodes(self):
        for i in range(1,self.size + 1):
            if i == 1:
                print('node {0}: key = {1}, left key = {2}, right key = {3}, '.format(i, self.nodes[i], self.nodes[2*i], self.nodes[2*i+1]))
            elif 2*i < self.size:
                print('node {0}: key = {1}, parent key = {2}, left key = {3}, right key = {4}, '.format(i, self.nodes[i], self.nodes[i//2], self.nodes[2*i], self.nodes[2*i+1]))
            elif 2*i == self.size:             
                print('node {0}: key = {1}, parent key = {2}, left key = {3}, '.format(i, self.nodes[i], self.nodes[i//2], self.nodes[2*i]))
            else:
                print('node {0}: key = {1}, parent key = {2}, '.format(i, self.nodes[i], self.nodes[i//2]))


if __name__ == '__main__':
    n = int(input())
    nodes = list(map(int, input().rstrip().split()))
    cbt = CompleteBinaryTree(nodes)
    cbt.print_nodes()


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

typedef struct{
  double x;
  double y;
} coor;

void kock(int n,coor p1,coor p2){
  if (n == 0) return;

  coor s,t,u;

  s.x = (2*p1.x + p2.x)/3;
  s.y = (2*p1.y + p2.y)/3;
  t.x = (p1.x + 2*p2.x)/3;
  t.y = (p1.y + 2*p2.y)/3;
  u.x = (t.x - s.x)*0.5 - (t.y - s.y)*(sqrt(3)/2) + s.x;
  u.y = (t.x - s.x)*(sqrt(3)/2) + (t.y - s.y)*0.5 + s.y;

  kock(n-1,p1,s);
  printf("%.8lf %.8lf\n",s.x,s.y);
  kock(n-1,s,u);
  printf("%.8lf %.8lf\n",u.x,u.y);
  kock(n-1,u,t);
  printf("%.8lf %.8lf\n",t.x,t.y);
  kock(n-1,t,p2);
}

int main(){
  int n;
  coor st,la;

  st.x = st.y = la.y = 0;
  la.x = 100;

  scanf("%d",&n);

  printf("%.8lf %.8lf\n",st.x,st.y);
  kock(n,st,la);
  printf("%.8lf %.8lf\n",la.x,la.y);

  return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <tuple>
#include <vector>

template <class... Ts> using tuple_t = std::tuple<Ts...>;
template <class T, class U> using map_t = std::map<T, U>;
template <class T, class U> using pair_t = std::pair<T, U>;
template <class T> using vector_t = std::vector<T>;
template <class T> using set_t = std::set<T>;

int min(const vector_t<int> &nums) {
  int min_ = std::numeric_limits<int>::max();
  for (auto &i : nums)
    if (min_ > i)
      min_ = i;
  return min_;
}

int max(const vector_t<int> &nums) {
  int max_ = std::numeric_limits<int>::min();
  for (auto &i : nums)
    if (max_ < i)
      max_ = i;
  return max_;
}

int main() {
  std::string S;
  uint64_t K;
  std::cin>>S;
  std::cin>>K;
  for(char c:S){
    switch(c){
        case '1':
          if(K==1)
          {
            std::cout<<1<<std::endl;
            return 0;
          }
          K-=1;
          continue;
      default:
        std::cout<<c<<std::endl;
        return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



int N, X, Y;
int main() {
    cin >> N >> X >> Y;
    --X, --Y;
    vector<vector<int>> dist(N, vector<int>(N, -1));
    for (int s = 0; s < N; ++s) {
        queue<int> que;
        que.push(s);
        dist[s][s] = 0;
        while (!que.empty()) {
            auto v = que.front(); que.pop();
            vector<int> nvs;
            if (v > 0) nvs.push_back(v-1);
            if (v < N-1) nvs.push_back(v+1);
            if (v == X) nvs.push_back(Y);
            if (v == Y) nvs.push_back(X);
            for (auto nv : nvs) {
                if (dist[s][nv] == -1) {
                    dist[s][nv] = dist[s][v] + 1;
                    que.push(nv);
                }
            }
        }
    }
    vector<int> res(N, 0);
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) res[dist[i][j]]++;
    }
    for (int d = 1; d < N; ++d) cout << res[d] << endl;
}





Measured memory_bytes: 16000
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define mod 1000000007
ll pw(int n){
	ll p = 1;
	rep(i, n) {
		p *= (i + 1); p %= mod;
	}
	return p;
}
int main() {
	int n, m;ll ans = 0; cin >> n >> m;
	if (abs(n - m) > 1) cout << 0 << endl;
	else if(m == n) {
		cout << (pw(m) * pw(n) * 2) % mod << endl;
	}
	else {
		cout << (pw(m) * pw(n)) % mod << endl;
	}
}

Measured memory_bytes: 256