akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <class T> T input() {T t; cin>>t; return t;}
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};

int main()
{
    int n;
    cin>>n;
    map<ll, ll> mp;
    REP(i,n) mp[input<ll>()]++;
    ll ans = 0ll;
    REPITR(itr,mp) ans += itr->e2 >= itr->e1 ? itr->e2 - itr->e1 : itr->e2;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 9568
//23:37

import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		char map[] ={'0','2','3','4','5','6','7','8','9','T','J','Q','K','A'};
		int invmap[] = new int[256];
		for(int i =1 ; i < 14;i++){
			invmap[map[i]] = i;
		}
//		System.out.println(Arrays.toString(invmap));
		for (;;) {
			String f = sc.next();
			if (f.equals("#")) {
				break;
			}

			char t = f.charAt(0);
			String[][] c = new String[4][13];
			for(int i =0 ; i < 4; i++){
				for(int j = 0; j < 13; j++){
					c[i][j] = sc.next();
				}
			}
			
			
			int index = 0;
			int pt[] = new int[2];
			for(int i =0 ; i < 13; i ++){
				int index2 = index;
				char mcolor = c[index][i].charAt(1);
				int mvalue = invmap[c[index][i].charAt(0)];
				for(int k = 1 ; k < 4; k++){
					int j = (index+k)%4;
					char color = c[j][i].charAt(1);
					int value = invmap[c[j][i].charAt(0)];
					if(color == t){
						if(mcolor == t){
							if(mvalue < value){
								index2 = j;
								mvalue = value;
							}							
						}else{
							mcolor = color;
							index2 = j;
							mvalue = value;
						}
					}
					if(color != mcolor){
						continue;
					}
					if(mvalue < value){
						index2 = j;
						mvalue = value;
					}
				}
//				System.out.println(index2);
				index = index2;
				pt[index2%2]++;
			}
			if(pt[0] > 6){
				System.out.println("NS "+(pt[0]-6));
			}else{
				System.out.println("EW "+(pt[1]-6));				
			}
		}
	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 12000
n = int(input())
tmp1=input()
tmp=tmp1[len(tmp1)-1]

s = set()
s.add(tmp1)

flg=True
for i in range(n-1):
    w = input()
    if w[0] != tmp:
        flg = False
        break
    tmp = w[len(w)-1]

    s.add(w)
    if(len(s) != i+2):
        flg = False
        break

if flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n,in,loot=0;
	vi a;
	a.push_back(0);
	cin >> n;
	int t = 0;
	rep(i, n) {
		cin >> in;
		loot += abs(in - t);
		a.push_back(in);
		t = in;
	}
	a.push_back(0);
	loot += abs(in);
	vi ans(n+2, loot);
	rep(i, n) {
		ans[i + 1] -= (abs(a[i + 2] - a[i + 1]) + abs(a[i + 1] - a[i]) - abs(a[i + 2] - a[i]));
	}
	rep(i, n) {
		cout << ans[i + 1] << endl;
	}
}

