akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
const int N=1e9+7;


const int MAX=1e5+7;
int mem[MAX];
//recursive solution
int step(int pos,int n,int arr[])
{
    if(pos==n-1) return 0;

    if(mem[pos]!=-1) return mem[pos];
    if(pos==n-2) return (step(pos+1,n,arr)+abs(arr[pos]-arr[pos+1]));
    else{
        return mem[pos]=min(step(pos+1,n,arr)+abs(arr[pos]-arr[pos+1]),step(pos+2,n,arr)+abs(arr[pos+2]-arr[pos]));
    }
}
int main()
{
   int n;
   cin>>n;
   int arr[n];
   forl(i,0,n) cin>>arr[i];
   memset(mem,-1,sizeof(mem));
   cout<<step(0,n,arr)<<endl;;

// iterative approach

//    int dp[n];
//    //dp[i] means minimum cost to reach (0..i) from 0
//    forl(i,0,n) dp[i]=N;
//    dp[0]=0;
//    forl(i,1,n)
//    {
//        fore(j,1,2)
//        {
//            if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
//        }
//    }
//    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 4864
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
vector<int> i2g;          // i2g[i] := アイテム i の所属するグループの番号(find)
vector<vector<int>> g2i;  // g2i[g] := グループ g に所属するアイテムたち

void union_init(int n) {
  i2g.resize(n);
  g2i.resize(n);
  for (int i = 0; i < n; ++i) {
    // 最初はアイテム i はグループ i に所属
    i2g[i] = i;
    g2i[i].assign(1, i);
  }
}

int find(int i){
  return i2g[i];
}

// アイテム ia の所属するグループとアイテム ib の所属するグループを 1 つにする
void merge(int ia, int ib) {
  if(i2g[ia]==i2g[ib])return;
  // ia の所属するグループが ib の所属するグループより小さくならないようにする
  if (g2i[i2g[ia]].size() < g2i[i2g[ib]].size()) {
    swap(ia, ib);
  }
  int ga = i2g[ia], gb = i2g[ib];
  // グループ gb に所属する全てのアイテムをグループ ga に移す
  for (int j : g2i[gb]) i2g[j] = ga;
  g2i[ga].insert(g2i[ga].end(), g2i[gb].begin(), g2i[gb].end());
  g2i[gb].clear();
}

// アイテム ia とアイテム ib は同じグループに所属しているか？
bool is_same_group(int ia, int ib) {
  return i2g[ia] == i2g[ib];
}


int main(){
	int n,m;
	int a[55]={},b[55]={};
	cin>>n>>m;
	FOR(i,0,m){
		cin>>a[i]>>b[i];
		a[i]--;
		b[i]--;
	}
	int c=0;
	FOR(i,0,m){
		union_init(n);
		FOR(j,0,m){
			if(i==j)continue;
			merge(a[j],b[j]);
		}
		int f=0;
		FOR(j,0,n){
			if(!is_same_group(0,j))f=1;
		}
		c+=f;
	}
	cout<<c<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll i,j,t=1,d,s;
	for(i=0;i<t;i++)
	{
		ll t2;
		cin>>d>>t2>>s;
		ll e=s*t2;
		if(e>=d)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
	}
}

Measured memory_bytes: 3616
x, y = map(int, input().split())

MOD = pow(10, 9) + 7


def my_pow(n, p, m):
    """
    calculate n^p (mod m) effectively
    """
    if p == 0:
        return 1
    elif p%2 == 0:
        return ((my_pow(n, p//2, m)) ** 2) % m
    else:
        return (my_pow(n, p-1, m) * n) % m


def combination(n, r):
    """
    calculate nCr using the factorial table
    return: nCr % MOD
    """
    # prepare the factorial table (0! to n!)
    factorial = [1] * (n+1)
    for i in range(1, n+1):
        factorial[i] = (i * factorial [i-1]) % MOD
    
    numerator = factorial[n]
    denominator = (factorial[n-r] * factorial[r]) % MOD
    # a^p-1 ≡ 1 (mod p) (p: prime)
    # a^p-2 ≡ a^-1
    fermat = my_pow(denominator, MOD-2, MOD)

    return (numerator * fermat) % MOD

    
if not (x+y)%3 == 0:
    print(0)
else:
    minimum = (x+y) // 3
    maximum = x + y - minimum
    if not (minimum <= x <= maximum and minimum <= y <= maximum):
        print(0)
    else:
        n = minimum
        r = y - minimum
        print(combination(n, r))




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

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

  	map<string,int> data;
  	for(int i=0;i<N;i++){
      string tmp;
      cin >> tmp;
      data[tmp]++;
    }
  	
  	int max=0;
  	for(auto p : data){
      if(p.second > max){
		max = p.second;
      }
    }
  
  	for(auto p : data){
      if(p.second == max){
        cout << p.first << endl;
      }
    }
  
  	return(0);
}


Measured memory_bytes: 25216
def resolve():
    
    N,M,R = map(int,input().split())
    r = list(map(int,input().split()))
    DP = [[2 ** 63 - 1 for _ in range(N)] for _ in range(N)]

    for i in range(N):
        DP[i][i] = 0

    for i in range(M):
        a,b,c = map(int,input().split())
        DP[a-1][b-1] = c
        DP[b-1][a-1] = c

    for k in range(N):
        for i in range(N):
            for j in range(N):
                DP[i][j] = min(DP[i][k]+DP[k][j],DP[i][j])

    import itertools
    ans = 2 ** 63 - 1 
    for v in itertools.permutations(r,R):
        s = 0
        for i in range(R-1):
            s += DP[v[i]-1][v[i+1]-1]
        ans = min(ans,s)
    print(ans)
resolve()

Measured memory_bytes: 59480
#include<bits/stdc++.h>
using namespace std;
const int N = 200005;

int n, m1, m2, par[N], sz[N], cp1[N], cp2[N], cc[N], ans[N];
bool vis[N];

vector<int> adj[N];

int Find (int X) {return par[X] = (par[X] == X ? X : Find(par[X]));}

void Union (int A, int B) {
	A = Find(A); B = Find(B);
	if(A == B) return;
	sz[B] += sz[A];
	par[A] = B;
}

void getcp (int M, int C[], bool T) {
	iota(par, par+n+1, 0);
	fill(sz, sz+n+1, 1);
	for(int i=1;i<=M;i++) {
		int A, B;
		scanf("%d%d",&A,&B);
		if(T) {
			adj[A].push_back(B);
			adj[B].push_back(A);
		}
		Union(A, B);
	}
	for(int i=1;i<=n;i++) C[i] = Find(i);
}

void dfs1 (int I) {
	vis[I] = true; cc[cp2[I]]++;
	for(auto &T : adj[I]) if(!vis[T]) dfs1(T);
}

void dfs2 (int I) {
	vis[I] = false; ans[I] = cc[cp2[I]];
	for(auto &T : adj[I]) if(vis[T]) dfs2(T);
}

void dfs3 (int I) {
	vis[I] = true; cc[cp2[I]] = 0;
	for(auto &T : adj[I]) if(!vis[T]) dfs3(T);
}

int main()
{
	scanf("%d%d%d",&n,&m1,&m2);
	getcp(m1, cp1, 1); getcp(m2, cp2, 0);
	for(int i=1;i<=n;i++) {
		if(!vis[i]) {dfs1(i); dfs2(i); dfs3(i);}
		printf("%d ",ans[i]);
	}
	puts("");
}


Measured memory_bytes: 13440
n = int(input())
t,a = map(int,input().split())
H = list(map(int,input().split()))
temp = []
for i in range(n):
  temp.append(a-(t-H[i]*0.006))
temp_abs = [abs(j) for j in temp]
mini_temp_abs = min(temp_abs)
for k in range(n):
  if temp_abs[k] == mini_temp_abs:
    print(k+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr first
#define sc second
#define ll  long long
#define mp make_pair
#define mod 1000000007

using namespace std;
string s;
int dp[20][2];

int f(int i,bool b){
    if(i == s.size()){
        return 0;
    }
    if(dp[i][b] != -1)return dp[i][b];
    int en = s[i]-'0';
    if(b)en = 9;
    int r =0;

    for(int j=0 ;j <=en ;j++){
        r = max(r,f(i+1,b||(j < s[i]-'0'))+j);
    }
    return dp[i][b] = r;
}
int main()  {
    memset(dp,-1,sizeof dp);
    cin>>s;
    cout<<f(0,0);
    return 0;
}


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

const int n_max = 100001;
vector <int> top_order;
vector <vector <int>> g (n_max);
vector <bool> visited (n_max, false);

void dfs_mod (int x) {
  for (int i : g[x]) {
    if (!visited[i]) {
      visited[i] = true;
      dfs_mod (i);
    }
  }
  top_order.push_back (x);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  #ifdef LOCAL_DEFINE
  freopen ("input.txt", "r", stdin);
  freopen ("output.txt", "w", stdout);
  #endif 
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u - 1].push_back (v - 1);
  }
  for (int i = 0; i < n; ++i) {
    if (!visited[i]) {
      dfs_mod(i);
    }
  }
  reverse (top_order.begin(), top_order.end());
  vector <int> dist (n, 0);
  for (int i = 0; i < top_order.size(); ++i) {
    for (int j : g[top_order[i]]) {
      dist[j] = max (dist[j], dist[top_order[i]] + 1);
    }
  }
  cout << *max_element (dist.begin(), dist.end());
}

Measured memory_bytes: 8696
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a[ohara],b[ohara],c[ohara],d,tmp,tmpp,m,h,w,y,sum,pos,k,bit[ohara];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz");
bool fl;
struct edge{int to,cost;};
unordered_map<ll,ll> mp;

//-------------------------↓↓↓↓↓↓------------------------

ll summ(ll i){
    ll s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
    }
    return s;
}

void add(ll i,ll x){
    while(i<=n+10){
        bit[i]+=x;
        i+=i&-i;
    }
}

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    rep(i,n){
        sum+=a[i];
        b[i+1]=sum-(i+1)*k;
    }
    rep(i,n+1)c[i]=b[i];
    sort(c,c+n+1);
    tmp=1;
    rep(i,n+1){
        mp[c[i]]=tmp;
        if(c[i]!=c[i+1])tmp++;
    }
    rep(i,n+1){
        if(i!=0)ans+=summ(mp[b[i]]);
        add(mp[b[i]],1LL);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 22344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n, 0), dist(n-1);
    rep1(i, n){
        cin >> x[i];
        if (i!=0) dist[i-1] = a * abs(x[i]-x[i-1]);
    }
    ll ans = 0; 
    for (ll i: dist){
        if (i>b) ans += b;
        else ans += i;
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 4768
#include <cstdio>
static const int MAXN = 502;

int h, w, d;
int s[MAXN][MAXN];
const char *colour = "GYRB";

inline void paint(int colour, int r, int c)
{
    for (int i = 0; i < d / 2; ++i)
        for (int j = -i; j <= i; ++j)
            if (r + i >= 0 && r + i < h && c + j >= 0 && c + j < w)
                s[r + i][c + j] = colour;
    for (int i = (d - 1) / 2; i >= 0; --i)
        for (int j = -i; j <= i; ++j)
            if (r + d - 1 - i >= 0 && r + d - 1 - i < h && c + j >= 0 && c + j < w)
                s[r + d - 1 - i][c + j] = colour;
}

int main()
{
    scanf("%d%d%d", &h, &w, &d);

    int r, c, p;
    if (d == 1) {
        for (r = 0; r < h; ++r)
            for (c = 0; c < w; ++c)
                paint((r & 1) << 1 | (c & 1), r, c);
    } else {
        for (r = 0, c = -1000, p = 0; r < 1000; r += d / 2, c += (d + 1) / 2, p ^= 1) {
            int rr = r, cc = c, q = 0;
            for (; cc < 1000; rr -= (d + 1) / 2, cc += d / 2, q ^= 1)
                paint((p << 1) | q, rr, cc);
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j)
            putchar(colour[s[i][j]]);//, putchar(' ');
        putchar('\n');
    }

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 10000000000000007LL
#define ll long long
using namespace std;
int cnt[51];
signed main(){
	int n,k;
	cin>>n>>k;
	vector<int> a;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
	}
	for(int i=0;i<n;i++){
		int cur = a[i];
		for(int j=0;j<=50;j++){
			if(cur%2==0){
				cnt[j]++;
			}
			cur /= 2;
		}
	}
	vector<int> good;
	for(int i=0;i<=50;i++){
		if( cnt[i] > n/2){
			good.pb(i);
		}
	}
	sort( good.begin(),good.end(),greater<int>() );
	ll ans = 0;
	for(int i=0;i<good.size();i++){
		if( ans + (1LL<<good[i]) <= k) ans += (1LL<<good[i]);
	}
	ll tans = 0;
	for(int i=0;i<n;i++){
		tans += ans ^ a[i];
	}
	cout<<tans<<endl;
	return 0;
}

Measured memory_bytes: 1528
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();

		int[] A = new int[N];
		int[] num = new int[N];
		for(int i=0;i<N;i++) {
			A[i] = sc.nextInt();
			num[A[i]-1]++;
		}

		Arrays.sort(num);

		int ans = 0;
		for(int i=num.length-1-K;i>=0;i--) {
			ans += num[i];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 67192
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

	void run(){
		sc=new Scanner(System.in);
		int[] s=new int[1000000];
		for(int i=2; i<1000000; i++)
			s[i]=s[i-1]+(isPrime(i)?1:0);
		for(;;){
			if(!sc.hasNext())
				break;
			int n=sc.nextInt();
			println(""+s[n]);
		}
		sc.close();
	}

	boolean isPrime(int n){
		int m=(int)sqrt(n);
		if(n==2)
			return true;
		if(n%2==0)
			return false;
		for(int i=3; i<=m; i++)
			if(n%i==0)
				return false;
		return true;
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 16000
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
typedef long long int lli;
const lli inf = 1e18;

lli digitsum(int n){
	int ret=0;
	while(n!=0){
		ret += n%10;
		n /= 10;
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	lli ans = inf;
	for(int i=1; i<n; i++){
		ans = min(ans, digitsum(i) +digitsum(n-i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        
using namespace std;
        
typedef long long ll;
#define mp make_pair
#define pub push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define db double

int n, m;
int cnt[26];
  
int main(){ 
    srand('D' + 'E' + 'N' + 'I' + 'S' + 'S' + 'O' + 'N' + time(NULL));
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //freopen("spoiler.in", "r", stdin);
    //freopen("spoiler.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++){
    	for (int j = 0; j < m; j++){
    		char c;
    		cin >> c;
    		cnt[c - 'a']++;
    	}
    }
    int ww = 0;
    int kk = 0;
    for (int i = 0; i < 26; i++){
    	if (cnt[i] % 2 == 1){
    		ww++;
    		cnt[i]--;
    		kk += cnt[i] / 4;
    	} else {
    		kk += cnt[i] / 4;
    	}
    }
    if (n % 2 == 0 && m % 2 == 0){
    	int sz = n * m / 4;
    	if (ww == 0 && kk >= sz) cout << "Yes";
    	else cout << "No";
    }
    if (n % 2 == 1 && m % 2 == 0){
    	int sz = (n / 2) * (m / 2);
    	if (ww == 0 && kk >= sz) cout << "Yes";
    	else cout << "No";
    }
    if (n % 2 == 0 && m % 2 == 1){
    	int sz = (n / 2) * (m / 2);
    	if (ww == 0 && kk >= sz) cout << "Yes";
    	else cout << "No";
    }
    if (n % 2 == 1 && m % 2 == 1){
    	int sz = (n / 2) * (m / 2);
    	if (ww == 1 && kk >= sz) cout << "Yes";
    	else cout << "No";
    }

}

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

using namespace std;

typedef long long ll;

int main(){
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector<int> op;
	vector<int> no;
	op.push_back(0);
	no.push_back(0);
	int seq = 0;
	for(int i = 0; i < (int)s.size(); i++){
		if(s[i] == '0'){
			if(seq >= 0)seq++;
			else{
				int sum = -seq + op[(int)op.size()-1];
				op.push_back(sum);
				seq = 1;
			}
		}
		else{
			if(seq <= 0)seq--;
			else{
				int sum = seq + no[(int)no.size()-1];
				no.push_back(sum);
				seq = -1;
			}
		}
	}
	if(seq > 0){
		int sum = seq + no[(int)no.size()-1];
		no.push_back(sum);
	}
	else{
		int sum = -seq + op[(int)op.size()-1];
		op.push_back(sum);
	}
	/*for(int i = 0; i < (int)no.size(); i++)cout << no[i] << ' ';
	cout << endl;
	for(int i = 0; i < (int)op.size(); i++)cout << op[i] << ' ';
	cout << endl;*/
	int m = 0;
	for(int i = 0; i < (int)no.size()-k; i++){
		int pre = no[i+k]-no[i];
		if(s[0] == '0'){
			pre+=op[i+k-1]-op[i];
		}else{
			pre+=op[i+k]-op[i+1];
		}
		if(!(i == 0 && s[0]=='0')){
			if(s[0] == '0')pre+=op[i]-op[i-1];
			else pre += op[i+1]-op[i];
		}
		if(!(i == (int)no.size()-k-1 && s[(int)s.size()-1]=='0')){
			if(s[0] == '0')pre+=op[i+k]-op[i+k-1];
			else pre+=op[i+k+1]-op[i+k];
		}
		//cout << pre << endl;
		m = max(m, pre);
	}
	if(m == 0){
		m = n;
	}
	cout << m << endl;


    return 0;
}

Measured memory_bytes: 1020
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

v, e = map(int, input().split())
a = list(input().split())

g = [[] for _ in range(v)]
for _ in range(e):
    s, t = map(int, input().split())
    g[s].append(t)
    g[t].append(s)

for i in range(v):
    if a[i] != '?':
        continue

    for c in alphabet:
        flag = True
        for to in g[i]:
            if a[to] == c:
                flag = False
                break
        
        if flag:
            a[i] = c
            break

print(''.join(a))



Measured memory_bytes: 31544
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N, M;
    cin >> N >> M;
    vector<int> d(N, -1);

    bool err = false;
    rep (i, M) {
        int s, c;
        cin >> s >> c;
        --s;
        if (1 < N && s == 0 && c == 0) {
            err = true;
        } 
        if (d[s] == -1) {
            d[s] = c;
        } else if (d[s] != c) {
            err = true;
        }
    }

    int ans = -1;
    if (!err) {
        ans = 0;
        rep(i, N) {
            if (d[i] == -1) {
                if (i == 0) {
                    if (N == 1) {
                        d[0] = 0;
                    } else {
                        d[0] = 1;
                    }     
                } else {
                    d[i] = 0;
                }
            }
            ans = ans * 10 + d[i];
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
    string S;
    cin >> S;
    vector<bool> app(26, false);

    for (char c : S) {
        app.at(c - 'a') = true;
    }

    rep (i, 26) {
        if (!app.at(i)) {
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }

    cout << "None" << endl;
}


Measured memory_bytes: 512
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  n = int(input())
  A = list(map(int,input().split()))
  for i in range(n):
    if A[i] % 2 == 0:
      if A[i] % 3 == 0 or A[i] % 5 == 0:
        pass
      else:
        print('DENIED')
        exit()
  print('APPROVED')
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(auto c:s){
        if(c == '+')
            ans++;
        else
            ans--;
    }
    cout << ans << endl;
}


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

int main() {
  string S; int N;
  cin>>N>>S;
  vector<int>A(N+1);
  int x=0;
  A.at(N)=x;
  for(int i=0;i<N;i++){
    if(S.at(i)=='I'){
      x++;
      A.at(i)=x;
    }
    if(S.at(i)=='D'){
      x--;
      A.at(i)=x;
    }
  }
  sort(A.begin(),A.end());
  cout<<A.at(N)<< endl;
}
    
  



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

vector<vector<int>> edge;
vector<vector<int>> tree;
int main() {
    int N;
    cin >> N;
    vector<int> a;
    vector<int> b;
    edge.resize(N);
    a.resize(N);
    b.resize(N);
    tree.resize(N);

    REP(i, N - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        edge[a[i]].push_back(b[i]);
        edge[b[i]].push_back(a[i]);
        tree[a[i]].push_back(b[i]);
        // cout << "e" << endl;
    }
    // cout << "edn" << endl;
    int K = 0;
    int mindex = 0;
    REP(i, N) {
        if(K < edge[i].size()) {
            K = edge[i].size();
            mindex = i;
        }
    }

    queue<int> que;
    vector<int> visited(N, 0);
    map<pair<int, int>, int> cedge;
    int c_ = 1;
    for(auto next : tree[0]) {
        visited[next] = c_;
        cedge[make_pair(0, next)] = c_;
        c_++;
        que.push(next);
    }
    cout << K << endl;
    while(!que.empty()) {
        auto now = que.front();
        que.pop();
        int c = 1;
        for(auto next : tree[now]) {
            if(c == visited[now]) {
                c++;
            }
            visited[next] = c;
            cedge[make_pair(now, next)] = c;
            c++;
            que.push(next);
        }
    }

    REP(i, N - 1) { cout << cedge[make_pair(a[i], b[i])] << endl; }
    return 0;
}

Measured memory_bytes: 17408
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;

    if( a+1 < b ){
        cout << b+b-1 << endl;
    }else if( b+1 < a ){
        cout << a+a-1 << endl;
    }else{
        cout << a+b << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a * n, b) << endl;
}

Measured memory_bytes: 3544
import java.io.PrintWriter

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readInteger()
    var ans = 0L
    for (i in 1L..n) {
        if (i % 3 == 0L) {
            ;
        } else if (i % 5 == 0L)  {
            ;
        } else {
            ans += i
        }
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 34556
#include <iostream>
#include <cstdio>
using namespace std;
 
int A[500000], S = 0;
 
int merge(int l, int m, int r){
    int n1 = m - l, n2 = r - m, i, j;
    int L[n1 + 1], R[n2 + 1];
    for(i = 0;i < n1;i++)L[i] = A[i + l];
    for(i = 0;i < n2;i++)R[i] = A[i + m];
    i = j = 0;
    for(int k = 0;k < r - l;k++){
        if(j == n2 || (i < n1 && L[i] <= R[j]))A[k + l] = L[i++];
        else A[k + l] = R[j++];
        S++;
    }
}

int mergeSort(int l, int r){
    if(l + 1 < r){
        int m = (l + r) / 2;
        mergeSort(l, m);
        mergeSort(m, r);
        merge(l, m, r);
    }
}
 
int main(){
    int n;
    scanf("%d", &n);
    for(int i = 0;i < n;i++)scanf("%d", &A[i]);
    mergeSort(0, n);
    for(int i = 0;i < n;i++){
        if(i)printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", S);
     
    return 0;
}

Measured memory_bytes: 7028
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    ll n,k; cin >> n >> k;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    sort(all(h), greater<ll>());
    ll ans = 0;
    rep(i,n){
        if(i < k)continue;
        else ans += h[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        Set<Integer> jedynki = new HashSet<>();
        Set<Integer> enki = new HashSet<>();
        for (int i = 0; i < m; ++i) {
            int x = in.nextInt();
            int y = in.nextInt();
            if (x == 1) jedynki.add(y);
            if (y == n) enki.add(x);
        }
        for (int x : jedynki) {
            if (enki.contains(x)) {
                System.out.println("POSSIBLE");
                return;
            }
        }
        System.out.println("IMPOSSIBLE");
    }
}


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

#define INF 2147483647 // 2^31-1

vector<int> value; // ノードの値を持つ配列
int N;             // 葉の数

void update(int i, int x) {
    // i 番目の葉の値を x に変える
    i += N - 1; // i 番目の葉のノード番号
    value[i] = x;
    while (i > 0) {
        i = (i - 1) / 2; // ノード i の親ノードの番号に変える
        value[i] = min(value[i * 2 + 1],
                       value[i * 2 + 2]); // 左右の子の min を計算しなおす
    }
}

int query(int a, int b, int k, int l, int r) {
    // [a, b) の区間に対するクエリについて
    // ノード k （区間 [l, r) 担当）が答える
    if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
    if (a <= l && r <= b)
        return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                         // に完全に含まれる
    else {
        int c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
        int c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
        return min(c1, c2); // 左右の子の値の min を取る
    }
}

int main(void) {
    int n, q;
    cin >> n >> q;
    N = 1;
    while (N < n) N *= 2; // 葉の数を計算（n以上の最小の2冪数）

    value = vector<int>(2 * N - 1, INF);

    for (int j = 0; j < q; j++) {
        int c;
        cin >> c;
        if (c == 0) {
            // update(i, x)
            int i, x;
            cin >> i >> x;
            update(i, x);
        } else {
            // find(s, t)
            int s, t;
            cin >> s >> t;
            cout << query(s, t + 1, 0, 0, N) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3896
//ABC151 C

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

int N,M;
int p;
string S;
int sum_a = 0;
int ac[100000],wa[100000];

int main() {
  cin >> N >> M;
  
  
  int ans_ac = 0;
  int ans_wa = 0;
  for(int i=0;i<M;i++){
    cin >> p >> S;
    p--;
    if(S == "AC" && ac[p] == 0){
      ac[p] = 1;
    }
    else if(S == "WA" && ac[p] == 0){
      wa[p]++;
    }
  }

  for(int i=0;i<N;i++){
    if(ac[i] == 1){
      ans_ac++;
      ans_wa += wa[i];
    }
  }
  
  printf("%d %d\n",ans_ac,ans_wa);

  //printf("%d\n",ans);
}


Measured memory_bytes: 1024
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {//
        n:usize,k:i64,
        mut a:[i64;n],
    }
    let mut ng = 0;
    let mut ok = INF;

    while (ok - ng).abs() > 1 {
        let mid = (ng + ok) >> 1;

        let check = |mid: i64| -> bool {
            let mut cnt = 0;
            for &x in a.iter() {
                // if mid > x {
                //     return false;
                // }
                cnt += (x + mid - 1) / mid - 1;
            }
            // dbg!(mid, cnt);
            cnt <= k
        };
        if check(mid) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    println!("{}", ok);
}
const INF: i64 = 1 << 60;


Measured memory_bytes: 5368
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int H, W;
        cin >> H >> W;
        vector<string> a(H);
        rep(i, 0, H) cin >> a[i];
        vector<bool> row(H, true);
        vector<bool> col(W, true);
        for (int i = 0; i < H; ++i) {
            bool flag = true;
            for (int j = 0; j < W; ++j) {
                if (a[i][j] == '#') flag = false;
            }
            if (flag) row[i] = false;
        }

        for (int j = 0; j < W; ++j) {
            bool flag = true;
            for (int i = 0; i < H; ++i) {
                if (a[i][j] == '#') flag = false;
            }
            if (flag) col[j] = false;
        }

        for (int i = 0; i < H; ++i) {
            if (!row[i]) continue;
            for (int j = 0; j < W; ++j) {
                if (col[j]) cout << a[i][j];
            }
            cout << endl;
        }
    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
x, k, d = gets.chomp.split(" ").map(&:to_i)

if x == 0 then
    if k & 1 == 1 then
        puts d
    else
        puts 0
    end
    exit
end

c = x.abs / d
if k <= c then
    puts x.abs - k*d
    exit
end

k -= c
sabun = x.abs % d
if sabun > (sabun-d).abs then
    sabun = (sabun-d).abs
    k -= 1
end

if k & 1 == 1 then
    puts (sabun - d).abs
else
    puts sabun
end

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

const ll INF = 1e18;

int main() {
	int v, e;
	cin >> v >> e;
	vector<vector<ll>> dp(v, vector<ll>(v, INF));
	rep(i, v) dp[i][i] = 0;
	rep(i, e) {
		int s, t, d;
		cin >> s >> t >> d;
		dp[s][t] = d;
	}
	rep(i, v) rep(j, v) rep(k, v) {
		if (dp[j][i] == INF || dp[i][k] == INF) continue;
		dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
	}
	rep(i, v) {
		if (dp[i][i] < 0) {
			cout << "NEGATIVE CYCLE" << endl;
			return 0;
		} 
	}
	rep(i, v) rep(j, v) {
		if (dp[i][j] != INF) cout << dp[i][j];
		else cout << "INF";
		if (j == v - 1) cout << endl;
		else cout << " ";
	}
	return 0;
}


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

int main(){
	int a, b, c, k, sum=0;
	cin >> a >> b >> c >> k;
	if(a<=k){
		sum += a;
		k-=a;
		if(k>0 && b<=k){
			k-=b;
			if(k>0 && c<=k){
				k-=c;
				sum -= c;
			}
			else{
				sum-=k;
			}
		}
	}
	else{
		sum+=k;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3172
program ABC160D
    implicit none
    integer(8)::N,X,Y,i,j,d
    integer(8),allocatable,dimension(:)::ans
    read*,N,X,Y
    allocate(ans(N-1))
    ans=0

    do i=1,N
        do j=i+1,N
            d=min(j-i,abs(X-i)+abs(Y-j)+1)
            ans(d)=ans(d)+1
        end do
    end do


    do i=1,N-1
        print'(i0)',ans(i)
    end do
end program ABC160D

Measured memory_bytes: 256
M=998244353
a,b,c,d=gets.split.map &:to_i
w=[]
t=1
w[c]=d.downto(b).with_object([]){|j,r|
  r[j]=t
  t=t*c%M
}
(c-1).downto(a){|i|
  t=0
  q=w[i+1]
  w[i]=d.downto(b).with_object([]){|j,r|
    x=q[j]
    r[j]=(x*j+t)%M
    t=(t+x)*i%M
  }
}
puts w[a][b]


Measured memory_bytes: 84812
import java.util.*;

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

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

    private void run() {
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double h = sc.nextDouble();
        double m = sc.nextDouble();

        double A = 2*Math.PI*m/60;
        double B = 2*Math.PI*((h+m/60)/12);
        double ans = Math.sqrt(Math.pow(a,2) + Math.pow(b,2) - 2*a*b*Math.cos(Math.abs(A-B)));
        System.out.println(ans);

    }
}



Measured memory_bytes: 37480
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
		int n, k;
	cin >> n >> k;
	if(n % k == 0)cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<bool,int> P;
signed main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>>cnt(N);
    for(int i = 0; i < M; i++) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        cnt[a].push_back(b);
        cnt[b].push_back(a);
    }
    queue<int>que;
    que.push(0);
    vector<P>okans(N);
    for(int i = 0; i < N; i++) {
        okans[i].first = false;
        okans[i].second = 0;
    }
    okans[0].first = true;
    while(!que.empty()) {
        int X = que.front();
        for(int i = 0; i < cnt[X].size(); i++) {
            if(okans[cnt[X][i]].first) {
                continue;
            }
            que.push(cnt[X][i]);
            okans[cnt[X][i]].first = true;
            okans[cnt[X][i]].second = X;
        }
        que.pop();
    }
    for(int i = 0; i < N; i++) {
        if(okans[i].first == false) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i < N; i++) {
        cout << okans[i].second+1 << endl;
    }
}

Measured memory_bytes: 13732
from collections import defaultdict

iCnt = int(input())
S = input()
M = 10**9 + 7

vCntDct = defaultdict(int)

for s in S:
    vCntDct[s] += 1

ans = 1
for v in vCntDct.values():
    ans *= (v + 1)
    ans %= M

print(ans - 1)

Measured memory_bytes: 39280
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var n = Int32.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(v => Int64.Parse(v)).ToList();

            var ret = Int64.MaxValue;

            for (int i = -100; i <= 100; i++)
            {
                ret = Math.Min(ret, a.Select(v => (v - i) * (v - i)).Sum());
            }

            Console.WriteLine(ret);
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 3032
// In the Name of God
#include<bits/stdc++.h>

#define test(t) int t; cin>>t; while(t--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORE(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long int
#define em emplace_back
#define pb push_back
#define INF 1e7+5
#define MOD int(1e9+7)
#define print printf
#define in scanf
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

template<class type>
void displaySingle(type &arr)
{
	for(auto i:arr)
		cout<<i<<" ";
	cout<<endl;
}

template<class type>
void displayDouble(type &arr)
{
	for(auto &&i : arr) 
	{
		for(auto &&j : i) 
			cout << j << " ";
		cout << std::endl;
	}
}

int main()
{
	fast
	ll n,w;
	cin>>n>>w;
	vector <ll> costs(n),weights(n);
	ll total_cost = 0;
	REP(i,n)
	{
		cin>>weights[i]>>costs[i];
		total_cost += costs[i];
	}
	vector <vector <ll>> dp(n+1,vector <ll>(total_cost+1,INT_MAX));
	REP(i,n+1)
		dp[i][0] = 0;
	FOR(i,1,n+1)
	{
		FOR(j,1,total_cost+1)
		{
			if(j-costs[i-1] >= 0)
			{
				dp[i][j] = min(dp[i-1][j],dp[i-1][j-costs[i-1]]+weights[i-1]);
			}
			else
			{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	//displayDouble(dp);
	FORD(i,total_cost,0)
	{
		if(dp[n][i] <= w)
		{
			cout<<i<<endl;
			break;
		}
	}
}

Measured memory_bytes: 83160
using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public List<char> a { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var t = Console.ReadLine().Trim();
        var d = new Dictionary<char, P>();
        var d2 = new Dictionary<char, P>();
        if (dcheck(d, s, t) && dcheck(d2, t, s)) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
    public static bool dcheck (Dictionary<char, P> d , string s, string t)
    {
        for (int i = 0; i < s.Length; i++)
        {
            if (d.ContainsKey(s[i]))
            {
                if (!d[s[i]].a.Contains(t[i])) d[s[i]].a.Add(t[i]);
            }
            else
            {
                d[s[i]] = new P();
                d[s[i]].a = new List<char>();
                d[s[i]].a.Add(t[i]);
            }
        }
        foreach (var x in d)
        {
            if (x.Value.a.Count() >= 2) return false;
        }
        return true;
    }
}


Measured memory_bytes: 14816
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
int md(int a, int b, int c, int d) {
	return abs(a - c) + abs(b - d);
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(n), b(n);
	rep(i, n)cin >> a[i] >> b[i];
	vector<int>c(m), d(m);
	vector<int>dist(n,INT32_MAX);
	vector<int>ans(n, -1);
	rep(i, m)cin >> c[i] >> d[i];
	rep(i, n) {
		rep(j, m) {
			int cand = min(dist[i], md(a[i], b[i], c[j], d[j]));
			if (cand < dist[i]) {
				dist[i] = cand;
				ans[i] = j + 1;
			}
		}
	}
	rep(i, n)cout << ans[i] << endl;


	return 0;
}




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

using namespace std;

#define int long long

signed main()
{
	cin.tie(0), cout.tie(0), ios::sync_with_stdio(0);

	//freopen("output", "w", stdout);

	string s;
	cin >> s;
	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
		cout << "Bad\n";
	else
		cout << "Good\n";

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.D
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadLong();
            var fResult = new long[10000001];
            for (int i = 2; i <= N; i++)
            {
                var x = 1L;
                for (int j = 0; ; j++)
                {
                    x = i * j;
                    if (x > N) break;
                    fResult[x]++;
                }
            }
            return Enumerable.Range(1, (int)N).Sum(x => x * (fResult[x] + 1));
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 106492
//2*10^9
//9*10^18
// __int128_t 
#include<bits/stdc++.h>
using namespace std;

#define ull unsigned long long int
#define ll long long int

const ll M=1e9+7;

//to handle when remainder is -neg we add + M
//but when rem is +pos that time also we add so use %M
//so it will work for both
ll mod(ll n){
    return (n%M + M)%M; 
}
ll modAdd(ll a, ll b){
    return mod(mod(a)+mod(b));
}
ll modMul(ll a, ll b){
    return mod(mod(a)*mod(b));
}
ll modMinus(ll a, ll b){
    return mod(mod(a)-mod(b));
}
ll modpow(ll x, ll n) 
{ 
    if (n == 0) 
        return 1%M;
    if (n == 1)
        return x%M; 
    ll u = modpow(x,n/2); 
    u = modMul(u,u); 
    if (n%2) 
        u = modMul(u,x); 
    return u; 
}
ll gcd(ll a,ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}
bool isPrime(ll n){
    int end = sqrt(n);
    for(int i=2;i<=end;i++)
        if(n%i==0)
            return false;
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
 
    
    int t=1;
    //cin>>t;
    
    while(t--){
       int n;
       cin>>n;

       vector<vector<int>> data(2,vector<int>(n));

       for(int i=0;i<n;i++)
        cin>>data[0][i]>>data[1][i];

        int count=0;
        bool ans=false;
        for(int i=0;i<n;i++){
            if(data[0][i]==data[1][i]){
                count+=1;
                if(count==3){
                    ans=true;
                    break;
                }
            }
            else
            {
                count=0;
            }
        }
        if(ans)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    
    }
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int H, W; cin >> H >> W;
    int cnt = 0;
    rep(i, H) {
        string s; cin >> s;
        rep(j, W) if (s[j] == '#') cnt++;
    }
    cout << (cnt == H + W - 1 ? "Possible" : "Impossible") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>

using namespace std;


#define INF pow(10, 9)
// typedef priority_queue<tuple<int,int,int>, vector< tuple<int, int, int> >, greater< tuple<int, int, int> > > PQ;

typedef long long int ll;




int main(void)
{

    int N;
    cin >> N;
    int NMax = pow(10, 5) * 2+1;
    vector<int> A(N), B(N), Count(NMax, 0);

    for(int i=0; i<N; i++)
    {
        cin >> A[i];
        Count[ A[i] ] ++;
    }
    bool flag = true;

    for(int i=0; i<N; i++)
    {
        int j = N-1-i;
        cin >> B[j];
        Count[ B[j] ] ++;
        if(Count[ B[j] ] > N)
        {
            flag = false;
            break;
        }
    }

    if(flag==false)
    {
        cout << "No" << endl;
    }
    else
    {
        int left = 0;
        for(int i=0; i<N; i++)
        {
            if(A[i] == B[i])
            {
                while(left<N && (A[left]==B[i] || A[i]== B[left]) )
                {
                    left ++;
                }
                swap(B[i], B[left]);
            }
        }
        cout << "Yes" << endl;
        for(int i=0; i<N; i++)
        {
            cout <<B[i] << " ";
        }
        cout << endl;
    }





    return 0;
}


Measured memory_bytes: 5628