akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int a, b, c, x , y, min;
    min = 0;
    cin>>a>>b>>c>>x>>y;
    if(x>y){
        if(2*c<a+b){
            min = min+2*c*y;
            if(2*c<a){
                min = min + 2*c*(x-y);
            }
            else{
                min = min + a*(x-y);
            }
        }
        else{
            min = a*x+b*y;
        }
    }
    else{
        if(2*c<a+b){
            min = min+2*c*x;
            if(2*c<b){
                min = min + 2*c*(y-x);
            }
            else{
                min = min + b*(y-x);
            }
        }
        else{
            min = a*x+b*y;
        }
    }
    cout<<min;
}

Measured memory_bytes: 256
n,x = map(int, input().split())
a = list(map(int, input().split()))
now = min(a[0],x)
ans = max(0,a[0]-x)
for i in a[1:]:
  SUM = now + i
  res = SUM - x
  if res > 0:
    ans += res
    now = i - res
  else:
    now = i
print(ans)
    

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





signed main() {
   
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  string nish;
  cin>>nish;
  int maxi=0;
  int flag=0;

  int total=(nish[0]=='R')+(nish[1]=='R')+(nish[2]=='R');
  if(nish=="RRR")
    cout<<"3"<<endl;
  else if(nish[0]=='R'&& nish[1]=='R' || nish[1]=='R' && nish[2]=='R')
    cout<<"2"<<endl;
  else
  {
    if(total>0)
      cout<<"1"<<endl;
    else
      cout<<"0"<<endl;
  }

  return 0;
  }

Measured memory_bytes: 3620
#include <stdio.h>

#define ll long long