Measured memory_bytes: 2168
// Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
//If you are not doing well now just stick to it and learn new things one day you will be...
//Compete with yourself 
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll)x.size()
#define all(x) x.begin(),x.end()
#define trav(a,x) for(auto &a:x)
#define fr(i,a,b)  for(ll i=a;i<=b;i++)
#define fr1(i,a)   for(ll i=0;i<a;i++)
#define frr(i,a,b) for(ll i=b;i>=a;i--)
#define frr1(i,a)   for(ll i=a-1;i>=0;i--)
#define sorta(a,n) sort(a,a+n)
#define sortd(a,n) sort(a,a+n,greater<ll>())
#define sorva(a) sort(a.begin(),a.end())
#define sortvd(a) sort(a.begin(),a.end(),greater<ll>())
#define tc(t) while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
using vi= vector<ll>;
using vvi= vector<vi>;
using vb =vector<bool>;
using vc =vector<char>;
using vs =vector<string>;
using vld =vector<ld>;
using pii =pair<ll,ll>;
using psi =pair<string,ll>;
using pci =pair<char,ll>;
using vpii =vector<pii>;
//}}}template*/
ll mod=1e9+7;
ll const maxn=1e5+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
ll modinverse(ll a, ll m){
    return powm(a,m-2,m);
}
bool prime(ll x){
    if(x<=1)return false;
    for(int i=2;i<=sqrt(x);i++)if(x%i==0)return false;
    return true;
}
ll divisor(ll x){
    ll cnt=0;
    for(int i=1;i<=sqrt(x);i++){
        if(x%i==0){
            if(i!=x/i)cnt+=2;
            else cnt+=1;
        }
    }
    return cnt;
}
vector<ll> sieve(ll n) {     
    bool prim[n+1]; 
    memset(prim, true, sizeof(prim)); 
  
    for (ll p=2; p*p<=n; p++) {
        if (prim[p] == true) { 
            for (int i=p*p; i<=n; i += p) 
                prim[i] = false; 
        } 
    }
    vector<ll>v;
    for(int i=2;i<=n;i++)if(prim[i])v.push_back(i);
    return v; 
}
vi v;
ll d;
ll dp[10005][101][2];
ll n;
void ini(string s){
    memset(dp,-1,sizeof(dp));
    v.clear();
    fr1(i,sz(s))v.pb(s[i]-'0');
    n=sz(v);
}
ll fun(ll pos,ll sum,ll f){
    if(pos==n){
        return sum%d==0;
    }
    if(dp[pos][sum][f]!=-1)return dp[pos][sum][f];
    ll lmt=9;
    if(!f)lmt=v[pos];
    ll ans=0;
    for(int dgt=0;dgt<=lmt;dgt++){
        ll nf=f;
        if(dgt<lmt)nf=1;
        ans=add(ans,fun(pos+1,(sum+dgt)%d,nf));
    }
    return dp[pos][sum][f]=ans%mod;
}
void solve(){
    string k;
    cin>>k>>d;
    ini(k);
    ll ans=fun(0,0,0);
    ans-=1;
    if(ans<0)ans+=mod;
    ans%=mod;
    cout<<ans<<"\n";
}
int main(){

    fio;
    ll t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
   return 0;
}

Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<string> blue(N);
  for(int i = 0; i < N; i++){
    cin >> blue.at(i);
  }
  int M;
  cin >> M;
  vector<string> red(M);
  for(int i = 0; i < M; i++){
    cin >> red.at(i);
  }
  int maxscore = 0;
  int score = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      if(blue.at(i) == blue.at(j)){
        score++;
      }
    }
    for(int j = 0; j < M; j++){
      if(blue.at(i) == red.at(j)){
        score--;
      }
    }
    if(maxscore < score){
      maxscore = score;
    }
    score = 0;
  }
  
  cout << maxscore << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  for(int i=0; i < n; i++)
    cin >> A.at(i);
  sort(A.begin(),A.end(),greater<int>());
  int alice_score = 0;
  int bob_score = 0;
  for(int i = 0; i < n; i++) {
    if(i % 2 == 0)
      alice_score += A.at(i);
    else
      bob_score += A.at(i);
  }
  cout << alice_score - bob_score << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int piece_n, X_n;
    cin >> piece_n >> X_n;
    vector<int> x;
    for (int i=0;i<X_n;i++){
        int tmp;
        cin >> tmp;
        x.push_back(tmp);
    }
    if (piece_n >= X_n){
        printf("0\n");
        return 0;
    }
    sort(x.begin(),x.end());
    int size = x.at(X_n -1)-x.at(0);
    int Leng[X_n - 1];

    for(int i=0;i<X_n - 1;i++){
        Leng[i] = abs(x.at(i) - x.at(i+1));
    }
    sort(Leng,Leng+X_n - 1);
    int Leng_sum_max = 0;
    for(int n=0,i=X_n -2;n<piece_n-1;i--){
        Leng_sum_max += Leng[i];
        n++;
    }
    cout << size - Leng_sum_max << endl;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
using namespace std;

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, x, t; cin >> n >> x >> t;
    int res = (n/x)*t;
    if(n%x)res += t;
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

