akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

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

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int ans=0;
	rep(i,s.size()){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3792
#include<iostream>
using namespace std;
const int maxn=1e5+10;
int n,a[maxn],b[maxn];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		b[a[i]]=i;
	for(int i=1;i<=n;i++){
		if(i==1)
		    cout<<b[i];
		else
			cout<<" "<<b[i];
	}
	return 0;
}

Measured memory_bytes: 1536
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10,mod=1e9+7;
inline void Dec(int &x,int y) { x-=y; if(x<0) x+=mod; }
inline void Add(int &x,int y) { x+=y; if(x>=mod) x-=mod; }
char S[N];
int n,m,f[N];
int main() {
	rd(n),rd(m);
	scanf("%s",S+1);
	char c=S[1];
	int p=1,r=1,L=m;
	
	while(r<=m&&S[r]==c) r++;
	if(r==m+1) {
		if(n==2) { printf("3\n"); return 0; }
		f[0]=1,f[1]=2;
		for(int i=2;i<=n;++i) f[i]=(f[i-1]+f[i-2])%mod;
		printf("%d\n",(f[n-3]+f[n-1])%mod);
		return 0;
	}
	
	L=min(L,(r-p)|1);	
	p=r;
	while(p<=m&&S[p]!=c) p++;
	
	while(1) {
		r=p;
		while(r<=m&&S[r]==c) r++;
		if(r>m) break;
		if((r-p)&1) L=min(L,r-p);
		p=r;
		while(p<=m&&S[p]!=c) p++;
	}
	int sum[2]={0,0};
	f[1]=1,sum[1]=1;
	for(int i=2;i<=n;++i) {
		f[i]=sum[i&1];
		if(i-L-1>=1) Dec(sum[i&1],f[i-L-1]);
		Add(sum[i&1],f[i]);
	}
	int ans=0;
	for(int i=1;i<=n;++i) {
		if(n-i>L||!((n-i)&1)) continue;
		Add(ans,f[i]*(ll)(n-i+1)%mod);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1280
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}

void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}

#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const double PI = acos(-1);
typedef long long ll;
#define int ll
#define fori(n) for(int i=0; i<int(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

void solve() {
    cins(s);
    if(s=="ABC")
        cout<<"ARC"<<endl;
    else
        cout<<"ABC"<<endl;
}

signed main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    solve();
}



Measured memory_bytes: 3616
#include<stdio.h>
#define MAX 101
#define IN 2147483647
int n,m[MAX][2];

int ren(void){
    int i,j,df[n+1][n+1],k,min=IN,h;
    for(i=1;i<=n;i++)df[i][i]=0;
    for(h=2;h<=n;h++){
        for(i=1;i<=n-h+1;i++){
            j=i+h-1;
            for(k=i;k<j;k++)if(min>df[i][k]+df[k+1][j]+m[i][0]*m[k][1]*m[j][1])min=df[i][k]+df[k+1][j]+m[i][0]*m[k][1]*m[j][1];
            df[i][j]=min;
            min=IN;
            }
    }
    return df[1][n];
}

int main(){
    int i,min;

    scanf("%d",&n);
    for(i=1;i<=n;i++)scanf("%d%d",&m[i][0],&m[i][1]);
    min=ren();
    printf("%d\n",min);
    return 0;
}


Measured memory_bytes: 2104
import sys
inp=[i.strip() for i in sys.stdin.readlines()]
if len(inp)==1:
    if len(inp[0].split())==2:
        A,B=map(int,inp[0].split())
        print(max(2*A-1,2*B-1,A+B))
    else:
        S=inp[0]
        N=len(S)
        X=""
        Y=""
        for i in range(N):
            if i%2==0:
                X=X+"0"
                Y=Y+"1"
            else:
                X=X+"1"
                Y=Y+"0"
        A=0
        B=0
        for i in range(N):
            if X[i]!=S[i]:
                A+=1
            if Y[i]!=S[i]:
                B+=1
        print(min(A,B))
else:
    if len(inp[0].split())==1:
        N=int(inp[0])
        H=[int(i) for i in inp[1].split()]
        ans=1
        for i in range(1,N):
            flag=1
            for j in range(i):
                if H[j]>H[i]:
                    flag=0
                    break
            if flag==1:
                ans+=1
        print(ans)
    else:
        N,K=map(int,inp[0].split())
        S=inp[1]
        L=[0]
        tmp="1"
        for i in range(N):
            if tmp!=S[i]:
                L.append(1)
            else:
                L[-1]+=1
            tmp=S[i]
        if tmp=="0":
            L.append(0)
        M=len(L)
        if M<=2*K+1:
            print(N)
            exit()
        X=[0 for i in range(M+1)]
        for i in range(M):
            X[i+1]=L[i]+X[i]
        ans=0
        for i in range(0,M-2*K,2):
            ans=max(ans,X[i+2*K+1]-X[i])
        print(ans)


