akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> part[100010];
//    bool already[100010] = {false};
//    vector<int> days;
    REP(i, N) {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        part[tmp1].push_back(tmp2);
    }
    int ans = 0;
    priority_queue<int> q;

    REP_1(i, M) {//M-i日目の話1<=i<=M
        for (int b:part[i]) {
            q.push(b);
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    printAns(ans);
}


Measured memory_bytes: 5632
while True:
    n = int(input())
    if n == 0:
        break
    org = ''
    dist = ''
    for i in range(n):
        c1, c2 = input().split()
        org += c1
        dist += c2
    m = int(input())
    oSt = ''
    for i in range(m):
        oSt += input()[0]
    print(oSt.translate(str.maketrans(org, dist)))

Measured memory_bytes: 8172
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

long long find_max(function<bool(long long)> solve, long long low, long long high) {
	long long ok = low, ng = high;
	while (ng - ok > 1) {
		int mid = (ok + ng) / 2;
		if (solve(mid)) {
			ok = mid;
		} else {
			ng = mid;
		}
	}
	return ok;
}

int main() {
	long long n, m;
	cin >> n >> m;
	vector<long long> A(n), S(n+1, 0);
	for (int i = 0; i < n; i++) cin >> A[i];
	sort(A.begin(), A.end());
	for (int i = n-1; i >= 0; i--) {
		S[i] = S[i+1] + A[i];
	}

	function<long long(long long)> g = [&](long long x) {
		long long res = 0;
		for (int i = n-1; i >= 0; i--) {
			auto itr = lower_bound(A.begin(), A.end(), x-A[i]);
			if (itr == A.end()) break;
			res += A.end() - itr;
		}
		return res;
	};
	function<bool(long long)> f = [&](long long x) {
		return g(x) >= m;
	};
	function<long long(long long)> sum = [&](long long x) {
		long long res = 0;
		for (int i = n-1; i >= 0; i--) {
			int idx = lower_bound(A.begin(), A.end(), x-A[i]) - A.begin();
			if (idx == n) break;
			res += S[idx] + A[i] * (n - idx);
		}
		return res;
	};

	long long x = find_max(f, 0, A[n-1]+A[n-1]+1);
	long long ans = sum(x) - (g(x) - m) * x;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4832
from functools import lru_cache

import sys
sys.setrecursionlimit(10**9)

N, K = map(int, input().split())

M = 10 ** 9 + 7

@lru_cache(maxsize=10**9)
def combinations(n, r):
    if n == 0 or r == 0: return 1
    return int((combinations(n, r-1) * (n-r+1)) // r)

def f(i):
    return (combinations(N - K + 1, i) % M) * (combinations(K - 1, i - 1) % M)

for i in range(1, K + 1):
    print(f(i) % M)


Measured memory_bytes: 47084
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    dp = [INF] * 101000
    dp[0] = 0
    for i in range(N-1):
        for j in range(1, K+1):
            if i + j <= N-1:
                dp[i+j] = min(dp[i+j], dp[i] + abs(H[i] - H[i+j]))
    
    print(dp[N-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 80636
#include <iostream>
using namespace std;
string s,t="keyence";
int u[7];
int main(void){
    cin>>s;
    for(int i=0;i<7;i++){
        if(s[i]==t[i])u[i]=1;
        else break;
    }
    for(int i=0;i<7;i++){
        if(s[s.size()-1-i]==t[6-i])u[6-i]=1;
        else break;
    }
    for(int i=0;i<7;i++){
        if(u[i]==0){cout<<"NO"<<endl;return 0;}
    }
    cout<<"YES"<<endl;
}


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

int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  printf("%s", b - a == c - b ? "YES" : "NO");
  return 0;
}

Measured memory_bytes: 128
import numpy as np

def main():
    N, M = map(int, input().split())
    PS = {}
    for i in range(M):
        row = input().split()
        row[0] = int(row[0])
        if row[0] not in PS:
            PS[row[0]] = [row[1]]
        else:
            PS[row[0]].append(row[1])

    n_correct = 0
    n_penalty = 0
    for p in PS:
        if 'AC' in PS[p]:
            n_correct += 1
            for result in PS[p]:
                if result == 'AC':
                    break
                if result == 'WA':
                    n_penalty += 1
    
    print('{} {}'.format(n_correct, n_penalty))
        


if __name__ == '__main__':
    main()

Measured memory_bytes: 37092
from string import ascii_uppercase


def main(h, w, s):
    h, w = 1, 0  # height, weight

    for row in s:
        for col in row:
            if col == 'snuke':
                print(ascii_uppercase[w] + str(h))
                return
            w += 1

        h += 1
        w = 0


if __name__ == "__main__":
    h, w = map(int, input().split(' '))

    s = [[i for i in input().split(' ')] for _ in range(h)]

    main(h, w, s)


Measured memory_bytes: 4088
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n; cin>>n;
    rep(p,n){
    vector<vector<bool> >flag(10,vb(10,true));
    vvi v(10,vi(10,0));
    rep(i,9)rep(j,9)cin>>v[i][j];
    for(int i=0;i<9;i++){
        vb used(10,false);
        for(int j=0; j<9;j++){
            if(!used[v[i][j]]){used[v[i][j]]=true;}
            else {
                flag[i][j]=false;
                rep(k,9)if(v[i][k]==v[i][j])flag[i][k]=false;
            }
        }
    }
    for(int j=0;j<9;j++){
        vb used(10,false);
        for(int i=0; i<9;i++){
            if(!used[v[i][j]]){used[v[i][j]]=true;}
            else {
                flag[i][j]=false;
                rep(k,9)if(v[k][j]==v[i][j])flag[k][j]=false;
            }
        }
    }
   
    for(int h=0; h<=8;h+=3){
        for(int w=0; w<=8;w+=3){
            vb used(10,false);
            for(int i=h; i<h+3;i++){
                for(int j=w; j<w+3;j++){
                    if(!used[v[i][j]])used[v[i][j]]=true;
                    else for(int k=h; k<h+3;k++){
                            for(int m=w; m<w+3;m++){
                                if(v[k][m]==v[i][j])flag[k][m]=false;
                        }
                    }
                }
            }
        }
    }
        if(p)cout<<endl;
    rep(i,9){
        rep(j,9){
            if(flag[i][j])cout<<" ";
            else cout<<"*";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}
};

Measured memory_bytes: 2968
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef pair<int64_t, int64_t> P;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i, 0, N) cin >> A[i] >> B[i];
    
    vector<vector<int>> dp(N+1, vector<int>(H+1, INF));
    dp[0][0] = 0;
    rep(i, 0 ,N){
        rep(j, 0, H + 1){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][min(j+A[i], H)] = min(dp[i+1][min(j+A[i], H)], dp[i+1][j] + B[i]);
        }
    }
    cout << dp[N][H] << endl;
}

Measured memory_bytes: 39424
from functools import cmp_to_key

n = int(input())
a = list(map(int, input().split()))

def group(a):
    d = {}
    for i, x in enumerate(a):
        d.setdefault(x, []).append(i)
    return list(map(
        lambda x: [x[0], x[1][0], len(x[1])],
        sorted(d.items(), key=cmp_to_key(lambda x, y: x[0] - y[0]), reverse=True)
    ))

ans = [0] * n
g = group(a)
g.append([0, 0, 0])
for c, n in zip(g[:-1], g[1:]):
    ans[c[1]] += (c[0] - n[0]) * c[2]
    n[1] = min(c[1], n[1])
    n[2] += c[2]

[print(a) for a in ans]

Measured memory_bytes: 46184
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int red = 0, blue = 0;
  for (int i = 0; i < S.size(); i++){
    if (S[i] == '0'){
      red++;
    } else {
      blue++;
    }
  }
  cout << min(red, blue) * 2;
}


Measured memory_bytes: 512
N, M = gets.split.map(&:to_i)
G = Array.new(N + 1){ [] }
E = M.times.map{ gets.split.map(&:to_i) }
E.each do |u,v|
  G[u] << v
  G[v] << u
end
used = Array.new(N + 1)
n = (1 .. N).count do |s|
  next false if used[s]
  
  q = [s]
  used[s] = true
  until q.empty?
    u = q.shift
    G[u].each do |v|
      next if used[v]
      used[v] = true
      q << v
    end
  end
  true
end
puts n - 1


Measured memory_bytes: 30524
/*
 * @Author: SugarSBN
 * @Date: 2018-07-16 18:32:09
 * @Language:   C++
 */
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<sstream>
#include<fstream>
using namespace std;
const int MAXN=2e6+11;
const double pi=acos(-1);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef double dbl;
#define For(a,b,c) for (int (a)=(b);(a)<(c);(a)++)
#define foreach(iter,V) for (__typeof((V.begin()) iter=(V).begin();iter!=(V).end();iter++)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
int n, m;
struct line{
    int p, q, c;
}rec[MAXN];
vector<pii> g[MAXN];
vi col[MAXN];
int ptr[MAXN];
int be[MAXN];
vi new_g[MAXN];
int new_vertex;
int main(){
   // freopen("in.txt", "r", stdin);
    scanf("%d%d", &n, &m);
    For(i,0,m){
        scanf("%d%d%d", &rec[i].p, &rec[i].q, &rec[i].c);
        rec[i].p--;
        rec[i].q--;
        g[rec[i].p].pb(mp(rec[i].c, rec[i].q));
        g[rec[i].q].pb(mp(rec[i].c, rec[i].p));
        col[rec[i].c].pb(rec[i].p);
        col[rec[i].c].pb(rec[i].q);
    }
    new_vertex = n;
    For(i, 0, n) {
        sort(g[i].begin(), g[i].end());
        ptr[i] = 0;
        be[i] = -1;
    }
    For(i,1,MAXN){
        if (col[i].size()==0)
            continue;
        For(j,0,col[i].size()){
            if (be[col[i][j]]!=i){
                be[col[i][j]] = i;
                queue<int> Q;
                Q.push(col[i][j]);
                new_g[col[i][j]].pb(new_vertex);
                new_g[new_vertex].pb(col[i][j]);
                while (!Q.empty()){
                    int v = Q.front();
                    Q.pop();
                    while(ptr[v]<g[v].size()&&g[v][ptr[v]].fi==i){
                        if (be[g[v][ptr[v]].se]!=i){
                            Q.push(g[v][ptr[v]].se);
                            be[g[v][ptr[v]].se] = i;
                            new_g[new_vertex].pb(g[v][ptr[v]].se);
                            new_g[g[v][ptr[v]].se].pb(new_vertex);
                        }
                        ptr[v]++;
                    }
                }
                new_vertex++;
            }
        }
    }
    int dist[MAXN];
    For(i, 0, new_vertex) dist[i] = -2;
    queue<int> Q;
    Q.push(0);
    dist[0] = 0;
    while(!Q.empty()){
        int v = Q.front();
        Q.pop();
        For(i,0,new_g[v].size()){
            if (dist[new_g[v][i]]==-2){
                dist[new_g[v][i]] = dist[v] + 1;
                Q.push(new_g[v][i]);
            }
        }
    }
    printf("%d\n", dist[n - 1] / 2);
    return 0;
}


Measured memory_bytes: 172544
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;

void solve()
{
  int mx=50000000;
  int n,x,m;
  cin>>n>>x>>m;
  mx=min(mx,n);
  int prev=x;
  int ans=x;

  ///r.push_back(x);
  unordered_map<int,int> mp;
  mp[x]=1;
  int ok=0;
  int freeze=0;
  vector<int> res;
  res.pb(x);
  for(int i=2;i<=mx;i++)
  {
      prev*=prev;
      prev%=m;
      if(!mp[prev])
      {
          mp[prev]=1;
      res.pb(prev);
      }
      else if(!ok)
      {
          ok=1;
          freeze=prev;
      }
      ans+=prev;
  }

  if(prev==0)
  {//cout<<"yes"<<endl;
      cout<<ans<<endl;
  }
  else if(prev==1)
  {
      ans+=n-mx;
      ///cout<<"yes"<<endl;
      cout<<ans<<endl;
  }
  else
  {

      int i=0;
      n-=mx;
      if(n==0)
      {
          cout<<ans<<endl;
          return;
      }
      vector<int> cyc;
      int yes=0;
      for(int i=0;i<res.size();i++)
      {
          if(res[i]==freeze)
          {
              yes=1;
          }
          if(yes)
            cyc.pb(res[i]);
      }
      ///cout<<n<<" "<<ans<<endl;
      for( i=0;i<cyc.size();i++)
      {
          if(cyc[i]==prev)
          {
              i++;
              break;
          }
      }

      for(;i<cyc.size();i++)
      {  if(n==0)
      break;
          ans+=cyc[i];
          n--;
      }
      if(n==0)
      {
          cout<<ans<<endl;
          return;
      }
      int sum=0;

      int r=cyc.size();
      for(int i=0;i<r;i++)
      {
          sum+=cyc[i];
      }
            if(r==0)
            {
                cout<<ans<<endl;
                return;
            }
      int f=(n/r);
      f*=sum;

      ans+=f;

      n=n%r;

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


}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
    return 0;
}


Measured memory_bytes: 6380
#include<iostream>
using namespace std;
int main()
{
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int num;
	cin>>num;
	cout<<a[num-1]<<endl;
	
	
	return 0;
 } 

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        scan.close();
        if (a + b < 10)
            System.out.println(a + b);
        else
            System.out.println("error");
    }
}

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

