akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(int i=int(x);i<int(y);++i)
#define For(i,x,y)  for(int i=int(x);i<=int(y);++i)
#define FOr(i,x,y)  for(int i=int(x);i>=int(y);--i)
#define pi acos(-1) 
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define Max(x,y)    ((x)=((x)<(y)?(y):(x)))
#define Min(x,y)    ((x)=((x)>(y)?(y):(x)))
#define E(x)        return writeln(x),0
#define LL			(long long)
#define p(x)        printf("~%lld~\n",LL(x))
#define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_; 
#endif 
#define NEG 1
    static const int GYN=2333333;
    char SZB[GYN],*SS=SZB,*TT=SZB;
    inline char gc(){   if (SS==TT){  TT=(SS=SZB)+fread(SZB,1,GYN,stdin); if (SS==TT) return '\n';  }   return *SS++;    }
#if NEG
    inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);}
	void writeln(ll x){write(x);puts("");}
}using namespace SHENZHEBEI;
const ll N=400010;
bitset<200100>f;
char s[200100];
ll n,k;
int main(){
	n=read(),k=read();
	if (k>2*n){
		for(;k>4*n;k-=2*n);
		for(;k>2*n;k-=2);
	}
	readstr(s+1);
	For(i,1,n)f[i]=s[i]=='A';
	For(i,1,k)if (f[1])	f[1]=0;
	else{
		f.flip(),f>>=1,f[n]=1;
	}
	For(i,1,n)putchar(f[i]?'A':'B');
}

Measured memory_bytes: 896
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 1e9+7;
const int maxn = 100+10;
const int N = 1e5+10;
const int E = 1e6+10; 
ll n,m,k;
ll x[maxn];

ll check(int y){
	ll res = 0;
	F(i,1,n){
		res += (x[i]-y)*(x[i]-y);
	}
	return res;
}


int main(){
	cin>>n;
	F(i,1,n){
		cin>>x[i];
	}
	ll ans = infll;
	F(i,1,100){
		ans = min(ans,check(i));
	} 
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		String T ="";
		String P ="";
		String TT = "";
		
		int point = 0;
		int hyouj = 0;
		
		T = as.next();
		P = as.next();
		
		TT = T;
		
		point = T.indexOf(P);
		if(point == 0){
			
			System.out.println(String.valueOf(point));
			T = T.substring(point+1);
			
		}
		while(point != -1){
			
			point = T.indexOf(P);
			if(point != -1){
			
				T = T.substring(point+1);
				hyouj = (TT.length()-T.length())-1;
				System.out.println(String.valueOf(hyouj));
				
			}
		}

	}

}

Measured memory_bytes: 26252
import java.io.InputStream;
import java.io.IOException;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        final MyScanner sc = new MyScanner();
        final long h = sc.nextLong();
        final long w = sc.nextLong();
        if (h == 1 || w == 1) {
            System.out.println(1);
        } else {
            System.out.println((long) (h * w / 2 + ((h * w) % 2)));
        }
    }
}

class MyScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int pointer = 0;
    private int bufLength = 0;

    private boolean hasNextByte() {
        if (pointer < bufLength) {
            return true;
        } else {
            pointer = 0;
            try {
                bufLength = in.read(buffer);
            } catch (final IOException e) {
                e.printStackTrace();
            }
            if (bufLength <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[pointer++];
        } else {
            return -1;
        }
    }

    private static boolean isNumberChar(final int c) {
        return '0' <= c && c <= '9';
    }

    private static boolean isPrintableChar(final int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[pointer])) {
            pointer++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        final StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long num = 0;
        boolean isNegative = false;
        int b = readByte();
        if (b == '-') {
            isNegative = true;
            b = readByte();
        }
        if (!isNumberChar(b)) {
            throw new NumberFormatException();
        }
        while (true) {
            if (isNumberChar(b)) {
                num *= 10;
                num += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return isNegative ? -num : num;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        final long temp = nextLong();
        if (temp < Integer.MIN_VALUE || Integer.MAX_VALUE < temp) {
            throw new NumberFormatException();
        }
        return (int) temp;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 32432
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double
using namespace std;

    const ll N = 1e3 + 7;
    const ll mod = 1e9 + 7;



void solve(){
    ll n;
    cin >> n;
    vector < ll > a(n + 1);
    ll sum = 0;
    map < ll , ll > mp;
    for(ll i = 1; i <= n; ++ i){
        cin >> a[i];
        sum += a[i];
        ++ mp[a[i]];
    }
    ll q , b , c;
    cin >> q;
    while(q --){
        cin >> b >> c;
        sum += (c - b) * mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << sum << "\n";
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tt = 1;
    //cin >> tt;
    while(tt --){
            solve();
    }
}

/**

**/


Measured memory_bytes: 10120
from itertools import permutations
def solve(N,C):
    node = [i for i in range(1,N+1)]
    lis = list(permutations(node))
    ans = 0
    for v in lis:
        flag = 0
        if v[0] != 1:
            continue
        for i in range(N-1):
            if (v[i],v[i+1]) in C:
                continue
            else:
                flag += 1
        if flag == 0:
            ans += 1
    return ans


def main():
    N,M = map(int,input().split(" "))
    C = set([])
    for _ in range(M):
        a,b = map(int,input().split(" "))
        C.add((a,b))
        C.add((b,a))
    print(solve(N,C))

if __name__ == "__main__":
    main()

Measured memory_bytes: 8052
import sys
import math

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    R = int(input())
    print(2 * R * math.pi)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
N = int(input())
Ss = []
for i in range(N):
  Ss.append(input())
 
C0, C1, C2, C3 = 0, 0, 0, 0
for S in Ss:
  if S == 'AC':
    C0 += 1
  elif S == 'WA':
    C1 += 1
  elif S == 'TLE':
    C2 += 1
  else:
    C3 += 1
print("AC x {}".format(C0))
print("WA x {}".format(C1))
print("TLE x {}".format(C2))
print("RE x {}".format(C3))

Measured memory_bytes: 16244
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意


ss = input()
t = input()

s = ss+ss


l = len(s)
d = [[-1]*26 for _ in range(l)]
#now = [-1]*27
prev = [-1]*27

ans = -1
for i,c in enumerate(s):
#        if now[j] == -1: continue
#        if d[now[j]][ord(c)-97] == -1:
#            d[now[j]][ord(c)-97] = i
    for k in range(max(0,prev[ord(c)-97]),i):
        d[k][ord(c)-97] = i
#    now[ord(c)-97] = i
    prev[ord(c)-97] = i

#print(now)
#print(d)

ans = ss.find(t[0])
if ans == -1:
    print(-1)
    exit()

ls = len(ss)
#print(ans)
lt = len(t)-1

res = ans
for i in range(lt):
#    print(res, d[res])
    if d[res][ord(t[i+1])-97] == -1:
        print(-1)
        exit()
    diff = d[res][ord(t[i+1])-97] - res 
    ans += diff
    res = (res+diff)%ls


print(ans+1)    

    
    















Measured memory_bytes: 103904
#include <iostream>
#include <cstring>

using namespace std;

int main(){

  char s[4];
  cin >> s;
  
  int a,b,c,d;
  char t[2];
  
  a=strncmp(s,"00",2); //positive
  b=strncmp(s,"13",2); //negative
  
  t[0]=s[2];
  t[1]=s[3];
  
  c=strncmp(t,"00",2); // positive
  d=strncmp(t,"13",2); // negative
  
  if(a>0 && b<0 && c>0 && d<0){
    cout << "AMBIGUOUS" << endl;
  }
  else if(a>0 && b<0){
    cout << "MMYY" << endl;
  }
  else if(c>0 && d<0){
    cout << "YYMM" << endl;
  }
  else {
    cout << "NA" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

struct node { int c,t; }a[660];
int m,n,cnt,s=1,f[550];
bool book[550];

bool cmp(node k1,node k2) { return k1.c>k2.c; }
int main()
{
	cin >> m >> n;	
	m--,n--;
	cout<<m*n<<endl;
	return 0;
}

Measured memory_bytes: 256
f a 0 = a == 0
f a b = a == b^2 || f a (b-1)
g [a,b] 
    | b<10 = a*10 + b
    | b == 100 = a*1000 +100
    | otherwise = a*100 + b
solve a = if f a 316 then "Yes" else "No"
main = getContents>>=putStrLn.solve.g.map read.words

Measured memory_bytes: 508
//  q3.cpp(2014/10/12-)


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;


int main(){
    int w,h,n,k=0,x,y,x_n,y_n,x_s,y_s;
    scanf("%d%d%d",&w,&h,&n);
    
    scanf("%d%d",&x_n,&y_n);
    
    for(int i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        
        if((x_n-x)*(y_n-y)>0)
            k+=max(abs(x_n-x),abs(y_n-y));
        else
            k+=abs(x_n-x)+abs(y_n-y);
        
        x_n=x;
        y_n=y;
    }
    
    printf("%d\n",k);
    
    return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;

public class Main {

	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int k = sc.nextInt();
	
		if (m==0) {
			if (k==0) {
				System.out.println("0 0");
			} else {
				System.out.println(-1);
			}
		} else if (m==1) {
			if (k==0) {
				System.out.println("0 0 1 1");
			} else {
				System.out.println(-1);
			}
		} else {
			if (k==0) {
				StringBuilder builder = new StringBuilder();
				for (int i=0;i<(1<<m);i++) {
					builder.append(i);
					builder.append(" ");
				}
				for (int i=(1<<m)-1;i>=0;i--) {
					builder.append(i);
					if (i>0) {
						builder.append(" ");
					}
				}
				System.out.println(builder);
				
			} else if (k<(1<<m)) {
				StringBuilder builder = new StringBuilder("0");
				builder.append(" "+k);
				builder.append(" 0");
				for (int i=1;i<(1<<m);i++) {
					if (i!=k) {
						builder.append(" ");
						builder.append(i);
					}
				}
				
				builder.append(" "+k);
				
				for (int i=(1<<m)-1;i>=1;i--) {
					if (i!=k) {
						builder.append(" ");
						builder.append(i);
					}
				}
				
				System.out.println(builder);
			} else {
				System.out.println(-1);
			}
		}
	}
}


Measured memory_bytes: 37056
/* ITP1_9_C: Card Game */

#include <iostream>
#include <string>

const int WINNING_POINTS = 3;

int main() {
    std::ios::sync_with_stdio(false);

    std::string word1;
    std::string word2;
    int taro_points = 0, hanako_points = 0;
    int n_fights;

    std::cin >> n_fights;
    for (int i = 0; i < n_fights; i++) {
        std::cin >> word1 >> word2;
        if (word1 > word2) {
            taro_points += WINNING_POINTS;
        }
        else if (word1 < word2) {
            hanako_points += WINNING_POINTS;
        }
        else {
            taro_points++;
            hanako_points++;
        }
    }

    std::cout << taro_points << " " << hanako_points << std::endl;
    return 0;
}

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

using namespace std;

typedef unsigned long long ll;
typedef unsigned long long ull;
typedef 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 << 18) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			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;
	}
	
	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 :: inp_ll;

const int MAXN = 1<<18;

int main()
{
	
	int a = inp();
	int b = inp();
	int c = inp();
	int k = inp();
	ll x = max(a, max(b, c));
	cout << a+b+c-x+(x<<k) << endl;
	
	return 0;
}


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

using namespace std;

int main() {
    int N,i,j,flog=0;
    cin >> N;
   for( i=1 ; i <10 ; i++){
       for(j=1 ;j<10 ;j++ ){
           if(N==i*j) {
               cout << "Yes" << endl;
              return 0;
           }

       }
   }

       cout <<"No"<< endl;
   }



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

int main() {
    int N;
    cin >> N;
    int P, mini = N, counter = 0;
    rep (i,N) {
        cin >> P;
        if (P == (mini=min(P,mini))) counter++;
    }
    cout << counter;
}


Measured memory_bytes: 384
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353




A, B, C = list(map(int, sys.stdin.buffer.readline().split()))
ok = len(set([A, B, C])) == 2
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 24572
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>

using namespace std;

int main(){
    int n;
    cin >> n;
    int inp;
    int a[n],b[n];
    int maxa;
    
    int num=0;
    for(int i=0;i<n;i++){

        cin >> inp;
        a[i]=inp;
        if(maxa<inp){
            maxa=inp;
        }
        

    }  
    vector<int> already(maxa+1,0);
    sort(a,a+n);
    for(int i=0;i<n;i++){
        inp=a[i];
        if(already.at(inp)==0){
            // a[num]=inp;
            // num++;
            for(int j=1;j*inp<maxa+1;j++){
                already[j*inp]++;
            }
        }else{
            already.at(inp)++;
        }
    }
    int res=0;  
    
    for(int i=0;i<n;i++){
        if(already[a[i]]==1){
            res++;
        }
    }
    cout << res << endl;

    return 0;
}

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

int main()
{
    int n, m, maxi, sum;
    double d;
    int a[n];
    maxi = 0;
    sum = 0;
    cin >> n >> m;
    rep(i, n) cin >> a[i];
    rep(i, n) sum += a[i];
    d = (double)sum / (double)(4 * m);
    for (int i = 0; i < n; i++)
    {
        if (a[i] < d)
        {
        }
        else
        {
            maxi++;
        }
    }
    if (maxi < m)
    {
        cout << "No";
    }
    else
    {
        cout << "Yes";
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e20);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a>b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a<b ? : a = b; }

bool comp(int a, int b) {
    return a > b;
}

int main() {
    int N;
    cin >> N;
    vint A(N);
    unordered_map<int, int> pos_map;
    rep(i, N) {
        cin >> A[i];
        pos_map[A[i]] = i;
    }
    set<int> pos;
    pos.insert(-1);
    pos.insert(N);
    ll count = 0;
    REP(i, 1, N + 1) {
        auto itR = pos.lower_bound(pos_map[i]);
        auto itL = prev(itR);
        pos.insert(itR, pos_map[i]);
        ll R = *itR - pos_map[i];
        ll L = pos_map[i] - *itL;
        count += (R * L) * i;
    }
    cout << count << endl;
    return 0;
}
 

Measured memory_bytes: 18632
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int N, W;
int v[100], w[100];
int dp[101][10001];

int main(void){
    cin >> N >> W;
    for(int i = 0; i < N; i++) cin >> v[i] >> w[i];

    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= W; j++){
            if(i>=1) dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if(j>=1) dp[i][j] = max(dp[i][j], dp[i][j-1]);
            if(i>=1 and j-w[i-1]>=0) dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]] + v[i-1]);
            // printf("dp(%d, %d) = %d\n", i, j, dp[i][j]);
        }
    }

    cout << dp[N][W] << '\n';

    return 0;
}