int main()
{
  int n, i, b0=0, b1=0, b2=0;
  ll a;

  scanf("%d", &n);
  for (i=0; i<n; i++){
    scanf("%lld", &a);
    if (a % 4 == 0) b2++;
    else if (a % 2 == 0) b1++;
    else b0++;
  }

  if (b1 == 0){
    if (b0 < b2+2) printf("Yes\n");
    else printf("No\n");
  } else{
    if (b0 < b2+1) printf("Yes\n");
    else printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct P {int x,y,z;};

int main() {
  int a,d,n,m,k;
  cin >> n >> a >> d >> m;
  P p[m];
  for(int i=0; i<m; i++) cin >> p[i].x >> p[i].y >> p[i].z;
  cin >> k;
  for(int i=m-1; i>=0; i--) {
    if(!p[i].x&&p[i].y<=k&&k<=p[i].z) k=p[i].z+p[i].y-k;
  }
  int ans=a+d*(k-1);
  for(int i=0; i<m; i++) {
    if(k<p[i].y||p[i].z<k) continue;
    if(!p[i].x) k=p[i].z+p[i].y-k;
    else if(p[i].x==1) ans++;
    else ans/=2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5236
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 305;
const int M = 305;

int n, m;
int a[N][M];

bool test(int p) {
  int cnt[M], first[N];
  bool select[N];
  fill(first + 1, first + n + 1, 1);
  fill(select + 1, select + m + 1, true);

  bool flag = true;
  while (flag) {
    fill(cnt + 1, cnt + m + 1, 0);
    for (int i = 1; i <= n; i++) {
      cnt[a[i][first[i]]]++;
    }

    flag = false;
    for (int i = 1; i <= m; i++) {
      if (cnt[i] > p) {
//        printf("%d [%d]\n", i, cnt[i]);
        select[i] = false;
        flag = true;
      }
    }
    for (int i = 1; i <= n; i++) {
      while (first[i] <= m && !select[a[i][first[i]]]) {
        first[i]++;
      }
      if (first[i] > m) return false;
    }
  }
  return true;
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) scanf("%d", a[i] + j);
  }

  int lb = 1, ub = n;
  while (lb < ub) {
    int mid = (lb + ub) / 2;
    if (test(mid)) ub = mid;
    else lb = mid + 1;
  }
  printf("%d", lb);

  return 0;
}


Measured memory_bytes: 512
// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define Nayon ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b
#define v_sum(a)         accumulate(a.begin(),a.end(),0)
#define v_max(a)         *max_element(a.begin(),a.end())
#define v_min(a)         *min_element(a.begin(),a.end())
#define v_uni(a)         a.erase(unique(a.begin(),a.end()),a.end())

using namespace std;




int main()
{
	string s;
	cin>>s;
		if(s[s.size()-1]=='s'){
		cout<<s<<"es"<<nl;
	}
	else{
		cout<<s<<"s"<<nl;
	}
}


Measured memory_bytes: 3556
use std::io::stdin;
use std::collections::HashMap;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    let mut m: HashMap<char, usize> = HashMap::new();
    for a in s.trim().chars() {
        if !m.contains_key(&a) {
            m.insert(a, 1);
        } else if let Some(x) = m.get_mut(&a) {
            *x += 1
        }
    }
    if m.keys().count() == 2 && m.iter().all(|(_, &a)| a == 2) {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int cnt, n, s;
void bt(int deep, int sum, int use);

int main(){
	while(cin >>n >>s){
		cnt = 0;
		if(n == 0 && s == 0) break;
		bt(0, 0, -1);
		cout <<cnt <<endl;
	}
	return 0;
}

void bt(int deep, int sum, int use){
	if(n <= deep){
		if(sum == s){
			cnt++;
		}
	} else{
		//cout <<"deep = " <<deep <<" " <<"sum = " <<sum <<" " <<"use = " <<use <<endl;
		for(int i = use + 1; i <= 9; i++){
			bt(deep + 1, sum + i, i);
		}
	}
}

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

int main(){
    
    string Sa,Sb,Sc;
    cin >> Sa >> Sb >> Sc;
    int a=0,b=0,c=0;
    char next='a';

    while(1){
        if(next=='a'){
            if(a==Sa.size()){
                cout << 'A' << endl;
                break;
            }
            else{
                next=Sa.at(a);
                a++;
            }
        }
        if(next=='b'){
            if(b==Sb.size()){
                cout << 'B' << endl;
                break;
            }
            else{
                next=Sb.at(b);
                b++;
            }
        }
        if(next=='c'){
            if(c==Sc.size()){
                cout << 'C' << endl;
                break;
            }
            else{
                next=Sc.at(c);
                c++;
            }
        }
    }
}

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

int main(void){

  int s,x[1200000],i,j,flag=0;
  scanf("%d",&s);
  
  for(i=0;i<1200000;i++){
    x[i]=s;     //iの時の値を入れる
   for(j=0;j<i;j++){
      if(x[j]==x[i]){
        flag=1;
      }
    }
    if(flag==1)
      break;
  
    if(s%2==0)
      s=s/2;
    else
      s=3*s+1;   //ここででてきたsはi++用
  
  }
     printf("%d",i+1);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())

int main() {
    int n;
    cin >> n;
    int S[n];
    Rep(i, n) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    int T[q];
    Rep(i, q) {
        cin >> T[i];
    }
    int ans = 0;
    Rep(i, q) {
        Rep(j, n) {
            if (S[j] == T[i]) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>



using namespace std;

int main()
{
	
	int N;
	cin >> N;
	
	if (N % 2) {
		N *= 2;
	}
	for (int i = N; i < i + 1;) {
		
			if (!(N % i)) {
				cout << i;
				break;
			}
			i++;
		
	}
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
int D;
int c[27], s[400][27];
int L[27];
int last[27];
long long ANS = 0;
long long ans = 0;
int main(){
    scanf("%d",&D);
    for (int i = 1; i <= 26; i++) scanf("%d",&c[i]);
    for (int i = 1; i <= D; i++){
        for (int j = 1; j <= 26; j++)
            scanf("%d",&s[i][j]);
    }
    for (int i = 1; i <= D; i++){
        int b1 = -1;
        long long ok = 0;
        for (int t = 1; t <= 26; t++){
            for (int x = 1; x <= 26; x++){
                for (int y = 1; y <= 26; y++){
                    ans = ANS;
                    for (int j = 1; j <= 26; j++){
                        last[j] = L[j];
                    }

                        ans += (s[i][t]+c[i]);
                        last[t] = i;

                        for (int j = 1; j <= 26; j++){
                            ans -= c[j]*(i-last[j]);
                        }

                    if (i != D){
                        ans += (s[i+1][x]+c[x]);
                        last[x] = i+1;
                        for (int j = 1; j <= 26; j++){
                            ans -= c[j]*(i+1-last[j]);
                        }
                    }

                    if (i < D-1){
                        ans += (s[i+2][y]+c[y]);
                        last[y] = i+2;
                        for (int j = 1; j <= 26; j++){
                            ans -= c[j]*(i+2-last[j]);
                        }
                    }

                    if (b1 == -1 || ans > ok){
                        b1 = t;
                        ok = ans;
                    }
                }
            }
            //printf("for %d: %lld\n",t,ans);
        }
        ANS += s[i][b1];
        L[b1] = i;
        for (int j = 1; j <= 26; j++){
            ANS -= c[j]*(i-L[j]);
        }
        printf("%d\n",b1);
        //printf("score %lld\n",ANS);
    }
}


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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  string n;
  cin >> n;
  for (auto ch : n) {
    if (ch == '1') {
      cout << '9';
    } else if (ch == '9') {
      cout << '1';
    } else {
      cout << ch;
    }
  }
  cout << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,j,h,w;
	while(1)	{
		scanf("%d %d",&h,&w);
		if(h==0 && w==0)	break;
		for(i=0;i<h;i++)	{
			for(j=0;j<w;j++)	{
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
#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 all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
class UnionFind {
private:
  vector <long long> par; // 親ノード
  vector <long long> rank; // 各ノードのランク
  long long n; // 全体のサイズ
public:
  // コンストラクタ
  UnionFind(long long sz_) : n(sz_), par(sz_), rank(sz_, 1) {
	for (long long i = 0; i < sz_; i++) {
		par[i] = i;
	  }
  }

  // メンバ関数
long long root(long long x) {
  if (par[x] == x) {
	  return x;
	}
  else {
	  par[x] = root(par[x]);
	  return par[x];
	}
}

void unite(long long x, long long y) {
  x = root(x);
  y = root(y);
  if (x == y) {
	  return;
	}
  if (rank[x] < rank[y]) {
	  swap(x, y);
	}
  rank[x] += rank[y];
  par[y]   = x;
}

bool isSame(long long x, long long y) {
  return root(x) == root(y);
}

long long siz(long long x) {
  return rank[root(x)];
}
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector <int> fcnt(n, 0), bcnt(n, 0);
  UnionFind uf(n);
  REP(i, m) {
	int a, b;
	cin >> a >> b;
	a--; b--;
	fcnt[a]++; fcnt[b]++;
	uf.unite(a, b);
  }
  REP(i, k) {
	int c, d;
	cin >> c >> d;
	c--; d--;
	if (uf.isSame(c, d)) {
		bcnt[c]++; bcnt[d]++;
	  }
  }
  REP(i, n) {
	cout << uf.siz(i) - fcnt[i] - bcnt[i] - 1 << (i == n - 1 ? "\n" : " ");
  }
  return 0;
}


Measured memory_bytes: 3200
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#define int long long

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << ": " << arg1 << " |";
	__f(comma + 1, args...);
}

int GCD(int a, int b) {
	for (;b; a %= b, swap(a, b));
	return a;
}
signed main() {
	int A, B, ans =0;
	cin >> A >> B;
	

	int G = GCD(A, B);
	for (int i = 2; i*i <= G; i++)
	{
		if (G % i == 0) {
			//cout << i << " ";
			ans++;
			while (G % i == 0) {
				G /= i;
			}
		}
	}
	if (G > 1) ans++;
	cout << ++ans;
	
}

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

int main(){
  int n,min,max;
  cin >> n;
  vector<int>x(n);
  for(int i=0;i<n;i++)
    cin >> x.at(i);
  sort(x.begin(),x.end());
  min = x.at(0);
  max = x.at(n-1);
  vector<int>dis(max-min+1,1e4);
  for(int i=min;i<max+1;i++){
    int sum=0;
    for(int j=0;j<n;j++)
        sum+=pow(x.at(j)-i,2);
    dis.at(i-min)=sum;
  }
  sort(dis.begin(),dis.end());
  cout << dis.at(0) << endl;
}

Measured memory_bytes: 256
// 必要なパッケージをインポートします。
import java.util.Scanner;
public class Main {
	static int[][]A;
	static int[]solve;
	static int N;
	static int M;
	static int ans = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main.N = sc.nextInt();
		Main.M = sc.nextInt();
		Main.A = new int[N+1][N+1];
		Main.solve = new int[N+1];
		for(int i = 0;i<M;i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			A[a][b]=1;
			A[b][a]=1;
		}
		dps(1);
		System.out.println(ans);
	}
	static void dps(int i) {
		solve[i]=1;
		for(int j=1;j<N+1;j++) {
			if(solve[j]!=1)break;
			if(j==N) {
				ans++;
			}
		}
		for(int j = 2; j<N+1;j++) {
			if(A[i][j]==1 && solve[j]==0) {
				dps(j);
				solve[j]= 0;
			}
		}
		return;
	}
}


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

#define SQR(x) ((x)*(x))

typedef long long ll;
typedef pair<int,int> ii;

int parent[100010];
vector<int>nodes[100010];

void maketree(int x){
    for(auto v:nodes[x]){
        if(v==parent[x])continue;
        parent[v]=x;
        maketree(v);
    }
}

int getval(int x){
    int ans=0;
    for(auto v:nodes[x]){
        if(v==parent[x])continue;
        ans=ans^(getval(v)+1);
    }
    return ans;
}


int main() {
   // freopen("hi.txt","r",stdin);
    int n;
    scanf("%d",&n);
    parent[1]=-1;
    int a,b;
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&a,&b);
        nodes[a].push_back(b);
        nodes[b].push_back(a);
    }
    maketree(1);
    if(getval(1)==0){
        printf("Bob");
    }
    else{
        printf("Alice");
    }
}


Measured memory_bytes: 10752
mod = int(1e9+7)

fac = [1]

def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def subtract(a, b):
    return (a - b) % mod

def mul(a, b):
    return (a * b) % mod

def my_pow(a, b):
    if b == 0:
        return 1
    if b % 2 == 1:
        return mul(a, my_pow(a, b-1))
    else:
        temp = my_pow(a, b/2)
        return temp * temp
    
def my_inv(a):
    return my_pow(a, mod-2)

def nCk(n, k, fac):
    if k > n:
        return 0
    #print(fac[n])
    #print(my_inv(mul(fac[n-k], fac[k])))
    return mul(fac[n], my_inv(mul(fac[n-k], fac[k])))

def main():
    n, k = [int(x) for x in raw_input().split()]
    
    a = [int(x) for x in raw_input().split()]
    
    fac = [0] * (n+5)
    
    #print(fac)
    
    fac[0] = 1
    
    for i in range(1, n+5):
        fac[i] = mul(fac[i-1], i)
    
    a.sort()
    
    ans = 0
    
    for i in range(n-1):
        #print(a[i])
        diff = subtract(a[i+1], a[i])
        ways = nCk(n, k, fac)
        #print(ways)
        ways = subtract(ways, nCk(i+1, k, fac))
        ways = subtract(ways, nCk(n-i-1, k, fac))
        ans = add(ans, mul(diff, ways))
    
    print(ans)
    

main()

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

#define ll long long
const int mod=1e9+7;

ll K(ll x,ll y=mod-2){
    ll t=1;
    for (;y;y>>=1,x=x*x%mod)
        if (y&1) t=t*x%mod;
    return t;
}

int n, l, m, a[26000], dp[26000][404];

void predp(){
    for (int i=1;i<l;++i) dp[0][i]=1;
    dp[0][l]=1;
    for (int i=1;i<=n;++i){
        static int g[404];
        memset(g,0,sizeof g);
        for (int j=1;j<l;++j)
            g[j]=(g[j-1]+dp[i-1][j])%mod;
        for (int j=1;j<l;++j){
            dp[i][j]=g[j];
            if (j!=l-1) dp[i][j]=(dp[i][j]+dp[i-1][j+1]*(ll)(l-j))%mod;
        }
        dp[i][l]=g[l-1];
    }
}

ll all(){
    return (ll)(n-m+1)*K(l,n-m)%mod;
}

void fuck(){
    int ans=0, lc=0, rc=0;
    {
        set<int>S;
        while (!S.count(a[lc+1])) S.insert(a[++lc]);
    }
    {
        set<int>S;
        while (!S.count(a[m-rc])) S.insert(a[m-(rc++)]);
    }
    for (int i=0;i+m<=n;++i)
        ans=(ans+(ll)dp[i][lc]*dp[n-m-i][rc])%mod;
    cout<<(all()-ans+mod)%mod<<endl;
}

int main(){
    cin>>n>>l>>m;
    for (int i=1;i<=m;++i) cin>>a[i];
    predp();
    {
        map<int,int>las; int mx=0;
        for (int i=1;i<=m;++i){
            mx=max(mx,las[a[i]]);
            las[a[i]]=i;
            if (i-mx>=l){
                cout<<all()<<endl;
                return 0;
            }
        }
    }
    {
        set<int>S;
        for (int i=1;i<=m;++i)
            S.insert(a[i]);
        if (S.size()!=m){
            fuck(); return 0;
        }
    }
    {
        ll ans=0, jc=1;
        for (int i=1;i<=l-m;++i) jc=jc*i%mod;
        for (int i=0;i+m<=n;++i){
            int le=i, ri=n-m-i;
            ans=(ans+(ll)dp[le][m]*dp[ri][m])%mod;
            //cout<<" "<<(ll)dp[le][m]*dp[ri][m]%mod<<endl;
            for (int j=1;j<l-m;++j){
                int j2=l-m-j;
                if (j>le||j2>ri) continue;
                ans=(ans-(ll)dp[le-j][l]*dp[ri-j2][j2+m]%mod*jc%mod+mod)%mod;
                //cout<<"  "<<(ll)dp[le-j][l]*dp[ri-j2][j2+m]%mod*jc%mod<<endl;
            }
        }
        cout<<(all()-ans+mod)%mod<<endl;
    }
}

Measured memory_bytes: 41344
#include <iostream>
#include <string>
#include <set>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::set<std::string> s;
    while (n--) {
        std::string in;
        std::cin >> in;
        s.insert(in);
    }

    std::cout << s.size() << std::endl;

    return 0;
}


Measured memory_bytes: 19220
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cmath>
#include <iomanip>
#include <cstdio>
using namespace std;

typedef long long ll;

const int maxn = 1e5+5;
int N,M;
int fa[maxn];
int size[maxn];
ll ans[maxn];
int l[maxn];
int r[maxn];

int find(int x)
{
    return fa[x] == x ? x : fa[x]= find(fa[x]); //这里一开始写错了，写成了x = find。。
}

void join(int a, int b)
{
    a = find(a), b = find(b);
    if(a != b)
    {
        size[a] += size[b];
        size[b] = 0;
       fa[b] = a;
    }
}
int main(){
	cin>>N>>M;

	for(int i=0;i<maxn;i++)
		fa[i] = i,size[i]=1;
	 memset(ans, 0, sizeof(ans));
		
	for(int i=1;i<=M;i++)
		scanf("%d%d", &l[i], &r[i]);
	ll cnt = N;
	ans[M+1] = cnt*(cnt-1)/2;
	for(int i = M;i>=2;i--){
		int x = find(l[i]);
		int y = find(r[i]);
		if(x!=y){
			ans[i] = ans[i+1]-size[x]*size[y];
			join(l[i],r[i]);
		}
		else 
			ans[i] = ans[i+1];
	}
	
	for(int i=2;i<=M+1;i++)
		  printf("%lld\n", ans[i]);
	
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,b,c,d;cin>>a>>b>>c>>d;
	ll t;cin>>t;
	if((abs(c-a)<=(b-d)*t)&&(abs(c-a)<=(b+d)*t))cout<<"YES"<<"\n";
	
	else cout<<"NO"<<'\n'; 
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

LL mul(LL a, LL b) { return a * b; }

int main() {
  map<map<char, int>, LL> m;
  int N; cin >> N;
  for (int i = 0; i < N; ++i) {
    string S; cin >> S;
    map<char, int> k;
    for (char c : S){
      k[c]++;
    }
    m[k]++;
  }

  LL cnt = 0;
  for (auto [k, c] : m) {
    LL tmp = mul(c, c-1);
    tmp = tmp/2LL;
    cnt += tmp;
  }
  cout << cnt << endl;
}


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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    int A, P;
    cin >> A >> P;
    int ans = 0;

    ans = (A * 3 + P * 1) / 2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)
import numpy as np



def main():
    N, M, X = map(int, input().split())
    C = []
    A = []
    INF = 10 ** 10
    ans = INF
    for i in range(N):
        lists = [int(c) for c in input().split()]
        ci = lists[0]
        ai = lists[1:]
        C.append(ci)
        A.append(ai)


    for i in range(1 << N):
        ability = np.zeros((M, ))
        cost = 0
        for j in range(N):
            if (i >> j) & 1:
                ability += np.array(A[j])
                cost += C[j]
        if sum(ability >= X) == M:
            ans = min(ans, cost)

    if ans == INF:
        print(-1)
    else:
        print(ans)
    

    
    



if __name__ == '__main__':
    main()


Measured memory_bytes: 27260
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

struct T {
    int s, t, c;
};

int n, c;

int main() {
    cin >> n >> c;

    V<T> v(n);
    REP(i, n) {
        int s, t, c; cin >> s >> t >> c;
        v[i] = {s, t, c};
    }

    sort(ALL(v), [](const T& a, const T& b) {
        if (a.t == b.t) {
            return a.s < b.s;
        }
        return a.t < b.t;
    });

    V<Pii> res(30, {-1, -1});
    for (auto x: v) {
        int maxi = -1e9, maxidx = -1;
        REP(i, 30) {
            if ((res[i].second == x.c && res[i].first > x.s) ||
                    (res[i].second != x.c && res[i].first >= x.s)) {
                continue;
            }
            if (maxi < res[i].first) {
                maxi = res[i].first;
                maxidx = i;
            }
        }
        res[maxidx] = {x.t, x.c};
    }

    int cnt = 0;
    REP(i, 30) {
        if (res[i] != make_pair(-1, -1)) cnt++;
    }
    cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    ll a[n];
    REP(i,n)cin >> a[i];
    ll sum=0;
    ll answer = 0;
    REP(i,n){
        if(i%2 == 0){
            if(a[i] + sum <= 0){
                answer += llabs(sum+a[i])+1;
                sum = 1;
            }
            else{
                sum += a[i];
            }
        }
        else{
            if(a[i] + sum >= 0){
                answer += llabs(sum + a[i]) + 1;
                sum = -1;
            }
            else{
                sum += a[i];
            }
        }
    }

    ll answer2 = answer;
    answer = 0;
    sum = 0;
    REP(i,n){
        if(i%2 == 1){
            if(a[i] + sum <= 0){
                answer += llabs(sum+a[i])+1;
                sum = 1;
            }
            else{
                sum += a[i];
            }
        }
        else{
            if(a[i] + sum >= 0){
                answer += llabs(sum + a[i]) + 1;
                sum = -1;
            }
            else{
                sum += a[i];
            }
        }
    }
    answer = min(answer,answer2);
    cout << answer << endl;
    return 0;
}

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

int n,m;
int main(){
  cin >> n >> m;
  vector<vector<int> > v(n);
  for(int i=0 ; i<m ; i++){
    int x,y;  cin >> x >>y;
    --x;  --y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  bool ok = false;
  for(int i=0 ; i<v[0].size() ; i++){
    int u = v[0][i];
    for(int j=0 ; j<v[u].size() ; j++)
    if(v[u][j] == n-1){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 12016
weeks = ["SUN","MON","TUE","WED","THU","FRI","SAT"]

ss = STDIN.gets.strip

i = 0
index = 0
weeks.each do |w|
  if ss == w
    index = i
    break
  end
  i += 1
end

if index == 0
  puts 7
else
  puts 7-index
end

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

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

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll M, K; std::cin >> M >> K;
  if ( M == 0 ) {
    if ( K != 0 ) std::cout << -1 << std::endl;
    else std::cout << "0 0" << std::endl;
    return 0;
  }
  else if ( M == 1 ) {
    if ( K != 0 ) std::cout << -1 << std::endl;
    else std::cout << "0 0 1 1" << std::endl;
    return 0;
  }
  else {
    ll nmax = std::pow(2LL,M);  nmax--;
    if ( K > nmax ) std::cout << -1 << std::endl;
    else {
      rep(i,nmax+1) if ( (nmax-i) != K ) std::cout << nmax-i << " ";
      std::cout << K << " ";
      rep(i,nmax+1) if ( i != K ) std::cout << i << " ";
      std::cout << K << std::endl;
    }
  }
  return 0;
}



Measured memory_bytes: 4120
package main

import (
	"fmt"
)

func main() {
	var l, r, d int
	fmt.Scan(&l, &r, &d)
	var cnt int
	for i := l; i <= r; i++ {
		if i%d == 0 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

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

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

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


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

using namespace std;

int main(void) {
	long long X,Y;
	cin >> X >> Y;

	long long num = X;
	long long len = 0;
	while (num < Y+1) {
		++len;
		num *= 2;
	}
	cout << len << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
	int k,s;
	cin >> k >> s;
	int x,y,z;
	long long count=0;
	for(x=0;x<=k;x++)
		for(y=0;y<=k;y++)
		{
			z=s-(x+y);
			if(0<=z and z<=k)count++;
		}
	cout << count << endl;
}

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

using namespace std;

#define M_MAX 12
#define N_MAX 100000
#define INFTY 1 << 29

int main(){
        int n,m=12;
        int coin[13]={0,1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
        int T[N_MAX + 1];

        cin >> n;

        // 最大値で初期化
        for(int i = 0; i < N_MAX; ++i) {
                T[i] = INFTY;
        }

        T[0] = 0;
        for(int i = 1; i <= m; ++i) {
                for(int j = 0; j + coin[i] <= n; ++j) {
                        T[j + coin[i]] = min(T[j + coin[i]],T[j] + 1);
                }
        }
        cout << T[n] << endl;
        return 0;
}


Measured memory_bytes: 640
function Main(input) {
  var nums = input.split(' ');
  var a = Math.floor(nums[0]);
  var b = Math.floor(nums[1]);
  
  function lcm(a, b) {
    var g = (n, m) => (m ? g(m, n % m) : n);
    return (a * b) / g(a, b);
  }
  
  console.log(lcm(a, b));
}
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
n = int(input())
x = "abcdefghijklmnopqrstuvwxyz"
s = ""
while True:
  if n%26 == 0:
    s = "z"+s
    n -= 26
    n =n//26
  else:
    s = x[n%26-1]+s
    n = n//26
  if n==0:
    break
print(s)

Measured memory_bytes: 9172
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
      int A =sc.nextInt();
      int B =sc.nextInt();
      int C =sc.nextInt();
      
      if(A<=B+C){
      System.out.print((B+C)-A);
      }
      else{
      System.out.print(0);
      }
    }
}

Measured memory_bytes: 20820
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if (c < b) {
			int tmp = b;
			b = c;
			c = tmp;
		}
		
		int ans = Math.max(0, c - a - b);
		System.out.println(ans);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 20948
#include <stdio.h>
#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a


int main(void){
  long long n, i, a, s = 0, M = -1000000, m = 1000000;
  scanf("%lld",&n);
  for(i = 0;i < n;i++){
    scanf("%lld",&a);
    s += a;
    M = max(M,a);
    m = min(m,a);
  }
  printf("%lld %lld %lld\n",m,M,s);
  return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  i64 n;
  cin >> n;
  vector<i64> a(n);
  for(int i = 0;i < n;i++) cin >> a[i];
  if(n % 3 == 0) {
    vector<i64> b = a;
    sort(all(b));
    b.erase(unique(all(b)), b.end());
    map<i64, i64> mp;
    for(int i = 0;i < n;i++) mp[a[i]]++;
    i64 s = n / 3;
    if(b.size() == 1) {
      if(b[0] == 0) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl; 
      }
    }
    else if(b.size() == 2) {
      i64 aa = min(mp.begin()->second, (++mp.begin())->second);
      i64 bb = max(mp.begin()->second, (++mp.begin())->second);
      i64 c = 0;
      if(mp.begin()->second == aa) {
        c = mp.begin()->first;
      }
      else {
        c = (++mp.begin())->first;
      }
      if(aa == s && bb == s * 2 && c == 0) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl; 
      }
    }
    else if(b.size() == 3) {
      auto i1 = mp.begin();
      auto i2 = ++mp.begin();
      auto i3 = ++(++mp.begin());
      if(i1->second == s && i2->second == s && i3->second == s && (b[0] ^ b[1] ^ b[2]) == 0) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    else {
        cout << "No" << endl;
        return 0;
    }
  }
  else {
    vector<i64> b = a;
    sort(all(b));
    b.erase(unique(all(b)), b.end());
    map<i64, i64> mp;
    for(int i = 0;i < n;i++) mp[a[i]]++;
    if(b.size() == 2) {
      i64 aa = min(mp.begin()->second, (++mp.begin())->second);
      i64 bb = max(mp.begin()->second, (++mp.begin())->second);
      i64 c = 0;
      if(mp.begin()->second == aa) {
        c = mp.begin()->first;
      }
      else {
        c = (++mp.begin())->first;
      }
      if(c == 0 && bb - aa == 1) {
        cout << "Yes" << endl;
        return 0;
      }
    }
    for(int i = 0;i < n;i++) {
      if(a[i] == 0) {

      }
      else {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
    return 0;
  }
}


Measured memory_bytes: 6272
#include<iostream>
using namespace std;
int main(void){
    long long n,a[10000],min=1000000,max=-1000000,sum=0;
     
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]<min){min=a[i];}
    if(a[i]>max){max=a[i];}
    sum=a[i]+sum;
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3192
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

std::set<int> parse(
    const std::string &s, size_t &i,
    const std::map<char, std::set<int>> &sets, const std::set<int> &univ,
    const std::vector<std::string> &ops={"uids"}, size_t preced=0) {

  if (preced == ops.size()) {
    if (s[i] == '(') {
      std::set<int> res=parse(s, ++i, sets, univ, ops, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    if (s[i] == 'c') {
      std::set<int> cmpl=parse(s, ++i, sets, univ, ops, preced);
      std::set<int> res;
      for (int x: univ)
        if (!cmpl.count(x)) res.insert(x);
      return res;
    }
    if (isupper(s[i])) {
      return sets.at(s[i++]);
    }
    assert(false);
  }

  std::set<int> lhs=parse(s, i, sets, univ, ops, preced+1);
  while (i < s.length()) {
    char op=s[i];
    if (!std::count(ops[preced].begin(), ops[preced].end(), op)) break;
    std::set<int> rhs=parse(s, ++i, sets, univ, ops, preced+1);

    if (op == 'u') {
      if (lhs.size() < rhs.size()) lhs.swap(rhs);
      for (int x: rhs)
        lhs.insert(x);
    } else if (op == 'i') {
      std::set<int> tmp;
      if (lhs.size() < rhs.size()) lhs.swap(rhs);
      for (int x: rhs)
        if (lhs.count(x)) tmp.insert(x);
      lhs = std::move(tmp);
    } else if (op == 'd') {
      std::set<int> tmp;
      for (int x: lhs)
        if (!rhs.count(x)) tmp.insert(x);
      lhs = std::move(tmp);
    } else if (op == 's') {
      std::set<int> tmp;
      for (int x: lhs)
        if (!rhs.count(x)) tmp.insert(x);
      for (int x: rhs)
        if (!lhs.count(x)) tmp.insert(x);
      lhs = std::move(tmp);
    }
  }
  return lhs;
}

int testcase_ends() {
  std::map<char, std::set<int>> sets;
  std::set<int> univ;
  while (true) {
    char ch;
    size_t n;
    if (scanf(" %c %zu", &ch, &n) == EOF) return 1;
    if (ch == 'R') break;
    std::set<int> set;
    for (size_t i=0; i<n; ++i) {
      int x;
      scanf("%d", &x);
      set.emplace(x);
      univ.emplace(x);
    }
    sets[ch] = set;
  }

  char buf[1<<18];
  scanf("%s", buf);
  std::string s=std::move(buf);
  size_t i=0;
  std::set<int> res=parse(s, i, sets, univ);
  if (res.empty()) {
    printf("NULL\n");
    return 0;
  }

  for (auto it=res.cbegin(); it!=res.cend(); ++it)
    printf("%d%c", *it, std::next(it)!=res.cend()? ' ':'\n');

  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2892
from collections import defaultdict

n = int(raw_input())
d = defaultdict(int)
for _ in range(n):
    s = raw_input()
    d[s] += 1

ordered_d = sorted(d.items(), key=lambda x: x[1], reverse=True)
res = []
last_cnt = 0
for i, (name, cnt) in enumerate(ordered_d):
    if i == 0:
        last_cnt = cnt
    if last_cnt != cnt:
        break
    res.append((name, cnt))
        
for name, _ in sorted(res, key=lambda r: r[0]):
    print name


Measured memory_bytes: 67376
n, m = map(int, input().split())
a = list()
for i in range(n) :   #1行ずつn行まで読み込みlistに格納
 a.append(list(map(int, input().split())))
b = list()
for j in range(m) :
 b.append(int(input()))
     
for i in range(n) :
 s = 0
 for j in range(m) :
   s += a[i][j] * b[j]
 print(s)


Measured memory_bytes: 5980
#include <bits/stdc++.h>
using namespace std;
long long n,x;
int main()
{
    cin>>n;
    x=n;
    if (n%2==0)
    {
        cout<<n;
        return 0 ;
    }
    n*=2;
    for (long long i=n;1;i++)
    {
        if (i%x==0&&i%n==0)
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

vector<char> station(26*2);
void init(){
    iota(station.begin(),station.begin()+26,0);
    for(int i = 0; i < 26;i++) station[i] += 'a';
    iota(station.begin()+26,station.end(),0);
    for(int i = 0; i < 26;i++) station[i+26] += 'A';
}
string solve(ll n){
    vector<int> k(n); for(auto& in:k) cin >> in;
    string s; cin >> s;
    for(int i = 0; i < s.length();i++){
        auto it = find(station.begin(),station.end(),s[i]);
        s[i] = station[((it-station.begin()) + 52*100 - k[i%n])%52];
    }
    return s;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll n;
    init();
    while(cin >> n,n){
        cout << solve(n) << endl;
    }
    return 0;
}



Measured memory_bytes: 3228
#include<stdio.h>

int fib( int);
int F[45];
int main() {
	int n,i;
	
	scanf("%d",&n);

	printf("%d\n",fib(n));

	return 0;
}
	
	
	
	int fib(int n) {
		int t;
		
	if(t=F[n]) return F[n];	
else	if(n==0 || n==1) t=1; 
	else t= fib(n-2) + fib(n-1);
F[n]=t;
return t;
			}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#include<math.h>
//#include<vector>
//#include <iostream>
//#include <algorithm>
#include <limits>
using namespace std;
#define nMAX numeric_limits<long long>::max()
int main(void){
	int N,K;
	int i,j,k;
	cin >> N;
	int a[N],b[N],c[N];
	for(i=0;i<N;i++){
		cin >> a[i]>>b[i]>>c[i];
	}
	long long dp[3][N+1];
	for(i=0;i<N+1;i++){
		dp[0][i] = nMAX;
		dp[1][i] = nMAX;
		dp[2][i] = nMAX;
	}
	dp[0][0]=a[0];
	dp[1][0] = b[0];
	dp[2][0] = c[0];
	for(i=1;i<N;i++){
		dp[0][i] = max(dp[1][i-1]+a[i],dp[2][i-1]+a[i]);
		dp[1][i] = max(dp[0][i-1]+b[i],dp[2][i-1]+b[i]);
		dp[2][i] = max(dp[1][i-1]+c[i],dp[0][i-1]+c[i]);
	}
	long long m = max(dp[0][N-1],dp[1][N-1]);
	cout << max(m,dp[2][N-1]) <<endl;
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e7+9;
int main()
{
    FASTINOUT;
     ll x,k,s;
     cin>>x>>k>>s;
     for (int i=0;i<k;i++)
         cout<<s<<" ";
     for (int i=k;i<x;i++)
         cout<<(s==1e9?s-1:s+1)<<" ";
    /*int x;
    cin>>x;
    pair<ll,ll>p[x];
    for (int i=0; i<x; i++)
        cin>>p[i].first>>p[i].second;
    sort(p,p+x);
    int ans=0;
    ll o=p[0].first+p[0].second;
    for (int i=1; i<x; i++)
    {
        if (o>p[i].first-p[i].second)
        {
            if (o>=p[i].first+p[i].second)
            {
                o=p[i].first+p[i].second;
                ans++;
                continue;
            }
            else{
            ans++;
            ++i;
            }
        }
        else
        {
            o=p[i].first+p[i].second;
        }
    }
    cout<<x-ans<<endl;*/
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a;
    for (int i = 1; i <= 5; i++) {
        cin >> a;
        if (!a) cout << i;
    }
}


Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int A = scn.nextInt(), B = scn.nextInt();
		boolean[] ans = new boolean[3];
		ans[A-1] = true;
		ans[B-1] = true;
		for(int i = 0;i < 3;i++ ) {
			if(!ans[i]) {
				System.out.println(i+1);
			}
		}

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0;
vl flag, color; vll path;
//***********//
int main() {
	ll A, B;
	cin >> N >> A >> B;
	vl X(N);
	for (i = 0; i < N; i++) {
		cin >> X[i];
	}
	for (i = 0; i < N-1; i++) {
		ll D = X[i + 1] - X[i];
		ans += min(D * A, B);
	}
	cout << ans;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  ll a[n], b[n], c[m], d[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i] >> d[i];
  }

  int ans[n];
  for (int i = 0; i < n; i++) {
    ll dist_min = 1e18;
    for (int j = 0; j < m; j++) {
      ll dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (dist < dist_min) {
        ans[i] = j + 1;
        dist_min = dist;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main {
    static long MOD = (long)(1e9+7);
    static long[][][] dp;
    static long recurse(String s, int mod, int idx, boolean isTight, int currRem) {
        if(idx==s.length()) {
            if(currRem==0)
                return 1;
            return 0;
        }
        int secIdx = isTight?1:0;
        if(dp[idx][secIdx][currRem]!=-1)
            return dp[idx][secIdx][currRem];
        int limit = 9;
        int currDig = s.charAt(idx)-'0';
        if(isTight)
            limit = currDig;
        long ans = 0;
        for(int i = 0; i<=limit; i++) {
            boolean newTight = isTight;
            if(i<limit)
                newTight = false;
            int newRem = (currRem+i)%mod;
            ans = (ans + recurse(s, mod, idx+1, newTight, newRem))%MOD;
        }
        return dp[idx][secIdx][currRem] = ans;
    }
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int rem = sc.nextInt();
        dp = new long[s.length()][2][rem];
        for(long[][] i: dp)
            for(long[] j: i)
                Arrays.fill(j, -1);
        long ans = (recurse(s, rem, 0, true, 0)+MOD-1)%MOD;
        System.out.println(ans);
    }
}

Measured memory_bytes: 58836