void solve() {
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    ll ini = 0;
    for (ll i = K; i <= N+1; i++) {
        ll n = N + 1 - (i - 1);
        ll an = (1 + (n - 1) * i);
        ans += an;
        ans %= MOD;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3624
//C - Ubiquity
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define LL long long
#define Cl(X,Y) memset((X),(Y),sizeof(X))
#define FOR(i,A,B) for(LL i=A;i<=B;i++)
#define BOR(i,A,B) for(LL i=A;i>=B;i--)
#define INF 0x3f3f3f3f
#define MOD 1000000007
using namespace std;

inline void File() {
    freopen(".in","r",stdin);
    freopen(".out","w",stdout);
}

inline LL Fast(LL A,LL B) {
    LL Res=1;
    while(B) {
        if(B & 1) Res=(Res*A)%MOD;
        A=(A*A)%MOD;
        B>>=1;
    }
    return Res%MOD;
}

int main() {
    // File();
    LL N;
    scanf("%lld",&N);
    cout<<((Fast(10,N)-2*Fast(9,N)+Fast(8,N))%MOD+MOD)%MOD;
    // fclose(stdin);
    // fclose(stdout);
  //  system("pause");
    return 0;
}

Measured memory_bytes: 3752
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long i64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5;
struct P 
{ 
    int a, b, i; 
    P(int a = 0, int b = 0, int i = 0):a(a), b(b), i(i) {};
    friend bool operator < (P p, P q) { return (i64)p.a*q.b < (i64)q.a*p.b; }
}a[N];
int n, p[N], fa[N], vis[N]; i64 ans = 0; priority_queue<P> q;
int find(int x) { return fa[x] == x?x:fa[x] = find(fa[x]); }
int main()
{
    n = read(), vis[1] = 1;
    for(int i = 2; i <= n; ++i) p[i] = read();
    for(int i = 1, x; i <= n; ++i) x = read(), q.push(a[fa[i] = i] = P(!x, x, i));
    for( ; q.size(); q.pop())
    {
        P t = q.top(); int x = t.i, y;
        if(!vis[x]&&a[x].a==t.a&&a[x].b == t.b)
            vis[x] = 1, y = find(p[x]), ans += (i64)a[y].b*t.a, fa[x] = y, a[y].a += t.a, a[y].b += t.b, q.push(a[y]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 8564
"""
author : halo2halo
date : 12, Jan, 2020
"""

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A,B, T = map(int, readline().split())
print(B*(T//A))


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k;
int a[100010];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		if(a[i]==k)
		{
			printf("POSSIBLE");
			return 0;
		}
	}
	sort(a+1,a+n+1);
	if(k>a[n])
	{
		printf("IMPOSSIBLE");
		return 0;
	} 
	for(int i=1;i<n;i++)
	{
		int md=a[i+1]-a[i];
		if(md==0)continue;
		if(a[n]%md==k%md)
		{
			printf("POSSIBLE");
			return 0;
		}
	}
	printf("IMPOSSIBLE");
	return 0; 
} 

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_N = 1000;
    ll N, T[MAX_N], A[MAX_N];
    cin >> N;
    REP(i, N) {
        cin >> T[i] >> A[i];
    }

    ll res[2] = {T[0], A[0]};
    FOR(i, 1, N, 1) {
        if (T[i] < res[0] || A[i] < res[1]) {
            ll r = max(ceil(res[0], T[i]), ceil(res[1], A[i]));
            res[0] = T[i] * r;
            res[1] = A[i] * r;
        } else {
            res[0] = T[i];
            res[1] = A[i];
        }
    }
    cout << res[0] + res[1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

// 最大公約数求める関数
auto my_gcd(auto n , auto m){
  if(n < m){
    auto tmp = n;
    n = m;
    m = tmp;
  }
  auto l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
int N,Y; cin >> N >> Y;
int x = -1,y = -1,z = -1;
for(int i = N; i >= 0;i--){
	for(int j = 0; j <= N - i; j++){
		if(10000 * i + 5000 * j + 1000 * (N - i - j) == Y){
			x = i; y = j; z = N - i - j;
		}
	}
}
	cout <<x << " " << y << " " << z << endl;
  }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    cin >> N;
    vector<double> T(N), V(N);
    vector< pair< double,double > > P;
    
    for ( int i = 0; i < N; i++ ) {
        cin >> T[i];
    }
    for ( int i = 0; i < N; i++ ) {
        cin >> V[i];
    }
    double t = 0;    
    for ( int i = 0; i < N; i++ ) {
        P.push_back( make_pair( t, V[i] ) );
        t += T[i];
    }
    P.push_back( make_pair( t, 0 ) );
    
    double ans = 0;
    double v = 0;
    for ( double time = 0.5; time <= t; time += 0.5 ) {
        
        double v_limit = 1000000;
        for ( int i = 0; i <= N; i++ ) {
            if ( P[i].first >= time ) { v_limit = min( v_limit, P[i].first - time + P[i].second );  continue; }
            v_limit = P[i].second;
        }
        
        double v_new;
        if ( v+0.5 <= v_limit ) { v_new = v + 0.5; } 
        else if ( v > v_limit ) { v_new = v - 0.5; }
        
        ans += v*0.5;
        if ( v != v_new ) { ans += v < v_new ? (0.5*0.5)/2.0 : -(0.5*0.5)/2.0; }
        
        v = v_new;
        
        // cout << time << " " << v << endl;
    }
    
    
    printf( "%.7f", ans );
    
    return 0;
}

Measured memory_bytes: 384
use proconio::input;

fn main() {
    input! {
        n: usize,
        ab: [(i64, i64); n],
    };
    let mut c = vec![];
    for (i, &(a_i, b_i)) in ab.iter().enumerate() {
        c.push((a_i + b_i, i));
    }
    c.sort_by_key(|(k, _)| -k);

    let mut odd = true;
    let mut s_a = 0_i64;
    let mut s_b = 0_i64;
    for &(_, i) in c.iter() {
        if odd {
            s_a += ab[i].0;
        } else {
            s_b += ab[i].1;
        }
        odd = !odd;
    }
    let ans = s_a - s_b;
    println!("{}", ans);
}


Measured memory_bytes: 7732
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int x[4] = { -1,0,1,0 };
int y[4] = { 0,1,0,-1 };
int g[4][4];
int m = 0;

bool solve(int dee, int t, int zx, int zy) {
	int c = 0;
	for (int i=0;i<4;i++) {
		for (int j=0;j<4;j++) {
			if (g[i][j] != 0) {
				int t = g[i][j]-1;
				c += abs(t / 4 - i) + abs(t % 4 - j);
			}
		}
	}

	if (c+dee>m) return false;
	if (c==0) return true;
	int dx,dy;
	for(int i=0;i<4;i++) {
		if (abs(i-t)!=2) {
			dx = zx+x[i];
			dy = zy+y[i];
			if (dx < 0 || dx == 4 || dy < 0 || dy == 4) continue;
            swap(g[dx][dy], g[zx][zy]);
            if (solve(dee + 1, i, dx, dy)) return true;
            swap(g[dx][dy], g[zx][zy]);

		}
	}
	return false;
}

int main() {
	int zx,zy;
	for (int i=0;i<4;i++) {
		for (int j=0;j<4;j++) {
			cin>>g[i][j];
			if (g[i][j]==0) {
				zx=i;zy=j;
			}
		}
	}
	for (m=0;m>=0;m++) {
		if (solve(0,9,zx,zy)) {
			cout<<m<<endl;
			return 0;
		}
	}


	return 0;
}



Measured memory_bytes: 3100
from collections import defaultdict

n, m = map(int, input().split())

aa = []
bb = []
cc = []
dd = []
answer = []

for i in range(n):
    a, b = map(int, input().split())
    aa.append(a)
    bb.append(b)

for i in range(m):
    c, d = map(int, input().split())
    cc.append(c)
    dd.append(d)

for i in range(n):
    ans = float('inf')
    for j in range(m):
        distance = abs(aa[i]-cc[j]) + abs(bb[i]-dd[j])
        if ans > distance:
            ans = min(distance, ans)
            num = j+1
    answer.append(num)

print(*answer, sep='\n')


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

int main(void)
{
    int n;
    cin>>n;
    long long int max=0,ms=0,tot_player;
    long long int arr[n][2];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<2;j++)
        {
            cin>>arr[i][j];
        }
        if(arr[i][0]>max)
        {
            max=arr[i][0];
            ms=arr[i][1];
        }
    }
    tot_player=max;
    while(ms--)
    {
        tot_player++;
    }

    cout<<tot_player<<endl;
    return 0;
}

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

signed main(){
    int n,mina=1001, maxa=-1,a;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >>a;
        if(mina>a)mina=a;
        if(maxa<a)maxa=a;
    }
    cout << maxa-mina;
    return 0;
}

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

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

#define INF 1e10

using namespace std;

int gcd(int p, int q) {
	if (p % q == 0) return q;
	return gcd(q, p % q);
}

signed main(void) {
	int K;
	int ans = 0;

	cin >> K;

	rep(a, K) {
		rep(b, K) {
			rep(c, K) {
				ans += gcd(gcd(a+1, b+1), c+1);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
 int N;
 cin >> N;
 map<string,int> mp;
 string s;
 uint64_t count = 0;

 for(int i=0;i<N;i++){
   cin >> s;
   sort(s.begin(),s.end());
   if(mp.count(s)){
     mp.at(s)++;
     count += mp.at(s);
   }else{
     mp[s] = 0;
   }
  }
cout << count;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

llong GCD(llong a, llong b){
	a = abs(a), b = abs(b);
	if(a < b) swap(a, b);
	if(b == 0) return a;
	while(b){
		a %= b;
		swap(a,b);
	}

	return a;
}

llong LCM(llong a, llong b){
	return a / GCD(a, b) * b;
}

int main(){
	llong N;
	vector<llong> A;

	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];

	vector<llong> le(N), ri(N);
	le[0] = A[0];
	ri[N-1] = A[N-1];
	for (int i = 1; i < N; i++){
		le[i] = GCD(le[i-1], A[i]);
		ri[N-i-1] = GCD(ri[N-i], A[N-i-1]);
	}

	llong ans = 0;
	ans = max(le[N-2], ri[1]);
	for (int i = 1; i < N-1; i++)
		ans = max(ans, GCD(le[i-1], ri[i+1]));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
import sys


class UnionFind:

    def __init__(self, nvertices):
        self.rank = [1] * (nvertices + 5)
        self.p = [i for i in range(nvertices + 5)]

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])
        return self.p[u]

    def unite(self, u, v):
        x = self.find_set(u)
        y = self.find_set(v)
        if x == y:
            return
        if self.rank[x] > self.rank[y]:
            self.p[y] = x
        else:
            self.p[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def is_connected(self, u, v):
        return self.find_set(u) == self.find_set(v)


def main():
    sys.setrecursionlimit(int(1e5))
    nvertices, nedges = map(int, input().split())
    edges = []
    for i in range(nedges):
        u, v, w = map(int, input().split())
        edges.append((w, u, v))

    edges.sort(key=lambda e: e[0])
    ans = 0
    uf = UnionFind(nvertices)
    for w, u, v in edges:
        if not uf.is_connected(u, v):
            uf.unite(u, v)
            ans += w

    print(ans)


main()

Measured memory_bytes: 26348
def d_patisserie_abc():
    N, M = [int(i) for i in input().split()]
    Cake = [[int(i) for i in input().split()] for j in range(N)]
    # 変数の意味は，左から順に， 綺麗さ, おいしさ, 人気度 をそれぞれ
    # 正の方向 (p) に最大化する場合と負の方向 (n) に最大化する場合である．
    # なお，nnn, nnp, npn, npp は，ppp, ppn, pnp, pnn を
    # 逆にすることで得られる．
    ppp, ppn, pnp, pnn = [], [], [], []
    for x, y, z in Cake:
        ppp.append(x + y + z)
        ppn.append(x + y - z)
        pnp.append(x - y + z)
        pnn.append(x - y - z)
    ppp.sort()
    ppn.sort()
    pnp.sort()
    pnn.sort()

    # 値が大きなものを M 個取って足して絶対値をとる
    pts = map(lambda x: abs(sum(x)),
              (ppp[:M], ppn[:M], pnp[:M], pnn[:M], ppp[::-1][:M],
               ppn[::-1][:M], pnp[::-1][:M], pnn[::-1][:M])
              )
    return max(pts)

print(d_patisserie_abc())

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

int f(int a, int hp) {
    return (hp+a-1)/a;
}

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (f(b,c) <= f(d,a)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];

  if (a[0] != 0) {
    cout << -1 << endl;
    return 0;
  }

  REP(i, n) {
    if (a[i] >= a[i - 1] + 2) {
      cout << -1 << endl;
      return 0;
    }
  }

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

  cout << ans << endl;

  return 0;
}


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

int main() {
  int N, K, R, S, P;
  string T;
  cin >> N >> K >> R >> S >> P >> T;

  map<char, int> m;
  m.emplace('r', P), m.emplace('s', R), m.emplace('p', S);

  vector<int> score(N);
  rep(i, N) score[i] = m[T[i]];

  rep(i, N) {
    if (i >= K) {
      if (T[i] == T[i - K]) {
        if (score[i] > score[i - K]) {
          score[i - K] = 0;
        } else {
          score[i] = 0;
        }
      }
    }
  }
  int sum = 0;
  rep(i, N) sum += score[i];
  cout << sum << endl;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
using namespace std;
#include<array>
#include<vector>
#include<string>
#include<functional>
template<int char_size=26>
struct trie{
	struct node{
		array<int,char_size>next,cnt;
		int id;
		node():id(-1){next.fill(-1);cnt.fill(0);}
	};
	vector<node>v;
	trie(){v.push_back(node());}
	int add(const string&s,int idx)
	{
		int p=0;
		vector<int>ids;
		for(int i=0;i<s.size();i++)
		{
			ids.push_back(p);
			int j=s[i]-'a';
			if(v[p].next[j]<0)
			{
				v[p].next[j]=v.size();
				v.push_back(node());
			}
			p=v[p].next[j];
		}
		v[p].id=idx;
		int ex=0;
		for(int i=s.size();i--;)
		{
			ex|=1<<(s[i]-'a');
			for(int j=0;j<26;j++)if(ex>>j&1)v[ids[i]].cnt[j]++;
		}
		return ids.back();
	}
};
int N;
string S[2<<17];
int id[2<<17];
main()
{
	cin>>N;
	trie<>P;
	for(int i=0;i<N;i++)
	{
		cin>>S[i];
		reverse(S[i].begin(),S[i].end());
		id[i]=P.add(S[i],i);
	}
	long ans=-N;
	for(int i=0;i<N;i++)
	{
		ans+=P.v[id[i]].cnt[S[i].back()-'a'];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 233480
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    S = input().rstrip()
    k = int(input())
    
    for i in range(k):
        if S[i]!="1":
            break
    print(S[i])

if __name__=="__main__":
    main()

Measured memory_bytes: 9076
from collections import deque
from collections import defaultdict
N, M = map(int, input().split())
d = [0]*N
G = defaultdict(list)
for i in range(M):
    s, t = map(int, input().split())
    d[t-1] += 1
    G[s-1].append(t-1)
q = deque([])
for i in range(N):
    if d[i] == 0:
        q.append(i)
ans = []
while q:
    s = q.popleft()
    ans.append(s)
    for t in G[s]:
        d[t] -= 1
        if d[t] == 0:
            q.append(t)
dp = [0] * (N+1)
num = 0
for i in range(0,N):
    for n in G[ans[i]]:
        dp[n] = max(dp[n], dp[ans[i]]+1)
print(dp[ans[-1]])

Measured memory_bytes: 76120
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
char s[105];
int f(char *c,int l,int k)
{
	for(int i=k,j=l-1;i<j;i++,j--)
		if(c[i]!=c[j]) return 0;
	return 1;
}
int main ( )
{
	memset(s,'\0',sizeof(s));
	
	scanf("%s",s);
	int l=strlen(s);
	if(f(s,l,0)&&f(s,(l-1)/2,0)&&f(s,l,(l+3)/2-1))
		cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

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

def readInts():
  return list(map(int,input().split()))
def main():
    x = int(input())
    # なんとか^2じゃない
    a = 1
    for i in range(1,x):
        for j in range(2,x):
            if i**j <= x:
                a = max(a,i**j)
            else:
                break
    print(a)
if __name__ == '__main__':
  main()


Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

#define rep(i, begin, end) for(int64_t i = (begin); i <= (end); i++)
#define rev(i, begin, end) for(int64_t i = (begin); (end) <= i; i--)

int64_t N, K;

int main(int argc, char **argv){
    std::cin >> N >> K;

    int64_t tmp = N / K;
    
    int64_t ret = tmp * tmp * tmp;

    if (K % 2 == 0) {
        if (tmp * K + K / 2 <= N) {
            tmp++;
        }
        ret += tmp * tmp * tmp;
    }

    std::cout << ret << std::endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()


void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

//ifstream &cin
ll gcd(ll a, ll b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll cnt(ll r, ll c, ll d){
    //cout << r / (c * d / gcd(c,d)) << endl;
    return r / c + r / d - r / (c * d / gcd(c,d));
}

int main() {
    fastik();
    //ifstream cin("input.txt");
    /*ll t = 1;
    cin >> t;
    while(t--){
       solve();
    }*/
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll g = gcd(c,d);
    ll ans = cnt(b,c,d) - cnt(a-1,c,d);
    //cout << cnt(a-1,c,d) << endl;// << cnt(a-1,c,d) << endl;
    cout << b-a+1 - ans;
}
/*
 *532105071133627368
  532105071133627368
 */

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

typedef long long lint;

char buf[1 << 17];

inline char read()
{
	static int idx = 1 << 17;
	if (idx == 1 << 17)
	{
		fread(buf, 1, 1 << 17, stdin);
		idx = 0;
	}
	return buf[idx++];
}
inline int readInt()
{
	int sum = 0, flg = 1;
	char now = read();

	while (now == 10 || now == 32) now = read();
	if (now == '-') flg = 0, now = read();
	while (now >= 48 && now <= 57)
	{
		sum = sum * 10 + now - 48;
		now = read();
	}

	return flg ? sum : -sum;
}
int main()
{
	int n = readInt();

	lint arr[200001];
	for (int i = 0; i < n; ++i)
	{
		arr[i] = readInt();
		if (i) arr[i] += arr[i - 1];
	}

	sort(arr, arr + n);

	lint ans = arr[0] == 0;
	int cnt = 1;

	for (int i = 1; i < n; ++i)
	{
		ans += !arr[i];

		if (arr[i] == arr[i - 1]) ++cnt;
		else ans += (lint)cnt * (cnt - 1) / 2, cnt = 1;
	}

	printf("%lld", ans + (lint)cnt * (cnt - 1) / 2);

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<pair<int,int>>> A(N);
    REP(i,N){
        int a;
        cin >> a;
        REP(j,a){
            int x, y;
            cin >> x >> y;
            --x;
            A[i].emplace_back(x,y);
        }
    }
    int ans = 0;
    for(int i=0;i<(1<<N);i++){
        int tmp = 0;
        bool ok = true;
        REP(j,N){
            if((i>>j) & 1){
                tmp++;
                REP(k,A[j].size()){
                    int x = A[j][k].first;
                    int y = A[j][k].second;
                    if((i>>x) & 1){
                        if(y == 0){
                            ok = false;
                            break;
                        }
                    }
                    else{
                        if(y == 1){
                            ok = false;
                            break;
                        }
                    }
                }
            }
        }
        //cout << i << " " << tmp << " " << ok << endl;
        if(ok) chmax(ans, tmp);
    }
    cout << ans << endl;
}

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

int main()
{
	int N=0,K=0,count=0;

	scanf("%d %d",&N,&K);

	

	if((N-1)%(K-1)==0){
		count = (N-1)/(K-1);
	}
	
	else{
		count = (N-1)/(K-1)+1;
	}


	
		printf("%d",count);

	return 0;
}


Measured memory_bytes: 128
n, a, b = map(int, raw_input().split(' '))
s = raw_input()

ab = a+b
abcount = 0
bcount = 0
for c in s:
    if c == 'a' and abcount < ab:
        abcount += 1
        print 'Yes'
    elif c == 'b' and abcount < ab and bcount < b:
        abcount += 1
        bcount += 1
        print 'Yes'
    else:
        print 'No'

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int k;
  string s;
  cin >> k >> s;
  
  if (s.size() <= k) cout << s << '\n';
  else cout << s.substr(0, k) << "..." << '\n';
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,k;cin>>n>>k;
  vector<int>a(n+1);
  rep(i, n)cin>>a[i+1];

  vector<int> used(n+1);
  ll c=1;
  ll loop_start=1;
  int count=0;
  while(true){
    count++;
    used[c]++;
    c=a[c];
    if(count==k) { cout<<c<<endl; return 0; }
    if(used[c]>1) { loop_start=c; break; }
  }
  int loop_count=0;
  int non_loop_count=0;
  rep1(i, n){
    if(used[i]==2)loop_count++;
    else if(used[i]==1)non_loop_count++;
  }

  ll t_c = (k-non_loop_count)%loop_count;
  int result = loop_start;
  rep(i, t_c) result = a[result];

//cout<<t_c<<' '<<loop_start<<' '<<non_loop_count<<' '<<loop_count<<endl;
//for(auto p:used)cout<<p<<' ';cout<<endl;
  cout<<result;

  return 0;
}

Measured memory_bytes: 4844
#include "bits/stdc++.h"
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };

lint H, W, dp[1000][1000], sy, sx, gy, gx;
char mp[1000][1000];

typedef pair<lint, plint> tlint;
int main() {
	cin >> H >> W;
	cin >> sy >> sx; sy--; sx--;
	cin >> gy >> gx; gy--; gx--;
	REP(i, H) {
		REP(j, W) {
			cin >> mp[i][j];
			dp[i][j] = INF;
		}
	}

	priority_queue<tlint> que;
	dp[sy][sx] = 0;
	que.push({ -dp[sy][sx], { sy, sx } });
	while (!que.empty()) {
		plint curr = que.top().second; que.pop();
		REP(k, 4) {
			lint ny = curr.first + dy[k], nx = curr.second + dx[k];
			if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
			if (mp[ny][nx] == '#') continue;
			if (dp[ny][nx] > dp[curr.first][curr.second]) {
				dp[ny][nx] = dp[curr.first][curr.second];
				que.push({ -dp[ny][nx], { ny, nx } });
			}
		}
		REP(i, 5) {
			REP(j, 5) {
				lint ny = curr.first - 2 + i, nx = curr.second - 2 + j;
				if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
				if (mp[ny][nx] == '#') continue;
				if (dp[ny][nx] > dp[curr.first][curr.second] + 1) {
					dp[ny][nx] = dp[curr.first][curr.second] + 1;
					que.push({ -dp[ny][nx], { ny, nx } });
				}
			}
		}
	}

	if (dp[gy][gx] == INF) cout << -1 << endk;
	else cout << dp[gy][gx] << endk;
}


Measured memory_bytes: 12684
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <random>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;

const int B = 60;
int N, a[B], b[B];

signed main() {
    cin >> N;
    
    bool ok = true;
    rep(i,0,N) cin >> a[i];
    rep(i,0,N) cin >> b[i];

    int ans = 0;
    while(1) {
        bool cost_nonzero = false;
        int ma = 0;
        rep(i,0,N) {
            int s = a[i], t = b[i];
            // printf("s = %lld, t = %lld\n", s, t);
            if(s < t) {
                ok = false;
                continue;
            }

            vector<int> dist(B, INF), mon(B);
            rep(k,0,B) {
                if(!(ans >> k & 1)) mon[k] = (1LL << k);
            }
            dist[s] = 0;

            priority_queue< pii, vector<pii>, greater<pii> > que;
            que.push(make_pair(dist[s], s));

            while(que.size()) {
                pii cur = que.top(); que.pop();
                int cost = cur.first, mo = cur.second;
                for(int k=1; k<=mo; k++) {
                    int n_mo = mo % k;
                    int n_cost = cost + mon[k];
                    if(dist[n_mo] > n_cost) {
                        dist[n_mo] = n_cost;
                        que.push(make_pair(dist[n_mo], n_mo));
                    }
                }
            }
            if(dist[t] == INF) ok = false;
            chmax(ma, dist[t]);
            cost_nonzero |= dist[t];
        }
        if(!cost_nonzero || !ok) break;
        repr(i,B-1,0) {
            if(ma >> i & 1) {
                ans |= ma;
                break;
            }
        }
    }
    cout << (ok ? ans : -1) << endl;
    return 0;
}

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

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

    string s, t;
    cin >> s >> t;

    bool ok = true;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != t[i]) ok = false;
    }

    if(ok) cout << "Yes" << '\n';
    else cout << "No" << '\n';
    return 0;
}


Measured memory_bytes: 3640
package main

import (
	"fmt"
	"math"
)

var H, W int

func main() {
	fmt.Scan(&H, &W)

	a := make([]string, H)
	for i := 0; i < H; i++ {
		fmt.Scan(&a[i])
	}

	for i := 0; i < W+2; i++ {
		fmt.Printf("#")
	}
	fmt.Printf("\n")

	for i := 0; i < H; i++ {
		fmt.Println("#" + a[i] + "#")
	}
	for i := 0; i < W+2; i++ {
		fmt.Printf("#")
	}
}

/*  ----------------------------------------  */

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}
type SortBy []XY

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y > a[j].y
	}
	return a[i].x > a[j].x
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll N;
vector<l_l> paths[55];
ll M;
ll u[25], v[25];
ll State[55];
ll parent[55];
ll pedge[55];
void dfs(int now) {
    for(auto tmp : paths[now]) {
        int to = tmp.first;
        ll index = tmp.second;
        if(to == parent[now]) continue;
        parent[to] = now;
        pedge[to] = index;
        dfs(to);
    }
}

void f(int node, int index) {
    if(parent[node] == -1) return;
    State[index] ^= (1LL << pedge[node]);
    f(parent[node], index);
}

ll ans = 0;

ll g(ll a) {
    if(a == 0LL) return 0;
    return (a & 1LL) + g(a >> 1);
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N - 1; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        paths[a].emplace_back(b, i);
        paths[b].emplace_back(a, i);
    }
    cin >> M;
    for(int i = 0; i < M; i++) {
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
    }
    parent[0] = -1;
    dfs(0);
    for(int i = 0; i < M; i++) {
        f(u[i], i);
        f(v[i], i);
    }
    for(ll bits = 0; bits < (1 << M); bits++) {
        ll NG = 0;
        for(int i = 0; i < M; i++) {
            if((1LL << i) & bits) NG |= State[i];
        }
        ll OK = N - 1 - g(NG);
        //cerr << bits << " " << NG << " " << OK << endl;
        if((g(bits) % 2) == 0) {
            ans += (1LL << OK);
        } else {
            ans -= (1LL << OK);
        }
    }
    cout << ans << endl;
    return 0;
}

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

int N;
vector<int> A, c, S;

int main() {
  map<int, int> m;
  cin >> N;
  A.resize(N);
  rep(i, N) {
    cin >> A[i];
    m[A[i]]++;
  }

  for (auto it = m.begin(); it != m.end(); it++) c.push_back((*it).second);
  sort(all(c));
  S.resize(c.size() + 1, 0);
  rep(i, c.size()) S[i + 1] = S[i] + c[i];

  int l = 0, n = c.size() - 1;
  for (int k = 1; k <= N; ++k) {
    int n = c.size() - 1 - l;
    while (c[n] * (k - l) > S[n + 1]) {
      --n;
      ++l;
    }
    cout << S[n + 1] / (k - l) << endl;
  }

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  if (a.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int w, h;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int dfs(vector<string>& mp, int x, int y){
  int cnt = 0;  
  for(int i=0;i<4;++i){
	int tx = x + dx[i];
	int ty = y + dy[i];
	if(tx < 0 || w <= tx || ty < 0 || h <= ty) continue;
	if(mp[ty][tx] == '#') continue;
	mp[ty][tx] = '#';
	cnt += dfs(mp, tx, ty) + 1;
  }
  return cnt;
}

int main(){
  while(true){
	if(!(cin >> w >> h)) return 0;
	if(w == 0 && h == 0) break;
	vector<string> vs(h);
	for(int i=0;i<h;++i)
	  cin >> vs[i];
	int x, y;
	for(int i=0;i<h;++i)
	  for(int j=0;j<w;++j)
		if(vs[i][j] == '@') x=j, y=i;
	vs[y][x] = '#';
	cout << 1+dfs(vs,x,y) << endl;
  }
  return 0;
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	double p = pow(0.5, m);
	int dat = m*1900+(n-m)*100;
	cout << (int)(dat/p+1e-5) << endl;
	return 0;
}


Measured memory_bytes: 256
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
const int mod =1e9+7;
int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    int h,w;
    scanf("%d %d",&h,&w);

    vector<string>graph(h+1);
    for(int i=0;i<h;i++){
        string a;
        cin >> a;
        graph[i] = a;
    }
    vector<vector<int>>dp(h+1,vector<int>(w+1,0));
    dp[0][0] = 1;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(graph[i][j] == '.')
                dp[i][j] = (dp[i][j] + ((i-1)>=0?dp[i-1][j]:0) + ((j-1)>=0?dp[i][j-1]:0))%mod;
        }
    }
    printf("%d\n",dp[h-1][w-1]);
	return 0;
}


Measured memory_bytes: 5248