akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node tree_Min(Node a){
  while( a->left != NIL )
  a = a->left;
  return a;
}
Node tree_Max(Node b){
  while( b->right != NIL )
  b = b->right;
  return b;
}

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  if ( x->right != NIL ) return tree_Min(x->right);
  Node y = x->parent;
  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
    Node x;
    Node y;
  if ( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);
  if ( y->left != NIL ) x = y->left;
  else x = y->right;
  if ( x != NIL ) x->parent = y->parent;
  if ( y->parent == NIL ){
    root = x;
  } else {
    if (y == y->parent->left) y->parent->left = x;
    else y->parent->right = x;
  }
  if ( y != z ){
    z->key = y->key;
  }
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node u){
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char C[20];
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", C);
    if ( strcmp(C, "find") == 0 ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( strcmp(C, "findMin") == 0 ){
	Node minn = tree_Min(t);
	printf("%d\n", minn->key);
      } else if ( strcmp(C, "findMax") == 0 ){
	Node maxn = tree_Max(t);
	printf("%d\n", maxn->key);
      } else {
	if ( t != NIL ) printf("yes\n");
	else printf("no\n");
      }
    } else if ( C[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( strcmp(C, "print") == 0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( strcmp(C, "delete") == 0 ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}


Measured memory_bytes: 20612
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int f[101]={0};

void fact(int n){
    int sub=n;
    for(int i=2;i<=n;i++){
        while(sub%i==0){
            f[i]++;
            sub=sub/i;
        }
    }
    
    return;
}

int main(){
    
    int n;
    cin >> n;
    int a1=0,a2=0,a3=0;
    
    for(int i=1;i<=n;i++){
        fact(i);
    }
    
    for(int i=2;i<=n;i++){
        if(f[i]>=74)a3++;
    }
    
    for(int i=2;i<=n;i++){
        for(int j=2;j<=n;j++){ //5*15 3*25 1*75
            if(i!=j){
            if(f[i]>=4&&f[j]>=14)a1++;
            if(f[i]>=14&&f[j]>=4)a1++;
            if(f[i]>=2&&f[j]>=24)a1++;
            if(f[i]>=24&&f[j]>=2)a1++;
            }
        }
    }
    
    for(int i=2;i<=n;i++){
        for(int j=2;j<=n;j++){
            for(int k=2;k<=n;k++){
                if(i!=j&&j!=k&&k!=i){
                    if(f[i]>=2&&f[j]>=4&&f[k]>=4)a2++;
                    if(f[i]>=4&&f[j]>=2&&f[k]>=4)a2++;
                    if(f[i]>=4&&f[j]>=4&&f[k]>=2)a2++;
                }
            }
        }
    }

    a1=a1/2;a2=a2/6;
    
    cout << a1+a2+a3<<endl;
    
    
    return 0;
}

Measured memory_bytes: 256
MOD=10**9+7
N=int(input())
A=list(map(int,input().split()))
ans=0
for j in range(60):
    k=2**j
    count=0
    for i in range(N):
        if(A[i]&k):
            ans=(ans+k*(i-count))%MOD
            count+=1
        else:
            ans=(ans+k*count)%MOD
print(ans)

Measured memory_bytes: 122808
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();

    if(str.equals("a")||str.equals("e")||str.equals("i")||str.equals("o")||str.equals("u")){
      System.out.println("vowel");
    }else{
      System.out.println("consonant");
    }
  }
}

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

using namespace std;
int cnt[5];

int main()
{
    int n;
    string s,t,Ans;  cin >> n >> s >> t;
    for(int i = 0;i<n;i++){
        Ans+=s[i];
        Ans+=t[i];
    }
    cout << Ans;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]

AC_num = str(S.count("AC"))
WA_num = str(S.count("WA"))
TLE_num = str(S.count("TLE"))
RE_num = str(S.count("RE"))

print("AC " + "x " + AC_num)
print( "WA " + "x " + WA_num)
print( "TLE " + "x " + TLE_num)
print( "RE " + "x " + RE_num)

Measured memory_bytes: 82796
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int x,y;
   cin >> x >> y;
   f(i,0,x+1){
      int tot = i*2+(x-i)*4;
      if(tot == y){
         cout << "Yes\n";
         return 0;
      }
   }
   cout << "No\n";
   return 0;
} 

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    int d;
    cin>>d;
    if(d == 25)cout<<"Christmas";
    else if(d == 24)cout<<"Christmas Eve";
    else if(d == 23)cout<<"Christmas Eve Eve";
    else if(d == 22)cout<<"Christmas Eve Eve Eve";
    return 0;
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	
*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
    int n;
    cin >> n;

    while(n > 0)
    {
        int ans = n % 10;
        if(ans == 9) {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


S = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

for b in B:
    for i in range(3):
        for j in range(3):
            if S[i][j] == b:
                S[i][j] = -1

ok = False
for i in range(3):
    bi = True
    for j in range(3):
        if S[i][j] != -1:
            bi = False
    if bi: ok = True

for j in range(3):
    bi = True
    for i in range(3):
        if S[i][j] != -1:
            bi = False
    if bi: ok = True

if S[0][0] == -1 and S[1][1] == -1 and S[2][2] == -1:
    ok = True
if S[0][2] == -1 and S[1][1] == -1 and S[2][0] == -1:
    ok = True

print("Yes" if ok else "No")

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    ll a,b,c,d,e,f,g;
    cin >> a >> b >> c >> d >> e >> f >> g;
    cout << b+max((a/2)*2+(d/2)*2+(e/2)*2,((a-1)/2)*2+((d-1)/2)*2+((e-1)/2)*2+((a>0&&d>0&&e>>0)?3:0)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include<iostream>
#include <cstring>
#define N 505
using namespace std;
typedef long long ll;
int c[505];
int s[505]; 
int f[505]; 
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&c[i],&s[i],&f[i]);
    for(int i=1;i<=n;i++){
        int ans=0;
        for(int j=i;j<n;j++){
            if(ans<s[j]) 
                ans=s[j];
            if(ans%f[j]!=0)
                ans=ans+f[j]-ans%f[j];
            ans+=c[j];
        }
        printf("%d\n",ans);
    }
}



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

int main(){
    int N;
    scanf("%d",&N);
    int P[N];
    //scanf("%d",P);
    for(int i=0;i<N;i++){
        scanf("%d",&P[i]);
    }
    int count=0;
    for(int i=1;i<N-1;i++){
        if((P[i-1]<P[i])&&(P[i]<P[i+1])){
            count++;
        }else if((P[i+1]<P[i])&&(P[i]<P[i-1])){
            count++;
        }
    }
    printf("%d\n",count);


}

Measured memory_bytes: 128
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;
const ll INF = 1000100100100100100;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 410;

int n; 
ll a[MAX_N];
ll dp[MAX_N][MAX_N];
ll ruiseki[MAX_N];

void init(){
    rep(i,MAX_N){
        rep(j,MAX_N){
            dp[i][j] = INF;
        }
    }
}

ll f(int l, int r){
    if(dp[l][r] != INF) return dp[l][r];

    if(l == r) return dp[l][r] = 0;

    ll res = INF;
    for(int m=l; m<r; m++){
        res = min(res, f(l,m)+f(m+1,r));
    }
    return dp[l][r] = res + ((l == 0) ? ruiseki[r] : (ruiseki[r]-ruiseki[l-1]));
}

int main()
{
    cin >> n;
    rep(i,n) cin >> a[i];

    rep(i,n){
        if(i == 0) ruiseki[i] = a[i];
        else{
            ruiseki[i] = ruiseki[i-1]+a[i];
        }
    }

    init();

    f(0,n-1);

    /*
    rep(i,n){
        rep(j,n){
            cout << dp[i][j] << " ";
        }cout << endl;
    }
    */

    cout << dp[0][n-1] << endl;
}

Measured memory_bytes: 4972
import math
x, y = map(int, input().split())

mod = 10**9 +7
n = (x+y)//3	# 移動回数

if ((x+y)%3):
	print('0')
	exit()

x -= n
y -= n

if (x<0 or y<0):
	print('0')
	exit()

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
N = x+y
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
 
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
 
ans = cmb(x+y,x,mod)
print(ans)

Measured memory_bytes: 82244
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(M);
    vector<long> step(N+1, -1);
    step[0]=step[1]=1;
    for(int i = 0; i < M; i++){
        cin >> a[i]; step[a[i]]=0;
    }
    for(int i = 2; i <= N; i++){
        if(step[i]==-1) step[i] = (step[i-2] + step[i-1]) % 1000000007;
    }
    cout << step[N] << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<vector<int>> friends(100005);
    vector<vector<int>> blocks(100005);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        friends[a].push_back(b);
        friends[b].push_back(a);
    }
    for(int i=0;i<k;i++){
        int c,d;
        cin>>c>>d;
        c--;d--;
        blocks[c].push_back(d);
        blocks[d].push_back(c);
    }
    vector<int> ans(n,-1);
    queue<int> q;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(-1!=ans[i]) continue;
        q.push(i);        
        while(q.size()>0){
            int temp=q.front();
            ans[temp]=cnt;
            q.pop();
            for(int j=0;j<friends[temp].size();j++){
                if(-1!=ans[friends[temp][j]]) continue;
                q.push(friends[temp][j]);
            }
        }
        cnt++;
    }
    vector<int> sumvec(cnt);
    for(int i=0;i<n;i++){
        sumvec[ans[i]]++;
    }

    for(int i=0;i<n;i++){       
        int sumfriend=friends[i].size();
        int ret= sumvec[ans[i]]-sumfriend-1;        
        
        for(int j=0;j<blocks[i].size();j++){
            if(ans[i]==ans[blocks[i][j]]) ret--;
        }
        cout<<ret<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 12664
#include<bits/stdc++.h>
#define int         int64_t
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mi        map<int,int>
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,t,a[200005],ans=0;
void solve(){
    int n,k,q;
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++) a[i]=k-q;
    for(int i=0;i<q;i++){
        int j;
        cin>>j;
        a[j]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]>0) cout<<"Yes\n";
        else cout<<"No\n";
    }
}
signed main()
{
    ios
    int test=1;
    //cin>>test;
    while(test--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1408
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>

using namespace std;

vector<int> vec[100010];
int table[20][100010];
int dep[100010];

int bin;

void dfs(int num,int par,int d){
    table[0][num] = par;
    dep[num] = d;
    bin = max(bin,(int)log2(d));
    for(int i=0;i<vec[num].size();i++){
        dfs(vec[num][i],num,d+1);
    }
}

int lca(int u,int v){
   if(dep[u] > dep[v]) swap(u,v);
   for(int i=bin;i>=0;i--){
       if( ((dep[v]-dep[u])>>i) & 1) v = table[i][v];
   }
   if(u == v) return u;
   for(int i=bin;i>=0;i--){
       if(table[i][u] != table[i][v]){
           u = table[i][u];
           v = table[i][v];
       }
   }
   return table[0][u];
}

int main()
{
    int n,k,c,q,u,v;
    
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&k);
        for(int j=0;j<k;j++){
            scanf("%d",&c);
            vec[i].push_back(c);
        }
    }
    
    bin = 0;
    dfs(0,-1,0);
    for(int i=0;i<bin;i++){
        for(int j=0;j<n;j++){
            if(table[i][j] == -1) table[i+1][j] = -1;
            else table[i+1][j] = table[i][ table[i][j] ];
        }
    }
    
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d %d",&u,&v);
        printf("%d\n",lca(u,v));
    }
    
    return(0);
}



