akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;

vector<vector<bool> > check, cont;
vector<vector<char> > board;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int w, h;

bool bfs(int i, int j, char t);
int cnt(int i, int j);

int main()
{
    while (cin >> w >> h, w) {
        board.assign(h, vector<char>(w));
        check.assign(h, vector<bool>(w, false));
        cont.assign(h, vector<bool>(w, false));
        getchar();
        bool bl = false, wh = false;
        rep(i, h) {
            rep(j, w) {
                cin >> board[i][j];
                if (board[i][j] == 'W') {
                    wh = true;
                } else if (board[i][j] == 'B') {
                    bl = true;
                }
            }
            getchar();
        }
        if (!bl && ! wh) {
            cout << 0 << " " << 0 << endl;
            continue;
        }
        int white = 0, black = 0;
        rep(i, h) {
            rep(j, w) {
                if (!check[i][j] && board[i][j] == '.') {
                    if (bfs(i, j, 'W')) {
                        white += cnt(i, j);
                    }  
                }
            }
        }
        check.assign(h, vector<bool>(w, false));
        rep(i, h) {
            rep(j, w) {
                if (!check[i][j] && board[i][j] == '.') {
                    if (bfs(i, j, 'B')) {
                        black += cnt(i, j);
                    }  
                }
            }
        }
        cout << black << " " << white << endl;
    }
    return 0;
}


int cnt(int i, int j)
{
    int ret = 1;
    cont[i][j] = true;
    rep(k, 4) {
        int ni = i + dx[k], nj = j + dy[k];
        if (0 <= ni && ni < h && 0 <= nj && nj < w) {
            if (!cont[ni][nj] && board[ni][nj] == '.') {
                ret += cnt(ni, nj);
            }
        }
    }
    return ret;
}

bool bfs(int i, int j, char t)
{
    bool ret = true;
    check[i][j] = true;
    //cout << "(" << i << "," << j << ")" << " ";
    rep(k, 4) {
        int ni = i + dx[k], nj = j + dy[k];
        if (0 <= ni && ni < h && 0 <= nj && nj < w) {
            if (!check[ni][nj]) {
                if (board[ni][nj] == t) {
                    ret &= true;
                } else if (board[ni][nj] == '.') {
                    ret &= bfs(ni, nj, t);
                } else {
                    ret = false;
                }
            }
        }
    }
    return ret;
}

Measured memory_bytes: 3224
import math
n, d = map(int, input().split())
x = [None]*n
ans = 0

for i in range(n):
    x[i] = list(map(int, input().split()))

for i in range(n):
    for j in range(i+1, n):
        res = 0
        for k in range(d):
            res += (x[i][k] - x[j][k])**2
        res = math.sqrt(res)
        if res.is_integer():
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

string S;
int main(void){
    cin >> S;
    char a = S[S.length()-1];
    if(a == '2' or a=='4' or a=='5' or a=='7' or a=='9') cout << "hon" << endl;
    else if(a=='3') cout << "bon" << endl;
    else cout << "pon" << endl;
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if(e-a <= k) puts("Yay!");
    else puts(":(");
    return 0;
}

Measured memory_bytes: 256
loop=int(input())
word=input()
word_list=list()
word_list.append(word)
 
for i in range(loop-1):
  word=input()
  for j in range(len(word_list)):
    if word_list[j]==word:
      print("No")
      break
  if word_list[i][-1]!=word[0]:
    print("No")
    break
  if j!=len(word_list)-1:
    break
  word_list.append(word)
  if i==loop-2:
    print("Yes")

Measured memory_bytes: 3064
S = input()[::-1]
n = len(S)
dp = [0]*2019
dp[0] = 1
X = 0
Y = 1
for s in S:
    Z=(int(s)*Y)%2019
    X = (X+Z)%2019
    dp[X] += 1
    Y = (10*Y)%2019
answer = 0
for i in range(2019):
    answer += dp[i]*(dp[i]-1)/2
print(int(answer))

Measured memory_bytes: 9372
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n;
	cin >> n;
	int d[110];
	rep(i, n) cin >> d[i];
	sort(d,d+n);
	int ans = 0;
	rep(i, n) {
		if (d[i] == d[i + 1]) {
			++ans;
		}
	}
	cout << n-ans << endl;
	return 0;
} 

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		if(b>a){
			System.out.println(1);
	}
	else if ((a%b)!=0){
		int c = a/b + 1;
		System.out.println(c);
	}
	else System.out.println(a/b);
}

}

Measured memory_bytes: 22996
using System;
using System.Linq;
public class c
{
  public static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    char[] X = Console.ReadLine().ToCharArray();
    int i;
    int e=0;
    int w=0;
    int min=99999999;
    int[]E=new int[N];
    int[]W=new int[N];
    for(i=0;i<N-1;i++)
    {
        if(X[i]=='W'){w++;}
      W[i+1]=w;
    }
    for(i=N-1;i>0;i--)
    {
        if(X[i]=='E'){e++;}
      E[i-1]=e;
    }
    for(i=0;i<N;i++)
    {
      if(min>W[i]+E[i])min=(W[i]+E[i]);
    }
    
