akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main implements Runnable{

	public static void main(String[] args) {
		new Thread(null,new Main(), "" ,Runtime.getRuntime().maxMemory()).start();
	}
	
	long gcd(long a,long b) {
		return a==0?b:gcd(b%a,a);
	}
	
	public void run() {
		FastScanner sc=new FastScanner();
		long N=sc.nextLong();
		long K=sc.nextLong();
		while(true) {
			if(N>K) {
				N=N%K;
			}else if(K-N<N){
				N=K-N;
			}else {
				break;
			}
		}
		System.out.println(N%K);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 25300
n = int(input())
h = [int(i) for i in input().split()]
m = [0, abs(h[0]-h[1])]
for i in range(2, n):
    v = min(m[0]+abs(h[i-2]-h[i]), m[1]+abs(h[i-1]-h[i]))
    m = [m[1], v]
print(m[1])

Measured memory_bytes: 13980
#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 <stack>
#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 PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	std::cout << std::fixed;
	std::cout << std::setprecision(12);
	std::cout << std::defaultfloat;
	LL a,b,c,d;
	LD e=1.0;
	cin>>a>>b>>c>>d;
	cout<<a*b/2;
	if((a*b)%2)cout<<".5";
	cout<<" ";
	if(a==c*2&&b==d*2){
		cout<<1;
	}else{
		cout<<0;
	}
	return 0;
}


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

int main(){
    int h,n;
    cin >> h >> n;
    vector<int> a(n);
    int attack=0;
    for(int i=0;i<n;i++){
        cin >> a.at(i);
        attack+=a.at(i);
    }
    if(attack>=h){
        cout << "Yes" <<endl;
    }else{
        cout << "No" << endl;
    }

    
}

Measured memory_bytes: 640
from fractions import gcd
def lcm(a, b):
    return a * b // gcd(a, b)
a, b, c, d = map(int, input().split())
a -= 1
count = b -(b // c + b // d - b // (lcm(c,d))) - a + (a // c + a // d - a // (lcm(c, d)))
print(count)

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

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int h,m,s,h1,m1,s1,p,q;

for(int i=1;i<=3;i++){
 cin>>h>>m>>s;
 p=h*3600+m*60+s;
 cin>>h1>>m1>>s1;
 q=h1*3600+m1*60+s1;
 p=q-p;
 cout<<p/3600<<' '<<p%3600/60<<' '<<p%3600%60<<'\n';
}
return 0;
}

Measured memory_bytes: 1160
h,w=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(h)]
ans=10**18
for i in range(h):
    for j in range(w):
        d=0
        for k in range(h):
            for l in range(w):
                d+=min(abs(k-i),abs(l-j))*a[k][l]
        ans=min(d,ans)
print(ans)


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

int main(void){
  int w,n,a[31],tempi,temp2;
  char temp;
  for(int i = 0; i < 31; i++){
    a[i] = i + 1;
  }
  cin >> w >> n;
  for(int i = 0; i < n; i++){
    cin >> tempi >> temp >> temp2;
    swap(a[tempi - 1],a[temp2 - 1]);
  }
  for(int i = 0; i < w; i++){
    cout << a[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3012
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = inpl()
now = 0
p = defaultdict(int)
p[0] += 1
for i in range(n):
    now += a[i]
    p[now%m] += 1
res = 0
for key in list(p):
    res += p[key]*(p[key]-1)//2
print(res)

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int n,q;
vector<vector<int>>to(200010);
long long weight[200010]={};

void dfs(int now,int before){
    if(before!=-1)weight[now]+=weight[before];

    for(auto next:to[now]){
        if(next==before)continue;
        dfs(next,now);
    }
    return;

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

    

    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }

    rep(i,q){
        int p;
        long long x;
        cin>>p>>x;
        p--;
        weight[p]+=x;
    }
    dfs(0,n);

    rep(i,n)cout<<weight[i]<<" ";
    cout<<endl;

    return 0;

}
/*


*/


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k,t;
  cin >> k >> t;
  vector<ll> a(t);
  rep(i,t){
    cin >> a[i];
  }
  sort(all(a));
  reverse(all(a));
  ll M = a[0];
  if(k/2 >= M){
    cout << 0 << endl;
    return 0;
  }
  ll m = 0;
  REP(i,1,t){
    m += a[i];
  }
  cout << M - m - 1 << endl;

  return 0;
}



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

int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;

	string ans;
	if(x + r > w || y + r > h) ans = "No";
	else if(x < r || y < r) ans = "No";
	else ans = "Yes";

	cout << ans << endl;
}