Measured memory_bytes: 20016
N = int(input())
H = list(map(int, input().split()))

dp = [float("inf")] * N
goal_index = N - 1
dp[0] = 0
for i in range(N):
	if i + 1 <= goal_index:
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i + 1] - H[i]))
	if i + 2 <= goal_index:
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i + 2] - H[i]))
		
print(dp[-1])

Measured memory_bytes: 52552
s = input().strip()

if (s == "SUN"):
    print(7)
elif (s == "MON"):
    print(6)
elif (s == "TUE"):
    print(5)
elif (s == "WED"):
    print(4)
elif (s == "THU"):
    print(3)
elif (s == "FRI"):
    print(2)
elif (s == "SAT"):
    print(1)


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

signed main(void)
{
	int n, m, ans;

	cin >> n >> m;
	ans = 0;
	for(int i = 1; i <= sqrt(m); i++)
	{
		if (m % i == 0)
		{
			if (m / n >= i)
				ans = max(ans, i);
			if (m / n >= m / i)
				ans = max(ans, (int)m / i);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int d;
	cin>>d;
	if(d==25){
		cout<<"Christmas"<<endl;
	}else{
		if(d==24){
			cout<<"Christmas Eve"<<endl;
		}else{
			if(d==23){
				cout<<"Christmas Eve Eve"<<endl;
			}else{
				if(d==22){
					cout<<"Christmas Eve Eve Eve"<<endl;
				}
			}
		}
	} 
}

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

int main() {
  int n;
  stack<int> q;
  cin >> n;
  vector<int> v(n);
  r(i,n)cin >> v[i];
  while(n){
    bool flag=true;
    for(int i = n-1; i>=0; i--){
      if(v[i]==i+1){
        q.push(v[i]);
        v.erase(v.begin()+i);
        n--;
        flag=false;
        break;
      }
    }
    if(flag)break;
  }
  if(!n){
    while(!q.empty()){
      cout<<q.top()<<endl;
      q.pop();
    }
  }
  else cout<<-1<<endl;
}


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

int main(){
  string s;

  while(cin >> s){
    for(int i = 0; i < s.size(); i++){
      int tmp = s[i] - 'A';
      tmp = (tmp - 3 + 26) % 26;
      cout << (char)(tmp + 'A');
    }
    cout << endl;
  }
}

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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   int N, K;
   cin >> N >> K;
   vector<int> h(N);
   rep(i, N) cin >> h.at(i);
   sort(h.begin(), h.end());

   int ans = 1000000000;
   rep(i, N - K + 1) {
     ans = min(ans, h.at(i + K - 1) -  h.at(i));
   }
   cout << ans << endl;
 }


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    int N;
    cin >> N;
    int px, py,pt;
    px = py = pt = 0;
    bool flag = true;
    for (int i = 0; i < N; ++i) {
        int t, x,y;
        cin >> t >> x >> y;
        int d = abs(px-x) + abs(py-y);
        if(d > t - pt || (t - pt - d) % 2  == 1) {
            flag = false;
        }
        pt = t;
        px = x; py = y;
    }
    if(flag) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int A,B,K;
int ans=0;
int i;
int answer[100]={0};
cin>>A>>B>>K;
  for(i=1;i<=B;i++)
  {
	if(A%i==0 and B%i==0)
	{
	  answer[ans]=i;
	  ans++;
    }
  }
cout<<answer[ans-K]<<endl;
return 0;
}

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

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