Measured memory_bytes: 7048
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    int n,k,ans=0,a;
    cin>>n>>k;
    rep(i,n)cin>>a,ans+=min(a,k-a);
    cout<<ans*2<<endl;
    return 0;
}


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


using namespace std;



int main(){
  int a,h,m,s;
  std::cin >> a;
  h=a/3600;
  m=(a-h*3600)/60;
  s=a-h*3600-m*60;
  std::cout << h<<":"<<m<<":"<<s<<'\n';

}

Measured memory_bytes: 3080
#include<stdio.h>

int main(){
    int H,W,x,y,temp,temp2;
    for(;;){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0){
            exit(0);
        }
        for(y=1;y<=H;y++){
            for(x=1;x<=W;x++){
                temp2=y%2;
                temp=x%2;
                if(y==1 || temp2>0){
                    //奇数行
                    if(x==1 || temp>0){
                        printf("#");
                    }else{
                        printf(".");
                    }
                }
                if(temp2==0){
                    //偶数行
                    if(x==1 || temp>0){
                        printf(".");
                    }else{
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2112
import math
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))


# a, bの公約数の集合 と a, bの最大公約数の約数の集合 は同値
# a, bの最大公約数の約数のうち、互いに素なもの <= a, bの最大公約数の素因数と(と 1)
# n の素因数分解はO(√ n)で行える

# ↑の方法とは異なる解法
def prime_factrize(n: int) -> list:
    # 素因数のリストを取得(重複する素因数を含む)
    # 例 : 18 -> [2, 3, 3]
    if n < 2:
        return []
    p_factors = []
    # 2だけ先に取り分けておく
    while n % 2 == 0:
        p_factors.append(2)
        n //= 2
    # 残りの奇数の素因数を探す
    f = 3
    while f * f <= n:
        if n % f == 0:
            p_factors.append(f)
            n //= f
        else:
            f += 2
    # nが素数の場合
    if n != 1:
        p_factors.append(n)
    return p_factors


def main():
    a, b = LI()
    # a, bの素因数を取り出し、共通する素因数(に1を加えたもの)の個数を数える
    pf_a = prime_factrize(a)
    pf_b = prime_factrize(b)
    pf = (set(pf_a) & set(pf_b)) | {1}
    print(len(pf))


main()


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int n,m,K,ans;
char ch[6][6],a[6][6];
int main(){
	cin>>n>>m>>K;
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>ch[i][j];
	for(int i=0;i<(1<<n);i++)
		for(int j=0;j<(1<<m);j++){
			for(int k=0;k<n;k++)for(int l=0;l<m;l++)a[k][l]=ch[k][l];
			for(int k=0;k<n;k++)if((1<<k)&i)
				for(int l=0;l<m;l++)a[k][l]='.';
			for(int k=0;k<m;k++)if((1<<k)&j)
				for(int l=0;l<n;l++)a[l][k]='.';
			int now=0;
			for(int k=0;k<n;k++)for(int l=0;l<m;l++)if(a[k][l]=='#')now++;
			if(now==K)ans++;
		}
	cout<<ans;
}

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

int main() {
	string s;
	bool ans = false;
	cin >> s;
	for (int i = 0;i < s.size();++i) {
		if (s[i] == 'C') {
			for (;i < s.size();++i) {
				if (s[i] == 'F') ans = true;
			}
			break;
		}
	}
	if (ans) cout << "Yes" << "\n";
	else cout << "No" << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define cinf(n,x) for(int i=0;i<(n);I++) cin >> x[i];

int main(){
  int A,B,C,D ;
  cin >> A >> B >> C >> D ;
  int ans = max(A*B,C*D) ;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  string s;
  cin>>s;
  rep(i,s.size()){
    if(s[i]=='?')s[i]='D';
  }
  cout<<s<<endl;
  return(0);
}


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

int main(){
    int n, t;
    map <int, int> ar;
    cin >> n;
    for (size_t i = 0; i < n; i++)
    {
        cin >> t;
        ar[t]++;
        if(ar[t] > 1)
        {
            cout << "NO\n";
            return 0;
        }   
    }
    cout << "YES\n";
    

    return 0;
}

Measured memory_bytes: 9600
#include "bits/stdc++.h"
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    int co = 0;//カウンター
    vector<int> data(N);
    for(int i = 0; i < N; i++){
        cin >> data.at(i);
        if(data.at(i) >= K)
        co++;
    }
    cout << co << endl;
}

Measured memory_bytes: 640
n = int(input())
table = [[0]*10 for _ in range(10)]
for i in range(1, n+1):
  start = int(str(i)[0])
  end = int(str(i)[-1])
  table[start][end] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans += table[i][j]*table[j][i]
print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗  default_value:初期値
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)

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

	vector<uint32_t> v(n);

	for (size_t i = 0; i < v.size(); i++) {
		cin >> v[i];
	}
	_sort(v,uint32_t,less);

	uint32_t result = 0;
	for (size_t i = 0; i < v.size(); i++) {

		size_t j;
		for (j = i+1; j < v.size(); j++) {
			if (v[i] == v[j]) { continue; }
			break;
		}
		if (j - i != v[i]) {
			result += ((j - i) < v[i] ? (j - i) : ((j - i) - v[i]));
		}
		i = j-1;
	}

	cout << result;

	return 0;
	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int N,A,B,C,D;cin >> N >> A >> B >> C >> D;
    A--,B--,C--,D--;
    string s;cin >> s;
    if(C < D){
        vector<int> dp(N,0);
        dp[B] = 1;
        /*
        for(int a = 0;a < N;a++){
            cout<<dp[a]<<" ";
        }
        */

        for(int a = B+1;a < N;a++){
            if(s.at(a) == '#')continue;
            if(a == 1){
                dp[a] = dp[a-1];
            }else{
                dp[a] = max(dp[a-1], dp[a-2]);
            }

        }
        /*
        for(int a = 0;a < N;a++){
            cout<<dp[a]<<" ";
        }
        */

        //cout<<endl;
        bool result1 = (dp[D] == true);
        dp = vector<int>(N, 0);
        dp[A] = 1;
        for(int a = A+1;a < N;a++){
            if(s.at(a) == '#')continue;
            if(a == 1){
                dp[a] = dp[a-1];
            }else{
                dp[a] = max(dp[a-1], dp[a-2]);
            }
        }
        bool result2 = (dp[C] == true);
        if(result1 && result2){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }else{
        vector<int> dp(N,0);
        dp[B] = 1;
        for(int a = B+1;a < N;a++){
            if(s.at(a) == '#')continue;
            if(a == 1){
                dp[a] = dp[a-1];
            }else{
                dp[a] = max(dp[a-1], dp[a-2]);
            }
        }
        bool result1 = (dp[D] == true);
        bool result3 = false;
        /*
        for(int a = B;a <= D-2;a++){
            if(dp[a] && dp[a+1] && dp[a+2])result3 = true;
        }
        */
        vector<int> dp1 = dp;
        dp = vector<int>(N, 0);
        dp[A] = 1;
        for(int a = A+1;a < N;a++){
            if(s.at(a) == '#')continue;
            if(a == 1){
                dp[a] = dp[a-1];
            }else{
                dp[a] = max(dp[a-1], dp[a-2]);
            }
        }
        bool result2 = (dp[C] == true);
        for(int a = B-1;a <= D-1;a++){
            if(dp[a] && dp1[a+1] && dp[a+2])result3 = true;
        }
        if(result1 && result2 && result3){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}


Measured memory_bytes: 2820
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=5050;
const ll INF=1e15;
ll a[maxn][maxn],dp[maxn],p[maxn],n,A,B;

int main(){
    cin >> n >> A >> B;
    for (int i=1;i<=n;i++) cin >> p[i];
    p[++n]=n+1;
    for (int i=0;i<=n;i++){
        a[i][i]=0;
        for (int j=i+1;j<=n;j++) a[i][j]=a[i][j-1]+(p[j]>p[i]?A:B);
    }
    for (int i=1;i<=n;i++){
        dp[i]=INF;
        for (int j=0;j<i;j++) if (p[j]<p[i]) dp[i]=min(dp[i],dp[j]+a[j][i-1]);
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 198912
#include <stdio.h>
#include <queue>
using namespace std;
int n, m, k;
long long ans;
long long a[100000];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
	}
	priority_queue<long long>q;
	for (int i = 0; i < n; i++) {
		q.push(a[i]);
	}
	for (int i = 0; i < m; i++) {
		k = q.top();
		q.push(k / 2);
		q.pop();
	}
	for (int i = 0; i < n; i++) {
		ans += q.top();
		q.pop();
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int a[10];
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	sort(a, a + 10, greater<int>());
	cout << a[0] << endl << a[1] << endl << a[2] << endl;
	return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define RB rbegin()
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define MD 1000000007
#define PPF pop_front()
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;u.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>u;
map<LL,LL>ww,cc;
LL ar[50000001];
LL br[50000001];
LL cr[500][500];
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    while(tt--)
    {
        UOSMOY;
        cin>>n;
        m=n;
        n%=1000;
        if(n==0)
        {
            cout<<0<<endl;
        }
        else
        {
            cout<<1000-n<<endl;
        }
    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 3660
while 1 :
	a,op,b = raw_input().split()
	if op == "?":
		break
	if op == "+":
		print int(a) + int(b)
	if op == "-":
		print int(a) - int(b)
	if op == "*":
		print int(a) * int(b)
	if op == "/":
		print int(a) / int(b)

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

#define Debug(x) x
typedef int regular_int;
#define int ll
typedef long long ll;

vector<int > G[200000];
int cnt[200000];

void magic(int x, int y){
    cnt[x] = y;
    for (int z: G[x]){
        if (!cnt[z]){
            magic(z, y);

        }
    }
}


regular_int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(12) << fixed;

	int N, M, Q;
	cin >> N >> M >> Q;
	vector<pair<int, int > > dist;
	for (int i = 0; i < Q; ++i) {
        int A, B, C;
        cin >> A >> B >> C;

        if (C){
            dist.push_back(make_pair(A, B));

        } else {
            G[A].push_back(B);
            G[B].push_back(A);


        }
	}

	int sum = 0;
	for (int i = 0; i < N; ++i) {
        if (!cnt[i]){
            magic(i, ++sum);

        }
	}

	for (auto x: dist){
        if (cnt[x.first] == cnt[x.second]){
            cout << "No" << endl;
            return 0;
        }
	}

	if (!dist.empty() && sum < 3){
        cout << "No" << endl;
        return 0;
	}

	if (M > (ll )sum * (sum - 1) / 2 + N - sum){
        cout << "No" << endl;
        return 0;
	}

	if (!dist.empty() && M < N){
        cout << "No" << endl;
        return 0;
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 10112
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef vector<vector<int> > Graph;
typedef pair<int, int> P; 
// MOD
//const int mod = 1000000007;
typedef long long ll;
long long INF = 1<<30;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
//int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}
 
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}


struct Unionfind{
    vector<int> par;

    Unionfind(int n) : par(n, -1){}

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    } 

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x]>par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

P s(int x){
    int a = x%10;
    int b = 0;
    while(x){
        b = x;
        b/=10;
    }
    return P(a, b);
}

int main() {
  int n; cin >> n;
  int b=n%10;
  if(b == 3) cout << "bon" << endl;
  else if(b==0 || b==1 || b==6 || b==8) cout << "pon" << endl;
  else cout << "hon" << endl;
}

Measured memory_bytes: 3132
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	while(true) {
    		int n = sc.nextInt();
    		if(n==0) break;
        	String [] step = new String[n];
        	for(int i=0;i<n;i++) {
        		step[i] = sc.next();
        	}
        	int count = 0;
        	for(int i=0;i<n-1;i++) {
        		char c1 = step[i].charAt(1);
        		char c2 = step[i+1].charAt(1);
        		if(c1 == c2) {
        			count++;
        		}
        	}
        	System.out.println(count);
    	}
    }
}



Measured memory_bytes: 37172
#include <stdio.h>
void henge(char [], int []);
int main(void){
    int i, w;
    char a[1000];
    int b[1000];
    while(1){
        a[0] = '\0';
        w=0;
        scanf("%s", a);
        if(a[0] == '0'){
            break;
        }
        henge(a, b);
        for(i = 0; i < 1000;i++){
            w += b[i];
        }
        printf("%d\n", w);
    }
    return 0;
}
void henge(char a[], int b[]){
    int i;
    for(i = 0; i < 1000; i++){
        b[i] = 0;
    }
    for(i = 0; i < 1000; i++){
        if(a[i] == '\0'){
            break;
        }
        b[i] = a[i] - '0';
    }
    return;
}


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


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	bool state = true;
	for(int i=0; i<s.length(); ++i){
		if(s[i] == '7'){
			cout << "Yes\n";
			state = false;
			break;
		}
	}
	if(state)
		cout << "No\n";
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int P, Q, R;
    cin >> P >> Q >> R;

    vector<int> arr;
    arr.push_back(P + Q);
    arr.push_back(R + Q);
    arr.push_back(P + R);
    arr.push_back(Q + R);
    arr.push_back(R + P);
    arr.push_back(Q + P);

    sort(arr.begin(), arr.end());
    cout << arr[0] << endl;
    return 0;
}


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

using namespace std;
int main()
{
    int n,i,sum=0;
    cin >> n;

    int a1[100],a2[100];

    for(i=0; i<n; i++)
        cin >>a1[i];

    for(i=0; i<n; i++)
        cin >>a2[i];

    for(i=0; i<n; i++)
    {
        if(a1[i]-a2[i]>0)
        {
            sum +=a1[i] - a2[i];
        }
    }

    cout<<sum<<endl;

    return 0;
}


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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int a,b,q;cin>>a>>b>>q;
  set<ll> st1,st2;
  for(int i=0;i<a;i++){ll t;cin>>t;st1.insert(t);}
  for(int i=0;i<b;i++){ll t;cin>>t;st2.insert(t);}
  st1.insert(-pow(10,15));
  st1.insert(pow(10,15));
  st2.insert(-pow(10,15));
  st2.insert(pow(10,15));

  for(int i=0;i<q;i++){
    ll x;cin>>x;
    ll ans=pow(10,15);
    for(int i=0;i<2;i++){
      auto it1 = st1.lower_bound(x);
      if(i)it1--;
      for(int j=0;j<2;j++){
        auto it2 = st2.lower_bound(x);
       if(j)it2--;
        for(int k=0;k<2;k++){
          ll t=abs(*it1-*it2);
          if(k){
            t += abs(x-*it1);
          }else{
            t += abs(x-*it2);
          }
          ans=min(t,ans);
        }
      }
    }
    cout<<ans<<endl;
  }
 
  return 0;
}


Measured memory_bytes: 13008
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
class Node{
public:
  int location;
  int p,l,r;
  Node(){}
};
class Point{
public:
  int id,x,y;
  Point(){}
  Point(int id,int x,int y): id(id),x(x),y(y){}
  bool operator < (const Point &p){return id<p.id;}
};
static const int MAX =1000000;
static const int NIL = -1;
int n;
Point P[MAX];
Node T[MAX];
int np;
bool lessX(Point &p1,Point &p2){return p1.x<p2.x;}
bool lessY(Point &p1,Point &p2){return p1.y<p2.y;}
int makeKDTree(int l,int r, int d){
  if(!(l<r))return NIL;
  int mid=(l+r)>>1;
  int t=np++;
  nth_element(P+l,P+mid,P+r,(d&1 ? lessY : lessX));
  T[t].location=mid;
  T[t].l=makeKDTree(l,mid,d+1);
  T[t].r=makeKDTree(mid+1,r,d+1);
  return t;
}
void find(int v,int sx,int tx,int sy,int ty,int d,vector<Point> &ans){
  int x=P[T[v].location].x;
  int y=P[T[v].location].y;
  if(sx<=x&&x<=tx&&sy<=y&&y<=ty)ans.push_back(P[T[v].location]);
  if(d%2==0){
    if(T[v].l!=NIL&&sx<=x)find(T[v].l,sx,tx,sy,ty,d+1,ans);
    if(T[v].r!=NIL&&x<=tx)find(T[v].r,sx,tx,sy,ty,d+1,ans);
  }
  else{
    if(T[v].l!=NIL&&sy<=y)find(T[v].l,sx,tx,sy,ty,d+1,ans);
    if(T[v].r!=NIL&&y<=ty)find(T[v].r,sx,tx,sy,ty,d+1,ans);
  }
}

bool ex(int v,int sx,int tx,int sy,int ty,int d,vector<Point> &ans){
  int x=P[T[v].location].x;
  int y=P[T[v].location].y;
  if(sx<=x&&x<=tx&&sy<=y&&y<=ty)return 1;
  if(d%2==0){
    if(T[v].l!=NIL&&sx<=x)if(ex(T[v].l,sx,tx,sy,ty,d+1,ans))return 1;
    if(T[v].r!=NIL&&x<=tx)if(ex(T[v].r,sx,tx,sy,ty,d+1,ans))return 1;
  }
  else{
    if(T[v].l!=NIL&&sy<=y)if(ex(T[v].l,sx,tx,sy,ty,d+1,ans))return 1;
    if(T[v].r!=NIL&&y<=ty)if(ex(T[v].r,sx,tx,sy,ty,d+1,ans))return 1;
  }
}
int main(){
  int x,y;
  cin>>n;
  rep(i,n){
    scanf("%d %d",&x,&y);
    P[i]=Point(i,x,y);
    T[i].l=T[i].r=T[i].p=NIL;
  }
  np=0;
  int root=makeKDTree(0,n,0);
  int q;
  cin>>q;
  int sx,sy,tx,ty;
  vector<Point>ans;
  rep(i,q){
    scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
    ans.clear();
    if(!ex(root,sx,tx,sy,ty,0,ans));
    find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(),ans.end());
    rep(j,ans.size())printf("%d\n",ans[j].id);
    cout<<endl;
  }return 0;
}


Measured memory_bytes: 16472
/**
*    author:  yuya1234
*    created: 14.07.2020 09:02:59
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //std::cout << std::fixed << std::setprecision(15);

  int n;
  cin>>n;

  map<int,int> a;
  vector<int> v;
  int tmp;
  REP(i,n)
  {
    cin>>tmp;
    v.emplace_back(tmp);
    if(a.count(tmp)==0)a.insert(make_pair(tmp,1));
    else a[tmp]=a.at(tmp)+1;
  }

  SORT(v);
  UNIQUE(v);

  int cnt=0;
  REP(i,SZ(v))
  {
    int aa=a.at(v[i]);
    if(v[i]>aa)cnt+=aa;
    else if (v[i]<aa)cnt+=aa-v[i];
  }

  cout<<cnt<<endl;

  return 0;
}

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

using lint = long long;

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    if (m == n) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#include <stdio.h>
int min(int a, int b){
	return (a < b) ? a : b;
}
int main()
{
	int N, k;
	int x = 1;
	scanf("%d%d", &N, &k);
	for (int i = 0; i < N; i++){
		x = min(x * 2, x + k);
	}
	printf("%d\n", x);
	return 0;
}

Measured memory_bytes: 128
//Left, Rightを決める.
//Ki昇順 -> 上から全てLeft -> 上からValidになるよう最低限Right -> 下から上限に注意してRight
#include <iostream>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef tuple<int, int, int> T;
typedef pair<int, int> P;
 
int n;
int K[200000], L[200000], R[200000];
 
int solve() {
	int i;
	
	/*cout << endl;
	rep(i, n) {
		cout << "K, L, R = " << K[i] << ", " << L[i] << ", " << R[i] << endl;
	}*/
	
	int ret = 0;
	rep(i, n) {
		ret += L[i];
	}
	
	priority_queue<P> que;	//(value, index)
	int left = 0;
	bool isR[200000] = {false};
	rep(i, n) {
		que.push(P(R[i] - L[i], i));
		left++;
		while (left > K[i]) {
			//cout << "i = " << i << endl;
			P now = que.top(); que.pop();
			int pos = now.second;
			isR[pos] = true;
			ret += now.first;
			left--;
		}
	}
	
	while (!que.empty()) { que.pop(); }
	
	/*rep(i, n) {
		if (isR[i]) cout << "R";
		else cout << "L";
	}
	cout << endl;
	
	int Cal = 0;
	rep(i, n) {
		if (isR[i]) Cal += R[i];
		else Cal += L[i];
	}
	cout << "Cal = " << Cal << ", ret = " << ret << endl;*/
	
	//右に変えた方が良いやつを考える
	priority_queue<P, vector<P>, greater<P>> queR;
	int right = 0;
	for (i = n - 1; i >= 0; i--) {
		if (R[i] - L[i] > 0 && isR[i] == false) {
			isR[i] = true;
			ret += R[i] - L[i];
		}
		if (isR[i]) {
			right++;
			queR.push(P(R[i] - L[i], i));
		}
		
		while (right > n - K[i]) {
			P now = queR.top(); queR.pop();
			int pos = now.second;
			isR[pos] = false;
			ret -= now.first;
			right--;
		}
	}
	
	/*rep(i, n) {
		if (isR[i]) cout << "R";
		else cout << "L";
	}
	cout << endl;*/
	
	int cal = 0;
	rep(i, n) {
		if (isR[i]) cal += R[i];
		else cal += L[i];
	}
	//cout << "cal = " << cal << ", ret = " << ret << endl;
	return cal;
}
 
