akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())

ts = {}
tlis = []

for i in range(N):
    B,C,A = map(int,input().split())

    if A not in ts:
        tlis.append(A)
        ts[A] = []
    ts[A].append([B,C])

ys = {}
ylis = []

for i in range(M):
    A,B,C = map(int,input().split())

    if A not in ys:
        ylis.append(A)
        ys[A] = []
    ys[A].append([B,C])

tlis.sort()
ylis.sort()

import bisect

nowi = bisect.bisect_right(tlis,0) - 1
nowj = bisect.bisect_right(ylis,0) - 1

#print (tlis,ylis,nowi,nowj)

for i in ts:
    
    ts[i].sort()

    new = []
    lastl = None
    lastr = None

    for tmp in ts[i]:
        nl,nr = tmp

        if lastl == None:
            lastl = nl
            lastr = nr

        elif lastr < nl:
            new.append([lastl,lastr])
            lastl = nl
            lastr = nr

        else:
            lastr = nr

    new.append([lastl,lastr])
    ts[i] = new

for i in ys:
    
    ys[i].sort()

    new = []
    lastl = None
    lastr = None

    for tmp in ys[i]:
        nl,nr = tmp

        if lastl == None:
            lastl = nl
            lastr = nr

        elif lastr < nl:
            new.append([lastl,lastr])
            lastl = nl
            lastr = nr

        else:
            lastr = nr

    new.append([lastl,lastr])
    ys[i] = new


from collections import deque

q = deque([ [nowi,nowj] ])
import sys
ans = 0

end = {}
end[(nowi,nowj)] = 1

if len(tlis) < 2 or len(ylis) < 2:
    print ("INF")
    sys.exit()

while len(q) > 0:

    ni,nj = q.popleft()

    
    if ni == -1 or nj == -1 or ni == len(tlis)-1 or nj == len(ylis)-1:
        print ("INF")
        sys.exit()

    up = ylis[nj]
    do = ylis[nj + 1]
    le = tlis[ni]
    ri = tlis[ni + 1]

    #print (ni,nj,up,do,le,ri)

    ans += (do-up) * (ri-le)

    #up
    flag = True

    nex = (ni,nj-1)

    if nex not in end:
        for tmp in ys[up]:
            L,R = tmp

            if L <= le and ri <= R:
                flag = False
                break

        if flag:
            end[nex] = 1
            q.append([nex[0],nex[1]])

    nex = (ni,nj+1)
    flag = True

    if nex not in end:
        for tmp in ys[do]:
            L,R = tmp

            if L <= le and ri <= R:
                flag = False
                break

        if flag:
            end[nex] = 1
            q.append([nex[0],nex[1]])

    nex = (ni-1,nj)
    flag = True
    if nex not in end:
        for tmp in ts[le]:
            L,R = tmp

            if L <= up and do <= R:
                flag = False
                break

        if flag:
            end[nex] = 1
            q.append([nex[0],nex[1]])

    nex = (ni+1,nj)
    flag = True
    if nex not in end:
        for tmp in ts[ri]:
            L,R = tmp

            if L <= up and do <= R:
                flag = False
                break

        if flag:
            end[nex] = 1
            q.append([nex[0],nex[1]])

print (ans)
        


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