#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll t[2],a[2],b[2];
    cin>>t[0]>>t[1]>>a[0]>>a[1]>>b[0]>>b[1];
    for (int i = 0; i < 2; i++)
    {
        a[i]-=b[i];
        b[i]=0;
    }
    if(a[0]<0) //a[0]>0
    {
        for (int i = 0; i < 2; i++)
        {
            a[i]*=-1;
        }        
    }
    for (int i = 0; i < 2; i++)
    {
        a[i]*=t[i];
    }

    ll diff = a[0]+a[1];
    //cout<<a[0]<<"\t"<<a[1]<<"\t"<<diff<<endl;//
    
    if(a[0]+a[1]==0)
    {
        cout<<"infinity"<<endl;
    }
    else if(a[1]>=0) //sa ga hiraku ippou
    {
        cout<<0<<endl;
        //cout<<"a"<<endl;
    }
    //a[0]>0,a[1]<0
    else if(a[0]+a[1]>0)
    {
        cout<<0<<endl;
        //cout<<"b"<<endl;
    }
    else
    {
        ll ans=(a[0]/(-diff))*2;
        if(a[0]%(-diff)!=0) ans++;
        cout<<ans<<endl;
    }
    
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int a[4];
	for (int i = 0; i < 4; ++i)
	{
		cin>>a[i];
	}
	sort(a,a+4);
	if (a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9)
	{
		cout<<"YES\n";
	}
	else
	{
		cout<<"NO\n";
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
l = sorted(list(map(int, input().split())))

a = 0
        
for i in range(n-2):
    for j in range(i+1, n-1):
        for k in range(j+1, n):
            if l[k] < l[i] + l[j] and l[i] < l[j] and l[j] < l[k]:
                a += 1

print(a)


Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

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


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}