using namespace std;

int main(int argc, char **argv) {
    int A, B;
    cin >> A >> B;

    int candidate = 0;
    while (true) {
        int eight = (int) (candidate * 0.08);
        int ten = (int) (candidate * 0.1);
        if (eight == A && ten == B) {
            cout << candidate << endl;
            break;
        }
        if (eight > A && ten > B) {
            cout << -1 << endl;
            break;
        }
        candidate++;

    }
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class BVaried {
public:
    void solve(istream& cin, ostream& cout) {
        string s;
        cin >> s;
        vector<int> cnt(26, 0);

        for(auto k : s) cnt[k - 'a']++;
        for(auto k: cnt) {
            if(k > 1) {
                cout << "no\n";
                return;
            }
        }
        cout << "yes\n";
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    BVaried solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#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 show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, int> P;


int main()
{
    int N;
    cin >> N;
    vector<string> s;
    rep(i, N){ string tmp; cin >> tmp; sort(tmp.begin(), tmp.end());s.push_back(tmp);}

//    show(s);
    sort(s.begin(), s.end());
//    show(s);


    ll ans = 0;
    ll tmp_cnt = 0;
    rep(i, N-1){
        if (s[i] == s[i+1]){
            tmp_cnt++;
        } else {
            ans += tmp_cnt * (tmp_cnt + 1) /2;
            tmp_cnt = 0;
        }
//        cout << tmp_cnt << endl;
    }
    ans += tmp_cnt * (tmp_cnt + 1) /2;

    cout << ans << endl;

}



Measured memory_bytes: 5748
N = int(input())
Hlist = list(map(int, input().split()))

Last_move_num = 0
move_num = 0
for i in range(0,N-1):

    if Hlist[i] >= Hlist[i+1]:
        move_num = move_num+1
    else:
        move_num = 0
    if move_num > Last_move_num:
        Last_move_num = move_num

print(Last_move_num)

Measured memory_bytes: 14252
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();

		if((a * b) % 2 == 0) {
			System.out.println("Even");
		}else {
			System.out.println("Odd");
		}
	}
}


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

int main() {
  int N;
  cin >> N;
  if(N % 1000 == 0){
  	cout << 0 << endl;
  }
  else{
    cout << 1000 * (N / 1000 + 1) - N << endl;
  }
}

Measured memory_bytes: 3576
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Double n = sc.nextDouble();
		Double m = sc.nextDouble();
		Double d = sc.nextDouble();
		
		Double ans = ((n * 2) - (d * 2)) / (n * n) * (m - 1);
		if (d == 0) {
			ans /= 2;
		}
		BigDecimal ans2 = new BigDecimal(ans);
		System.out.println(ans2.toPlainString());
	}
}