const int maxi=1e6+5;
ll fac[maxi],inv[maxi],finv[maxi];
void cominit(){
  fac[0]=fac[1]=finv[0]=inv[1]=finv[1]=1;
  for(int i=2;i<maxi;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll com(int n,int k){
  if(n<k||n<0||k<0)return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

//a^n.mod
ll powmod(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cominit();
  ll n,m,k;cin>>n>>m>>k;
  ll ans=0,tmp=m;
  for(int x=n-1;x>=0;x--){
      ll now=tmp*com(n-1,x)%mod;
      if(x<=k)ans+=now;
      ans%=mod;
      tmp=tmp*(m-1)%mod;
  }
  cout<<ans<<endl;
  return 0;
  }


Measured memory_bytes: 27068
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	//int lo= 1, hi=50000, mid;
	//double x=-1;
	int i;
	bool flag = false;
	for(i=1; i<=(n+1); i++){
		if(int(i*1.08)==n){
			//x = n;
			flag = true;
			break;
		}
	}
	if(flag){
		cout << i << endl;
	}
	else{
		cout << ":(" << endl;
	}
	return 0;
}


Measured memory_bytes: 3616
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
class UnionFind:
    #ノード番号は0-indexである
    def __init__(self, n):
        self.parents = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.length = [1 for _ in range(n)] 
        self.numberOfElements = n
    #UnionFindを初期化する関数
    def makeSet(self, n):
        self.parents = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.length = [1 for _ in range(n)]
        self.numberOfElements = n

    #ノードxのrootを探して返す関数
    def findRoot(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.findRoot(self.parents[x])
            return self.parents[x]

    #ノードxとノードyを連結する関数
    def uniteNode(self, x, y):
        x = self.findRoot(x)
        y = self.findRoot(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parents[x] = y
            self.length[y] += self.length[x]
        else:
            self.parents[y] = x
            self.length[x] += self.length[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    #ノードxが含まれるグループの要素数を返す関数
    def getLength(self, x):
        x = self.findRoot(x)
        return self.length[x]        

    #ノードxとノードyが同じグループであるかを返す関数
    def isSameGroup(self, x, y):
        return self.findRoot(x) == self.findRoot(y)

    #グループの数を返す関数
    def getNumberOfGroup(self):
        s = set()
        for i in range(self.numberOfElements):
            s.add(self.findRoot(i))
        return len(s)

def main():
    n, m = map(int, readline().split())
    uf = UnionFind(n)
    for _ in range(m):
        x, y, z = map(int, readline().split())
        uf.uniteNode(x-1, y-1)
    print(uf.getNumberOfGroup())
if __name__ == '__main__':
    main()


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

using namespace std;

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

ll sqr(ll x) {
  return x * x;
}

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

  ll N, D, x, y, ans = 0ll;
  cin >> N >> D;
  for(int i = 0; i < N; ++i) {
    cin >> x >> y;
    ans += (sqr(x) + sqr(y) <= sqr(D));
  }
  cout << ans << "\n";
  
  return 0;
}


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

string s;
int main(){
    cin >> s;
    int ans = 0;
    int n = s.size();
    for(int i = 0;i<n;i++){
        ans += (s[i] - '0');
    }
    if(ans % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3756
import numpy as np
import math

def is_month(month):
    if (month >= 1) and (month <= 12):
        return True
    else:
        return False

def is_yymm(one, two):
    if is_month(two):
        return True
    else:
        return False

def is_mmyy(one, two):
    if is_month(one):
        return True
    else:
        return False
def main():
    S = input()
    one = int(S[0:2])
    two = int(S[2: 4])
    if is_yymm(one, two) and is_mmyy(one, two):
        print("AMBIGUOUS")
    elif(is_yymm(one, two) and ~is_mmyy(one, two)):
        print("YYMM")
    elif(~is_yymm(one, two) and is_mmyy(one, two)):
        print("MMYY")
    else:
        print("NA")

if __name__ == '__main__':
    main()

Measured memory_bytes: 18860
W,H,N=map(int,input().split())
xl,xr,yh,yl=0,W,H,0
for i in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        xl=max(xl,x)
    elif a==2:
        xr=min(xr,x)
    elif a==3:
        yl=max(yl,y)
    elif a==4:
        yh=min(yh,y)
print(max(xr-xl,0)*max(yh-yl,0))

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

const int N = 1e6 + 100;
const int md = 998244353;

int n, a1[N], a2[N];
int f[N], g[N], mu[N];
int pr[N], tot;
int inv[N];
bool vis[N];

void prew(int mx) {
  inv[1] = 1, mu[1] = 1;
  for (int i = 2; i <= mx; i++) {
    inv[i] = 1ll * (md - md / i) * inv[md % i] % md;
    if (vis[i] == 0) {
      pr[++tot] = i;
      mu[i] = md - 1;
    }
    for (int j = 1; j <= tot && i * pr[j] <= mx; j++) {
      vis[i * pr[j]] = 1;
      if (i % pr[j] == 0) break ;
      mu[i * pr[j]] = md - mu[i];
    }
  }
  for (int i = 1; i <= mx; i++) {
    for (int j = i * 2; j <= mx; j += i) {
      a1[i] = (a1[i] + a1[j]) % md;
      a2[i] = (a2[i] + a2[j]) % md;
    }
    g[i] = 1ll * (1ll * a1[i] * a1[i] - a2[i] + md) % md * inv[2] % md;
  }
}

int main() {
  scanf("%d", &n);
  int mx = -1;
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    mx = max(mx, a);
    a1[a] = (a1[a] + a) % md;
    a2[a] = (a2[a] + 1ll * a * a % md) % md;
  }
  prew(mx);
  int ans = 0;
  for (int d = 1; d <= mx; d++) {
    for (int T = d, t = 1; T <= mx; T += d, t++) {
      ans = (ans + 1ll * inv[d] * mu[t] % md * g[T] % md) % md;
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 24448
#include<cstdio>
#include<iostream>
using namespace std;
const long long INF=1e18;
long long a,b,c;
long long k;
long long Abs(long long x){
	return x<0?-x:x;
}
int main(){
	scanf("%lld%lld%lld",&a,&b,&c);
	scanf("%lld",&k);
	if(Abs(a-b)>INF){printf("Unfair\n");return 0;}
	if(k%2==1){
		printf("%lld\n",b-a);
	}else{
		printf("%lld\n",a-b);
	}
	return 0;
}


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

int main(){
    int N;
    set<int> mochi;

    cin >> N;
    for(int i=0;i<N;i++){
        int d;
        cin >> d;
        mochi.insert(d);
    }

    cout << mochi.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <utility>
#include <queue>
#include <bitset>
#include <math.h>
#include <numeric>
#include <stack>

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

int gcd(int x,int y){
    return y ? gcd(y,x%y) : x;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m1,m2,d1,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1!=m2)cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
while 1:
	n = input()
	if n == 0: break
	a = map(int,raw_input().split())
	da = [a[i+1] - a[i] for i in range(n)]
	d = sorted(list(set(da)), key = lambda x:da.count(x))[-1]
	for i in range(n):
		if i == 0 and a[i] + d != a[i+1]:
			if a[i+1] + d != a[i+2]:
				print a[i+1]
			else:
				print a[i]
			break
		elif a[i] + d != a[i+1]:
			print a[i+1]
			break

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

int d[1000][1000],ans[1000][1000];
int dx[]{1,-1,0,0},dy[]{0,0,1,-1};
int main(){
	int r,c,x1,y1,x2,y2;cin>>r>>c>>x1>>y1>>x2>>y2;
	queue<P>que;
	memset(d,-1,sizeof(d));
	ans[x1][y1]=1;d[x1][y1]=0;que.push(P(x1,y1));
	while(!que.empty()){
		P p=que.front();que.pop();
		rep(i,4){
			int nx=p.first+dx[i]+r,ny=p.second+dy[i]+c;
			while(nx>=r)nx-=r;while(ny>=c)ny-=c;
			if(d[nx][ny]==-1){
				d[nx][ny]=d[p.first][p.second]+1;
				que.push(P(nx,ny));
			}
			if(d[nx][ny]==d[p.first][p.second]+1)
				(ans[nx][ny]+=ans[p.first][p.second])%=MOD;
		}
	}
	printf("%d\n",ans[x2][y2]);
}

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

int H,W;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
vector<vector<int> > maze;

bool range(int i, int j){
  return (i>=0 && i<W && j>=0 && j<H && maze[i][j] != 0);
}

void dfs(int i, int j){
  int l,check = maze[i][j];
  maze[i][j] = 0;
  REP(l,4){
    if(range(i+dx[l],j+dy[l]) && check == maze[i+dx[l]][j+dy[l]]) dfs(i+dx[l],j+dy[l]);
  }
}

int main(void){
  int i,j,count;
  while(true){
    count = 0;
    cin >> H >> W;
    if(H*W==0) break;
    maze = vector<vector<int> >(W,vector<int>(H));
    REP(j,H)REP(i,W){
      char x;
      cin >> x;
      if(x=='#') maze[i][j] = 1;
      else if(x=='@') maze[i][j] = 2;
      else maze[i][j] = 3;
    }
    REP(j,H)REP(i,W){
      if(range(i,j)){
        dfs(i,j);
        count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}



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

using namespace std;

int main()
{
         int n, k;
        cin >> n >> k;
        vector<int> h(n);
        vector<int> dp(n);
        for (int i = 0; i < n; i++)
            cin >> h[i];
        for (int i = 0; i < n; i++)
        {
            bool first = true;
            for (int j = 1; j <= k; j++)
            {
                if (i - j >= 0)
                {
                    if (first)
                    {
                        dp[i] = dp[i - j] + abs(h[i] - h[i - j]);
                        first = false;
                    }
                    else
                        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
                }
            }
        }
        cout << dp[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
using namespace std;



int main(int argc, char *args[]) {
	string s;
	
	cin >> s;
	int N = s.size();
	string ans;
	for (int i = 0; i < N; i += 2) {
		ans += s[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((s (read-line))
         (n (length s))
         (dp (make-array (list (+ n 1) 13) :element-type 'uint32 :initial-element 0)))
    (declare (uint31 n))
    (setf (aref dp 0 0) 1)
    (loop for pos from 0 below n
          for base of-type uint31 = 1 then (mod (* base 10) 13)
          do (if (char= #\? (aref s (- n pos 1)))
                 (dotimes (d 10)
                   (let ((num (mod (* d base) 13)))
                     (dotimes (m 13)
                       (setf (aref dp (+ pos 1) (mod (+ m num) 13))
                             (mod (+ (aref dp (+ pos 1) (mod (+ m num) 13))
                                     (aref dp pos m))
                                  +mod+)))))
                 (let* ((d (digit-char-p (aref s (- n pos 1))))
                        (num (mod (* d base) 13)))
                   (dotimes (m 13)
                     (setf (aref dp (+ pos 1) (mod (+ m num) 13))
                           (aref dp pos m))))))
    (println (aref dp n 5))))

#-swank (main)


Measured memory_bytes: 21856
#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 n,q;
  cin >> n;
  int tmp;
  int cnt[100000+7]={};

  ll sum = 0;
  rep(i,n){
    cin >> tmp;
    sum += tmp;
    cnt[tmp]++;
  }

  cin >> q;
  int b,c;
  rep(i,q) {
    cin >> b >> c;
    sum += (c-b)*cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 4024
import java.util.*;

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

        int N = sc.nextInt();
        int[] A = new int[N];
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
            if(map.containsKey(A[i]))
                map.put(A[i], map.get(A[i])+1);
            else
                map.put(A[i], 1);
        }
        sc.close();

        long sum = 1;
        int mod = (int)Math.pow(10, 9)+7;
        for(Integer key: map.keySet()){
            if(N%2 == 1){
                if(key%2 == 1){
                    sum = 0;
                } else {
                    if(key == 0){
                        if(map.get(key) != 1)
                            sum = 0;
                    } else {
                        if(map.get(key) != 2)
                            sum = 0;
                        else
                            sum = (sum*2) % mod;
                    }
                }
            } else {
                if(key%2 == 0){
                    sum = 0;
                } else {
                    if(map.get(key) != 2)
                        sum = 0;
                    else
                        sum = (sum*2) % mod;
                }
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 66268
import java.io.*;

class Main{
	public static void main(String[]args)throws IOException{
		
		BufferedReader br=
			new BufferedReader(new InputStreamReader(System.in));
		
		String str=br.readLine();
		
		String[] num=str.split(" ");
		
		int a=Integer.parseInt(num[0]);
		int b=Integer.parseInt(num[1]);
		
		System.out.println(a*b +" "+ (a+b)*2);

	}
}

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

using namespace std;

int ipow(int a,int b){
    int ans=1;
    for (int i = 0; i < b; ++i) {
        ans=ans*a;
    }
    return ans;
}

int main() {
    int d,n;
    cin>>d>>n;
    if(n!=100)cout<<n*ipow(100,d)<<endl;
    else cout<<(n+1)*ipow(100,d)<<endl;
    return 0;
}

Measured memory_bytes: 256
X,N=map(int, input().split())
try: 
    p=list(map(int, input().split()))
except:
    print(X)
    exit(0)
if X not in p:
    print(X)
    exit(0)
c=1
while 1:
    if X-c not in p:
        print(X-c)
        exit(0)
    if X+c not in p:
        print(X+c)
        exit(0)
    c+=1
    

Measured memory_bytes: 9200
N,M = gets.split.map(&:to_i)
D = Array.new(N + 1)

fail = M.times.find do
  s,c = gets.split.map(&:to_i)
  if D[s] && D[s] != c
    true
  elsif N > 1 && s == 1 && c == 0
    true
  else
    D[s] = c
    false
  end
end

if fail
  puts -1
else
  (1 .. N).each do |s|
    if s == 1 && N > 1
      D[s] ||= 1
    else
      D[s] ||= 0
    end
  end
  puts D[1 .. N].join
end

Measured memory_bytes: 1788
/*

Author: @karngyan
Team: BlundersPride

*/

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

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 1e5+10 , m = 1e9 + 7;
ll a[110];
ll dp[105][N];

ll go(ll i , ll k)
{
	if(k < 0)
		return 0;
	if(k == 0)
		return 1;
	if(i < 0)
		return 0;
	ll &ans = dp[i][k];
	if(ans != -1)
		return ans;

	ans = (go(i - 1 , k) + go(i , k-1) - go(i-1 , k - a[i] - 1) + m ) %m;
	//go(i,k) = distribute k to i people
	//ith can get 0 to a[i]
	//so go(i,k) = go(i-1 , k)                     + go(i , k-1)                     - go(i-1 , k - a[i] - 1)
	//             give 0 to i and cal go(i-1 , k)   distribute k-1 to i people(fun)   in no way can distribute k-a[i]-1 to i-1 people
	return ans;

}

signed main()
{
	fast;
	memset(dp , -1 ,sizeof dp);
////////////////////////////////////////////////////////////////////////////////////////////
	ll n , k ;
	cin >> n >> k;
	rep(i,0,n)
		cin >> a[i];

	cout<<go(n-1 , k)<<endl;


////////////////////////////////////////////////////////////////////////////////////////////

	
	return 0;
}


Measured memory_bytes: 87040
N = int(input())

ans = []
def dp(arg, level):
    global N
    if len(arg) == N:
        ans.append(arg)
        return
    #
    orda = ord('a')
    for i in range(level):
        dp(arg + chr(orda + i), level)
    dp(arg + chr(orda + level), level + 1)
    return

dp('', 0)
for ansi in ans:
    print(ansi)

Measured memory_bytes: 12668
def main():
    from sys import stdin
    input = stdin.readline

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    
    for cnt in range(min(k, 41)):
        ans = []
        bit = [0]*(n+1)
        for i, j in enumerate(a):
            x, y = max(i-j, 0)+1, min(i+j+1, n)+1
            while x < n+1:
                bit[x] += 1
                x += x & (-x)
            while y < n+1:
                bit[y] -= 1
                y += y & (-y)
        for i in range(n):
            ret, x = 0, i+1
            while x > 0:
                ret += bit[x]
                x -= x & (-x)
            ans.append(ret)
        a = ans

    print(*ans)


main()

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

int main(){
    int dp[35];
    rep(i,35) dp[i] = 0;
    dp[0] = 1;
    rep(i,35){
        dp[i+1] += dp[i];
        dp[i+2] += dp[i];
        dp[i+3] += dp[i];
    }
    int n;
    while(cin >> n && n) {
        int step = dp[n];
        int ans = step/3650;
        if(step%3650 != 0) ans++;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

//i番目のビットを返す
bool getBit(int num, int i){
	return ((num & (1 << i)) != 0);
}

//i番目を1にする
int setBit(int num, int i){
	return num | (1 << i);
}

//i番目を0にする
int clearBit(int num, int i){
	int mask = ~(1 << i);
	return num & mask;
}

//i番目をvで置き換える
int updateBit(int num, int i, int v){
	int mask = ~(1 << i);
	return (num & mask) | (v << i);
}

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

	map<int,int> m;
	vector<int> v;
	bool f = false;
	rep(i,n){
		int d;
		cin >> d;
		m[d]++;
		if(m[d] >= 3) f = true;
	}

	if(f){
		cout << 0 << endl;
		return 0;
	}

	vector<int> two;
	for(auto i : m){
		if(i.second == 2) two.emplace_back(i.first);
		else v.emplace_back(i.first);
	}

	int ans = 0;
	rep(i,1 << v.size()){
		vector<int> a,b;
		for(auto j : two){
			a.emplace_back(j);
			a.emplace_back(24 - j);
			b.emplace_back(j);
			b.emplace_back(24 - j);
		}
		rep(j,v.size()){
			if(getBit(i,j)){
				a.emplace_back(v[j]);
				b.emplace_back(24 - v[j]);
			}else{
				a.emplace_back(24 - v[j]);
				b.emplace_back(v[j]);
			}
		}
		a.emplace_back(0);
		b.emplace_back(24);
		int mini = INF;
		rep(j,a.size()){
			rep(k,a.size()){
				if(j == k) continue;
				int dif = abs(a[j] - a[k]);
				mini = min(mini, min(dif, 24 - dif));
			}
		}
		rep(j,b.size()){
			rep(k,b.size()){
				if(j == k) continue;
				int dif = abs(b[j] - b[k]);
				mini = min(mini, min(dif, 24 - dif));
			}
		}
		ans = max(ans, mini);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N,T = map(int,input().split())
ci = []
ti = []
for i in range(N):
  c, t = input().split()
  ci.append(int(c))
  ti.append(int(t))

#print(ci,ti)

lowest=1000

if min(ti)>T:
  print('TLE')
else:
  for i in range(N):
    if ti[i]<=T and ci[i]<=lowest:
      lowest=ci[i]
  print(lowest)
  

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
	int n, t;
	int st, fi;

	while (scanf("%d", &t), t != 0){
		int t_cnt = 0;
		scanf("%d", &n);
		for (int i = 0; i < n; i++){
			scanf("%d%d", &st, &fi);
			t_cnt += fi - st;
		}
		if (t <= t_cnt){
			cout << "OK" << endl;
		}
		else {
			cout << t - t_cnt << endl;
		}
	}

	return (0);
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
template <class T>
inline void _read(T &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t) && t != '-') t = getchar();
	if (t == '-')
	{
		_read(x);
		x *= -1;
		return;
	}
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
int n;
int a[MAXN], x[MAXN];
int main()
{
	_read(n);
	int tot = 0;
	for (int i = 1, x; i <= n; ++i)
		_read(a[i]), tot += a[i];
	int num = tot / 2;
	int po = 0;
	for (int i = 2; i <= n; i += 2)
	{
		po += 2 * a[i];
	}
	x[1] = tot - po;
	for (int i = 2; i <= n; ++i)
		x[i] = 2 * a[i - 1] - x[i - 1];
	for (int i = 1; i <= n; ++i)
		printf("%d ", x[i]);
	return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll n,m;
  cin >> n >> m;
  ll sum  = 0;
  if(2*n > m){
    sum = m/2;
  }
  else{
    sum = n;
    m -= 2*n;
    sum += m/4;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
vector<int>year(1, 0), month{ 0,0,31,28,31,30,31,30,31,31,30,31,30,31 }, day;
int YEAR(int n) {
	if (n < year.size())return year[n];

	int x = year.size() - 1;
	while (year.size() <= n) {
		if (x % 4 == 0 && (x % 100 != 0 || x % 400 == 0))year.push_back(year[x] + 366);
		else year.push_back(year[x] + 365);
		x++;
	}

	return year[n];
}
int Month(int y, int m) {
	int res = month[m];
	if (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0)) {
		if(m>=3)res++;
	}
	return res;
}
signed main() {
	rep(i, 1, month.size())month[i] += month[i - 1];
	while (1) {
		int y1, y2, m1, m2, d1, d2;
		cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
		if (y1 < 0 || y2 < 0 || m1 < 0 || m2 < 0 || d1 < 0 || d2 < 0)break;

		cout << YEAR(y2) - YEAR(y1) + Month(y2, m2) - Month(y1, m1) + d2 - d1 << endl;;
	}
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include<iomanip>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int a, p; cin >> a >> p;
	cout << (a * 3 + p) / 2 << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    T = tuple(map(int, input()))
    ans = 0
    for i in range(0, 1000):
        a = i // 100
        b = (i // 10) % 10
        c = i % 10
        flag1 = False
        flag2 = False
        flag3 = False
        for t in T:
            if flag2:
                if t == c:
                    flag3 = True
                    break
            if flag1:
                if t == b:
                    flag2 = True
                    continue
            if t == a:
                flag1 = True

        if flag3:
            ans += 1
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 9196
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	vector<ll> a(1000001);
	vector<bool> used(100000001);
	cin >> a[1];
	used[a[1]] = true;
	for (int i = 2; ; i++){
		if (a[i-1]%2){
			a[i] = 3*a[i-1]+1;
		}else{
			a[i] = a[i-1]/2;
		}
		if (used[a[i]] == true){
			cout << i << endl;
			return 0;
		}else{
			used[a[i]] = true;
		}
	}
 	return 0;
 }

Measured memory_bytes: 20224
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():
    N=int(input())
    V=sorted(list(map(int,input().split())))

    while True:
        V[1]=(V[0]+V[1])/2
        V.pop(0)
        if len(V)==1:
            print(V[0])
            break


resolve()

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


int main() {
    int cnt=0;
    string s, t;

    cin >> s >> t;

    for (int i=0; i<s.size(); i++) {
        if (s[i] != t[i]) cnt ++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3920
#include<cstdio>
#include<cstring>
const int MAXN=405,MOD=1000000007;

int N,C;
long long mpow[MAXN][MAXN],sum[MAXN][MAXN],dp[MAXN][MAXN];
int A[MAXN],B[MAXN];

int main()
{
	for(int i=1;i<MAXN;i++)
	{
		mpow[i][0]=1;
		for(int j=1;j<MAXN;j++)
			mpow[i][j]=(mpow[i][j-1]*i)%MOD;
	}
	
	scanf("%d%d",&N,&C);
	for(int i=1;i<=N;i++)
		scanf("%d",&A[i]);
	for(int i=1;i<=N;i++)
		scanf("%d",&B[i]);
		
	for(int i=0;i<=C;i++)
		for(int j=1;j<=N;j++)
			for(int k=A[j];k<=B[j];k++)
				sum[i][j]=(sum[i][j]+mpow[k][i])%MOD;
	
	dp[0][0]=1;
	for(int i=1;i<=N;i++)
		for(int j=0;j<=C;j++)
			for(int k=0;k<=j;k++)
				dp[i][j]=(dp[i][j]+dp[i-1][j-k]*sum[k][i]%MOD)%MOD;
	
	printf("%lld\n",dp[N][C]);
	
	return 0;
}


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

int main() {
  int n;
  ll c=0;
  cin >> n;
  for(int a=1;a<sqrt(n*1.0);a++){
    for(int b=a;a*b<n;b++){
      if(a==b)
        c++;
      else
        c+=2;
    }
  }
  cout << c;
  return 0;
}

Measured memory_bytes: 3676
n=int(input())
a=[]
b=list(map(int,input().split()))
for i in range(n):
  for j in range(n-i-1,-1,-1):
    if b[j]==j+1:
      a.append(b.pop(j))
      break
if len(a)<n:
  print(-1)
  exit()
a.reverse()
for i in a:
  print(i)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	int K;
	cin>>s>>K;
	vector<string> v;
	for(int i = 0; i < s.size(); i += 1)
		for(int j = 0; j < K; j += 1)
			if(i + j < s.size())
				v.push_back(s.substr(i, j + 1));
	sort(v.begin(), v.end());
	unique(v.begin(), v.end());
	cout<<v[K - 1];
}

Measured memory_bytes: 1660
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

struct st{
	int lower,upper,c;
};

int main(){
	int d,n;
	cin>>d>>n;
	vector<int> day(d);
	vector<st> clo(n);
	rep(i,d)cin>>day[i];
	rep(i,n)cin>>clo[i].lower>>clo[i].upper>>clo[i].c;
	
	int dp[300][200];
	rep(i,300)rep(j,200)dp[i][j] = -INF;
	
	rep(i,d){
		int t = day[i];
		for(int j=0;j<n;j++){
			if( clo[j].lower<=t && t<=clo[j].upper ){
				if(i==0)dp[0][clo[j].c] = 0;
				else{
					rep(k,200){
						dp[i][clo[j].c] = max( dp[i-1][k]+(int)abs(k-clo[j].c) , dp[i][clo[j].c] );
					}
				}
			}
		}
	}
	
	
	int ans = 0;
	rep(i,200){
		ans = max(ans,dp[d-1][i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3324
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;

int main()
{
	int i, j, k, l, m, X, M, flag;
	long long int Q, H, S, D,N,P,sum;
	j = k = 0;
	cin >> N >> P;
	vector<int>A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] % 2 == 0)
			j++;
		else
			k++;
	}
	if (N == 1) {
		if (P == 1) {
			if (k == 1)
				cout << "1" << endl;
			else
				cout << "0" << endl;
		}
		else {
			if (k == 1)
				cout << "0" << endl;
			else
				cout << "1" << endl;
		}

	}
	else {
		if (k == 0) {
			if (P == 1) {
				cout << "0" << endl;
			}
			else {
				sum = 1;
				for (i = 1; i <= j; i++) {
					sum *= 2;
				}
				cout << sum << endl;
			}


		}
		else {
			sum = 1;
			for (i = 1; i <= j + k - 1; i++) {
				sum *= 2;
			}
			cout << sum << endl;
		}
	}

	return 0;
}





Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		sc.fill(a);

		double average = Arrays.stream(a).average().getAsDouble();
		int index = 0;
		for (int i = 0; i < a.length; i++) {
			if (Math.abs(a[i] - average) < Math.abs(a[index] - average)) {
				index = i;
			}
		}

		System.out.println(index);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 26580
# -*- coding: utf-8 -*-


def main():
    """Function."""
    n = int(input())

    nums = []
    for i in range(1, 10):
        nums.append(int(str(i)*3))

    if n == 999:
        print(999)
    else:
        for i in range(len(nums)):
            if n <= nums[i]:
                print(nums[i])
                break


if __name__ == "__main__":
    main()


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

int main(void){
    char str[20];
    char c;
    for(int i = 0;i < 19;i++){
        cin >> c;
        if(islower(c) == 0)str[i] = ' ';
        else str[i] = c;
    }
    cout << str << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//コピペするとこ



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


int main()
{
  int h, w ;
  cin >> h>> w ;
  int cnt= 0; 
  REP(i,h){
    string s ;
    cin >> s ;
    REP(j,w){
      if(s.at(j)=='#'){
        cnt++ ;
      }
    }
  }
  if(cnt==h+w-1){
    cout <<"Possible"<<endl ;
  }
  else{
    cout <<"Impossible"<<endl ;
  }
      
  return 0 ;
}




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

int main() {
    int N, a, b, sumA=0, sumB=0, Min;
    cin >> N;
    for (int A=1; A<N; A++){
     		int B=N-A;
      		a=A, b=B;
            sumA=0, sumB=0;
            while (true){
              		sumA += a%10;
                    a = (a-a%10)/10;
                    if (a==0) break;
            }
            while (true){
              		sumB += b%10;
                    b = (b-b%10)/10;
              		if (b==0) break;
            }
            if ((Min>sumA+sumB)||A==1){
              		Min = sumA+sumB;
            }
    }
    cout << Min << endl;
              		
}

Measured memory_bytes: 3640
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    a, b = map(int, input().split())
    ans = a - 2 * b
    if ans >= 0:
        print(ans)
    else:
        print(0)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38452
#include<cstdio>
#include<algorithm>
#include<vector>
int main(){
    int n;
    scanf("%d",&n);
    std::vector<std::pair<long long,long long>> vp;
    for(int i=0;i<n;i++){
        long long a,b;
        scanf("%lld%lld",&a,&b);
        vp.push_back({a+b,a});
    }
    std::sort(vp.begin(),vp.end());
    long long ans=0;
    for(int i=0;i<n;i++){
        if(i%2==0)ans+=vp[n-1-i].second;
        else ans-=vp[n-1-i].first-vp[n-1-i].second;
    }
    printf("%lld",ans);
    return 0;
}

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

ll gcd(ll e, ll f)
{
    if(f==0) return e;

    else return gcd(f,e%f);
}

int main()
{
    ll a,b,c,d,i,j,lcm,sb,sa;

    cin>>a>>b>>c>>d;

    sa=a-1;
    sb=b;
    a=a-1;
    lcm=c*d/gcd(c,d);

    sb-=b/c+b/d-b/lcm;

    sa-=a/c+a/d-a/lcm;

    cout<<sb-sa<<endl;

    return 0;
}


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

int main(){
	int m;
	int f;
	int r;
	char a;
	while(true) {
		cin >> m >> f >> r;
		if ( m == -1 && f == -1 ) {
			break;
		}else if ( m == -1 || f == -1 ) {
			a = 'F';
		}else if ( m + f >= 80 ) {
			a = 'A';
		}else if ( m + f >= 65 ) {
			a = 'B';
		}else if ( m + f >= 50 ) {
			a = 'C';
		}else if ( m + f >= 30 ) {
			if ( r >= 50 ) {
				a = 'C';
			}else {
				a = 'D';
			}
		}else {
			a = 'F';
		}
		cout << a << endl;
	}
    return 0;
}

Measured memory_bytes: 1152
using System.Linq;
using static System.Console;

public static class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        var s = new string[n];
        for(int i = 0; i < n; ++i)
        {
            s[i] = ReadLine();
        }
        WriteLine("AC x " + s.Count(x => x == "AC").ToString());
        WriteLine("WA x " + s.Count(x => x == "WA").ToString());
        WriteLine("TLE x " + s.Count(x => x == "TLE").ToString());
        WriteLine("RE x " + s.Count(x => x == "RE").ToString());
    }
}

Measured memory_bytes: 31880
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int temp[n];
  temp[0]=0;
  for(int i=1;i<n;i++)
  {
    if(i-2>=0)
      temp[i]=min(abs(arr[i-2]-arr[i])+temp[i-2],abs(arr[i-1]-arr[i])+temp[i-1]);
    else
    	temp[i]=abs(arr[i-1]-arr[i])+temp[i-1];
                      }
                      
   cout<<temp[n-1];
                      }


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

int main()
{
  vector<int> a(9);
  for (int i = 0; i < 9; ++i) cin >> a.at(i);
  int N;
  cin >> N;
  vector<int> b(N);
  for (int i = 0; i < N; ++i) cin >> b.at(i);
  vector<int> bingo(9);
  for (int i = 0; i < 9; ++i) {
    bingo.at(i) = 0;
    for (int j = 0; j < N; ++j) {
      if (a.at(i) == b.at(j)) {
        bingo.at(i) = 1;
        continue;
      }
    }
  }
  string result = "No";
  if (bingo.at(0) && bingo.at(1) && bingo.at(2)) result = "Yes";
  if (bingo.at(3) && bingo.at(4) && bingo.at(5)) result = "Yes";
  if (bingo.at(6) && bingo.at(7) && bingo.at(8)) result = "Yes";
  if (bingo.at(0) && bingo.at(3) && bingo.at(6)) result = "Yes";
  if (bingo.at(1) && bingo.at(4) && bingo.at(5)) result = "Yes";
  if (bingo.at(2) && bingo.at(5) && bingo.at(8)) result = "Yes";
  if (bingo.at(0) && bingo.at(4) && bingo.at(8)) result = "Yes";
  if (bingo.at(2) && bingo.at(4) && bingo.at(6)) result = "Yes";
  cout << result << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

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

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 100010;
const int MAXP = 10000000;
const u64 MOD = 1000000007;
const f80 MI = f80(1)/MOD;
const int INF = 1000000010;

int h, k, w;
int a[11];
int F[111][11];

int main()
{
	
	cin >> h >> w >> k;
	F[0][0] = 1;
	for (int i = 1; i <= h; ++ i)
	{
		for (int j = 0; j < w; ++ j)
		{
			for (int s = 0; s < 1<<(w-1); ++ s)
			{
				for (int p = 0; p < w-1; ++ p)
					a[p] = s>>p&1;
				int flag = 0;
				for (int p = 0; p < w-2; ++ p)
					if (a[p] && a[p+1]) flag = 1;
				if (flag) continue;
				if (a[j])
					(F[i][j+1] += F[i-1][j]) %= MOD;
				else if (j-1 >= 0 && a[j-1])
					(F[i][j-1] += F[i-1][j]) %= MOD;
				else
					(F[i][j] += F[i-1][j]) %= MOD;
			}
		}
	}
	cout << F[h][k-1] << endl;
	
	return 0;
}


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

#define INF INT_MAX
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,a,n) for(int i=0;i<n;i++)

using namespace std;

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

	int N,M,C;
	cin >> N >> M >> C;
	vector<int> B(M,0);
	int ans = 0;
	int a;
	for(int i=0;i < M;i++)cin >> B[i];
	for(int j = 0;j < N;j++){
		int sum = 0;
		for(int i=0;i < M;i++){
			cin >> a;
			sum += a*B[i];
		}
		if(sum + C > 0)ans++;
	}
	
	cout << ans << endl;
   
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{	
	string a;
	getline(cin, a);

	for (int i = 0; i < 1210; i++)
	{
		if (a[i] == '\0')
		{
			break;
		}
		else if ('a' <= a[i] && a[i] <= 'z') a[i] += 'A' - 'a';
		else if ('A' <= a[i] && a[i] <= 'Z') a[i] += 'a' - 'A';
	}

	cout << a << endl;

	return 0;
}



Measured memory_bytes: 3144
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

void solve()
{
    int n;
    scanf("%d", &n);
    vector<ll> a(n), b(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%lld%lld", &a[i], &b[i]); a[i] *= 2; b[i] *= 2;
    }
    sort(a.begin(), a.end());
    ll tmp0 = ((n % 2) ? a[n / 2] : (a[n / 2 - 1] + a[n / 2]) / 2);

    sort(b.begin(), b.end());
    ll tmp1 = ((n % 2) ? b[n / 2] : (b[n / 2 - 1] + b[n / 2]) / 2);
    ll ans = (n%2? (tmp1 - tmp0)/2 + 1: tmp1 - tmp0 + 1);
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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


#include <cstdlib>  // abs() for integer 絶対値求めやつ


#include <cmath>    // abs() for float, and fabs()


#include <algorithm>


 


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


#define SORT(a) sort((a).begin(),(a).end());


#define che(a,string) cout<<string<<":"<<(a)<<endl;


#define ch(a,string) cout<<string<<":"<<(a)<<" ";


using namespace std;


typedef pair<int,int> P;








int main(){

	int k; cin >> k ;
	int odd,even;
	odd= (k+1)/2;
	even =k/2;
	cout << odd*even<<endl;}
	


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

int main(){
  long long N, A, B;
  cin >> N >> A >> B;

  long long X = A+B;
  long long c = N/X;
  long long z;
  if(c != 0)z = N%(X*c);
  else{z=0;
    if(N<A)cout<<N<<endl;
    else{cout<<A <<endl;}
    return 0;
  }
  long long g;
  if(z<=A)g = z;
  if(z>A)g = A;
  long long ans = A*c+ g;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256