int main(){
    int n;
    ll ans = 0;
    cin >> n;
    vector<ll>a(n);
    vector<ll>b(n-1);
    
    rep(i,n) cin >> a[i];

    reverse(all(a));

    for(int i = 0; i <= n-2; i++){
        if(i == 0) b[i] = a[0];
        else{
            b[i] = b[i-1]+ a[i];
            b[i] %= mod;
        }
    }
    reverse(all(a));
    reverse(all(b));

    for(int i = 0; i < n-1; i++){
        ll ad=(a[i]*b[i])%mod;
        ans += ad;
        ans %= mod;
    }

    cout << ans%mod << endl;

    return 0;
}


Measured memory_bytes: 6420
// inputに入力データ全体が入る
function Main(input) {
    input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);
    var half = a / 2;
    var roundHalf = Math.round(half);
    var total = 0;
	//出力
  if(parseInt(half, 10) === half){
   	total = (1 + a) * half;
  }else{
    total = (1 + a) * (roundHalf - 1);
    total += roundHalf;
  }
 console.log(total);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int N; cin>>N;
  vector<string> S(N);
  char ed; bool ans=false;
  string w; int C;
  for(int i=0;i<N;i++){
    cin>>w;
    C=w.size();
    if(i!=0){
      for(int j=0;j<i;j++){
        if(w==S[j]){
          ans=true;
        }
      }
      if(ed!=w[0]){
        ans=true;
      }
    }
    ed=w[C-1];
    S[i]=w;
    if(ans)
      break;
  }
  if(ans)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

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