Measured memory_bytes: 1192
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<vector<pair<int, int>>> G(N);
  F0R(i, N - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    G[u].emplace_back(v, w);
    G[v].emplace_back(u, w);
  }
  vector<int> rs(N);
  auto dfs = [&](auto dfs, int v, int p, int d)->void {
    rs[v] = d & 1;
    for (auto& l : G[v]) {
      if (l.first == p) continue;
      dfs(dfs, l.first, v, d + l.second);
    }
  };
  dfs(dfs, 0, -1, 0);
  F0R(i, N) {
    cout << rs[i] << newl;
  }
}
#endif


Measured memory_bytes: 12628
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorders
{
	public class Program
	{
		static void Main(string[] args)
		{
			string n = Console.ReadLine();
			int l = n.Length;

			int bitmax = 1 << 10;
			var dp0 = new long[l, bitmax];
			var dp1 = new long[l, bitmax];
			dp0[0, 0] = 1;
			for (int i = 1; i <= n[0] - '0'; i++) {
				if (i != n[0] - '0') {
					dp0[0, 1 << i] = 1;
				} else {
					dp1[0, 1 << i] = 1;
				}
			}

			for (int i = 1; i < l; i++) {
				int nn = n[i] - '0';
				for (int k = 0; k < 1 << 10; k++) {
					for (int j = 0; j < 10; j++) {
						dp0[i, k | (1 << j)] += dp0[i - 1, k];
						if (j < nn) {
							dp0[i, k | (1 << j)] += dp1[i - 1, k];
						} else if (j == nn) {
							dp1[i, k | (1 << j)] += dp1[i - 1, k];
						}
					}
				}

				dp0[i, 0] = 1;
			}

			int ansFlag = (1 << 3) | (1 << 5) | (1 << 7);
			long ans = dp0[l - 1, ansFlag] + dp1[l - 1, ansFlag];
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 11156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class A01Matrix {
public:
void solve(std::istream& cin, std::ostream& cout) {
    int H, W, a, b;
    cin >> H >> W >> a >> b;

    for (int h = 0; h < b; h++){
        for (int w = 0; w < a; w++)
            cout << 1;
        for (int w = a; w < W; w++)
            cout << 0;
        cout << endl;
    }
    for (int h = b; h < H; h++){
        for (int w = 0; w < a; w++)
            cout << 0;
        for (int w = a; w < W; w++)
            cout << 1;
        cout << endl;
    }
}
};

int main() {
	A01Matrix solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <cstdlib>
#define ll long long
#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define MX 100010
using namespace std;

int a;
int N;
string str;

int main(){
        cin >> N >> str;
        FOR(i,0,N){
                if(str[i] == 'R') a++;
        }
        if(N - a < a) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
}


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

int main(void) {
	int N;
	int nodeNum;
	int i, j;
	int** edges;
	int* edgeCount;
	int edgeId;
	if (scanf("%d", &N) != 1) return 1;
	if(N < 1) {
		puts("No");
		return 0;
	}
	for (nodeNum = 2; ; nodeNum++) {
		int edgeNum = nodeNum * (nodeNum - 1) / 2;
		if (edgeNum > N) {
			puts("No");
			return 0;
		}
		if (edgeNum == N) break;
	}

	edges = malloc(sizeof(*edges) * nodeNum);
	if (edges == NULL) return 2;
	for (i = 0; i < nodeNum; i++) {
		edges[i] = malloc(sizeof(edges[i][0]) * (nodeNum - 1));
		if (edges[i] == NULL) return 2;
	}
	edgeCount = calloc(nodeNum, sizeof(*edgeCount));
	if (edgeCount == NULL) return 2;

	edgeId = 1;
	for (i = 0; i < nodeNum; i++) {
		for (j = i + 1; j < nodeNum; j++) {
			edges[i][edgeCount[i]++] = edgeId;
			edges[j][edgeCount[j]++] = edgeId;
			edgeId++;
		}
	}

	puts("Yes");
	printf("%d\n", nodeNum);
	for (i = 0; i < nodeNum; i++) {
		printf("%d", edgeCount[i]);
		for (j = 0; j < edgeCount[i]; j++) {
			printf(" %d", edges[i][j]);
		}
		putchar('\n');
		free(edges[i]);
	}

	free(edges);
	free(edgeCount);
	return 0;
}


Measured memory_bytes: 2432
#include<stdio.h>

int main(void)
{
	int a, b[10000], c, d, s, i;
	scanf("%d", &a);
	for (i = 0; i < a; i++){
		scanf("%d", &b[i]);
	}
	d = a - 1;
	for (i = d; i >= 0; i--){
		if (i > 0){
			printf("%d ", b[i]);
		}
		else{
			printf("%d", b[i]);
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2056
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define tp(A, B, C) tuple<A, B, C>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> aoeui, pair<int, int> boeui){return aoeui.se < boeui.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define pt(a, b, c) emplace_back(make_tuple(a, b, c))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; i++)
#define foris(i, a, b) for(ll i = a; i < b; i++)
#define forise(i, a, b) for(ll i = a; i <= b; i++)
#define ford(i, n) for(ll i = n; i >= 0; i--)
#define fords(i, a, b) for(ll i = a; i >= b; i--)
#define fordse(i, a, b) for(ll i = a; i > b; i--)
#define fora(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define digits(i) (int)((log(i)/(log(10))+1)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;

string s;

int main() {
  io();
  
  cin >> s;
  int e = 0;
  fori(i, 4) {
    foris(j, i+1, 4) {
      if(s[i] == s[j]) ++e;
    }
  }
  if(e == 2) cout << "Yes";
  else cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define BOOST        std::ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define sp           <<" "<<
#define ll           long long
#define ld           long double
#define AZI(i,x)     for(auto i=x.begin();i!=x.end();i++)
#define AZ(x)        x.begin(),x.end()
#define P(x,y)       pair < x,y >
#define V(x)         vector < x >
#define fi           first
#define se           second
#define pb           push_back
#define mp           make_pair
#define PI           3.14159265358979323846264338327950288419716939937510
 
const ll mod=1e9+7,N=1e5+5,INF = 1e18;

ll power(ll a,ll b)
{
    a = a%mod;
    ll result = 1;

    while(b)
    {
        if(b&1)
            result = (result*a)%mod;
        b >>= 1, a = (a*a)%mod;
    }
    return result;
}

bool cmp(P(ll,int) a,P(ll,int) b)
{
    if(a.fi == b.fi)
        return a.se>b.se;

    return a.fi > b.fi;
}

int main() 
{ 
    BOOST

    int n,m;
    cin>>n>>m;

    V(ll) a(n);
    P(ll,int) bc[m];
    // map<ll,int> ma;
    for(auto &i : a)
    {
        cin>>i;
        // ma[i]++;
    }

    for(int i=0;i<m;i++)
    {
        cin>>bc[i].se>>bc[i].fi;
    }

    sort(bc,bc+m,cmp);
    sort(AZ(a));

    int index = 0;
    bool chk = 0;
    for(int i=0;i<m;i++)
    {
        int j;
        for(j = index; j<n && bc[i].se>0;j++)
        {
            if(a[j]>=bc[i].fi)
            {
                chk = 1;
                break;
            }

            a[j] = bc[i].fi;
            bc[i].se--;
        }
        if(chk)
            break;
        index = j;
        // auto it = lower_bound(AZ(a),bc[i].fi);

        // int index =(int)( it - a.begin() );
        // index--;
        // for(int i=index;i>=0 && bc[i].se>0;i--)
        // {
        //     a[i] = bc[i].fi;
        //     bc[i].se--;
        // }
    }
    ll ans = 0;

    for(auto i : a)
        ans+=i;
    cout<<ans<<"\n";
    return 0;    
} 

Measured memory_bytes: 2560
import sys
input = sys.stdin.readline

# 不変
N = [0] + list(map(int, tuple(input().rstrip("\n"))))

# 計算用
Ncopy = N.copy()
ans = 0
# 繰り上げ発生時に変更
flag = False
for i in range(len(N)-1, 0, -1):
    if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i-1] <= 4):
        ans += Ncopy[i]
        flag = False
    else:
        Ncopy[i-1] += 1
        # 最後だけ特殊
        if not flag:
            ans += 10 - N[i]
        else:
            ans += 9 - N[i]
        Ncopy[i] = 0
        flag = True

if Ncopy[0] == 1:
    ans += 1

print(ans)

Measured memory_bytes: 20692
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10 ;
int a[maxn], mx[20][maxn] ;
int query (int l, int r) {
	int k = log2 (r - l + 1) ;
	return max (mx[k][l], mx[k][r - (1 << k) + 1]) ;
}
int main() {
	int n, t ;
	scanf("%d%d", &n, &t) ;
	for (int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]) ;
		mx[0][i] = a[i] ;
	}
	for (int i = 1; i < 20; i ++)
		for (int j = 1; j <= n - (1 << i) + 1; j ++)
			mx[i][j] = max (mx[i - 1][j], mx[i - 1][j + (1 << (i - 1))]) ;
	int mx_val = 0, cnt = 0 ;
	for (int i = 1; i < n; i ++) {
		int x = query (i + 1, n) ;
		if (x - a[i] >= mx_val) {
			if (x - a[i] == mx_val) cnt ++ ;
			else mx_val = x - a[i], cnt = 1 ;
		}
	}
	printf("%d\n", cnt) ;
	return 0 ;
}

Measured memory_bytes: 10424
n, m = map(int, input().split())
l = [[] for i in range(n+1)]

for i in range(m):
  p, y = map(int, input().split())
  l[p].append([p, y, i])

for i in range(1, len(l)):

  temp = sorted(l[i], key=lambda x: x[1])

  for j in range(len(temp)):
    temp[j] = [str(temp[j][0]).zfill(6), str(j+1).zfill(6), temp[j][2]]
  
  l[i] = temp

ans = []

for item in l:
  ans += item

for item in sorted(ans, key=lambda x: x[2]):
  print(item[0] + item[1])

Measured memory_bytes: 52568
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N = 1000;

int lcs(string X, string Y) { 
	int c[N + 1][N + 1];
	int m = X.size();
	int n = Y.size();
	int maxl = 0;
	X = ' ' + X;
	Y = ' ' + Y;
	for( int i = 0; i <=m; i++ ) c[i][0] = 0;
	for( int j = 1; j <=n; j++ ) c[0][j] = 0;
	
	for( int i = 1;i <=m; i++ ) { 
		for( int j = 1; j <=n; j++ ) {
			if( X[i] == Y[j] ) {
				c[i][j] = c[i - 1][j - 1] + 1;
			} else {
				c[i][j] = max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = max(maxl, c[i][j]);
		}
	}
	
	return maxl ;
}

int main() {
	string s1, s2;
	int n; cin >> n;
	for( int i = 0; i< n; i++ ){
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
	
}



Measured memory_bytes: 7108
console.log(function(args){
  const _tmp = args.trim().split('\n');
  const [N,K] = _tmp[0].split(' ').map(BigInt);
  const A = [0].concat(_tmp[1].split(' ').map(v=>v|0));
  const map = Array(N).fill(0);
  const route = [1];
  let fixed = 0, loop = 0;
  for ( let i = 0; i < N; i++ ) {
    if ( !map[A[route[i]]] ) route[i+1] = A[route[i]];
    else {
      const a = map[A[route[i]]];
      fixed = BigInt(a);
      loop = BigInt(i-a+1);
      break;
    }
    map[A[route[i]]] = i+1;
  }
  if ( K < fixed ) return route[K];
  index = ( (K-fixed) % loop) + fixed;
  return route[index];

}(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 57648
n = input()

if n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9':
  print('hon')
  
if n[-1] == '0' or n[-1] == '1' or n[-1] == '6' or n[-1] == '8':
  print('pon')
  
if n[-1] == '3':
  print('bon')

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


/*//______OPTIMISATION______//
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/

//________________MACROS_______________//
#define   fast 	 		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define   int   		long long int
#define   pb  			push_back
#define   f     		first
#define   s     		second
#define   deb(x) 		cerr << #x << " " << x << endl;
#define   debb(x, y) 		cerr << #x << " = " << x << "," << #y << " = " << y << endl <<endl;
#define   in            	insert
#define   lb            	lower_bound
#define   ub            	upper_bound
#define   all(x)        	x.begin(), x.end()
#define   endl              '\n'
bool isPrime(int n)
{
	for(int i = 2; i * i <= n; i++)
	{
		if(n % i == 0)
		{
			return false;
		}
	}
	return true;
}

bool isPowerOfTwo (int x)
{
    return (x && (!(x&(x-1))));
}

int countDigit(int num)
{
	return (floor(log10(num)) + 1);
}
signed main()
{
    int n ;
    cin >> n ;

    int ans = 0 , num ;
    for (int i = 1; i <= n ; i ++)
    {
        cin >> num;
        if (i % 2 and num % 2)
        {
            ans ++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3600
import sys
N,Y=list(map(int,open(0).read().split()))

for x in range(N+1):
  for y in range(N-x+1):
    z = N - (x + y)
    if x*10000+y*5000+z*1000 == Y:
      print(x,y,z)
      sys.exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DDivRemNumber solver = new DDivRemNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDivRemNumber {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long res = 0;
            for (long i = 1; i * i + i < n; i++) {
                if (n % i == 0) {
                    res += n / i - 1;
                }
            }
            out.println(res);
        }

    }
}



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

#define MOD 1000000007
#define MOD_DEFAULT MOD
ll _mpow(ll b, ll x, ll m)
{
    if (x == 0)
        return 1;
    if (x & 1)
        return _mpow(b * b % m, x / 2, m) * b % m;
    return _mpow(b * b % m, x / 2, m);
}
inline ll mpow(ll b, ll x, ll m = MOD_DEFAULT) { return _mpow(b % m, x, m); }

int main()
{
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    vector<ll> fact(r2 + 1 + c2 + 1 + 1);

    fact[0] = fact[1] = 1;
    for (int i = 2; i < fact.size(); i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
    }

    auto f = [&](int r, int c) {
        return fact[r + c] * mpow(fact[r], MOD-2, MOD) % MOD * mpow(fact[c], MOD-2, MOD) % MOD;
    };
    auto g = [&](int r, int c) {
        return f(r + 1, c + 1) - 1;
    };

    ll ans = g(r2, c2) + MOD - g(r2, c1 - 1) + MOD - g(r1 - 1, c2) + g(r1 - 1, c1 - 1);
    ans %= MOD;

    cout << ans << endl;
}

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

int n,m,bil,sum;

int main(){
	cin>>n>>m;
	for(int i = 1;i <= m;i ++){
		cin>>bil;
		sum = sum + bil;
	}
	if(sum <= n){
		cout<<n - sum;
	}else{
		cout<<-1<<endl;
	}
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    string S, T; cin >> S >> T;
    int N = (int)S.size();
    int M = (int)T.size();
    
    
    vector<vector<int>> dp(N+1, vector<int>(M+1));
    vector<PII> V;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if(S[i]==T[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }
            else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
        }
    }
    

    int i = N;
    int j = M;
    string ans = "";
    while(i>0 && j>0){
        if(S[i-1]==T[j-1]){
            ans = S[i-1] + ans;
            i--;
            j--;
        }
        else if(dp[i][j]==dp[i][j-1]) j--;
        else i--;
    }
    cout << ans << endl;
    
    return 0;
}





Measured memory_bytes: 35584
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main(void){
    ll n,a,b;
    cin >> n >> a >> b;
    if((a+b)%2==0){
        cout << b-(a+b)/2 << endl;
    }
    else{
        ll l = b-1;
        ll r = n-a;
        ll lmid = a + (b-a)-(b-a+1)/2;
        ll rmid = (n-b+1) + n -((a+(n-b+1) )+n)/2;
        cout << min(l,min(r,min(lmid,rmid))) << endl;
    }
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();

        final Map<Integer, List<Edge>> graph = new HashMap<>();
        for (int i = 0; i < m; i++) {
            final int a = scanner.nextInt();
            final int b = scanner.nextInt();
            final int c = scanner.nextInt();

            graph.computeIfAbsent(a, v -> new ArrayList<>()).add(new Edge(a, b, c));
        }

        final Deque<Edge> queue = new ArrayDeque<>(graph.get(1));
        final long[] array = new long[n + 1];
        Arrays.fill(array, Long.MIN_VALUE);
        array[1] = 0;

        for (int i = 0; i < n * n; i++) {
            if (queue.isEmpty()) {
                System.out.println(array[n]);
                return;
            }

            final Edge edge = queue.pollFirst();
            if (array[edge.from] + edge.weight <= array[edge.to]) {
                continue;
            }
            array[edge.to] = array[edge.from] + edge.weight;
            final List<Edge> next = graph.get(edge.to);
            if (next != null) {
                queue.addAll(next);
            }
        }

        final long answer = array[n];

        final List<Edge> edges = graph.values().stream().flatMap(Main::flatten).collect(Collectors.toList());
        for (int i = 0; i < n; i++) {
            for (final Edge edge : edges) {
                if (array[edge.from] + edge.weight > array[edge.to]) {
                    array[edge.to] = array[edge.from] + edge.weight;
                }
            }
        }

        if (array[n] > answer) {
            System.out.println("inf");
        } else {
            System.out.println(array[n]);
        }
    }

    private static <T> Stream<T> flatten(final List<T> list) {
        return list.stream();
    }

    static class Edge {
        int from;
        int to;
        long weight;

        Edge(final int from, final int to, final long weight) {
            this.from = from;
            this.to = to;
            this.weight = weight;
        }
    }
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

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

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

  int N;
  cin >> N;
  vector<vector<int>> G(N);

  int a, b;
  for(int i = 0; i < N-1; i++){
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> dist_f(N);
  queue<int> q;
  for(int i = 0; i < N; i++){
    dist_f[i] = -1;
  }
  dist_f[0] = 0;
  q.push(0);

  while(!q.empty()){
    int v = q.front();
    q.pop();

    for(auto nv : G[v]){
      if(dist_f[nv] >= 0) continue;

      dist_f[nv] = dist_f[v] + 1;
      q.push(nv);
    }
  }

  vector<int> dist_s(N);
  for(int i = 0; i < N; i++){
    dist_s[i] = -1;
  }
  dist_s[N-1] = 0;
  q.push(N-1);

  while(!q.empty()){
    int v = q.front();
    q.pop();

    for(auto nv : G[v]){
      if(dist_s[nv] >= 0) continue;

      dist_s[nv] = dist_s[v] + 1;
      q.push(nv);
    }
  }

  int dist_f_s = dist_f[N-1];
  int check = -1;
  for(int i = 0; i < N; i++){
    if(dist_f[i] == dist_f_s/2 + 1 && dist_s[i] == (dist_f_s - dist_f_s/2 - 1)){
      check = i;
    }
  }

  vector<int> dist_ans(N);
  for(int i = 0; i < N; i++){
    dist_ans[i] = -1;
  }

  dist_ans[check] = 0;

  dist_ans[0] = 0;
  q.push(0);

  while(!q.empty()){
    int v = q.front();
    q.pop();

    for(auto nv : G[v]){
      
      if(dist_ans[nv] >= 0) continue;

      dist_ans[nv] = dist_ans[v] + 1;
      q.push(nv);
    }
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    if(dist_ans[i] >= 0){
      ans++;
    }
  }

  ans--;


  if(ans * 2 <= N){
    cout << "Snuke" << endl;
  }else{
    cout << "Fennec" << endl;
  }

  return 0;
}


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

using namespace std;

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

  vector<int> h(n, 0);

  for (int i=0; i<n; i++){
    cin >> h[i];
  }

  vector<int> dp(n);

  dp[1] = abs(h[0] - h[1]);

  for (int i=2; i<n; i++){
    dp[i] = min (dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
  }

  cout << dp[n-1];

  return 0;

}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N, H[SIZE];

  cin >> N;

  for (int i=0; i<N; i++)
    cin >> H[i];

  H[N] = INF;
  for (int i=N-1; i>=0; i--) {
    if (H[i+1] <  H[i]) {
      H[i]--;
    }
    if (H[i+1] < H[i]) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");

  return 0;
}


Measured memory_bytes: 640
n,x = map(int, input().split())

lis = list(map(int, input().split()))

p = [0]

for i in range(1,n+1):
    p.append(p[i-1]+lis[i-1])
    
cnt = 0
for j in p:
    if j <= x:
        cnt += 1
    else:
        break
    
print(cnt)

Measured memory_bytes: 3060
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/


// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::{i32, i64, isize, u32, u64, usize};

use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_integer::{binomial, gcd, lcm, Integer};
use permutohedron::Heap;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

// code...
#[fastout]
fn main() {
    input! {
        n: usize
    }
    println!("{}", n as f64 * 2. * 3.14159265358979);
}


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

int main () {
  long long int N;
  vector<long long int> A;
  long long int sum = 0;

  cin >> N;
  for (long long int i = 0; i < N; i++) {
    long long int n;
    cin >> n;
    A.push_back(n);
    sum += n;
  }
  sort(A.begin(), A.end());
  cout << A.front() << ' ' << A.back() << ' ' << sum << endl;
}

Measured memory_bytes: 3280
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int cmp(const void *a, const void *b)
{
	return *(int*)b - *(int*)a;
							   //降順なら
}

int main()
{
	char S[10];
	scanf("%s", S);
	int i,j;
	int k = 0;
	int len=strlen(S);
	int B[10] = { 0 };
	int ans[10] = {0};
	for (i = 0;i<len;i++)
	{
		if (S[i] == 'A' || S[i] == 'T' || S[i] == 'C' || S[i] == 'G')
		{
			B[i] = 1;
		}
	}
	for (i = 0;i < len;i++)
	{
		if (B[i] == 1)
		{
			ans[k]++;
			for (j = i+1;j< len;j++)
			{
				if(B[j] == 0)break;
				else ans[k]++;
			}
			k++;
			i = j;
		}
	}
	qsort(ans, 10, sizeof(int), cmp);
	printf("%d\n", ans[0]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b - a == c - b) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import numpy as np

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

A = []
for i in range(N):
    A.append(list(map(int, input().split(" "))))
    

ans = 9999999999999999

A_np = np.asarray(A)
for i in range(M):
    tmp = np.bincount(A_np[:, 0]).max()
    a = np.bincount(A_np[:, 0]).argmax()
    if tmp < ans:
        ans = tmp
    
    A_flatten = A_np.flatten()
    A_flatten = np.delete(A_flatten, np.where(A_flatten == a)[0])
    A_np = A_flatten.reshape((N, M-1-i))
    
print (ans)
    

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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1e18+1;


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

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

	vector<int> cum(N, 0);

	cum[0] = A[0];
	map<int, int> cnt;
	cnt[0] = 1;
	cnt[A[0]]++;
	int ans = 0;
	if ( A[0] == 0 ) ans++;
	for ( int i = 1; i < N; i++ ) {
		cum[i] = cum[i-1]+A[i];
		//cout << cnt[cum[i]] << " " << cum[i] << endl;
		ans += cnt[cum[i]];
		cnt[cum[i]] += 1;		
	}

	cout << ans << endl;

	
	return 0;
}


Measured memory_bytes: 15872
k,n = map(int,raw_input().split())
a = map(int,raw_input().split())
b = [0]*n
for i in range(1,n):
    b[i-1] = a[i]-a[i-1]
b[n-1] = a[0]+k-a[n-1]
b.sort()
b.pop(n-1)
print sum(b)

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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	int a,b;
	cin >> a >> b;
	if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
	else cout << "Impossible" << endl;

	
//////////////////////////////////////////////
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <string>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cstdlib>
using namespace std;

int main(){
  string t,st;
  double x,y;
  stack<double> s;
  while(getline(cin,t)){
    stringstream ss(t);
    while(ss>>st){
      if(st=="+"||st=="-"||st=="*"||st=="/"){
	y=s.top();
	s.pop();
	x=s.top();
	s.pop();
	switch(st[0]){
	case '+':
	  x+=y;break;
	case '-':
	  x-=y;break;
	case '*':
	  x*=y;break;
	case '/':
	  x/=y;break;
	}
	s.push(x);
      }
      else s.push(atof(st.c_str()));
    }
    cout<<fixed<<setprecision(6)<<s.top()<<endl;
    s.pop();
  }
    return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;

int main(){
    ll N, K; cin >> N >> K;
    if(K == 1) {cout << N*N*N << endl; return 0;}
    if(K % 2 == 1) { cout << (N/K) * (N/K) * (N/K) << endl; return 0;}
    else if(K % 2 == 0){
        ll ans = 0; ans += (N/K) * (N/K) * (N/K);
        ll cnt=0;
        for(int i = 1; i <= N; i++) if(i % K == K/2) cnt++;
        ans+= cnt*cnt*cnt; 
        cout << ans << endl;
    }


}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
int main(){
    int n;
    int m;
    std::scanf("%d", &n);
    std::scanf("%d", &m);

    std::unordered_map<int, int> map;
    for(int i = 0; i < m; ++i){
        int s;
        int t;
        std::scanf("%d", &s);
        std::scanf("%d", &t);
        if(map.find(s) == map.end() && map.find(t) == map.end()){
            int small = std::min(s, t);
            int large = std::max(s, t);
            map.insert(std::make_pair(small, small));
            map.insert(std::make_pair(large, small));
        } else if(map.find(s) == map.end()){
            int key = map[t];
            while(key != map[key]){
                key = map[key];
            }
            if(key <= s){
                map.insert(std::make_pair(s, key));
            } else {
                map[key] = s;
                map.insert(std::make_pair(s, s));
            }
        } else if(map.find(t) == map.end()){
            int key = map[s];
            while(key != map[key]){
                key = map[key];
            }
            if(key <= t){
                map.insert(std::make_pair(t, key));
            } else {
                map[key] = t;
                map.insert(std::make_pair(t, t));
            }
        } else {
            int keys = map[s];
            while(keys != map[keys]){
                keys = map[keys];
            }
            int keyt = map[t];
            while(keyt != map[keyt]){
                keyt = map[keyt];
            }
            int small = std::min(keys, keyt);
            int large = std::max(keys, keyt);
            map[large] = small;
        }
    }

    int q;
    std::scanf("%d", &q);
    for(int i = 0; i < q; ++i){
        int s;
        int t;
        std::scanf("%d", &s);
        std::scanf("%d", &t);
        if(map.find(s) == map.end() || map.find(t) == map.end()){
            printf("no\n");
            continue;
        }
        int keys = map[s];
        while(keys != map[keys]){
            keys = map[keys];
        }
        int keyt = map[t];
        while(keyt != map[keyt]){
            keyt = map[keyt];
        }
        if(keys == keyt){
            std::printf("yes\n");
        } else {
            std::printf("no\n");
        }
    }

    return 0;
}




Measured memory_bytes: 6388
#include<stdio.h>

int main(void) {
  int s;
  scanf("%d", &s);
  int i = 1;

  while(1) {
	  if ( s == 1 || s == 2 || s == 4 ) break;
	  else {
		  s = (s%2)?3*s+1:s/2;
	  }
	  i++;
  }

  printf("%d", i+3);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<numeric>
#include<regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9

int Bucket[200001]; // グローバル変数はデフォルトで0に初期化される

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

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

	vector<int> v;

	for (int i = 0; i <= 200000; i++) {
		if (Bucket[i] != 0) v.push_back(Bucket[i]);
	}

	if (v.size() <= K) {
		cout << 0 << endl;
		return 0;
	}

	sort(v.begin(), v.end());
	
	int ans = 0;

	for (int i = 0; i < v.size() - K; i++) {
		ans += v[i];
	}
	
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 2168
unittest
{
//	assert( [ "3", "-2 5 -1" ].parse.expand.solve == "2\n2 3\n3 3" );
	assert( [ "3", "-2 5 -1" ].parse.expand.solve == "2\n2 3\n2 3" );
	assert( [ "2", "-1 -3" ].parse.expand.solve == "1\n2 1" );
	assert( [ "5", "0 0 0 0 0" ].parse.expand.solve == "0" );
}



import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// 最大値と最小値を検索
	auto ma = 0L;
	auto mi = 0L;
	foreach( i, a; as )
	{
		if( as[ ma ] < a ) ma = i;
		if( a < as[ mi ] ) mi = i;
	}
	
	// 最大値と最小値のうち、絶対値の大きいほうを使う
	string[] anss;
	if( -as[ mi ] <= as[ ma ] )
	{
		// 最大値を初期値にして累積和的に計算
		for( auto i = 1L; i < as.length; i++ )
		{
			if( as[ i - 1 ] <= as[ i ] ) continue;
			while( as[ i ] < as[ i - 1 ] )		// 最大2回足し算すれば左より右のほうが大きくなる
			{
				as[ i ] += as[ ma ];
				anss ~= format( "%s %s", 1 + ma, 1 + i );
			}
			ma = i;
		}
	}
	else
	{
		// 最小値を初期値にして累積和的に計算
		for( auto i = as.length.signed - 2; 0 <= i; i-- )
		{
			if( as[ i ] <= as[ i + 1 ] ) continue;
			while( as[ i + 1 ] < as[ i ] )		// 最大2回足し算すれば左より右のほうが大きくなる
			{
				as[ i ] += as[ mi ];
				anss ~= format( "%s %s", 1 + mi, 1 + i );
			}
			mi = i;
		}
	}
	if( anss.length == 0 ) return "0";
	else                   return format( "%s\n%s", anss.length, anss.join( "\n" ) );
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>
#include <cmath> 

using namespace std;
 
int main() {
    int a,b;
    cin>>a>>b;
  
    int c;
    if(a > b)  c = a;
    else c = b;
    for(int i = 1;i<c;i++){
      if(abs(a-i) == abs(b-i)){
        cout<<i;
        return 0;
      }
    }
    cout<<"IMPOSSIBLE";
    return 0;
}

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

int main(){
    int N,ans;
    scanf("%d", &N);
    set<string>st;
    for(int i=0;i<N;i++){
        char x[10];
        scanf("%s", x);
        string xx(x);
        st.insert(x);
    }
    ans = st.size();


    printf("%d", ans);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n, cnt1 = 0,cnt2=0;
	bool flag = true;
	cin >> n;
	vector<int>arr(n), ar(n),tmp;
	iota(all(ar), 1);
	rep(i, n)cin >> arr[i];
	tmp = arr;
	while (1) {
		flag = true;
		rep(i, n - 1) {
			if (ar[i] == arr[i]) {
				flag = false;
				swap(arr[i], arr[i + 1]); cnt1++;
			}
		}
		if (flag)break;
	}
	if (arr[n - 1] == ar[n - 1])cnt1++;
	arr = tmp;
	while (1) {
		flag = true;
		for(int i = n-1;i>0;i--) {
			if (ar[i] == arr[i]) {
				flag = false;
				swap(arr[i], arr[i - 1]); cnt2++;
			}
		}
		if (flag)break;
	}
	if (arr[0] == ar[0])cnt2++;
	cout << min(cnt1,cnt2) << endl;
	return 0;
}



Measured memory_bytes: 4516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n;
string s,t,ans;
int main(){
	cin >> n >> s >> t;
	for(int i=0;i<n;i++)
		ans+=s[i],ans+=t[i];
	cout << ans;
	return 0;
}

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

using namespace std;

int main()
{
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  for(int i=0;i<k;i++){
    if(b<=a)
      b*=2;
    else if(a<b||c<=b)
      c*=2;
    if(a<b&&b<c){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int a, b, k;
    cin >> a >> b >> k;

    if(k >= a+b){
        cout << 0 << " " << 0 << endl;
    }

    else if(k >= a){
        cout << 0 << " " << b-(k-a) << endl;
    }

    else{
        cout << a-k << " " << b << endl;
    }

    return 0;
}

Measured memory_bytes: 3616