signed main() {
	int caseNum;
	cin >> caseNum;
	while (caseNum--) {
		int i;
		cin >> n;
		vector<T> tup;
		rep(i, n) {
			int k, l, r;
			cin >> k >> l >> r;
			tup.push_back(T(k, l, r));
		}
		sort(tup.begin(), tup.end());
		rep(i, n) {
			K[i] = get<0>(tup[i]);
			L[i] = get<1>(tup[i]);
			R[i] = get<2>(tup[i]);
		}
		int res = solve();
		cout << res << endl;
	}
	return 0;
}

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

int main(){
  int a[3][3];
  int open[3][3];
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> a[i][j];
      open[i][j] = 0;
    }
  }
  int n;
  int b[100];
  cin >> n;
  for(int k=0; k<n; k++){
    cin >> b[k];
    for(int i=0; i<3; i++){
      for(int j=0; j<3; j++){
        if(a[i][j] == b[k]){
          open[i][j] = 1;
        }
      }
    }
  }
  if(open[0][0] == 1 && open[0][1] == 1 && open[0][2] == 1){
    cout << "Yes\n";
    return 0;
  }
  if(open[1][0] == 1 && open[1][1] == 1 && open[1][2] == 1){
    cout << "Yes\n";
    return 0;
  }
  if(open[2][0] == 1 && open[2][1] == 1 && open[2][2] == 1){
    cout << "Yes\n";
    return 0;
  }
  if(open[0][0] == 1 && open[1][0] == 1 && open[2][0] == 1){
    cout << "Yes\n";
    return 0;
  }
  if(open[0][1] == 1 && open[1][1] == 1 && open[2][1] == 1){
    cout << "Yes\n";
    return 0;
  }
  if(open[0][2] == 1 && open[1][2] == 1 && open[2][2] == 1){
    cout << "Yes\n";
    return 0;
  }
  if(open[0][0] == 1 && open[1][1] == 1 && open[2][2] == 1){
    cout << "Yes\n";
    return 0;
  }
  if(open[0][2] == 1 && open[1][1] == 1 && open[2][0] == 1){
    cout << "Yes\n";
    return 0;
  }
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 256