akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		int N = Integer.parseInt(tokens[0]);
		int K = Integer.parseInt(tokens[1]);
		String S = in.readLine();
		in.close();
		for (int i = 0; i < N; ++i) {
			if (i + 1 == K) {
				System.out.print(Character.toLowerCase(S.charAt(i)));
			} else {
				System.out.print(S.charAt(i));
			}
		}
		System.out.println("");
	}

}


Measured memory_bytes: 20436
L = [[] for i in range(5)]

for i in range(2,55556):
    D = 0
    for j in range(2,int(i**(1/2))+1):
        if i % j == 0:
            D = -1
            break
    if D == 0:
        L[i%5].append(i)

#print(L)
#for i in range(5):
#    print(len(L[i]))

N = int(input())
print(" ".join(map(str,L[1][:N])))


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

int main(){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < s.size();i++){
        if(s[i] != t[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3848
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::string s, T; std::cin >> s >> T;
  std::string S("{");
  for(int i = 0; i+T.size() <= s.size(); ++i) {
    std::string tmp = s;
    bool ok = true;
    for(int j = 0; j < T.size(); ++j) {
      if(s[i+j] == T[j]) continue;
      else if(s[i+j] == '?') tmp[i+j] = T[j];
      else { ok = false; break; }
    }
    if(!ok) continue;
    for(char& c: tmp) if(c == '?') c = 'a';
    if(S > tmp) S = tmp;
  }
  if(S == "{") S = "UNRESTORABLE";
  fin(S);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int main(){
    int x, y, a, b, c, p, q, t=0;
    ll sum=0;
    cin >> x >> y  >> a >> b >> c;
    vector<pair<int,int> > v;
    
    for (int i=0; i<a+b+c; i++){
        cin >> p;
        q = 1;
        if (i>=a) q=2;
        if (i>=a+b) q=3;
        v.pb(mp(p,q));
    }

    sort(v.begin(), v.end());   
    reverse(v.begin(), v.end());

    
    for (int i=0; i<v.size(); i++){
        if (x+y==t) break;
        if (v[i].se == 1 && x){
            x--;
            sum+=v[i].fi;
        }
        else if (v[i].se == 2 && y){
            y--;
            sum+=v[i].fi;
        }
        else if (v[i].se == 3){
            t++;
            sum+=v[i].fi;
        }
        
    }

    cout << sum;

    return 0;
}

Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 1;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, k;
        cin >> n >> k;
        int a[n];
        for(int &it : a){
            cin >> it;
        }
        int l = 1, r = 1e10;
        while(l <= r){
            int mid = (l + r) / 2;
            int cnt = 0;
            for(int &it : a){
                cnt += (it / mid) - (it % mid == 0);
            }
            if(cnt <= k){
                r = mid - 1;
            }else{
                l = mid + 1;
            }
        }
        cout << l << '\n';
    }
}

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

using namespace std;

int main() {
	int n, q;
	cin >> n;
	vector<int> a(n);
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	cin >> q;
	vector<int> b(q);
	for (int i = 0;i < q;i++) {
		cin >> b[i];
	}
	sort(a.begin(), a.end());
	unique(a.begin(), a.end());
	int count = 0;
	for (int i = 0;i < q;i++) {
		if (lower_bound(a.begin(), a.end(), b[i]) == a.end())continue;
		if (*lower_bound(a.begin(), a.end(), b[i]) == b[i])count++;
	}
	cout << count << endl;
}


Measured memory_bytes: 3156
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define N 13
#define pi M_PI

int main(){
    int n;
    scanf("%d",&n);
    int card[100];
    for(int i=0;i<n;i++){
        scanf("%d",&card[i]);
        if(i) printf(" ");
        printf("%d",card[i]); 
    }
        printf("\n");
    for(int i=1;i<n;i++){
        int v=card[i];
        int j=i-1;
        while(j>=0&&card[j]>v){
            card[j+1]=card[j];
            j--;
        }
        card[j+1]=v;
        for(int k=0;k<n;k++){
            if(k) printf(" ");
            printf("%d",card[k]);
        }
        printf("\n");
    }
   return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<utility>
using namespace std;

bool larger(pair<int, string> d1, pair<int, string> d2){
	return (d1.first > d2.first);
}

int main(){
	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		cin.ignore(INT_MAX, '\n');
		
		vector<string> dic;
		for(int i = 0;i < n;i++){
			char line[1024];
			cin.getline(line, sizeof(line));
			dic.push_back(string(strtok(line, " ")));
			char *buf;
			while(buf = strtok(NULL, " ")){
				dic.push_back(string(buf));
			}
		}
		sort(dic.begin(), dic.end());
		
		char ch;
		cin >> ch;
		int begin = 0;
		while(begin < dic.size() && dic[begin][0] != ch) begin++;
		
		if(begin == dic.size()) cout << "NA";
		
		int end = begin;
		while(end < dic.size() && dic[end][0] == ch) end++;
		
		vector<pair<int, string> > res;
		for(int i = begin;i < end;i++){
			int idx = 0;
			bool hit = false;
			for(;idx < res.size();idx++){
				if(res[idx].second == dic[i]){
					hit = true;
					break;
				}
			}
			if(hit) res[idx].first++;
			else{
				pair<int, string> data(0, dic[i]);
				res.push_back(data);
			}
		}
		
		sort(res.begin(), res.end(), larger);
		
		int len = res.size();
		if(len > 5) len = 5;
		for(int i = 0;i < len;i++){
			cout << res[i].second;
			if(i < len - 1) cout << ' ';
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 956
#include <cstdio>
#include <cstring>
#define MAXN 200100
#define MAXM 4010
#define LL long long

const LL P=1000000007;
int n,p[MAXN][2];
int s1[MAXM][MAXM],s2[MAXM][MAXM];
LL f[MAXM],fac[MAXN],invfac[MAXN];

LL getPow(LL x,LL y){
	LL res=1;
	while(y){
		if(y&1) res=res*x%P;
		x=x*x%P;
		y>>=1;
	}
	return res;
}

void init(){
	fac[0]=1;
	for(int i=1;i<MAXN;i++) fac[i]=fac[i-1]*i%P;
	invfac[MAXN-1]=getPow(fac[MAXN-1],P-2);
	for(int i=MAXN-2;i>=0;i--) invfac[i]=invfac[i+1]*(i+1)%P;
}

LL getC(int x,int y){
	return fac[x]*invfac[y]%P*invfac[x-y]%P;
}

int main(){
	scanf("%d",&n);
	init();
	for(int i=1;i<=n;i++){
		scanf("%d%d",&p[i][0],&p[i][1]);
		s1[2000-p[i][0]][2000-p[i][1]]++;
		s2[2000+p[i][0]][2000+p[i][1]]++;
	}
	LL ans=0;
	for(int i=0;i<=4000;i++)
		for(int j=0;j<=4000;j++){
			if(!j) f[j]=(f[j]+s1[i][j])%P;
			else f[j]=(f[j]+s1[i][j]+f[j-1])%P;
			if(s2[i][j]) ans=(ans+s2[i][j]*f[j])%P;
		}
	for(int i=1;i<=n;i++)
		ans=(ans-getC(2*p[i][0]+2*p[i][1],2*p[i][0]))%P;
	ans=ans*500000004LL%P;
	printf("%lld\n",(ans+P)%P);
}


Measured memory_bytes: 73216
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int a, p;
    cin >> a >> p;
    cout << (p + a * 3) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N,K,x[110];cin>>N>>K;
  for(int t=1;t<=N;t++)cin>>x[t];

  int sum=0;
  for(int t=1;t<=N;t++){
    sum+=min(2*x[t],2*(K-x[t]));
  }

  cout<<sum<<"\n";
  return 0;
}


Measured memory_bytes: 256
from collections import Counter

H, W, M = map(int, input().split())
dh, dw = Counter(), Counter()
used = set()

for _ in range(M):
    h, w = map(int, input().split())
    dh[h] += 1
    dw[w] += 1
    used.add((h, w))

ih = dh.most_common()
iw = dw.most_common()
s = ih[0][1] + iw[0][1]
ans = 0

for h, sh in ih:
    for w, sw in iw:
        if sh+sw < s or ans == s:
            break
        b = sh + sw - ((h, w) in used)
        ans = max(ans, b)
print(ans)


Measured memory_bytes: 121152
//Grid Repainting

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, ll>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

vector<string> pictureframe(vector<string> md,char fm){
    int w=md[0].size();
    int h=md.size();
    string s(w+2,fm);
    vector<string>picfm(h+2,s);
    rep(i,1,h+1)rep(j,1,w+1)picfm[i][j]=md[i-1][j-1];
    return picfm;
}

signed main (){
    int h,w;cin>>h>>w;
    vecrep(h,a,string);
    int whi = -1;
    rep(i,0,h)rep(j,0,w)if(a[i][j]=='.')whi++;
    a = pictureframe(a,'#');
    queue<p>q;
    q.push(mp(1,1));
    vector<vector<int>>dist(h+2,vector<int>(w+2,-1));
    dist[1][1]=0;
    int dx[4]={1,0,-1,0};
    int dy[4]={0,1,0,-1};
    while(!q.empty()){
        p t = q.front();
        q.pop();
        rep(i,0,4){
            if(a[t.first+dy[i]][t.second+dx[i]]=='#'||dist[t.first+dy[i]][t.second+dx[i]]!=-1)continue;
            dist[t.first+dy[i]][t.second+dx[i]]=dist[t.first][t.second]+1;
            q.push(mp(t.first+dy[i],t.second+dx[i]));
        }
    }
    int c = dist[h][w];
    if(c==-1)cout<<c<<nnn;
    else cout<<whi-c<<nnn;
    return 0;
}

Measured memory_bytes: 3620
n = int(input())
t,a = map(int,input().split())
H = list(map(int,input().split()))
A = []

for i in range(n):
    tmp = abs((t-int(H[i])*0.006)-a)
    A.append(tmp)

B = min(A)
print(A.index(B)+1)

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

public static class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        long count = 0;

        for (int a = 1; a < N; a++)
        {
            count += (N - 1) / a;
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 27536
#include <iostream>
#include<string>
using namespace std;
int main(){
    string a;
    cin>>a;
    for(int i=0;i<19;i++){
        if(i==5||i==13){
            cout<<" ";
        }else{
        cout<<a[i];
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque


def merge(a, l, m, r):
    global c
    ll = deque(a[l:m])
    rl = deque(a[m:r])
    ll.append(10e10)
    rl.append(10e10)
    for k in range(l, r):
        a[k] = (ll if ll[0] < rl[0] else rl).popleft()
    c += r - l


def merge_sort(a, l, r):
    if l + 1 < r:
        m = (l + r) // 2
        merge_sort(a, l, m)
        merge_sort(a, m, r)
        merge(a, l, m, r)


if __name__ == '__main__':
    n, a, c = int(input()), list(map(int, input().split())), 0
    merge_sort(a, 0, n)
    print(*a)
    print(c)



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

int main()
{
  int A, B, H, M;
  cin >> A >> B >> H >> M;

  double hour_angle = 30.0 * H + M / 2.0;
  double min_angle = M * 6.0;
  double angle = abs(hour_angle - min_angle);

  angle *= acos(-1) / 180;

  cout << fixed << setprecision(20) << sqrt(pow(A, 2) + pow(B, 2) - 2 * A * B * cos(angle)) << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    int ans = 0;
    int tmp = mod;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        ans += s[i];
        if(tmp > s[i] && s[i]%10 != 0) tmp = s[i]; 
    }
    if(ans%10 != 0) cout << ans << endl;
    else if(tmp != mod) cout << ans-tmp << endl;
    else cout << 0 << endl;
    return 0; 
}

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

int main() {
  int N ;
  cin >> N ;
  string S ;
  int y = 0 ;
  for ( int h = 0; h < N; h++ ){
    cin >> S;
   if ( S == "Y" ){
      y = y + 1;
    }
  }
  if ( y >= 1){
    cout << "Four" << endl;
  }else {
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int A, B, C, K;

        public void Run()
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            bool flg = false;
            for (int i = 0; i < S.Length; i++)
            {
                bool innerFlg = true;
                for (int j = 0; j < S.Length; j++)
                {
                    if (S[j] != T[(i + j) % S.Length])
                        innerFlg = false;
                }

                if (innerFlg) flg = true;
            }

            Console.WriteLine(flg ? "Yes" : "No");
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
const int mod=1e9+7;

int n,m,x[N],y[N];

int add(int a, int b){
	a+=b;
	if (a>=mod) a-=mod;
	return a;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i=1;i<=n;i++){
		cin >> x[i];
	}
	for (int i=1;i<=m;i++){
		cin >> y[i];
	}
	int baris=0;
	for (int i=1;i<n;i++){
		baris=add(baris,1ll*i*(n-1-i+1)%mod*
		(x[i+1]-x[i])%mod);
	}
	int ans=0;
	for (int i=1;i<m;i++){
		ans=add(ans,1ll*i*(m-1-i+1)%mod*
		(y[i+1]-y[i])%mod*baris%mod);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
    
    for (int i = 1; i <= 5; i++) {
      int A_i = scan.nextInt();
      if (A_i != i) {
        System.out.println(i);
        return;
      }
    }
  }
}


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

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = ReadInt();
            var que = new Queue<string>();
            for (int i = 1; i <= 9; i++) que.Enqueue(i.ToString());
            var cnt = 0;
            while (cnt < K)
            {
                cnt++;
                var X = que.Dequeue();
                if (cnt == K)
                {
                    Console.WriteLine(X);
                    return;
                }
                else
                {
                    var chk = int.Parse(X.Substring(X.Length - 1, 1));
                    if (chk == 0)
                    {
                        que.Enqueue(X + "0");
                        que.Enqueue(X + "1");
                    }
                    else if (chk == 9)
                    {
                        que.Enqueue(X + "8");
                        que.Enqueue(X + "9");
                    }
                    else
                    {
                        que.Enqueue(X + (chk - 1).ToString());
                        que.Enqueue(X + chk.ToString());
                        que.Enqueue(X + (chk + 1).ToString());
                    }
                }
            }

            Console.WriteLine();
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static string[] ReadArrayString() { return Read().Split(' '); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}


Measured memory_bytes: 35404
#include <stdio.h>

int isPrime(long int n){
	long int i;
	for(i = 2; n >= i*i; i++){
		if(!(n % i)) return 0;
	}
	return 1;
}
int main(void) {
	int n, i, cou = 0;
	scanf("%d", &n);
	for(i = 0; n > i; i++){
		long int b;
		scanf("%ld", &b);
		if(isPrime(b)) cou++;
	}

	printf("%d\n", cou);
	return 0;
}

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

int main(){
	int H, W, i, j;
	while(1){
		cin >> H >> W;
		if(H==0 && W==0) break;
		i = 0;
		while(i < H){
			j = 0;
			while(j < W){
				cout << "#";
				j++;
			}
			i++;
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
a, b, k = [int(i) for i in input().split()]
s = set()
for i in range(a, a+k):
    if i in range(a, b+1):
        s.add(i)

for i in range(b-k+1, b+1):
    if i in range(a, b+1):
        s.add(i)

for i in sorted(list(s)):
    print(i)

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

int main(){
    int n,Q;
    vector<pair<int,int> > q;
    cin >> n >> Q;
    string s;
    cin >> s;
    vector<bool> v;

    for(int i=0;i<Q;i++){
        int a,b;
        cin >> a >> b;
        q.push_back(make_pair(a,b));
    }
    
    v.push_back(false);
    for(int i=1;i<s.size();i++){
        if(s[i]=='C' && s[i-1]=='A'){
            v.push_back(true);
        }else{
            v.push_back(false);
        }
    }
    

    int sum=0;
    vector<int> t;
    for(int i=0;i<v.size();i++){
        if(v[i]==true){
            sum++;
        }
        t.push_back(sum);
    }

    vector<int> ans;
    for(int i=0;i<Q;i++){
        int tmp=0;
        tmp=t[q[i].second-1]-t[q[i].first-1];
        if(q[i].first==1)tmp+=v[0];
        ans.push_back(tmp);
    }
    for(int i=0;i<ans.size();i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3060
import bisect
inf = 10**15
mod = 10**9+7
n, m = map(int, input().split())
ken = [[] for i in range(n)]
py = [list(map(int, input().split())) for i in range(m)]
for i in range(m):
    p, y = py[i]
    ken[p-1].append(y)
for tmp in ken:
    tmp.sort()
for i in range(m):
    p, y = py[i]
    ind = bisect.bisect_left(ken[p-1], y)
    print('{ans:06}{anse:06}'.format(ans=p, anse=ind+1))

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

int main(void){
	char s[20];

	scanf("%s",s);

	for(int i=(strlen(s)-1);i>=0;i--){
		printf("%c",s[i]);
	}printf("\n");

    return 0;
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000



int main(){

	int X;
	cin>>X;
	
	if(X>=30)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int n;
	cin >> n;
	int num=0;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		if(a%2)
			num++;
	}
	if(num%2)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace __gnu_pbds;
using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll x;
    cin >> x;
    ll hap = x / 500;
    x -= 500 * hap;
    hap *= 1000;
    hap += x / 5 * 5;
    cout << hap << '\n';
}



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

double dp[3005][3005];

void Main() {
    int N;
    cin >> N;
    vector<double> P(N);
    rep(i, N) cin >> P[i];

    dp[0][0] = 1;
    rep(i, N) {
        double p = P[i];
        rep(j, i + 1) {
            dp[i + 1][j + 1] += dp[i][j] * p;
            dp[i + 1][j] += dp[i][j] * (1 - p);

        }
    }
    double ans = 0;

    rep(j, N+1) {
        if (j > N / 2) {
            ans += dp[N][j];
        }
    }
    cout << ans << endl;

}

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


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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;

int dp[3001][3001];

int main(){
    string s,t;
    cin >> s >> t;
    int n = s.length(), m = t.length();
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    string ans = "";
    int i = n, j = m;
    while(i > 0 && j > 0){

        if(dp[i-1][j] != dp[i][j] && dp[i][j-1] != dp[i][j])
            ans += s[i-1], i--, j--;
        else if(dp[i-1][j] != dp[i][j])
            j--;
        else
            i--;
    }

    for(int i = ans.length()-1; i >= 0; i--) cout << ans[i];

    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int x;
    cin>>x;
    int a1=0,a2=0;
    while(a2<x){
        a1+=100;
        a2+=105;
    }
    if(a1<=x&&x<=a2)cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>

#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INPUT1(n, a) for(int i##n = 0; i##n < n; i##n++) {cin >> a[i##n]; } //n = count, a = vector 
#define OUTPUT1(n, a) cout << "---count---" << endl << n << endl << "---content---" << endl; for(const auto b : a){cout << b << endl; }
#define INPUT2(x, y, field) for(int i##x = 0; i##x < y; i##x++) { for(int j##x = 0; j##x < x; j##x++) { cin >> field[i##x][j##x]; } }
#define OUTPUT2(x, y, field) cout << "---count---" << endl << x << " " << y << endl <<"---content---" << endl; for(int i##x = 0; i##x < y; i##x++) { cout << i##x << "   "; for(int j##x = 0; j##x < x; j##x++) { cout << field[i##x][j##x] << " "; } cout << endl; }

using namespace std;
using ll = long long;

const int INF = 1001001001;

int main()
{
	ll n, k, ans(0);
	cin>>n>>k;
	vector<ll> h(n);
	rep(i,n)cin>>h[i];
	sort(h.begin(),h.end());
	
	rep(i,n-k)ans+=h[i];
	cout<<ans<<endl;
}


Measured memory_bytes: 1920
n, k = map(int, input().split())

table = [[0] * (n + 1) for _ in range(71)]

table[0] = list(map(int, input().split()))
table[0].insert(0, 0)

for i in range(70):
    for j in range(1, n + 1):
        table[i + 1][j] = table[i][table[i][j]]

v = 1

for i in range(70, -1, -1):
    if k >= (1 << i):
        v = table[i][v]
        k -= 1 << i

print(v)

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

bool f(string s) {
  ll N = s.size();
  rep(i,N) {
    if (s[i] != s[N-1-i])
      return false;
  }
  return true;
}

// start       end        length
// 0           N-1        N
// 0          (N-1)/2-1   (N-1)/2
// (N+3)/2-1   N-1        (N-1) - ((N+3)/2-1) +1

signed main() {
  string s;
  cin >> s;
  ll N = s.size();
  cout << (f(s)  && f(s.substr(0, (N-1)/2)) && f(s.substr((N+3)/2-1, (N-1)-((N+3)/2-1)+1)) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e+7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int prime[1001000];//i番目の素数
bool is_prime[1001010];//is_prime[i]がtrueならiは素数
					   //n以下の素数の数を返す
int sieve(int n) {
	int p = 0;
	for (int i = 0; i <= n; ++i) {
		is_prime[i] = true;
	}
	is_prime[0] = false;
	is_prime[1] = false;
	for (int i = 2; i <= n; ++i) {
		if (is_prime[i]) {
			prime[p] = i;
			p++;
			for (int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}
	return p;
}

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}

const ll MOD = 1e9 + 7;
ll powmod(ll a, ll k) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= MOD;
		}
		ap = ap * ap;
		ap %= MOD;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a) {
	return powmod(a, MOD - 2);
}
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
///////////////////////////////////////


int main(){
	set<string>st;
	int n; cin >> n;
	REP(i, n) {
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 19256
// header {{{
// header {{{
#include <bits/stdc++.h>
using namespace std;
 
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
 
#define ASSERT(expr...) assert((expr))
 
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
 
using f32 = float;
using f64 = double;
// }}}
 
constexpr i64 INF = 1'010'000'000'000'000'017LL;
 
constexpr i64 MOD = 1'000'000'007LL;
 
constexpr f64 EPS = 1e-12;
 
constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

 
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <int>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
 
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
 
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
 
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}
 
// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
 
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}
 
//--------------------------------------------------------------------
 
bool isOK(int mid, double key){
 
    if((double)mid*mid > key) {
             return true;
     } else {
              return false;
     }
}

 int binary_search(double key) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}


bool isKaibun(string st){
    bool ans = true;
    int n = st.length();
    REP(i,n/2){
        if(st[i] != st[n-i-1]){
            return false;
        }
    }
    return true;
}

int toInt(char a){
    return a-'0';
}



void solve() {
    ll N,K;
    cin >> N >> K;
    cout << min(N%K,abs(N%K-K)) << endl;
}



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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1ll << 60;
ll MOD = 1e9 + 7;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

vector<int> t(1000000);

int main()
{

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }

    vector<int> l(n), r(n);
    REP(i, n - 1)
    l[i + 1] = gcd(l[i], a[i]);
    for (int i = n - 1; i >= 1; --i)
        r[i - 1] = gcd(r[i], a[i]);

    int ans = 1;
    REP(i, n)
    ans = max(ans, gcd(l[i], r[i]));

    Cout(ans);

    return 0;
}

Measured memory_bytes: 5376
fn main() {
  let (n, m, k): (i32, i32, i32) = read_tuple();
  
  let mut nps: Vec<(i32, i32)> = vec![];
  for i in 0 .. n + 1 {
    nps.push((i,n-i));
  }
  
  let mut mps: Vec<(i32, i32)> = vec![];
  for i in 0 .. m + 1 {
    mps.push((i,m-i));
  }
  
  let mut vec: Vec<i32> = vec![];
  for (n1, n2) in nps {
    for (m1, m2) in mps.clone() {
      vec.push(n1*m1 + n2*m2);
    }
  }
  
  println!("{}", if vec.contains(&k) {"Yes"} else {"No"});
}

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr, T3: std::str::FromStr>() -> (T1, T2, T3) {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  let z = it.next().unwrap().parse::<T3>().ok().unwrap();
  (x, y, z)
}

Measured memory_bytes: 9464
from itertools import combinations
from math import sqrt

n,d = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(n)]

count = 0
for i,j in combinations(range(n),2):
    ans = 0
    for k in range(d):
        ans += (x[i][k]-x[j][k])**2
    if sqrt(ans).is_integer():
        count += 1
print(count)

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N+1,0);
    for(int i=1;i<=N;i++) cin >> A[i];
    map<int,int> m;
    int ans = 0;
    for(int i=1;i<=N;i++){
        map<int,int>::iterator it = m.upper_bound(-A[i]);
        if(it==m.end()){
            m[-A[i]]++;
            ans++;
        }else{
            m[it->first]--;
            if(m[it->first]==0) m.erase(it);
            m[-A[i]]++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5248
n, m = gets.chomp.split.map(&:to_i).sort!
if n == 1
  if m == 1
    puts "1"
  elsif m == 2
    puts "0"
  else
    puts m - 2
  end
  exit
elsif n == 2
  puts "0"
  exit
end

puts (n - 2) * (m - 2)

Measured memory_bytes: 1788
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

alias OP = Tuple!(long, long);

void main()
{
    auto N = readln.chomp.to!int;
    auto as = readln.split.to!(long[]);
    sort(as);

    if (N == 2) {
        writeln(as[1] - as[0]);
        writefln("%d %d", as[1], as[0]);
        return;
    }

    long[] ps, ms;
    long r;
    r += as[$-1];
    r -= as[0];
    foreach (a; as[1..$-1]) {
        if (a < 0) {
            ms ~= a;
            r -= a;
        } else {
            ps ~= a;
            r += a;
        }
    }
    writeln(r);
    if (ps.empty) {
        writefln("%d %d", as[$-1], as[0]);
        r = as[$-1] - as[0];
    } else {
        writefln("%d %d", as[0], as[$-1]);
        r = as[0] - as[$-1];
    }
    while (ps.length > 1) {
        writefln("%d %d", r, ps[0]);
        r -= ps[0];
        ps = ps[1..$];
    }
    if (!ps.empty) {
        writefln("%d %d", ps[0], r);
        r = ps[0] - r;
    }
    while (!ms.empty) {
        writefln("%d %d", r, ms[0]);
        r -= ms[0];
        ms = ms[1..$];
    }
}

Measured memory_bytes: 5976
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String moji = sc.next();
			String answer = "No";
			if (moji.charAt(2) == (moji.charAt(3))) {
				if (moji.charAt(4) == (moji.charAt(5))) {
					answer = "Yes";
				}

			}
			System.out.println(answer);

		} finally

		{
			sc.close();
		}
	}

}


Measured memory_bytes: 23380
#include<stdio.h>

int main()
{
	int box, num, x, y, ball[2][100000]= {{1, }, {}}, i;

	scanf("%d%d", &box, &num);

	for(i= 0; i< box; i++)
		ball[1][i]= 1;

	for(i= 0; i< num; i++)
	{
		scanf("%d%d", &x, &y);
		ball[1][x- 1]--;
		ball[1][y- 1]++;

		if(ball[0][x- 1])
		{
			ball[0][y- 1]++;
			if(!ball[1][x- 1])
				ball[0][x- 1]= 0;
		}
	}

	x= 0;
	for(i= 0; i< box; i++)
		if(ball[0][i])
			x++;

	printf("%d\n", x);

	return 0;
}

Measured memory_bytes: 896
// AtCoDeerくんとペンキ
#include <iostream>
using namespace std;
int main(){
    int c[3],ans=0;
    for(int i=0;i<3;i++){
        cin>>c[i];
        for(int j=0;j<i;j++){
            if(c[i]==c[j]){
                ans--;
                break;
            }
        }
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    ll N, M;
    ll tAns[100000];
    ll p;
    string S;
    ll ac = 0;
    ll wa = 0;

    cin >> N >> M;

    for(ll i = 0; i < 100000; i++){
        tAns[i] = 0;
    }
    for(ll i = 0; i < M; i++){
        cin >> p >> S;
        if(tAns[p] != -1){
            if(S.compare("WA") == 0){
                tAns[p]++;
            }else{
                ac++;
                wa += tAns[p];
                tAns[p] = -1;
            }
        }
    }

    cout << ac << " " << wa << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main() {
    set<int> s;
    int n;
    cin>>n;
    rep(i,n){
        int q,x;
        cin>>q>>x;
        if(q){
            fin(s.count(x));
            
        } else s.insert(x),fin(s.size());;
        
    }
    
}




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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    string t;
    cin >> s;
    cin >> t;
    
    string str = t.substr(0, s.length());
    if(t.length() == s.length()+1 && t.length()<=11 && str == s) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


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

int a[500][500];

void calc(int l, int r, int lv){
    if(l < r-1){
        int m = (l+r)/2;
        for(int i=l; i<m; i++)
        for(int j=m; j<r; j++)
            a[i][j] = lv;
        calc(l, m, lv+1);
        calc(m, r, lv+1);
    }
}

int main(){
    int n;
    cin >> n;
    calc(0, n, 1);
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++)
            cout << a[i][j] << ' ';
        cout << endl;
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

const int mod=1e9+7;

int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	if(n<m) swap(n,m);
	if(n>m+1) return 0*puts("0");
	int ans=1;
	rep(i,1,n)
		ans=1ll*ans*i%mod;
	rep(i,1,m)
		ans=1ll*ans*i%mod;
	if(n==m) ans=ans*2%mod;
	return printf("%d\n",ans),0;
}

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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

class union_find
{
	int  _setnum;
	vector<int> par, nume;
public:
	union_find(){
	}
	
	union_find(int x){
		par.resize(x);
		nume.resize(x);
		init();
	}
	
	~union_find(){
		//
		
	}
	
	void clear(){
		_setnum = 0;
		par.clear();
		nume.clear();
	}
	
	void init(){
		_setnum = par.size();
		for(int i = 0; i < par.size(); i++){
			par[i] = i;
			nume[i] = 1;
		}
	}
	
	void resize(int x){
		
		par.resize(x);
		nume.resize(x);
		init();
	}

	int find(int x){
		return par[x] == x ? x : par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
	
		if(x == y)return;
		
		_setnum--;
		
		if(nume[x] > nume[y]) std::swap(x,y);
		
		par[x] = y;
		nume[y] += nume[x];
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
	
	int numel(int x){
		return nume[find(x)];
	}
	
	int size(){
		return par.size();
	}
	
	int setnum(){
		return _setnum;
	}
};


signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, M;
	union_find uf;
	
	cin>>N>>M;
	
	uf.resize(N);
	
	for(int i = 0; i < M; i++){
		int A, B;
		
		cin>>A>>B;
		
		A--, B--;
		
		uf.unite(A, B);
	}
	
	cout<<uf.setnum()-1<<endl;
	
	return 0;
}

Measured memory_bytes: 4764
n,m,k=map(int,input().split())

import sys
sys.setrecursionlimit(10**9) #再帰の上限をあげる

root=[-1 for i in range(n+1)] #自分が親ならグループの人数のマイナス倍を、そうでないなら（元）親の番号を示す

def r(x):   #親は誰？
    if root[x]<0:
        return x
    else:
        root[x]=r(root[x])
        return root[x]

def unite(x,y):
    x=r(x)
    y=r(y)
    if x==y:
        return
    if x>y:
        x,y=y,x
    root[x]+=root[y]
    root[y]=x


fre=[[] for _ in range(n+1)]
bro=[[] for _ in range(n+1)]

for i in range(m):
    a,b=map(int,input().split())
    unite(a,b)
    fre[a].append(b)
    fre[b].append(a)

for i in range(k):
    a, b = map(int, input().split())
    bro[a].append(b)
    bro[b].append(a)

ans=[]
for i in range(1,n+1):
    anser=-root[r(i)]-1
    anser-=len(fre[i])
    for j in bro[i]:
        if r(i)==r(j):
            anser-=1
    ans.append(str(anser))
print(" ".join(ans))




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

struct State {
	int high, from, to;
	State(int h, int f, int t) : high(h), from(f), to(t) {}
	
	static bool greater_high(const State& lhs, const State& rhs){
		return lhs.high > rhs.high;
	}
};

vector<State> amida;

int main() {
	int n, m, a, h, p, q;
	while(cin >> n >> m >> a && (n || m || a)){
		amida.clear();
		for(int i = 0; i < m; ++i){
			scanf("%d%d%d", &h, &p, &q);
			amida.push_back(State(h, p, q));
		}
		stable_sort(amida.begin(), amida.end(), State::greater_high);
		int now = a;
		for(int i = 0; i < m; ++i){
			if(now == amida[i].from){
				now = amida[i].to;
			}
			else if(now == amida[i].to){
				now = amida[i].from;
			}
		}
		cout << now << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h> 
using namespace std; 
int main() { 
    long long A, B; 
    cin >> A >> B; 
    if(A % 2 != B % 2) { 
      cout << "IMPOSSIBLE" << endl; 
    } else { 
      cout << (A + B) / 2 << endl; 
    } 
     return 0; 
 }


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

ll f(ll n, ll a, ll b) {
  if (abs(b - a) % 2 == 0) {
    return abs(b - a) / 2;
  } else {
    if (b < a) swap(a, b);
    return min(a + f(n, 1, b - a), n - b + 1 + f(n, a + n - b + 1, n));
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n, a, b;
  cin >> n >> a >> b;
  cout << f(n, a, b) << endl;
  return 0;
}


Measured memory_bytes: 256