using namespace std;

constexpr int64_t one = 1;

int main() {
  int64_t N, K;
  cin >> N >> K;
  vector<int64_t> nums(N);
  for (int64_t n = 0; n < N; ++n) {
    cin >> nums[n];
  }
  
  vector<vector<int64_t>> dp(2, vector<int64_t>(42, -1));
  dp[0][0] = 0;
  for (int d = 0; d <= 40; ++d) {
    int64_t digit = 40 - d;
    int64_t mask = one << digit;
    int64_t ones = 0, zeros = 0;
    for (int64_t n = 0; n < N; ++n) {
      if (nums[n] & mask) {
        ++ones;
      } else {
        ++zeros;
      }
    }
    if (K & mask) {
      dp[0][d+1] = dp[0][d] + zeros * mask;
      dp[1][d+1] = dp[0][d] + ones * mask;
      if (dp[1][d] != -1) {
        dp[1][d+1] = max(dp[1][d+1], 
                         max(dp[1][d] + ones * mask, dp[1][d] + zeros * mask));
      }
    } else {
      dp[0][d+1] = dp[0][d] + ones * mask;
      if (dp[1][d] != -1) {
        dp[1][d+1] = dp[1][d] + max(ones * mask, zeros * mask);
      }
    }
  }
  cout << max(dp[0][41], dp[1][41]) << endl;

  return 0;
}


Measured memory_bytes: 3908
#include<iostream>
#include<cstdio>
using namespace std;
using ll = long long;
char s[52][52];