    Console.WriteLine(min);
  }
}

Measured memory_bytes: 15072
#include <stdio.h>

int main (int argc, char* argv[])
{
  int n, a, b, c, d, i;

  while (scanf("%d", &n) != EOF) {
    i = 0;
    for (a=0; a<10; a++) {
      for (b=0; b<10; b++) {
	for (c=0; c<10; c++) {
	  for (d=0; d<10; d++) {
	    if (a + b + c + d == n) {
	      i++;
	    }
	  }
	}
      }
    }
    printf("%d\n", i);
  }

  return 0;
}

Measured memory_bytes: 0
def read_input():
    n = int(input())
    wlist = list(map(int, input().split()))

    return n, wlist


def submit():
    n, wlist = read_input()

    right = sum(wlist)
    left = 0
    min_diff = right

    for w in wlist:
        left += w
        right -= w


        if abs(right - left) < min_diff:
            min_diff = abs(right - left)

    print(min_diff)



if __name__ == '__main__':
    submit()


Measured memory_bytes: 38492
#include <stdio.h>

int main () {

    int n, x, i, j, k, y;

    for (; ; ) {

        y = 0;

        scanf("%d", &n); scanf("%d", &x);

        if (n == 0 && x == 0) {
            break;
        }

        for (i = 1; i <= n; i++) {
            for (j = 1; j <= n; j++){
                for (k = 1; k <= n; k++) {
                    if (i + j + k == x && i < j && j < k) {
                        y += 1;
                    }
                }
            }
        }

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

    }

    return 0;

}



Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
 
int main()
    {
    int n;
    cin>>n;
    while(n>0)
    {
       int digit=n%10;
        if(digit==7)
        {
            cout<<"Yes";
            return 0;
        }
        n=n/10;
    }
    cout<<"No";
    return 0;
    
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int a;
    int check=1;
    for(int i=0;i<n;i++){
     scanf("%d",&a);
    if(a%2==0){
       if(a%3==0 || a%5==0){
         continue;
       }
       else {
        check=0;
        break;
       }
    }
    }

    if(check==1){
        printf("APPROVED\n");
    }
    else cout<<"DENIED\n";
    return 0;
}

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

namespace CTypicalStairs
{
    class Program
    {
        const int LAW = 1000000007;

        static void Main(string[] args)
        {
            // 入力の取得
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = inputs[0];
            var m = inputs[1];

            // 壊れている床の一覧を取得
            var brokenStairs = new int[m];
            for (var i = 0; i < m; i++)
            {
                brokenStairs[i] = int.Parse(Console.ReadLine());
            }

            // 連続する壊れていない床の距離を計算
            var distances = new int[m + 1];
            for (var i = 0; i <= m; i++)
            {
                var current = i != m ? brokenStairs[i] : n + 1;
                var prev = i != 0 ? brokenStairs[i - 1] : -1;

                // 壊れた階段が連続していたら、0を出力して終了
                if (current - prev == 1)
                {
                    Console.WriteLine(0);
                    return;
                }

                distances[i] = (current - 1) - (prev + 1);
            }

            // 0 ~ a1 - 1 まで P1 通り、a1 + 1 ~ a2 - 1 まで P2 通り… am + 1 ~ N まで Pm+1 通り
            // 総数は P1 * P2 * … * Pm+1 通り
            var maxDistance = distances.Max();
            var patternMap = CalcPatternMap(maxDistance);

            var patternCount = 1;
            foreach (var distance in distances)
            {
                patternCount = (int)(Math.BigMul(patternCount, patternMap[distance]) % LAW);
            }

            // 解答の出力
            Console.WriteLine(patternCount);
        }