Measured memory_bytes: 8004
import sys
input = sys.stdin.readline
from bisect import bisect_left
from collections import Counter

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

mod = 10**9+7

A.sort()
B.sort()
dic_A = Counter(A)
dic_B = Counter(B)

ans = 1
for n in reversed(range(1, N*M+1)):
    if n in dic_A.keys() and n in dic_B.keys():
        if dic_A[n] != 1 or dic_B[n] != 1:
            ans = 0
    elif n in dic_A.keys():
        if dic_A[n] != 1:
            ans = 0
        else:
            prob = M - bisect_left(B, n)
            ans = ans * prob % mod
    elif n in dic_B.keys():
        if dic_B[n] != 1:
            ans = 0
        else:
            prob = N - bisect_left(A, n)
            ans = ans * prob % mod
    else:
        prob_A = N - bisect_left(A, n)
        prob_B = M - bisect_left(B, n)
        prob = prob_A * prob_B - (N*M-n)
        ans = ans * prob % mod
print(ans) 


Measured memory_bytes: 3700
#include <stdio.h>

int main(void)
{
	int n, x;
	int i, j;
		
	scanf("%d", &n);

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

		if (x % 3 == 0)
				printf(" %d", i);
		else
		{
			while (1)
			{
				if (x % 10 == 3)
				{
					printf(" %d", i);
					break;
				}

				if (x == x / 10)
					break;

				x /= 10;
			}	
		}
	}

	putchar('\n');

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
  string s; cin >> s;
  stack<char> t;
  for(auto x : s){
    if(SZ(t)&&t.top()!=x) t.pop();
    else t.push(x);
  }
  cout<<SZ(s)-SZ(t) << "\n";
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(T x,T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> T modinv(T x,const T mod){return modpow(x,mod-2,mod);}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> T deg2rad(T deg) {return deg*2*M_PI/360;}
template<class T> T rad2deg(T rad) {return rad*360/(2*M_PI);}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const ll MAX=5e6;

struct edge { ll to,cost; };

void warshall_floyd(int V, vector<vector<ll>> &d) {
  REP(k,V)REP(i,V)REP(j,V) {
    d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
  }
}

int main() {
  // クエリへの返答。最小の燃料補給回数（or -1）
  // ワーシャルフロイトで全ての街間の最短コストを調べる
  // 辿りつけないのは、最短距離の中にL以上のコスト道が含まれている場合
  ll N,M,L;cin>>N>>M>>L;

  // WF
  vector<vector<ll>> d(N,vector<ll>(N,LLONG_MAX/4));
  REP(i,N) d[i][i] = 0;
  REP(i,M) {
    ll A,B,C;cin>>A>>B>>C;
    A--;B--;
    if (C<=L) {
      d[A][B] = C;
      d[B][A] = C;
    }
  }

  // まずは一度WF
  REP(k,N)REP(i,N)REP(j,N) {
    d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
  }

  // L以下のコストを1にする
  REP(i,N)REP(j,N) {
    if (d[i][j]<=L) d[i][j]=1;
  }

  // サイドWF
  REP(k,N)REP(i,N)REP(j,N) {
    d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
  }

  ll Q;cin>>Q;
  REP(i,Q) {
    ll s,t;cin>>s>>t;
    s--;t--;
    d[s][t]==LLONG_MAX/4 ? OUT(-1) : OUT(d[s][t]-1);
  }

  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<numeric>
#include<string>
using namespace std;

int main(){
    int n,k,r,s,p;
    string t;
    cin>>n>>k;
    cin>>r>>s>>p;
    cin>>t;

    vector<int> score(n,0);
    for(int i=0;i<k;++i){
        int temp;
        if(t[i]=='r') temp=p;
        else if(t[i]=='s') temp=r;
        else temp=s;
        score[i]=temp;
    }

    for(int i=k;i<n;++i){
        if(t[i]!=t[i-k]){
            int temp;
            if(t[i]=='r') temp=p;
            else if(t[i]=='s') temp=r;
            else temp=s;
            score[i]=temp;
            continue;
        }

        if(score[i-k]==0){
            int temp;
            if(t[i]=='r') temp=p;
            else if(t[i]=='s') temp=r;
            else temp=s;
            score[i]=temp;
        }
    }

    long long ans=accumulate(score.begin(),score.end(),0);
    cout<<ans<<endl;
}

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

int main() {
 int A,B = 0;
 cin >> A >> B;

 int res = 0;

 res = A-2*B;
 if(res>0) {
	cout << res << endl;
 } else {
	cout << 0 << endl;
 }
}



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_W = 50;
const int MAX_H = 50;
int w, h;
int c[MAX_W][MAX_H+1];

inline bool check(int hx, int hy){ return 0 <= hx && hx < w && 0 <= hy && hy < h; }

int main()
{
  while(cin >> h >> w, w){
    int res = 0;
    rep(i, w) rep(j, h) cin >> c[i][j];

    rep(i, w) rep(j, h) if(c[i][j]){
      stack<pii> st;
      st.push(mp(i, j));
      c[i][j] = 0;
      res += 1;
      while(!st.empty()){
        pii here = st.top();  st.pop();
        int hx = here.first;
        int hy = here.second;
        erep(dx, -1, 1) erep(dy, -1, 1) if(dx || dy){
          int nx = hx + dx;
          int ny = hy + dy;
          if(!check(nx, ny)) continue;
          if(!c[nx][ny]) continue;
          st.push(mp(nx, ny));
          c[nx][ny] = 0;
        }
      }
    }

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1228
# -*- coding: utf-8 -*-
import sys

def main():
	y, x = map(int, input().split(" "))
	
	design_drawing = []
	for _ in range(y):
		line = input()
		design_drawing.append(list(line))
	
	for y, line in enumerate(design_drawing):
		for x, dot in enumerate(line):
			if dot == "#":
				if y != 0:
					if design_drawing[y-1][x] == "#":
						continue
				if y < len(design_drawing)-1:
					if design_drawing[y+1][x] == "#":
						continue
				if x != 0:
					if design_drawing[y][x-1] == "#":
						continue
				if x < len(line)-1:
					if design_drawing[y][x+1] == "#":
						continue
				print("No")
				sys.exit()
	print("Yes")
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
N=int(input())
list=[0 for i in range(N)]
for  i in range(N):
 x,l=map(int,input().split())
 list[i]=[x-l,x+l]
list.sort(key=lambda x: x[1])
ans=0
haji=-(10**10)
for  i in range(N):
 if list[i][0]>=haji:
  ans+=1
  haji=list[i][1]
print(ans)


Measured memory_bytes: 56240
#include<cstdio>
#include<iostream>
#define MAX 100000
using namespace std; 
typedef long long llong;

int n, k;
llong T[MAX];

//k辆最大运载量为P的卡车能装多少货物？
int check(llong P){
	int i = 0;
	for(int j = 0; j < k; j++){
		llong s = 0;
		while( s + T[i] <= P){
			s += T[i];
			i++;
			if(i == n) return n;
		}
	}
	return i;
}

int solve(){
	llong left = 0;
	llong right = 100000 * 10000; //货物数×1件货物的最大重量
	llong mid;
	while(right - left > 1){
		mid = (left + right) / 2;
		int v = check(mid);// mid == 检查 mid == p 时能装多少货物 
		if( v >= n) right = mid;
		else left = mid; 
	} 
	return right;
}

int main(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> T[i];
	}
	llong ans = solve();
	cout << ans << endl;
	return 0;
}


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

nt, nx, ny = 0, 0, 0
canTravel = True
for i in range(N):
	t, x, y = map(int, input().split())
	d = (x - nx) + (y - ny)
	dt = t - nt
	if(d <= dt and d % 2 == dt % 2):
		continue
	else:
		canTravel = False
		break

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



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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    map<int,int> mp;
    REP(i,n){
        int x;
        cin >> x;
        mp[x]++;
    }
    int ans = 0;
    for(const auto& i:mp){
        int x = i.first;
        int n = i.second;
        if(x<=n)ans+=n-x;
        else ans+=n;
    }
    cout << ans << endl;
    return 0;
}  

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

int main(){
  int n;cin>>n;
  int sum=0;
  int p[n];for(int i=0;i<n;i++){
    cin>>p[i];
    sum+=p[i];
  }
  bool flag=true;
  for(int i=0;i<n;i++){
    if(p[i]*2>=sum)flag=false;
  }
  cout<<(flag?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char a[200000+5],b[200000+5];
int map1[30],map2[30];
int main(){
    scanf("%s",a);
    scanf("%s",b);
    int n=strlen(a);
    for(int i=0;i<n;i++)
        if(map1[a[i]-'a'+1]==0&&map2[b[i]-'a'+1]==0)
            map1[a[i]-'a'+1]=b[i]-'a'+1,map2[b[i]-'a'+1]=a[i]-'a'+1;
        else{
            if((map1[a[i]-'a'+1]!=b[i]-'a'+1)||(map2[b[i]-'a'+1]!=a[i]-'a'+1)){
                printf("No\n");
                return 0;
            }
        }
    printf("Yes\n");
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b)
{
	return a.first + a.second > b.first + b.second;
}
pair<int, int> copmress(string &s)
{
	stack<char> st;
	for (int i = 0; i < s.length(); ++i)
	{
		if (s[i] == '(')
			st.push('(');
		else
		{
			if (!st.empty() && st.top() == '(')
				st.pop();
			else
				st.push(')');
		}
	}
	int required = 0, profit = 0;
	while (!st.empty())
	{
		char ch = st.top();
		st.pop();
		if (ch == ')')
			required ++;
		else
			profit ++;
	}
	return make_pair(required, profit - required);
}
int main(int argc, char const *argv[])
{
	int n, cs = 0, sum = 0;
	vector<pair<int, int> > pos, neg;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		pair<int, int> p = copmress(s);
		p.first = max(p.first, -p.second);
		sum += p.second;
		if (p.second >= 0)
			pos.push_back(p);
		else
			neg.push_back(p);
	}
	if (sum)
		return cout << "No", 0;
	sort(pos.begin(), pos.end());
	sort(neg.begin(), neg.end(), cmp);
	for (int i = 0; i < pos.size(); ++i)
	{
		if (cs >= pos[i].first)
			cs += pos[i].second;
		else
			return cout << "No", 0;
	}
	for (int i = 0; i < neg.size(); ++i)
	{
		if (cs >= neg[i].first)
			cs += neg[i].second;
		else
			return cout << "No", 0;
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 11256
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    s = sc.strarr()[0]
    if s == 'MON':
        print('6')
    elif s == 'TUE':
        print('5')
    elif s == 'WED':
        print('4')
    elif s == 'THU':
        print('3')
    elif s == 'FRI':
        print('2')
    elif s == 'SAT':
        print('1')
    elif s == 'SUN':
        print('7')


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


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

int main(){
    int n;
    cin >> n;
    long long ans = 0;
    map<int, int> map;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        map[a]++;
        ans += a;
    }
    int q;
    cin >> q;

    for(int i = 0; i < q; i++){
        int b,c;
        cin >> b >> c;
        if(map[b] != 0){
            ans += (c - b)*map[b];
            map[c] += map[b];
            map[b] = 0; 
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 7840
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll Mod=1e9+7;
void upd(ll &x,ll v)
{
	x=(x+v)%Mod;
}
struct mat
{
	int n,m;
	ll a[55][55];
	void clear()
	{
		memset(a,0,sizeof(a));
	}
	void init()
	{
		for (int i=1;i<=n;i++)
		{
			a[i][i]=1;
		}
	}
	mat operator * (const mat b) const
	{
		mat res;
		res.clear();
		res.n=n;
		res.m=b.m;
		for (int i=1;i<=n;i++)
		{
			for (int j=1;j<=b.m;j++)
			{
				for (int k=1;k<=m;k++)
				{
					upd(res.a[i][j],a[i][k]*b.a[k][j]);
				}
			}
		}
		return res;
	}
};
int n;
ll k;
mat pw(mat x,ll y)
{
	mat res;
	res.n=res.m=x.n;
	res.init();
	while (y)
	{
		if (y&1)
		{
			res=res*x;
		}
		x=x*x;
		y>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%lld",&n,&k);
	mat a,res;
	a.n=a.m=res.m=n;
	res.n=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			scanf("%d",&a.a[i][j]);
		}
		res.a[1][i]=1;
	}
	a=pw(a,k);
	res=res*a;
	ll ans=0;
	for (int i=1;i<=n;i++)
	{
		upd(ans,res.a[1][i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
import copy
n, m, q = map(int, input().split())
a = [0]*q
b = [0]*q
c = [0]*q
d = [0]*q
for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())
A = [1]
ans = 0
def dfs(lis):
    if len(lis) == n+1:
        now = 0
        for i in range(q):
            if lis[b[i]] - lis[a[i]] == c[i]:
                now += d[i]
        global ans
        ans = max(now, ans)
        return 0
    lis.append(lis[-1])
    while lis[-1] <= m:
        newlis = copy.deepcopy(lis)
        dfs(newlis)
        lis[-1] += 1
dfs(A)
print(ans)

Measured memory_bytes: 9356
N,K = map(int,input().split())

s = []

for i in range(N):
    s.append(False)
    
for i in range(K):
    d = int(input())
    a = list(map(int,input().split()))
    for j in range(d):
        s[a[j]-1] = True
        
cut = 0
for i in range(N):
    if not s[i]:
        cut += 1

print(cut)

Measured memory_bytes: 9124
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map(String::toInt)
    val dList = readLine()!!.split(' ').map { it.toCharArray().first() }
    for (i in n until 100000) {
        if(i.toString().toCharArray().all { dList.contains(it).not() }){
            println(i)
            break
        }
    }
}

Measured memory_bytes: 38368
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,ar[100],i,a;
  double sum=0,r,c,d;
  priority_queue<double> q;
  cin>>n;
  for(i=0; i<n; i++)
  {
    cin>>a;
    q.push(-a);    
  }
  //cout<<q.size()<<endl;
   while(q.size()>1)
   {
     c=q.top()*(-1); q.pop();
     d=q.top()*(-1); q.pop();

     r=(c+d)/2;
     q.push(-r);
   }
   double ans=q.top()*-1;
   printf("%0.06lf\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    char text[3];
  int ans= 0;
    scanf("%s",text);

  // Aか？
	for (int i=0; i<3; i++){
      if(text[i] == 'A'){
        ans++;
      }
    }
  
  if(ans==0 || ans == 3) {
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }
    return 0;
}

Measured memory_bytes: 128
# A - Candy Distribution Again
N,x = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
tmp = 0
ans = 0
for a in A:
    tmp += a
    if tmp<=x:
        ans += 1
    else:
        break
if ans==N and tmp!=x:
    ans -= 1
print(ans)

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

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector<int> time;
		for(int i = 0; i < n; ++i)
		{
			int tl;
			cin >> tl;
			time.push_back(tl);
		}
		for(int i = 0; i < m; ++i)
		{
			int tr;
			cin >> tr;
			time.push_back(tr);
		}
		sort(time.begin(), time.end());
		int max_diff = time[0];
		for(int i = 0; i < time.size() - 1; ++i)
		{
			if(time[i + 1] - time[i] > max_diff)
			{
				max_diff = time[i + 1] - time[i];
			}
		}
		cout << max_diff << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

using namespace std;

string s; int n; 

inline void remove_cube(int k)
{
  	s.erase(s.begin()+k);
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
 
  	cin >> s, n = s.size();
  
  	for(int i = n-2; i >= 0; i--)
      	if(s.size() > i+1 and s[i] != s[i+1])
          	remove_cube(i+1), remove_cube(i);
  
  	cout << n - s.size(); 
}
  


Measured memory_bytes: 512
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>

using namespace std;


int state[1000000];
int main()
{
    int s;
    
    cin >> s;
    int ans = 1;
    while (1) {
        state[s]++;
        if (state[s] == 2)break;
        if (s % 2 == 0)s = s / 2;
        else s = 3 * s + 1;
        ans++;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3188
#include<cstdio>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std; 
int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	n=max(n,m);
	printf("%d\n",(k-1)/n+1); 
}

Measured memory_bytes: 128
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printyn(test) printf(test ? "YES\n" : "NO\n");
#define all(x) (x).begin(), (x).end()

using ll = long long;

#include <stdio.h>
#include <algorithm>
//#include <vector>

using namespace std;


int main() {

	int a, countof5 = 0, countof7 = 0;
	rep(i, 3) {
		scanf("%d", &a);
		if (a == 5)++countof5;
		else if (a == 7)++countof7;
	}
	printyn(countof5 == 2 && countof7 == 1);

	return 0;
}

Measured memory_bytes: 128
x, k, d = io.read("*n","*n","*n")

x = math.abs(x)

if math.abs(x) // d >= k then
  print(math.abs(x) - k*d)
elseif (k - x // d) % 2 == 0 then
  print(math.abs(x - x // d * d))
else
  print(math.min(math.abs(x - x // d * d - d), math.abs(x - x // d * d + d)))
end


Measured memory_bytes: 2696
#include<iostream>
using namespace std;
int main() {
	for (int i = 0; i < 4; i++) {
		int a, b;
		cin >> a >> b;
		switch (a) {
		case 1:
			cout << b * 6000 << endl;
			break;
		case 2:
			cout << b * 4000 << endl;
			break;
		case 3:
			cout << b * 3000 << endl;
			break;
		case 4:
			cout << b * 2000 << endl;
			break;
		}
	}
}

Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
using namespace std;

int main() {
	int N, X;
	cin >> N >> X;

	int cord = 0;
	int ans = 0;

	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}

	for (int i = 0; i <= N; i++) {
		if (cord <= X) {
			cord += vec[i];
			ans++;
		}
	}
	cout << ans << endl;
}


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

int N;
string ans;
int main(){
    cin >> N;
    if(N == 0){
        cout << 0 << endl;
        return 0;
    }
    for(int k = 0; N != 0; k++){
        if(N % 2 == 0){
            ans.push_back('0');
        }else{
            ans.push_back('1');
            if(k % 2 == 0){
                N -= 1;
            }else{
                N += 1;
            }
        }
        N /= 2;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
        
}


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

int main() {
    string s;
    cin >> s;

    int n = s.size();
    int a = count(s.begin(), s.end(), '0');
    int ans = min(a, n - a) * 2;

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


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

int main() {
    string s;
    cin >> s;
    if(s == "abc" || s == "acb" || s == "bac" || s == "bca" || s == "cab" || s == "cba") cout << "Yes" << endl;
    else cout << "No" << endl;
 }

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N (100*200*100*8+10)
int n;
int t[N], v[N], d[N];

int main(){
	cin>>n;
	rep(i, n){
		cin>>t[i];
		t[i] *= 2;
	}
	rep(i, n){
		cin>>v[i];
		v[i] *= 2;
	}
	int T = 0;
	rep(i, n) T += t[i];
	fill(d, d+N, INF);
	int p = 0;
	d[0] = 0;
	rep(i, n){
		rep(j, t[i]){
			++p;
			chmin(d[p], v[i]);
		}
		chmin(d[p], v[i+1]);
	}
	d[T] = d[T+1] = 0;
	rep(i, T) chmin(d[i+1], d[i]+1);
	for(int i = T-1; i >= 0; i--) chmin(d[i], d[i+1]+1);
	//rep(i, T) chmin(d[T-i-1], d[T-i]+1);
	ll res = 0;
	rep(i, T) res += d[i];
	cout.precision(9);
	cout<<fixed<<res/4.0<<endl;
	return 0;
}


Measured memory_bytes: 65920
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;
    int white = 0, black = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == '.') {
            white++;
        }
    }
    black = N - white;
    int ans = min(white, black);
    int right_white = white;
    int left_black = 0;
    for (int i = 0; i < N; i++) {
        ans = min(ans, right_white + left_black);
        if (S[i] == '#') {
            left_black++;
        } else {
            right_white--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    string s;cin>>s;
    if(s[2]==s[3] && s[4]==s[5]){
        cout<<"Yes"<<"\n";
    }else
    cout<<"No\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}


Measured memory_bytes: 256
//F[i][j]表示一个硬币在X[i]另一个硬币在j的最小代价
//考虑转移：
//F[i][j] <- F[i - 1][j] + |X[i] - X[i - 1]|
//F[i][X[i - 1]] <- F[i - 1][j] + Abs(j - X[i])
//线段树维护即可 

#include <cstdio>
#include <algorithm>

using namespace std;

void Get_Val(int &Ret)
{
	Ret = 0;
	char ch;
	while (ch = getchar(), ch > '9' || ch < '0')
		;
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
}

typedef long long int LL;

const int Max_N(200050);
const int Max_Q(200050);

#define LEFT  (segt[cur].l)
#define RIGHT (segt[cur].r)
#define MID   (segt[cur].mid)
#define TAG   (segt[cur].Tag)
#define MIN   (segt[cur].Min)
#define MINA  (segt[cur].Mina)
#define MINB  (segt[cur].Minb)
#define LCH   (cur << 1)
#define RCH   ((cur << 1) | 1)

struct node
{
	int l, r, mid;
	LL Tag, Min, Mina, Minb;
};
node segt[Max_N << 2];

inline void pushup(const int &cur)
{
	MIN = min(segt[LCH].Min, segt[RCH].Min);
	MINA = min(segt[LCH].Mina, segt[RCH].Mina);
	MINB = min(segt[LCH].Minb, segt[RCH].Minb);
}

inline void Add(const int &cur, const LL &v)
{
	TAG += v, MIN += v, MINA += v, MINB += v;
}

inline void pushdown(const int &cur)
{
	if (TAG)
		Add(LCH, TAG), Add(RCH, TAG), TAG = 0LL;
}

void build_tree(const int &cur, const int &l, const int &r)
{
	LEFT = l, RIGHT = r, MID = l + ((r - l) >> 1), TAG = 0LL, MIN = MINA = MINB = 0X3F3F3F3F3F3F3F3FLL;
	if (l == r)
		return;
	build_tree(LCH, l, MID), build_tree(RCH, MID + 1, r);
}

void change(const int &cur, const int &pos, const LL &v)
{
	if (LEFT == RIGHT)
	{
		MIN = min(MIN, v);
		MINA = MIN - pos;
		MINB = MIN + pos;
		return;
	}
	pushdown(cur);
	if (pos <= MID)
		change(LCH, pos, v);
	else
		change(RCH, pos, v);
	pushup(cur);
}

LL queryA(const int &cur, const int &l, const int &r)
{
	if (LEFT == l && RIGHT == r)
		return MINA;
	pushdown(cur);
	if (r <= MID)
		return queryA(LCH, l, r);
	else
		if (l > MID)
			return queryA(RCH, l, r);
		else
			return min(queryA(LCH, l, MID), queryA(RCH, MID + 1, r));
}

LL queryB(const int &cur, const int &l, const int &r)
{
	if (LEFT == l && RIGHT == r)
		return MINB;
	pushdown(cur);
	if (r <= MID)
		return queryB(LCH, l, r);
	else
		if (l > MID)
			return queryB(RCH, l, r);
		else
			return min(queryB(LCH, l, MID), queryB(RCH, MID + 1, r));
}

inline int Abs(const int &x)
{
	return x >= 0 ? x : -x;
}

int N, Q, A, B, X[Max_Q];

void init()
{
	Get_Val(N), Get_Val(Q), Get_Val(A), Get_Val(B);
	for (int i = 1;i <= Q;++i)
		Get_Val(X[i]);
}

void dp()
{
	build_tree(1, 1, N);
	for (int x = 1;x <= N;++x)
	{
		change(1, x, Abs(x - A) + Abs(X[1] - B));
		change(1, x, Abs(x - B) + Abs(X[1] - A));
	}
	LL t;
	for (int i = 2;i <= Q;++i)
	{
		t = min(X[i] + queryA(1, 1, X[i]), queryB(1, X[i], N) - X[i]);
		Add(1, Abs(X[i] - X[i - 1]));
		change(1, X[i - 1], t);
	}
	printf("%lld\n", segt[1].Min);
}

int main()
{
	init();
	dp();
	return 0;
}

Measured memory_bytes: 26752
/*  ex3_4
    supercomputerjoi    */

#include <stdio.h>

int main(void){

    int num;
    int count;  // loop count
    char yesOrNo = 'n'; // flag

    // input N
    scanf("%d", &num);

    // check N can be divided each number
    for(count = 1; count <= 9; count++){
        if(num % count == 0){
            // check another one is under 10
            if(num / count < 10){
                // change flag
                yesOrNo = 'y';
            }
        }
    }

    // branch by flag
    if(yesOrNo == 'y'){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

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

class Nums {
public:
	int a, b, c;

	Nums(int _a, int _b, int _c) {
		a = _a;
		b = _b;
		c = _c;
	}

	bool operator<(const Nums& other) const {
		return a < other.a;
	}
};

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

  int x,y,z,k;
  cin >> x >> y >> z >> k;
  vector<ll> A(x),B(y),C(z);
  rep(i, x) cin >> A[i];
  rep(i, y) cin >> B[i];
  rep(i, z) cin >> C[i];

	A.push_back((long long)-1e17);
	B.push_back((long long)-1e17);
	C.push_back((long long)-1e17);

  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());
  sort(C.begin(),C.end());
  reverse(C.begin(),C.end());

  priority_queue<pair<ll, Nums>> pq;
  pq.push(make_pair(A[0] + B[0] + C[0], Nums(0,0,0)));
  vector<ll> ans(k);
  set<int> used;
  used.insert(0);

  rep(i, k) {
    auto v = pq.top(); pq.pop();
    ans[i] = v.first;

    rep(j, 3) {
      ll a = v.second.a;
      ll b = v.second.b;
      ll c = v.second.c;
      if(j == 0) a++;
      else if(j == 1) b++;
      else if(j == 2) c++;

      int hash = (a << 20) + (b << 10) + c;
      if(used.find(hash) == used.end()) {
        used.insert(hash);
        pq.push(make_pair(A[a] + B[b] + C[c], Nums(a,b,c)));
      }
    }
  }

  rep(i, k) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
bool judge(vector<int> const& a,int n){
  bool flag=false;
  rep(i,n){
    if(a[i]>=n){
      flag=true;
      break;
    }
  }
  return flag;
}
int calc(vector<int>& a,int n){
  int res=0;
  rep(i,n){
    int buf=a[i]/n;
    a[i]%=n;
    res+=buf;
    rep(j,n){
      if(i==j)continue;
      else{
        a[j]+=buf;
      }
    }
  }
  return res;
}
signed main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  int res=0;
  while(judge(a,n)){
    res+=calc(a,n);
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll l,r,d;
  cin>>l>>r>>d;
  ll ans=0;
  for(ll i=l;i<=r;i++)
  {
    if(i%d==0)
      ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
n = int(input())
xl = [tuple(map(int,input().split())) for _ in range(n)]
xl.sort(key = lambda x:x[0]+x[1])
maxi = -10**9-7
ans = n
for i in range(n):
  if maxi <= xl[i][0]-xl[i][1]:
    maxi = xl[i][0]+xl[i][1]
  else:
    ans -= 1
    
print(ans)
    

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
vector<int> a(n),b(n),c(m),d(m);
rep(i,n){
    cin>>a[i]>>b[i];
}
rep(i,m){
    cin>>c[i]>>d[i];
}
vector<int>move(n);
rep(i,n){
    ll dist=INF;
    int idx;
    rep(j,m){
        ll tmp_dist=abs(a[i]-c[j])+abs(b[i]-d[j]);
        if(dist>tmp_dist){
            dist=tmp_dist;
            idx=j+1;
        }
    }
    move[i]=idx;
}
rep(i,n){
    cout<<move[i]<<endl;
}

return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.trim_right().to_string()
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn gcd(a: usize, b: usize) -> usize {
    use std::cmp::{max, min};
    let mi = min(a, b);
    let ma = max(a, b);

    let r = ma % mi;
    if r == 0 {
        return mi;
    }

    gcd(mi, r)
}

fn main() {
    let k = parse_line!(usize);

    let mut sum = 0;
    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                sum += gcd(gcd(a, b), c);
            }
        }
    }

    println!("{}", sum);
}


Measured memory_bytes: 2152
/*
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<complex>
*/

#include<bits/stdc++.h>

#define X real()
#define Y imag()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define FastF freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)
#define Fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0)
using ll = long long;
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vi::iterator vii;
typedef vector<ll> vl;
typedef vl::iterator vli;
typedef long double C;
typedef complex<C> P;
const int INF = 1e9 + 5;
const ll INFF = 1e18 + 5;
const int M = 1e9 + 7;
const double pi = acos(-1);

int main()
{
	//FastF;
	Fast;
	int n; cin >> n;
	vi dp(3, 0);
	for (int day = 0; day < n; ++day) {
		vi new_dp(3, 0);
		vi c(3);
		for (int i = 0; i < 3; ++i) 
			cin >> c[i];
		for (int i = 0; i < 3; ++i) {
			for (int j = 0; j < 3; ++j) {
				if (i != j) {
					new_dp[j] = max(new_dp[j], dp[i] + c[j]);
				}
			}
		}
		dp = new_dp;
	}
	cout << max({ dp[0],dp[1],dp[2] }) << '\n';
	return 0;
}

Measured memory_bytes: 256
h, w, k = map(int, input().split())
ans = 0
s = [input() for _ in range(h)]
for hi in range(2**h):
	hl = []
	for hj in range(h):
		if (hi >> hj) & 1:
			hl.append(hj)
	tmp = s[:]
	for j in hl:
		tmp[j] = "."*w
	for wi in range(2**w):
		wl = []
		for wj in range(w):
			if (wi >> wj) & 1:
				wl.append(wj)
		cnt = 0
		for i in range(h):
			for j in range(w):
				if j not in wl:
					if tmp[i][j] == "#":
						cnt += 1
		if cnt == k:
			ans += 1
print(ans)

Measured memory_bytes: 68488
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <time.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,string> pip;
typedef vector<pip> vip;
const int inf=2*1e9+1;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Graph{
	private:
	int V;
	vvp List;
	int dfs_back(int v,int r,vi& rank){
		for(int i=0;i<List[v].size();i++){
			P p=List[v][i];
			if(rank[v]==rank[p.first]+1){
				if(r) return dfs_back(p.first,r-1,rank);
				else return p.second;
			}
		}
	}
	int dfs(int v,int r,vi& rank){
		rank[v]=r;
		if(v==V-1) return dfs_back(v,(r+1)/2-1,rank);
		for(int i=0;i<List[v].size();i++){
			int u=List[v][i].first;
			if(rank[u]==-1){
				int f=dfs(u,r+1,rank);
				if(f!=-1) return f;
			}
		}
		return -1;
	}
	int DFS(int v,vi& used,int e){
		used[v]=1;
		int res=1;
		for(int i=0;i<List[v].size();i++){
			P p=List[v][i];
			if(p.second!=e&&!used[p.first]) res+=DFS(p.first,used,e);
		}
		return res;
	}
	public:
	Graph(int v){
		V=v;
		List=vvp(v);
	}
	void add_edge(int s,int t,int i){
		List[s].push_back({t,i});
		List[t].push_back({s,i});
	}
	string solve(){
		vi rank(V,-1),used(V,0);
		int e=dfs(0,0,rank);
		int num=DFS(0,used,e);
		if(num>V-num) return "Fennec";
		else return "Snuke";
	}
};

int n;

int main(){
	cin>>n;
	Graph g(n);
	for(int i=0;i<n-1;i++){
		int s,t;
		cin>>s>>t;
		g.add_edge(s-1,t-1,i);
	}
	cout<<g.solve()<<endl;
}

Measured memory_bytes: 11392
N = int(input())
lists = []
max = 0
for i in range(N):
    s = int(input())
    lists.append(s)
sum_lists = sum(lists)
if sum_lists % 10 != 0:
    print(sum_lists)
    exit()
for i in range(N):
    tmp = sum_lists - lists[i]
    if tmp % 10 != 0:
        if max < tmp:
            max = tmp
print(max)

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

}

signed main() {
	string s, t;

	cin >> s >> t;

	vector<vector<ll>> dp(s.size() + 1, vector<ll>(t.size() + 1, 0));

	FOR(i, 1, s.size() + 1) {
		FOR(j, 1, t.size() + 1) {
			if (s[i - 1] == t[j - 1]) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
			}
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			dp[i][j] = max(dp[i][j], dp[i][j - 1]);
		}
	}
	
	ll x = s.size();
	ll y = t.size();
	string ans = "";

	while (x > 0 && y > 0) {
		if (dp[x][y] == dp[x - 1][y]) {
			x--;
		}
		else if (dp[x][y] == dp[x][y - 1]) {
			y--;
		}
		else {
			ans = s[x - 1] + ans;
			x--;
			y--;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 70784
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
int a[N];
ll sm[N];

int main() {
  int n; ll m; scanf("%d %lld", &n, &m);
  for (int i = 0; i < n; i++)
    scanf("%d", a+i);
  sort(a, a+n);
  // for (int i = n-1; ~i; i--)
  //   sm[i] = sm[i+1] + a[i];
  int lo = 2*a[0], hi = 2*a[n-1];
  while (lo <= hi) {
    int mi = (lo+hi) / 2;
    ll cnt = 0;
    for (int i = 0; i < n; i++)
      cnt += n - (lower_bound(a, a+n, mi-a[i]) - a);
    if (cnt < m)
      hi = mi-1;
    else
      lo = mi+1;
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int x = n - (lower_bound(a, a+n, hi+1-a[i]) - a);
    m -= x;
    ans += x * 1ll * a[i] * 2ll;
  }
  ans += hi * 1ll * m;
  printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4480