int main(){
	int h,w;
	scanf("%d %d",&h,&w);
	for(int i=1;i<=h;i++)	scanf("%s",s[i]+1);
	for(int i=0;i<=w+1;i++){
		s[0][i]='.';
		s[h+1][i]='.';
	}
	for(int i=0;i<=h+1;i++){
		s[i][0]='.';
		s[i][w+1]='.';
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(s[i][j]=='#'){
				if(s[i+1][j]!='#'&&s[i-1][j]!='#'&&s[i][j+1]!='#'&&s[i][j-1]!='#'){
					printf("No\n");
					return 0;
				}
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: i64 = itr.next().unwrap().parse().unwrap();
    let a: i64 = itr.next().unwrap().parse().unwrap();
    let b: i64 = itr.next().unwrap().parse().unwrap();
    let c: i64 = itr.next().unwrap().parse().unwrap();
    let d: i64 = itr.next().unwrap().parse().unwrap();

    for i in 0..n {
        let upper = a + d * (n - 1 - i) - c * i;
        let lower = a + c * (n - 1 - i) - d * i;
        if lower <= b && b <= upper {
            println!("YES");
            return;
        }
    }
    println!("NO");
}


Measured memory_bytes: 2148
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

const int MOD=1e9+7;

int main(){
  ll m,n;
  cin>>m>>n;
  
  ll ans=1,x=m;
  while(n>0){
    if(n&1) ans=ans*x%MOD;
    x=x*x%MOD;
    n/=2;
  }
  cout<<ans<<endl;
 
  return 0;
}


Measured memory_bytes: 3104
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

int pasta(int i,int af1,int af2);
//int pastac(int i,int p,int pn);

int day[102];
int memo[102][4][4];
int n,k;

main(){
  int temp;
  scanf("%d %d",&n,&k);
  for(int i=0;i<k;i++){
    scanf("%d",&temp);
    scanf("%d",&day[temp-1]);
  }
  //  printf("%d\n",pastac(0,0,0));
  printf("%d\n",pasta(0,0,0));
}




int pasta(int i,int af1,int af2){
  int f[4]={0};
  int res=0;

  if(i==n) return 1;
  if(memo[i][af1][af2]) return memo[i][af1][af2];

  if(af1==af2) f[af1]=1;
  if(af1==day[i+1]) f[af1]=1;
  if(day[i+1]==day[i+2]) f[day[i+1]]=1;

  for(int j=1;j<=3;j++){
    if(f[j])continue;
    if(day[i]){
      if(day[i]==j) res+=(pasta(i+1,day[i],af1))%10000;
    }
    else res+=(pasta(i+1,j,af1))%10000;
  }
  return  memo[i][af1][af2]=(res)%10000;
}

/*
int pastac(int i,int p,int pn){
  int res=0;
  if(i>=n) return 1;
  if(memo[i][p][pn]) return memo[i][p][pn];

  if(day[i]){
    if(p==day[i]){
      if(pn==2) return 0;
      return memo[i][p][pn]=(pastac(i+1,p,pn+1))%10000;
    }
    return memo[i][p][pn]=(pastac(i+1,day[i],1))%10000;
  }

  for(int j=1;j<=3;j++){
    if(j==p){
      if(pn!=2)res+=(pastac(i+1,p,pn+1))%10000;
    }
    else res+=(pastac(i+1,j,1))%10000;
  }

  return memo[i][p][pn]=res%10000;

}
*/

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {

	int n,m;
	cin>>n>>m;
	
	int A[n][m];
	int b[m];
	int c[n];
	
	for(int i=0;i<n;++i){
	    for(int j=0;j<m;++j){
	    cin>>A[i][j];
	    }
	}
	for(int j=0;j<m;++j){
	    cin>>b[j];
	}
	
	for(int i=0;i<n;++i){
	    c[i]=0;
	}
	
	    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            c[i]+=A[i][j]*b[j];
        }
        printf("%d", c[i]);
//    if(i!=n-1){
    printf("\n");
//	}
    }
	return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <vector>
#include <list>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
int main(){ 
    vector<int> attryi;
    int check = 0;
    int size = 0, temp;
    cin >> size;
    for(int i = 0;i<size;i++){
        cin >> temp;
        attryi.push_back(temp);
    }
    for(int i = 0;i<size-2;i++){
        if(((attryi.at(i) < attryi.at(i+1)) && (attryi.at(i+1) < attryi.at(i+2)))||((attryi.at(i) > attryi.at(i+1)) && (attryi.at(i+1) > attryi.at(i+2))))check++;
    }
    cout << check << endl;
    
}

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

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int r, c, sum, sumOfAll;
		int[][] sheet;
		String[] size = in.readLine().split(" ");
		r = Integer.parseInt(size[0]);
		c = Integer.parseInt(size[1]);
		StringBuilder sb = new StringBuilder((r + 1) * (c + 1));
		sheet = new int[r][c];
		for (int i = 0; i < r; i += 1) {
			sum = 0;
			String[] array = in.readLine().split(" ");
			for (int j = 0; j < c; j += 1) {
				sheet[i][j] = Integer.parseInt(array[j]);
				sb.append(sheet[i][j]).append(" ");
				sum += sheet[i][j];
			}
			sb.append(sum + System.getProperty("line.separator"));
		}
		sumOfAll = 0;
		for (int m = 0; m < c; m += 1) {
			sum = 0;
			for (int n = 0; n < r; n += 1) {
				sum += sheet[n][m];
			}
			sumOfAll += sum;
			sb.append(sum).append(" ");
		}
		sb.append(sumOfAll);
		System.out.println(sb);
	}
}

Measured memory_bytes: 23132
INT_MAX=10**18+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
n,l=INPUT()
A=[]
for i in range(n):
    x=input()
    A.append(x)
A.sort()
ans=""
for ele in A:
    ans+=ele
print(ans)


Measured memory_bytes: 38256
/*
 * ALDS1_7_C.cpp
 *
 *  Created on: May 1, 2018
 *      Author: 13743
 */

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

struct Node {
	int pa, lc, rc;
};

Node T[25];
vector<int> pre;
vector<int> in;
vector<int> post;

void preorder(int u) {
	if(u == -1) return;
	pre.push_back(u);
	preorder(T[u].lc);
	preorder(T[u].rc);
}

void inorder(int u) {
	if(u == -1) return;
	inorder(T[u].lc);
	in.push_back(u);
	inorder(T[u].rc);
}

void postorder(int u) {
	if(u == -1) return;
	postorder(T[u].lc);
	postorder(T[u].rc);
	post.push_back(u);
}