        /// <summary>
        /// 各距離までの経路数 % 1000000007 の一覧を返す
        /// </summary>
        /// <param name="maxDistance"></param>
        /// <returns></returns>
        static int[] CalcPatternMap(int maxDistance)
        {
            if (maxDistance < 1) return new[] { 1 };

            var patternMap = new int[maxDistance + 1];

            patternMap[0] = 1;
            patternMap[1] = 1;
            for (var i = 2; i <= maxDistance; i++)
            {
                patternMap[i] = (patternMap[i - 2] + patternMap[i - 1]) % LAW;
            }

            return patternMap;
        }
    }
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	ll n , m ;
	cin>> n >> m ;
	vector<ll> a(n);
	rep(i,n) cin >>a[i];
	map<ll,ll> P;//mod M / 回数
	ll wa = 0 ;P[wa] ++;
	rep(i,n) {
		wa += a[i];
		wa %= m ;
		P[wa] ++ ;
	}
	ll ans = 0 ;
	for(auto x: P){
		ll N = x.second;
		ans += N * (N-1) / 2 ;
	}
	cout << ans << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <cmath>

int main()
{
  int n, d;
  std::cin >> n >> d;
  std::vector<std::vector<int>> pos(n, std::vector<int>(d));
  for(int i=0; i<n; i++)
    for(int j=0; j<d; j++)
      std::cin >> pos[i][j];
  int count=0;
  for(int i=0; i<n-1; i++)
    for(int j=i+1; j<n; j++)
    {
      double d2=0.0;
      for(int k=0; k<d; k++)
        d2 += pow(static_cast<double>(pos[i][k]-pos[j][k]), 2.0);
      if(d2 == pow((double)((int)sqrt(d2)),2.0))
         count++;
    }
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
N, M = map(int, input().split())
H = list(map(int, input().split()))

ans = np.array(list(range(N)))

for _ in range(M):
  A, B = map(int, input().split())
  if H[A-1] > H[B-1]:
    ans[B-1] = -1
  elif H[A-1] < H[B-1]:
    ans[A-1] = -1
  else:
    ans[B-1] = -1
    ans[A-1] = -1
print(len(ans[ans!=-1]))

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

int main()
{
    int n, m, r, l, r_, l_;
    cin >> n; cin >> m;
    cin >> r; cin >> l;
    for (int i=1; i < m; i++) {
        cin >> r_; cin >> l_;
        if (r_ > r) r = r_;
        if (l_ < l) l = l_;
    }
    if (n < l) l = n;
    int cnt = 0;
    for (int i=r; i <= l; i++) cnt++;
    cout << cnt << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n;
  cin >> n;
  vi a(100005);
  ll sum = 0;
  rep(i, n) {
    int A;
    cin >> A;
    a[A]++;
    sum += ll(A);
  }
  int q;
  cin >> q;
  vi b(q), c(q);
  rep(i, q) cin >> b[i] >> c[i];
  rep(i, q) {
    ll sa = ll(c[i] - b[i]);
    sum += ll(sa*a[b[i]]);
    a[c[i]] += a[b[i]];
    a[b[i]] = 0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 4548
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const ll MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
     int n;cin >> n;
     vector<int>a(n);
     for(int i = 0;i<n;i++) cin >> a[i];
     sort(a.begin(),a.end());
     int ans = 0;
     for(int i = 0;i<n-2;i++){
        int k = i+2;
        for(int j = i+1;j<n-1;j++){
            while(a[i]+a[j]>a[k]&&k!=n) k++;
            ans += k - j -1;
        }
     }
     cout << ans;

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

Measured memory_bytes: 3636
from itertools import combinations as comb


def main():
    a, b, c = map(int, input().split())
    li = comb([a, b, c], 2)
    Count = 0
    for l in li:
        if l[0] == l[1]:
            Count += 1

    if Count == 1:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
from collections import defaultdict as dd
N = int(input())

waru = 1000000007

def pwari(n):
    th = round(n ** 0.5)
    ans = (n,1)
    for i in range(2,th+1):
        if n % i ==0:
            ans = (i,n//i)
            break
            
    return(ans)

def soinsu(n):
    pf_dic = dd(lambda:0)
    
    flag = 1
    
    while flag:

        waru,red = pwari(n)[:]
        if waru == n:
            pf_dic[str(waru)] += 1
            flag = 0
        else:
            pf_dic[str(waru)] += 1
            n = red
    return(pf_dic)

p_dic = dd(lambda:0)
for i in range(1,N+1):
    pf_dic = soinsu(i)
#     print(i,pf_dic)
    for p in pf_dic.keys():
#         print(i,p,pf_dic[p])
        p_dic[p] += pf_dic[p]

# print("p_dic:",p_dic)
ans = 1
for p in p_dic.keys():
    if p == "1":
        pass
    else:
        ans *= (p_dic[p]+1)
    
print(ans % waru)
        

Measured memory_bytes: 3316
#include<stdio.h>
int a[501][501]={0},n,m,p,t,i,j,z,d,c,si,sj,qq,s,h,mm;
int main()
{
    scanf("%d %d %d %d",&n,&m,&t,&p);
    while(!((n==0)&&(m==0)&&(p==0)&&(t==0)))
    {
       si=0;
       sj=0;
       /*8
       for(i=1;i<=100;i=i+1)
         for(j=1;j<=100;j=j+1)
           a[i][j]=0;
           */
       //printf();
       for(i=1;i<=m;i=i+1)
         for(j=1;j<=n;j=j+1)
         {
              a[i][j]=1;
         }

       for(z=1;z<=t;z=z+1)
       {
            scanf("%d %d",&d,&c);
            if(d==1)
            {
                for(i=si;i<=m;i=i+1)
                   for(j=sj+c;j>=sj+1;j=j-1)
                    {
                        qq=sj+c-j;
                        if(sj+c+1+qq>n)
                        {
                            n=sj+c+1+qq;
                            for(mm=1;mm<=m;mm=mm+1)
                                a[mm][sj+c+1+qq]=0;
                        }
                        a[i][sj+c+1+qq]=a[i][sj+c+1+qq]+a[i][j];
                    }
               sj=sj+c;
            }
            if(d==2)
            {
                for(j=sj;j<=n;j=j+1)
                   for(i=si+c;i>=si+1;i=i-1)
                    {
                        qq=si+c-i;
                        if(si+c+1+qq>m)
                        {
                            m=si+c+1+qq;
                            for(mm=1;mm<=n;mm=mm+1)
                                a[si+c+1+qq][mm]=0;
                        }
                        a[si+c+1+qq][j]=a[si+c+1+qq][j]+a[i][j];
                    }
                si=si+c;
            }
            /*
            printf("----------\n");
            for(i=1;i<=2*m;i=i+1)
            {

               for(j=1;j<=2*n;j=j+1)
                 printf("%d ",a[i][j]);
               printf("\n");
            }
            printf("----------\n");
            printf("si=%d sj=%d\n",si,sj);
            */

       }
       /*
       printf("----------\n");
       for(i=1;i<=2*m;i=i+1)
       {

           for(j=1;j<=2*n;j=j+1)
            printf("%d ",a[i][j]);
           printf("\n");
       }
       printf("----------\n");
       printf("si=%d sj=%d\n",si,sj);
       */
       for(z=1;z<=p;z=z+1)
       {
           scanf("%d %d",&d,&c);
           d=d+1;
           c=c+1;
           printf("%d\n",a[c+si][d+sj]);
       }

       scanf("%d %d %d %d",&n,&m,&t,&p);
    }
    return 0;
}


Measured memory_bytes: 2648
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> G[1000000];
vector<pair<int, int> > bridge;
vector<int> articulation;
int ord[1000000], low[1000000];
bool vis[1000000];

void dfs(int v, int p, int &k)
{
	vis[v] = true;
	
	ord[v] = k++;
	low[v] = ord[v];
	
	bool isArticulation = false;
	int ct = 0;
	
	for (int i = 0; i < G[v].size(); i++){
		if (!vis[G[v][i]]){
			ct++;
			dfs(G[v][i], v, k);
			low[v] = min(low[v], low[G[v][i]]);
			if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
			if (ord[v] < low[G[v][i]]) bridge.push_back(make_pair(min(v, G[v][i]), max(v, G[v][i])));
		}
		else if (G[v][i] != p){
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}
	
	if (p == -1 && ct > 1) isArticulation = true;
	if (isArticulation) articulation.push_back(v);
}

int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);
	
	for (int i = 0; i < m; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		G[--x].push_back(--y);
		G[y].push_back(x);
	}
	
	int k = 0;
	for (int i = 0; i < n; i++){
		if (!vis[i]) dfs(i, -1, k);
	}
	
	sort(bridge.begin(), bridge.end());
	sort(articulation.begin(), articulation.end());
	

	printf("%d\n", bridge.size());

	
	return (0);
}

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

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,k; cin>>n>>k;
	vector<int> a(n);
	int g=0;
	for (int i=0; i<n; i++)
		cin>>a[i], g=gcd(g,a[i]);
	for (auto it : a)
		if(it>=k && (it-k)%g==0) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
    char b;
    cin >> b;
    
    switch(b) {
        case 'A':
            cout << 'T';
            break;
        case 'C':
            cout << 'G';
            break;
        case 'G':
            cout << 'C';
            break;
        case 'T':
            cout << 'A';
            break;
    }
    cout << endl;
}


Measured memory_bytes: 256
/*input
11 10 9
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, n; cin >> a >> b >> n;
    cout << (n < b - 1 ? (a * n)/b - a * (n/b) : (a * (b - 1))/b - a * ((b - 1)/b));

    return 0;
}

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

const int MAX = 100005;

// int main(){
//     int n, m, P[MAX];
//     cin >> n >> m;

//     for(int i = 0; i <= n; i++){
//         P[i] = 0;
//     }

//     int p;
//     int ac = 0;
//     int wa = 0;
//     string s;
//     rep(i,m){
//         cin >> p >> s;
//         if(s == "AC"){
//             if(P[p] = -1) continue;
//             ac++;
//             wa += P[p];
//             P[p] = -1;
//         }else{
//             if(P[p] = -1) continue;
//             P[p]++;
//         }
//     }

//     cout << ac << " " << wa << endl;

//     return 0;
// }

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

    int wa_num[MAX];
    for(int i = 0; i <= n; i++) wa_num[i] = 0;

    int p;
    string s;
    int ac = 0;
    int wa = 0;
    for(int i = 0; i < m; i++){
        cin >> p >> s;
        if(s == "AC"){
            if(wa_num[p] >= 0){
                ac++;
                wa += wa_num[p];
                wa_num[p] = -1;
            }
        }else if(s == "WA"){
            if(wa_num[p] >= 0) wa_num[p]++;
        }
    }

    cout << ac << " " << wa << endl;
}

Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from math import ceil

D, G = [int(t) for t in input().split()]
p = []
c = []
for i in range(D):
    p_, c_ = [int(t) for t in input().split()]
    p.append(p_)
    c.append(c_)

def solve(G, i):
    """100i点以下の問題だけでGを達成する最小問題数"""
    if i <= 0:
        return float('inf')
    n = min(ceil(G / (100 * i)), p[i-1])
    s = 100 * i * n
    if n == p[i-1]:
        s += c[i-1]
    if G > s:
        n += solve(G - s, i - 1)
    return min(n, solve(G, i - 1))

print(solve(G, D))

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

#define M 11000

int main() {
  int a, b, i; cin >> a >> b;
  int ans =-1;
  rep (i, M) {
    if (i *8 / 100 == a && i /10 == b){
      ans = i;
      break;
    }
  }
cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
LL n,a,b;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    cout<<n/(a+b)*a+min(n%(a+b),a)<<endl;
    return 0;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 100'000 + 6;

inline i64 sign(i64 x) {
    if (x > 0) {
        return 1;
    }
    if (x < 0) {
        return -1;
    }
    return 0;
}

i64 gcd(i64 a, i64 b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

i64 op(pair<pair<i64, i64>, i64> c, map<pair<pair<i64, i64>, i64>, i64>& q) {
    pair<pair<i64, i64>, i64> p = { {c.first.second, c.first.first}, -c.second };
    auto it = q.find(p);
    if (it == q.end()) {
        return 0;
    }

    auto r = it->second;
    q.erase(it);
    return r;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    i64 n;
    cin >> n;

    vector<i64> a(n);
    vector<i64> b(n);

    for (i64 i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    i64 z = 0;
    map<pair<pair<i64, i64>, i64>, i64> q;
    for (i64 i = 0; i < n; i++) {
        if (!a[i] && !b[i]) {
            z += 1;
            continue;
        }
        if (!a[i]) {
            q[{{0, 1}, sign(sign(a[i]) * sign(b[i]))}] += 1;
            continue;
        }
        if (!b[i]) {
            q[{{1, 0}, sign(sign(a[i]) * sign(b[i]))}] += 1;
            continue;
        }

        i64 g = gcd(abs(a[i]), abs(b[i]));
        q[{{abs(a[i]) / g, abs(b[i]) / g}, sign(sign(a[i]) * sign(b[i]))}] += 1;
    }

    vector<i64> p;
    p.push_back(1);
    for (i64 i = 1; i <= n; i++) {
        p.push_back((p.back() * 2) % mod);
    }

    i64 R = 1;
    while(!q.empty()) {
        auto it = q.begin();
        auto c = *it;
        q.erase(it);
        i64 r = p[c.second] + p[op(c.first, q)] - 1;
        r %= mod;
        R *= r;
        R %= mod;
    }

    R -= 1;
    R += z;
    R = (R + mod) % mod;

    cout << R << endl;


    return 0;
}

Measured memory_bytes: 24068
#include <bits/stdc++.h>
using namespace std;
#define arep(i, x, n) for (int i = int(x); i < (int)(n); i++)
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9 + 7
using ll = long long;

int main() {
    ll a;
    ll b;
    ll c;
    cin >> a >> b >> c;

    ll cnt = 0;
    bool isFind = false;
    if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) {
        isFind = true;
    } else if (a == b && b == c) {
        cnt = -1;
        isFind = true;
    }
    while (!isFind) {
        ll tempA = a / 2;
        ll tempB = b / 2;
        ll tempC = c / 2;

        a = tempB + tempC;
        b = tempA + tempC;
        c = tempA + tempB;

        cnt = cnt + 1;
        if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) {
            isFind = true;
        } else if (a == b && b == c) {
            cnt = -1;
            isFind = true;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
 
int a[2005];
 
int main() {
  int n, k, q;
  cin >> n >> k >> q;
  for (int ni = 0; ni < n; ni++) {
    cin >> a[ni];
  }
  int answer = 1000000000;
  for (int ni = 0; ni < n; ni++) {
    vector<int> candidates;
    vector<int> buffer;
    for (int nj = 0; nj < n; nj++) {
      if (a[nj] < a[ni]) {
        if (buffer.size() >= k) {
          sort(buffer.begin(), buffer.end());
          candidates.insert(candidates.end(), buffer.begin(), buffer.begin() + (buffer.size() - k + 1));
        }
        buffer.clear();
      } else {
        buffer.push_back(a[nj]);
      }
    }
    if (buffer.size() >= k) {
      sort(buffer.begin(), buffer.end());
      candidates.insert(candidates.end(), buffer.begin(), buffer.begin() + (buffer.size() - k + 1));
    }
    sort(candidates.begin(), candidates.end());
    if (candidates.size() >= q) {
      answer = min(answer, candidates[q - 1] - candidates[0]);
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import collections
import math
list = input().split()
N = int(list[0])
M = int(list[1])
a = input().split()
x = 0
hako = [0]
for i in a:
    hako.append(int(i))
B = []
b = 0
for i in hako:
    b += i
    B.append(b%M)
c = collections.Counter(B)
aaa =[]
for i in c:
    if c[i] >= 2:
        aaa.append(c[i])
def kumi(n):
    return int(math.factorial(n)/(2*math.factorial(n-2)))
for i in aaa:
    x += kumi(i)
print(x)

Measured memory_bytes: 22884
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define pii pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define w 405
int n;
ll op(ll x , ll y)
{
    return x+y;
}
ll combine(vl &a)
{
   ll ans[w+1][w+1];
   ll ope[w+1][w+1];
   for(int i=1;i<=n;i++)
   {
       ans[i][i]=0;
       ope[i][i]=a[i];
   }
   for(int l=2;l<=n;l++)
   {
       for(int i=1;i<=n-l+1;i++)
       {
           int j=i+l-1;
           ans[i][j]=1e18+5;
           for(int k=i;k<j;k++)
           {
               ll temp=ans[i][k]+ans[k+1][j]+ope[i][k]+ope[k+1][j];
               ope[i][j]=op(ope[i][k],ope[k+1][j]);
               ans[i][j]=min(ans[i][j],temp);
           }
       }
   }
   return ans[1][n];
}
void solve()
{
//    int n;
    cin>>n;
    vl a(n+1);
    loop(i,1,n+1)
    cin>>a[i];
    ll x=combine(a);
    cout<<x;
}
int main() {
	// your code goes here
	io;
	int t ;

    solve();
	return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int i, j, k;
  int n1 = mid -left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  i=0, j=0;
  for(k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  int mid;
  if(left+1 < right) {
    mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

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

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);

  return 0;
}


Measured memory_bytes: 5588
n, m = map(int, input().split())
if n % 2:
    for i in range(m): print(i + 1, n - i)
elif n % 4 == 0:
    for i in range(m // 2 + 1): print(i + 1, n - i)
    for i in range(m // 2 + 1, m): print(i + 1, n - i - 1)
else:
    for i in range(m // 2): print(i + 1, n - i)
    for i in range(m // 2, m): print(i + 1, n - i - 1)

Measured memory_bytes: 9280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int temp=n-1;
	int a[n+1]={0};
	while(temp--)
	{
		int x;
		cin>>x;
		a[x]=a[x]+1;	
	}
	
	for(int i=1;i<=n;i++)
	cout<<a[i]<<endl;
	
}

Measured memory_bytes: 4416
#include <iostream>

using namespace std;

int main()
{
    int year, month, day;

    while (cin >> year >> month >> day) {
        if (year >= 1990 || (year == 1989 && month >= 2) ||
            (year == 1989 && month == 1 && day >= 8))
            cout << "heisei " << year - 1989 + 1;
        else if (year >= 1927 || (year == 1926 && month == 12 && day >= 25))
            cout << "showa " << year - 1926 + 1;
        else if (year >= 1913 || (year == 1912 && month >= 8) ||
                 (year == 1912 && month == 7 && day >= 30))
            cout << "taisho " << year - 1912 + 1;
        else if (year >= 1869 || (year == 1868 && month >= 10) ||
                 (year == 1868 && month >= 9 && day >= 8))
            cout << "meiji " << year - 1868 + 1;
        else {
            cout << "pre-meiji" << endl;
            continue;
        }

        cout << " " << month << " " << day << endl;
    }

    return 0;
}

Measured memory_bytes: 1164
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    int powder = sc.nextInt();
    int[] donuts = new int[num];
    for (int i = 0; i < num; i++) {
      donuts[i] = sc.nextInt();
      powder -= donuts[i];
    }
    Arrays.sort(donuts);
    System.out.println(num + powder / donuts[0]);
    
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

struct dat {
    int a, b, c, d;
};

int N, M, Q;
vector<dat> x;
vector<int> num;
int ans = 0;

void dfs(int depth) {
    if (depth == N) {
        int tmp = 0;
        for (int i = 0; i < Q; ++i) {
            if (num[x[i].b] - num[x[i].a] == x[i].c)
                tmp += x[i].d;
        }
        ans = max(ans, tmp);
        return;
    }

    int s = (depth == 0 ? 0 : num[depth - 1]);
    for (int i = s; i < M; ++i) {
        num[depth] = i;
        dfs(depth + 1);
    }
}

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

    cin >> N >> M >> Q;
    x.resize(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> x[i].a >> x[i].b >> x[i].c >> x[i].d;
        x[i].a--, x[i].b--;
    }

    num.resize(N);
    dfs(0);
    cout << ans << endl;
    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

const string NO = "IMPOSSIBLE";

void solve(long long A, long long B) {
  if (B < A)
    swap(A, B);

  if ((B + A) % 2 == 0) {
    cout << (B + A) / 2 << endl;
  } else {
    cout << NO << endl;
  }
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
long long sum[200005],xo[200005];
int n;
long long x;
int check(int x,int y){
	/*for(int i=1;i<=22;i++){
		if(sum[x][i]%2==1){
			if(sum[x][i]!=sum[y][i]) return 0;
		}
		else {
			if(sum[y][i]>sum[x][i]+1) return 0;
		}
	}
	return 1;*/
	if((xo[y]^xo[x])==(sum[y]-sum[x])){
		return 1;
	}
	else return 0;
}
long long ans=0,cnt;
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		cnt=0;
		sum[i]=sum[i-1]+x;
		xo[i]=xo[i-1]^x;
	}
	for(int i=1;i<=n;i++){
		int l=1,r=i;
		while(l<r){
			int mid=(l+r)/2;
			if(check(mid-1,i)) r=mid;
			else l=mid+1;
		}
		ans+=i-l+1;
	}
	cout<<ans;
}