Measured memory_bytes: 25172
#include <iostream>
#include <numeric>
#include <vector>

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

  std::vector<int> b(n - 1);
  for (auto&& bi : b) std::cin >> bi;

  std::vector<int> a(n, 0);
  a[n - 1] = b[n - 2];

  for (int i = n - 2; i >= 0; --i) {
    if (a[i + 1] > b[i]) a[i + 1] = b[i];
    a[i] = b[i];
  }

  const auto sum = std::accumulate(a.begin(), a.end(), 0);
  std::cout << sum << std::endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */

#include <bits/stdc++.h>

using namespace std;

class CWalkOnMultiplicationTable {
public:
    void solve(std::istream &in, std::ostream &out) {
        long long n;
        in >> n;
        long long res = n + 1;
        for (long long a = 1; a * a <= n; a++) {
            if (n % a == 0) {
                long long b = n / a;
                res = min(res, a + b - 2);
            }
        }
        out << res << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    CWalkOnMultiplicationTable solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


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

int main() {
    int n;
    map<string, bool> map;
    cin >> n;
    string s;
    for(int i = 0; i < n; i++) {
        cin >> s;
        map[s] = true;
    }
    int size = map.size();
    if (size == 4) {
        cout << "Four" << endl;
    } else if (size == 3) {
        cout << "Three" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n) {int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s) {int c;for(;;){c=gcu();if(c=='\n'||c==' ')return true;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
template <typename T>
void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

int main() {
	vector<int> l(10);
	while (scan(l[0])) {
		int sum = l[0];
		for_each(l.begin() + 1, l.end(), [&](int &n) {sum += in(), n = sum;});
		int v1 = in(), vl = in() + v1, pos = v1 * sum;
		int i = 1;
		for (int n: l) {
			if (pos - n * vl <= 0) {
				out(i, '\n');
				break;
			}
			i++;
		}
	}
}


Measured memory_bytes: 2460
a = []
for i in range(5):
    a.append(int(input()))

b = []
c = []
for j in range(5):
    if a[j] % 10 == 0:
        c.append(10)
        b.append(a[j]-10)
    else:
        #10で割った余りを引く
        num = a[j] % 10
        c.append(num)
        b.append(a[j] - c[j])

b_sum = sum(b)
c_min = min(c)
c_sum = c_min + 4*10
 
print(b_sum + c_sum)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    string S; cin>>S;
    cout<<S.substr(0,3)<<endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  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 {
      cout << "Christmas Eve Eve Eve" << endl;
  }
}

Measured memory_bytes: 256
N=int(input())
list_s=[str(input()) for s in range(N)]
M=int(input())
list_t=[str(input()) for t in range(M)]
X=0
C=0
for i in range(N):
  A=list_s.count(list_s[i])
  B=list_t.count(list_s[i])
  if (A-B)>X:
    X=A-B
for i in range(M):
  A=list_s.count(list_t[i])
  B=list_t.count(list_t[i])
  if (A-B)>X:
    X=A-B

print(X)
  

Measured memory_bytes: 3064
from math import factorial

n = int(input())
mod = pow(10, 9) + 7
ans = 0
k = n // 3
while k > 0:
  a = n - 3 * k
  ans += factorial(a + k - 1) // (factorial(k - 1) * factorial(a))
  ans %= mod
  k -= 1
print(ans)


Measured memory_bytes: 9108
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cassert>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

//通行可能をtrueとする
constexpr char WallCharacter = '#';
vector<vector<bool>> read_grid_map(ll H, ll W)
{
    vector<vector<bool>> grid(H, vector<bool>(W));
    char c;
    scanf("%c", &c);
    for (ll i = 0; i < H; i++)
    {
        char c;
        for (ll j = 0; j < W; j++)
        {
            scanf("%c", &c);
            grid[i][j] = (c != WallCharacter);
        }
        scanf("%c", &c);
    }
    return grid;
}

int main()
{
    ll H, W;
    ll CH, CW;
    ll DH, DW;
    scanf("%lld", &H);
    scanf("%lld", &W);
    scanf("%lld", &CH);
    scanf("%lld", &CW);
    scanf("%lld", &DH);
    scanf("%lld", &DW);
    CH--;
    CW--;
    DH--;
    DW--;

    vector<vector<bool>> mazemap = read_grid_map(H, W);

    ll ans = 127;
    if (!mazemap[CH][CW])
    {
        ans = -1;
        printf("%lld\n", ans);
        return 0;
    }

    priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, greater<pair<ll, pair<ll, ll>>>> nexts;
    nexts.push({0, {CH, CW}});
    vector<vector<ll>> depthmap(H, vector<ll>(W, __LONG_LONG_MAX__));
    while (!nexts.empty())
    {
        auto current = nexts.top();
        nexts.pop();
        for (ll l = -2; l < 3; l++)
        {
            for (ll m = -2; m < 3; m++)
            {
                pair<ll, ll> currentpos = current.second;
                currentpos.first += l;
                currentpos.second += m;
                ll depth = current.first;
                if (currentpos.first < 0 || currentpos.second < 0 || currentpos.first >= H || currentpos.second >= W)
                    continue;

                if (!mazemap[currentpos.first][currentpos.second])
                    continue;

                if (!(abs(l) <= 1 && abs(m) <= 1 && abs(l) != abs(m)))
                    depth++;

                if (depthmap[currentpos.first][currentpos.second] > depth)
                {
                    depthmap[currentpos.first][currentpos.second] = depth;
                    nexts.push({depth, {currentpos.first, currentpos.second}});
                }
            }
        }
    }

    ans = depthmap[DH][DW];
    if (ans == __LONG_LONG_MAX__)
        ans = -1;
    printf("%lld\n", ans);
}


Measured memory_bytes: 11796
#include<stdio.h>
#include<string.h>
int main(){
  char s[100001];
  int q,i,rev=0,len;
  scanf("%s",s);
  scanf("%d",&q);
  len=strlen(s);
  char be[q+1],af[q+1];
  int benum=0,afnum=0;
  int t[q+1],f;
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
    if(t[i]==1)
      rev++;
    else{
      scanf("%d ",&f);
      if((rev+f)%2==0)
        scanf("%c",&af[afnum++]);
      else
        scanf("%c",&be[benum++]);
    }
  }
  if(rev%2==0){
    for(i=benum-1;i>=0;i--)
      printf("%c",be[i]);
    for(i=0;i<len;i++)
      printf("%c",s[i]);
    for(i=0;i<afnum;i++)
      printf("%c",af[i]);
    }
  else{
    for(i=afnum-1;i>=0;i--)
      printf("%c",af[i]);
    for(i=len-1;i>=0;i--)
      printf("%c",s[i]);
    for(i=0;i<benum;i++)
      printf("%c",be[i]);
    }
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

double a, b;

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> a >> b;
	double ans = 1/a+1/b;
	printf("%.11f\n", 1/ans);
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	int mod = 1000000007;
	
	public static void main(String[] args) {
		Main mainObj = new Main();
		mainObj.solve();
	}
	
	public void solve() {
		Scanner sc = new Scanner(System.in);
		String pattern = sc.nextLine();
		sc.close();
		
		int[][] dp = new int[pattern.length()][13];
		
		char firstChar = pattern.charAt(0);
		if(firstChar == '?') {
			for(int j = 0; j < 10; j++) {
				dp[0][j] = 1;
			}
		}else {
			dp[0][Integer.parseInt(String.valueOf(firstChar))] = 1;
		}
		
		for(int i = 1; i < pattern.length(); i++) {
			char nowChar = pattern.charAt(i);
			if(nowChar == '?') {
				for(int k = 0; k < 13; k++) {
					int numOfSameMod = dp[i - 1][k];
					for(int j = 0; j < 10; j++) {
						int modValue = (k * 10 + j) % 13;
						dp[i][modValue] = calcMod(dp[i][modValue] + numOfSameMod);
					}
				}
			}else {
				int nowDigit = Integer.parseInt(String.valueOf(nowChar));
				for(int k = 0; k < 13; k++) {
					int numOfSameMod = dp[i - 1][k];
					int modValue = (k * 10 + nowDigit)%13;
					dp[i][modValue] = calcMod(dp[i][modValue]+ numOfSameMod);
				}
			}
		}
		
		System.out.println(dp[pattern.length() - 1][5]);
	}
	
	int calcMod(int value) {
		return value%mod;
	}
}


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

int main()
{
    int k, x;
    cin >> k >> x;
    if (500 * k >= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

const int N = 1e5 + 10;

vector <int> G[N];
vector <int> sav;
int a[N], rec[N];

void dfs(int x, int id){
	rec[x] = id;
	sav.push_back(a[x]);
	for (int i = 0; i < (int)G[x].size(); i++){
		if (!rec[G[x][i]]) dfs(G[x][i], id);
	}
}

int main(){
	int n, m, u, v, ans;
	scanf("%d %d",&n,&m);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	for (int i = 1; i <= m; i++){
		scanf("%d %d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	memset(rec, 0, sizeof(rec));
	ans = 0;
	for (int i = 1; i <= n; i++){
		if (!rec[i]){
			sav.clear();
			dfs(i, i);
			for (int j = 0; j < (int)sav.size(); j++){
				if (rec[sav[j]] == i) ans++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 10108
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    S = []
    T = []
    for _ in range(N):
        a,b = map(int, input().split())
        S.append(a)
        T.append(b)
    S.sort()
    T.sort(reverse=True)
    if N % 2 == 1:
        print(T[N//2] - S[N//2] + 1)
    else:
        x = (T[N//2-1] + T[N//2])/2
        y = (S[N//2-1] + S[N//2])/2
        print(int((x - y) * 2) + 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 25556
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

const ll mod = 1000000007;
ll powe(ll x, ll y)
{
    if(!y) return 1;
    ll ret = powe(x, y>>1);
    ret = ret * ret % mod;
    if(y&1) ret = ret * x % mod;
    return ret;
}
ll inv(ll x){return powe(x, mod - 2);}
ll C(ll x, ll y)
{
    ll ans = 1;
    for(int i=0; i<y; i++)
    {
        ans = ans * (x - i) % mod;
    }
    for(int i=1; i<=y; i++) ans = ans * inv(i) % mod;
    return ans;
}

ll p, q;

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> p >> q;
    if((p+q)%3!=0)
    {
        cout << 0 << endl;
        return 0;
    }
    ll r = (p+q) / 3;
    ll a = p-r;
    ll b = q-r;
    if(a<0 || b<0)
    {
        cout << 0 << endl;
        return 0;
    }
    cout << C(a+b, a) << endl;
}


Measured memory_bytes: 256
s = list(input())
n = len(s)
flg = True
s4 = reversed(s)
if s != s[::-1]:
    flg = False
s2 = s[0:((n-1)//2)]
s5 = reversed(s)
if s2 != s2[::-1]:
    flg = False
s3 = s[(n+3)//2 -1:n]
s6 = reversed(s)
if s3 != s3[::-1]:
    flg = False
if flg == True:
    print('Yes')
else:
    print('No')
#print(s[::-1])

Measured memory_bytes: 3064
S = input()

def isMM(num):
    if 1 <= num <= 12:
        return True
    return False

if isMM(int(S[0:2])) and isMM(int(S[2:])):
    print('AMBIGUOUS')
elif isMM(int(S[0:2])):
    print('MMYY')
elif isMM(int(S[2:])):
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
def solve(n):
	if n > 0:
		for i in range(n,0,-1):
			if i <= ans[-1]:
				ans.append(i)
				solve(n-i)
				ans.pop()
	else:
		print ' '.join(map(str,ans[1:]))
while 1:
	n = input()
	if n==0: break
	ans = [n]
	solve(n)

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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);
 

void solve() {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    REP(i, N){
        int x;
        cin >> x;
        ans += min(x, abs(K-x)) * 2;
    }
    cout << ans << endl;
}
 
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace Competitive
{
    
    internal class Solution
    {
        public int N;
        public long[] A;

        public void Run()
        {
            N = Input.ReadInt();
            A = new long[N+1];

            for (int i = 0; i <= N; i++)
            {
                if (i == 0 || i == 1)
                {
                    A[i] = 1;
                }
                else
                {
                    A[i] = A[i - 1] + A[i - 2];
                }
            }

            Console.WriteLine(A[N]);
        }

    }

    
    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}


Measured memory_bytes: 9176
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string str;
	while(getline(cin,str))
	{
		for(int i=0;i<str.size();i++)
		{
			string sstr; sstr=str.substr(i,5);
			if(sstr=="apple") {string tmp="peach"; for(int j=0;j<5;j++) str[i+j]=tmp[j];}
			else if(sstr=="peach") {string tmp="apple"; for(int j=0;j<5;j++) str[i+j]=tmp[j];}
		}
		cout << str << endl;
	}
}

Measured memory_bytes: 1188
sx,sy,gx,gy=map(int,input().split())

ans=""

#行きn=1右,上
ans+="R"*(gx-sx)
ans+="U"*(gy-sy)

#帰りn=1左,下
ans+="L"*(gx-sx)
ans+="D"*(gy-sy)

#行きn=2下,右+1,上+1,左
ans+="D"
ans+="R"*(gx-sx+1)
ans+="U"*(gy-sy+1)
ans+="L"

#帰りn=2上,左+1,下+1,右
ans+="U"
ans+="L"*(gx-sx+1)
ans+="D"*(gy-sy+1)
ans+="R"

print(ans)

Measured memory_bytes: 3064
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N = getN()
A = getList()

imos = copy.deepcopy(A)
for i in range(N - 1):
    imos[-i - 2] += imos[-i - 1]

ans = 0
for i in range(N - 1):
    ans += A[i] * imos[i + 1]
    ans %= mod
print(ans % mod)

Measured memory_bytes: 104724
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

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

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

// (K-1)C(i-1) * (N-K+1)C(i)

type combi struct {
	fac  []int
	finv []int
	inv  []int
	mod  int
}

func (c *combi) init(n int, m int) {
	c.fac = make([]int, n)
	c.finv = make([]int, n)
	c.inv = make([]int, n)
	c.mod = m

	c.fac[0] = 1
	c.fac[1] = 1
	c.finv[0] = 1
	c.finv[1] = 1
	c.inv[1] = 1
	for i := 2; i < n; i++ {
		c.fac[i] = c.fac[i-1] * i % c.mod
		c.inv[i] = c.mod - c.inv[c.mod%i]*(c.mod/i)%c.mod
		c.finv[i] = c.finv[i-1] * c.inv[i] % c.mod
	}
}

func (c *combi) combi(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return c.fac[n] * (c.finv[k] * c.finv[n-k] % c.mod) % c.mod
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	var c combi
	mod := int(1e9) + 7
	c.init(n+1, mod)
	for i := 0; i < k; i++ {
		//if n-k >= i && k-1 >= i {
		//debugf("i: %d, n:%d, k:%d\n", i, n, k)
		b := c.combi(k-1, i)
		r := c.combi(n-k+1, i+1)
		debugf("%d: %d * %d = %d\n", i, b, r, (b*r)%mod)
		_, _ = fmt.Fprintf(writer, "%d\n", (b*r)%mod)
		//} else {
		//	break
		//}
	}
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func answer2(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	m := max(n-k+3, k+3)
	mod := uint64(1e9) + uint64(7)
	dp := make([][]uint64, m)
	for i := 0; i < m; i++ {
		dp[i] = make([]uint64, m)
	}
	for i := 0; i < m; i++ {
		dp[i][0] = 1
		dp[0][i] = 1
	}
	for i := 1; i < m; i++ {
		for j := 1; j < m; j++ {
			dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod
		}
	}
	//debugf("%v\n", dp)

	for i := 0; i < k; i++ {
		if i == 0 {
			debugf("%d: %d * %d = %d\n", i, dp[n-k][i+1], dp[k-i-1][i], (dp[n-k][i+1]*dp[k-i-1][i])%mod)
			_, _ = fmt.Fprintf(writer, "%d\n", (dp[n-k][i+1]*dp[k-i-1][i])%mod)
		} else {
			if n-k-i >= 0 && k-i-1 >= 0 {
				debugf("%d: %d * %d = %d\n", i, dp[n-k-i][i+1], dp[k-i-1][i], (dp[n-k-i][i+1]*dp[k-i-1][i])%mod)
				_, _ = fmt.Fprintf(writer, "%d\n", (dp[n-k-i][i+1]*dp[k-i-1][i])%mod)
			} else {
				break
			}
		}
	}

}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


Measured memory_bytes: 768
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

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


	int N;
	cin >> N;
	pair<ll, ll> AB[200200], BA[200200];
	int a0 = 0, b0 = 0;
	int ab00 = 0;
	int ka = 0, kb = 0;
	rep(i, N) {
		ll a, b;
		cin >> a >> b;

		if (a == 0 && b == 0) {
			ab00++;
			continue;
		}
		if (a == 0) {
			a0++;
			continue;
		}
		if (b == 0) {
			b0++;
			continue;
		}

		ll G = gcd(a, b);
		a /= G;
		b /= G;
		if (a < 0) {
			a = -a;
			b = -b;
		}
		if (b > 0) AB[ka++] = { a,b };
		else BA[kb++] = { -b,a };
	}

	ll kotae = 1;
	sort(AB, AB + ka);
	sort(BA, BA + kb);
	BA[kb] = { 2e18, 2e18 };

	pair<ll, ll> mae = AB[0];
	int p = 0;
	int kA = 0;
	rep(i, ka) {
		ll a = AB[i].first;
		ll b = AB[i].second;
		if (mae != AB[i]) {
			int tmp = 0;

			pair<ll, ll> mae2 = BA[p];
			int kB = 0;
			while (p < kb && BA[p] <= mae) {
				if (mae2 != BA[p]) {
					kotae = kotae * modpow(2, kB) % mod;
					mae2 = BA[p];
					kB = 1;
				}
				else kB++;
				p++;
			}

			if (mae == mae2) {
				tmp = kB;
			}
			else {
				kotae = kotae * modpow(2, kB) % mod;
			}

			if (tmp) {
				kotae = kotae * (modpow(2, kA) + modpow(2, kB) - 1) % mod;
			}
			else {
				kotae = kotae * modpow(2, kA) % mod;
			}

			mae = AB[i];
			kA = 1;
		}
		else kA++;
	}

	int tmp = 0;
	pair<ll, ll> mae2 = BA[p];
	int kB = 0;
	while (p < kb) {
		if (mae2 != BA[p]) {
			if (AB[ka - 1] == mae2) {
				tmp = kB;
			}
			else {
				kotae = kotae * modpow(2, kB) % mod;
			}
			mae2 = BA[p];
			kB = 1;
		}
		else kB++;
		p++;
	}

	if (AB[ka - 1] == mae2) {
		tmp = kB;
	}
	else {
		kotae = kotae * modpow(2, kB) % mod;
	}

	if (tmp) {
		kotae = kotae * (modpow(2, kA) + modpow(2, kB) - 1) % mod;
	}
	else {
		kotae = kotae * modpow(2, kA) % mod;
	}

	kotae = kotae * (modpow(2, a0) + modpow(2, b0) - 1) % mod;

	co((kotae - 1 + ab00 + 2 * mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 9932
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  int a[n][m];
  for (int i = 0; i < n; ++i) {
    cin >> c[i];
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  int ans = 1e9;
  int ok_cnt = 0;
  for (int bit = 0; bit < (1 << n); ++bit) {
    bool ok = true;
    int res = 0;
    vector<int> understand(m);
    for (int i = 0; i < n; ++i) {
      if (bit >> i & 1) {  // buy
        res += c[i];
        for (int j = 0; j < m; ++j) {
          understand[j] += a[i][j];
        }
      }
    }
    for (int i = 0; i < m; ++i) {
      if (understand[i] < x) {
        ok = false;
      }
    }
    if (ok) {
      ans = min(ans, res);
      ok_cnt++;
    }
  }
  if (ok_cnt == 0) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int64_t abs(int64_t n) {
  if (n < 0) {
    n = -n;
  }
  return n;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int64_t factorial(int64_t n) {
  if (n == 1) {
    return 1;
  }
  int64_t ans = factorial(n-1);
  return ans*n;
}

int main() {
  int64_t n;
  cin >> n;
  vector <int64_t> v(n);
  vector <int64_t> data(n);
  rep(i, n) {
    cin >> v.at(i);
    data.at(i) = v.at(i);
  }
  sort(v.begin(), v.end());
  double mid1 = (double)v.at((n/2)-1), mid2 = (double)v.at(n/2);
  double mid = (mid1+mid2)/2.0;
  rep(i, n) {
    if (data.at(i) <= mid) {
      cout << (int64_t)mid2 << endl;
    } else {
      cout<< (int64_t)mid1 << endl;
    }
  }
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
main(){
  int W,H,N;
  cin>>W>>H>>N;
  int x_min=0,x_max=W,y_min=0,y_max=H;
  for(int i=0;i<N;++i){
    int x,y,a;
    cin>>x>>y>>a;
    switch(a){
      case 1:
        x_min=max(x_min,x);
        break;
      case 2:
        x_max=min(x_max,x);
        break;
      case 3:
        y_min=max(y_min,y);
        break;
      case 4:
        y_max=min(y_max,y);
        break;
    }
  }
  int w=max(0,x_max-x_min);
  int h=max(0,y_max-y_min);
  cout<<(w*h)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N, A;
    cin >> N >> A;
    if (N % 500 <= A) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


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

int main() {
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		string s;
		cin >> s;
		if(s[0] == 'Y'){
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three"  << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T,U;
  int A,B;
  
  cin >> S >> T;
  cin >> A >> B;
  
  cin >> U;
  
  if(S == U){
    A -= 1;
  }else{
    B -= 1;
  }
  
  cout << A << " " << B <<endl;
}

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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

vector<ll> cnt,used;
vector<vector<ll>> G;
void dfs(ll root, ll num){
    used[root]=1;
    cnt[root]+=num;
    for(ll x:G[root]){
        if(used[x]==0)dfs(x, cnt[root]);
    }
    return;
}

int main() {
    ll n, m, i, j, k;
    ll q;
    cin >> n >> q;
    cnt.resize(n+1);
    used.resize(n+1);
    for(i=0;i<=n;i++){
        cnt[i]=used[i]=0;
    }
    G.resize(n+1);
    for(i=0;i<n-1;i++){
        ll a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(i=0;i<q;i++){
        ll p,x;
        cin >> p >> x;
        cnt[p]+=x;
    }
    dfs(1LL, 0LL);
    for(i=0;i<n;i++){
        cout << cnt[i+1] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 22656
#include <iostream>
#include <algorithm>
const int MAXN = 1e5+2;
using namespace std;
int a[MAXN<<1];
int dis[MAXN<<1];
int main(){
	int k;
	cin >> k;
	int n;
	cin >> n;
	for(int i = 0;i < n;i++)
	cin >> a[i];
	sort(a,a+n);
	for(int i = 0;i < n-1;i++)
	dis[i] = a[i+1]-a[i];
	dis[n-1] = a[0]+k-a[n-1];
	sort(dis,dis+n);
	int ans;
	ans =k - dis[n-1];
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 1792