int main() {
	int n;
	cin >> n;
	for(int i=0; i<n; i++) {
		T[i].pa = -1;
	}
	for(int i=0; i<n; i++) {
		int id, l, r;
		cin >> id >> l >> r;
		T[id].lc = l;
		T[id].rc = r;
		if(l != -1) {
			T[l].pa = id;
		}
		if(r != -1) {
			T[r].pa = id;
		}
	}
	int root;
	for(int i=0; i<n; i++) {
		if(T[i].pa == -1) root = i;
	}
	preorder(root);
	inorder(root);
	postorder(root);

	cout << "Preorder" << endl;
	for(int i=0; i<n; i++) {
		cout << " " << pre[i];
	}
	cout << endl;
	cout << "Inorder" << endl;
	for(int i=0; i<n; i++) {
		cout << " " << in[i];
	}
	cout << endl;
	cout << "Postorder" << endl;
	for(int i=0; i<n; i++) {
		cout << " " << post[i];
	}
	cout << endl;
}



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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


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

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

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, K;
  cin >> N >> K;
  vector< int > P(3);
  cin >> P;
  swap(P[1], P[2]);
  string T;
  cin >> T;

  const string V = "rps";

  int64 ret = 0;
  for(int i = 0; i < K; i++) {
    auto dp = make_v< int >(3);
    for(int j = i; j < N; j += K) {
      int cur = V.find(T[j]);
      auto dp2 = make_v< int >(3);
      for(int k = 0; k < 3; k++) {
        for(int l = 0; l < 3; l++) {
          if(k == l) continue;
          if((cur + 1) % 3 == l) {
            chmax(dp2[l], dp[k] + P[l]);
          } else {
            chmax(dp2[l], dp[k]);
          }
        }
      }
      dp.swap(dp2);
    }
    ret += max({dp[0], dp[1], dp[2]});
  }
  cout << ret << endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main()
{
	long b,N,K;
	int count=0;
	int count2=0;
	long a,c;
	scanf("%ld%ld",&N,&K);

	if(K == 1)
	{
		printf("0\n");
		return 0;
	}
	/* a=K;
	while(a>0)
	{
		a=a/10;
		count++;
	}
	c=N;
	while(c>0)
	{
		c=c/10;
		count2++;
	}
	while(count2 > count+1)
	{
		N = N / 10;
		count2--;
	} */
	a = N/K;
	N= N - (a*K);
	while(1)
	{
		b = N;
		N = N - K;
		if(N < 0)
		{
			N = N * -1;
		}
		if(b < N)
		{
			N = b;
			break;
		}

	}

	printf("%ld\n",N);
	return 0;
}

Measured memory_bytes: 128
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL primes[101];