Measured memory_bytes: 6756
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define fd(i,j,k) for(int i=j;i>=k;i--)
#define fr(i,j) for(int i=beg[j];i;i=nex[i])
using namespace std;
int const mn=5e5+3;
int n,q,d[mn],f[mn],g[mn];
int main(){
	scanf("%d%d",&n,&f[0]);
	fo(i,1,n)scanf("%d",&d[i]),f[i]=min(f[i-1],abs(f[i-1]-d[i]));
	fd(i,n,1)g[i]=(d[i]<=g[i+1]*2+1)?d[i]+g[i+1]:g[i+1];
	scanf("%d",&q);
	fo(i,1,q){
		int x;
		scanf("%d",&x);
		if(f[x-1]>g[x+1])printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 7680
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mp make_pair
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
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; }


int migi[2002][2002];
int hidari[2002][2002];
int ue[2002][2002];
int shita[2002][2002];

int main(){
  int h, w; cin >> h >> w;
  vector<vector<char>> v(h, vector<char> (w));
  rep(i, h)rep(j, w) cin >> v[i][j];

  int ans = 0;

  rep(i, h){
    rep(j, w){
      if(v[i][j]=='#') migi[i][j] = 0;
      else if(j == 0) migi[i][j] = 1;
      else migi[i][j] = migi[i][j-1] + 1;
    }
  }

  rep(i, h){
    rrep(j, w){
      if(v[i][j]=='#') hidari[i][j] = 0;
      else if(j == w-1) hidari[i][j] = 1;
      else hidari[i][j] = hidari[i][j+1] + 1;
    }
  }

  rep(j, w){
    rep(i, h){
      if(v[i][j]=='#') ue[i][j] = 0;
      else if(i == 0) ue[i][j] = 1;
      else ue[i][j] = ue[i-1][j] + 1;
    }
  }

  rep(j, w){
    rrep(i, h){
      if(v[i][j]=='#') shita[i][j] = 0;
      else if(i == h-1) shita[i][j] = 1;
      else shita[i][j] = shita[i+1][j] + 1;
    }
  }

  rep(i, h) {
    rep(j, w){
      if(v[i][j]=='#') continue;
      chmax(ans, ue[i][j] + shita[i][j] + hidari[i][j] + migi[i][j] - 3);
    }
  }

  cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    vector<long long>vec(N+1,0);
    vec.at(0) = 2ll;
    if(N>0){
      vec.at(1) = 1ll;
    }
    if(N>1){
      for(int i =0;i<N-1;i++){
        vec.at(i+2)= vec.at(i+1)+vec.at(i);
      }
    }
    cout << vec.at(N) << endl;

}

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

using namespace std;


int main()
{
	int n;
	cin >> n;
	vector<int> w(n);
	vector<int> sum(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		if (i > 0) sum[i] = sum[i - 1] + w[i];
		else sum[0] = w[0];
	}

	for (int i = 1; i < n; i++) {
		if ((sum[i - 1] < sum[n - 1] / 2) && (sum[i] >= sum[n - 1] / 2)) {
			cout << min(abs(sum[n-1] - 2 * sum[i - 1]), abs(sum[n-1] - 2 * sum[i]));
			break;
		}
	}

    return 0;
}

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

int main() {
 
   
        long long n,i,j,k,sum=0,count=0,ans=0;
        cin>>n;
        string s,t;
        cin>>s>>t;
        for(i=0;i<n;i++)
        {
            cout<<s[i]<<t[i];
        }
        
        
       

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

lint fold(string s) {
    int n = s.size();
    lint d = 1;
    lint res = 0;

    for (int i = n-1; i >= 0; i--) {
        int nd = s[i] - '0';
        res += nd * d;
        d *= 10;
    }

    return res;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();

    lint res = 0;

    rep(f, 1 << (n-1)) {
        vector<string> v;
        string p = "";

        rep(i, n) {
            p += s[i];
            if ((f >> i) & 1) {
                v.push_back(p);
                p = "";
            }
        }
        if (p.size() > 0) v.push_back(p);

        for (auto&& e : v) {
            res += fold(e);
        }
    }

    cout << res << endl;
    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> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 1e5+10;

int N;
ll A[MAX], B[MAX];

ll solve() {
    ll res = 0;
    REP (i, N) {
        ll k = min(A[i], B[i]);
        res += k;
        A[i] -= k;
        B[i] -= k;
        k = min(A[i+1], B[i]);
        res += k;
        A[i+1] -= k;
        B[i] -= k;
    }
    return res;
}

int main() {
    cin >> N;
    REP (i, N+1) cin >> A[i];
    REP (i, N) cin >> B[i];
    cout << solve() << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



ll N;
vector<ll> C;


ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}


int main(){

	scanf("%lld",&N);

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

		scanf("%lld",&tmp);
		C.push_back(tmp);
	}

	sort(C.rbegin(),C.rend());

	ll mult1 = mod_pow(2,N-1,MOD);
	ll mult2 = mod_pow(2,N-2,MOD);

	ll ans = 0;

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

		tmp = mult1+mult2*i;
		tmp %= MOD;
		tmp *= C[i];
		tmp %= MOD;

		ans += tmp;
		ans %= MOD;
	}

	tmp = mod_pow(2,N,MOD);
	ans *= tmp;

	ans %= MOD;

	printf("%lld\n",ans);

	return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, y;
	cin >> n >> y;
	y /= 1000;
	vvi dp(n + 1, vi(y + 1, 0));
	dp[0][0] = 1;
	REP(i, n) {
		REP(j, y + 1) {
			if (j >= 1 && dp[i][j - 1])		dp[i + 1][j] = 1;


			if (j >= 5 && dp[i][j - 5])	dp[i + 1][j] = 5;

			if (j >= 10 && dp[i][j - 10])dp[i + 1][j] = 10;
		}
	}
	if (dp[n][y] == 0) {
		cout << -1 << " " << -1 << " " << -1 << endl;
		return 0;
	}
	else {
		int a = 0, b = 0, c = 0, j = y;
		RREP(i, n) {
			if (dp[i + 1][j] == 1) {
				c++;
				j--;
			}
			else if (dp[i + 1][j] == 5) {
				b++;
				j -= 5;
			}
			else {
				assert(dp[i + 1][j]);
				a++;
				j -= 10;
			}
		}
		cout << a << " " << b << " " << c << endl;

	}
}


Measured memory_bytes: 156800
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int y_ = sc.nextInt();
		for(int x = 0; x <= n; x++) {
			for(int y = 0; y <= n-x; y++) {
				int z = n-x-y;
				if(y_ == 10000*x + 5000*y + 1000*z) {
					System.out.println(x + " " + y + " " + z);
					return;
				}
			}
		}
		System.out.println("-1 -1 -1");
	}
}

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