void prime_factor(int n) {
	for (int i = 2; i*i <= n; i++) {
		while (n%i == 0) {
			primes[i]++;
			n /= i;
		}
	}

	if (n != 1) {
		primes[n]++;
	}
}

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

	for (int i = 0; i < n; i++) {
		int x = i + 1;

		prime_factor(x);
	}

	LL ans = 0;

	for (int i = 1; i <= 100; i++) {
		if (primes[i] >= 74) {
			ans++;
		}
	}

	for (int i = 1; i <= 100; i++) {
		if (primes[i] >=24) {
			for (int j = 1; j <= 100; j++) {
				if (i != j && primes[j] >= 2) {
					ans++;
				}
			}
			
		}
	}

	for (int i = 1; i <= 100; i++) {
		if (primes[i] >= 14) {
			for (int j = 1; j <= 100; j++) {
				if (i != j && primes[j] >= 4) {
					ans++;
				}
			}

		}
	}

	for (int i = 1; i <= 100; i++) {
		if (primes[i] >= 4) {
			for (int j = i+1; j <= 100; j++) {
				if (primes[j] >= 4) {
					for (int k = 1; k <= 100; k++) {
						if (i!=k &&j!=k &&primes[k] >= 2) {
							ans++;
						}
					}
				}
			}

		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    var input = input.split("\n");
    var tmp = input[0].split(" ");
    var N = tmp[0];
    var K = tmp[1];

    var pattern = K;
    for (i = 1;i < N;i++) {
	pattern *= K - 1;
    }

    console.log(pattern);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 6904
#include <iostream>
#include <vector>
#include <queue>
#include <cstdlib>
#include <cmath>
typedef long long ll;

using namespace std;

int main(){
    int s,w;
    cin >> s >> w;
    if(s <= w){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>
#include <assert.h>
#include <vector>
#include <cstring>
#include <bitset>
#include <random>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

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

struct edge {
    int to;
    ll val;
};

const ll inf = 1e18;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin >> n >> m;

    vector<vector<edge> > g(n);

    while (m--) {
        int u, v;
        ll x;
        cin >> u >> v >> x;
        --u, --v;
        g[u].pb({v, x});
        g[v].pb({u, x});
    }

    vector<pll> vct(n);
    vector<bool> used(n, false);
    vct[0] = {1, 0};
    used[0] = true;

    queue<int> q;
    q.push(0);

    bool ok = true;

    vector<ll> must;

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (edge& e : g[v]) {
            ll a = e.val;
            if (!used[e.to]) {
                used[e.to] = true;
                q.push(e.to);
                vct[e.to].first = -vct[v].first;
                vct[e.to].second = a - vct[v].second;
            } else {
                if (vct[e.to].first + vct[v].first == 0 && vct[e.to].second + vct[v].second == a) {
                    continue;
                }
                if (vct[e.to].first + vct[v].first == 0) {
                    ok = false;
                    continue;
                }
                ll num = a - vct[e.to].second - vct[v].second;
                ll den = vct[e.to].first + vct[v].first;
                if (den < 0) {
                    num *= (-1), den *= (-1);
                }
                if (num % den) {
                    ok = false;
                    continue;
                }
                must.pb(num / den);
            }
        }
    }

    if (!ok) {
        cout << "0\n";
        return 0;
    }

    sort(all(must));
    must.resize(unique(all(must)) - must.begin());
    if (sz(must) > 1) {
        cout << "0\n";
        return 0;
    }

    if (sz(must) == 1) {
        for (int v = 0; v < n; ++v) {
            ll x = vct[v].first * must[0] + vct[v].second;
            if (x <= 0) {
                cout << "0\n";
                return 0;
            }
            for (edge& e : g[v]) {
                ll y = vct[e.to].first * must[0] + vct[e.to].second;
                if (x + y != e.val) {
                    cout << "0\n";
                    return 0;
                }
            }
        }
        cout << "1\n";
        return 0;
    }

    ll xmin = -inf, xmax = inf;

    for (int v = 0; v < n; ++v) {
        assert(vct[v].first == 1 || vct[v].first == -1);
        if (vct[v].first == 1) {
            xmin = max(xmin, ll(1) - vct[v].second);
        } else {
            xmax = min(xmax, vct[v].second - 1);
        }
    }

    cout << max(xmax - xmin + 1, ll(0)) << "\n";

}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A = 0, B = 0, C = 0, D = 0;
  cin >> A >> B >> C >> D;
  int left = A + B;
  int right = C + D;

  if (left > right) {
    cout << "Left" << endl;
  } else if (left < right) {
    cout << "Right" << endl;
  } else if (left == right) {
    cout << "Balanced" << endl;
  } 
}

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

typedef long long lint;
#define REP(i, x, n) for(lint i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(lint i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const lint inv = MOD - 2;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int N, T;
    cin >> N >> T;
    int ans = IINF;
    rep(i, N){
        int c, t;
        cin >> c >> t;
        if(t <= T){
            ans = min(ans, c);
        }
    }
    if(ans == IINF){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,0,n)cin>>a[i];
    descSort(a);
    double ans=a[n-1];
    for(int i=n-1;i>0;i--){
        ans=(ans+a[i-1])/2.0;
    }
    printf("%.6lf\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	int ans=k;
	rep(i,n-1){
		ans*=k-1;
	}
	cout<<ans<<endl;
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

const int prime[] = {
     2,  3,  5,  7, 11,
    13, 17, 19, 23, 29, 
    31, 37, 41, 43, 47, 
    53, 59, 61, 67, 71, 
    73, 79, 83, 89, 97
};

map<int, int> fact(int n)
{
    map<int, int> res;
    for (auto &p: prime) {
        if (p > n) break;
        for (int i = p; i <= n; i *= p) res[p] += n / i;
    }
    return res;
}

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

    int n; cin >> n;
    auto f = fact(n);

    int n74 = 0, n24 = 0, n14 = 0, n4 = 0, n2 = 0;
    for (auto &e: f) {
        if (e.second >= 74) n74++;
        if (e.second >= 24) n24++;
        if (e.second >= 14) n14++;
        if (e.second >=  4) n4++;
        if (e.second >=  2) n2++;
    }

    int ans = 0;
    ans += n74;
    ans += n24 * (n2 - 1);
    ans += n14 * (n4 - 1);
    ans += n4 * (n4 - 1) / 2 * (n2 - 2);

    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;

int n, k;
int h[N];

bool read () {
	if (scanf("%d%d", &n, &k) != 2)
		return false;
	forn(i, n)
		scanf("%d", &h[i]);
	return true;
}

li dp[N];

void solve() {
	forn(i, n + 1) dp[i] = INF64;
	dp[0] = 0;
	forn(i, n) forn(j, k) if (i + j + 1 < n)
		dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(h[i] - h[i + j + 1]));
	printf("%lld\n", dp[n - 1]);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

	while(read()) {	
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 1408