int main()
{
  int n;
  cin>>n;
   int a,b,c;
   int A[n][3];
  for(int i=0;i<n;i++)
  {

    cin>>A[i][0]>>A[i][1]>>A[i][2];
  }

  int dp[n][3];

  dp[0][0]=A[0][0];
  dp[0][1]=A[0][1];
  dp[0][2]=A[0][2];

  for(int i=1;i<n;i++)
  {
    a=dp[i-1][0];
    b=dp[i-1][1];
    c=dp[i-1][2];

    dp[i][0]=max(b,c)+A[i][0];

    dp[i][1]=max(a,c)+A[i][1];

    dp[i][2]=max(a,b)+A[i][2];


      
  }

   cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
   return 0;
}



Measured memory_bytes: 2560
[n,a,b] = [int(i) for i in input().split()]
cnt = 0
for i in range(1,n+1):
  t = i
  s = 0
  while t != 0:
    s += t % 10
    t //= 10
  if s >= a and s <= b:
    cnt += i
print(cnt)

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

int main(){

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

  
  if(n<m)for(int i=0;i<m;i++)cout<<n;
  else for(int i=0;i<n;i++)cout<<m;
}


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

int main() {
  std::string s;
  std::map<char, int> count;

  while (std::cin >> s) {
    std::transform(s.cbegin(), s.cend(), s.begin(), tolower);
    for(auto c:s){
      count[c]++;
    }
  }

  for (char i = 'a'; i <= 'z'; i++) {
    std::cout << i << " : " << count[i] << std::endl;
  }
}



Measured memory_bytes: 3220
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&c<48)c=getchar();if(c=='-')f=-1,c=getchar();while(c>47)x=x*10+(c^48),c=getchar();return f*x;}

const int maxn = 2e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;

int n, m;
int node[maxn<<2], lazy[maxn<<2];

inline void push_down(int l, int r, int now) {
    int m=(l+r)/2, &d=lazy[now];
    lazy[now<<1]=d, lazy[now<<1|1]=d;
    node[now<<1]=l-d, node[now<<1|1]=m+1-d;
    d=0;
}

void update(int x, int y, int d, int l=1, int r=n, int now=1) {
    if(x<=l&&r<=y) {
        node[now]=l-d;
        lazy[now]=d;
        return;
    }
    if(lazy[now]) push_down(l,r,now);
    int m=(l+r)/2;
    if(x<=m) update(x,y,d,l,m,now<<1);
    if(y>m) update(x,y,d,m+1,r,now<<1|1);
    node[now]=min(node[now<<1],node[now<<1|1]);
}

int query(int x, int l=1, int r=n, int now=1) {
    if(l==r) return l-node[now];
    if(lazy[now]) push_down(l,r,now);
    int m=(l+r)/2, ans;
    if(x<=m) ans=query(x,l,m,now<<1);
    else ans=query(x,m+1,r,now<<1|1);
    node[now]=min(node[now<<1],node[now<<1|1]);
    return ans;
}

int main() {
    m=read(), n=read();
    for(int i=1; i<=m; ++i) {
        int a=read(), b=read();
        if(a==1) update(a,b,-inf);
        else update(a,b,query(a-1));
        printf("%d\n", node[1]>n?-1:i+node[1]);
    }
}

Measured memory_bytes: 7796