akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

char grid[9][9];

int main()
{
    int h,w,x,y,t,flag;
    while(~scanf("%d%d",&h,&w))
    {
        flag=0;
        memset(grid,0,sizeof(grid));
        scanf("%*c");
        for(x=0;x<h;x++)
        {
            for(y=0;y<w;y++)
            {
                scanf("%c",&grid[x][y]);
            }
            scanf("%*c");
        }
        x=y=0;
        while((x!=h-1||y!=w-1)&&!flag)
        {
            if(grid[x][y]=='#')
            {
            if(grid[x][y+1]=='#')
            {
                y++;
            }
            else
            {
                x++;
                if(x<h&&y<w)
                {
                    for(t=y+1;t<=w-1;t++)
                    {
                            if(grid[x-1][t]=='#')
                            {flag=1;break;}
                    }
                    for(t=0;t<y;t++){if(grid[x][t]=='#'){flag=1;break;}}
                }
            }
            }
            else
                flag=1;
        }
        if(grid[h-1][w-1]=='.')
            flag=1;
        if(!flag)
            printf("Possible\n");
        else
            printf("Impossible\n");
    }
    return 0;
}


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

/************* Using *************/
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using graph_t = vector<vector<ll>>;

/*********** Constants ***********/
const auto INF  = static_cast<int>(1e10);
const auto INFL = static_cast<ll>(1e18);
const auto MOD  = static_cast<ll>(1e9 + 7);
const auto NIL  = nullptr;

/*********** Variables ***********/
ll A, B, K;

/************* Utils *************/

/*********** Functions ***********/
bool init() {
    cin >> A >> B;
    return true;
}

void solve() {
    if ((max(A, B) - min(A, B)) % 2) {
        K = -1;
    }
    else {
        K = min(A, B) + (max(A, B) - min(A, B)) / 2;
    }
}

void output() {
    if (K < 0) {
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        cout << K << endl;
    }
}

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


Measured memory_bytes: 256
#include<stdio.h>

int n,A[2000];

int solve(int,int);

int main(){

  int q,mi[2000],i,left=0,right;

  scanf("%d",&n);

  for(i=0;i<n;i++){

    scanf("%d",&A[i]);

  }

  right = n;
  
  scanf("%d",&q);

  for(i=0;i<q;i++){

    scanf("%d",&mi[i]);
    
  }

  for(i=0;i<q;i++){

    if(solve(0,mi[i])==1) printf("yes\n");
    else printf("no\n");

  }
  return 0;
}

int solve(i,m){

  int res;
  
  if(m==0) return 1;

  if(i>n) return 0;

  res =( solve(i+1,m)||solve(i+1,m-A[i]) );

  return res;

}

Measured memory_bytes: 588
/*
        Choo Lo jo mujhe tum kabhi, kho na jaoon main raat din
    Nazaron mein tum ho basey
        Keh do jo tum ek baar, Mere ho bas tum mere
    Nazaron mein tum ho basey
*/
 
#include<bits/stdc++.h>
#include<cstdio>
 
#define deb(x) cout << #x << " -> " << x << el
#define db double
#define ll long long int
#define ull unsigned long long int
#define umap unordered_map
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define sclu(x) scanf("%llu", &x)
#define scd(x) scanf("%lf", &x)
#define pass cout<<"pass\n"
#define vi vector<int>
#define pb push_back
#define vec vector
#define el "\n"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define umap unordered_map
#define f(i,x,y) for(int i=x;i<y;++i)
#define ff(i,x,y) for(int i=x;i<=y;++i)
#define mem(x) memset(x, 0, sizeof(x))
#define mems(x,y) memset(x, y, sizeof(x))
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ppi pair<int, pii>
#define mat vector<vector<ll> > 
#define mod 1000000007
#define MAX 100005
 
using namespace std;

void solve() {
	string a, b;
	cin >> a >> b;

	int an = a.length(), bn = b.length();

	vec<vi> dp(an + 1, vi(bn + 1, 0));

	for(int i = 1; i <= an; ++i) {
		for(int j = 1; j <= bn; ++j) {
			if(a[i-1] == b[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}

	string s;
	int i = an, j = bn;
	while(i != 0 and j != 0) {
		if(dp[i][j] == dp[i][j - 1]) {
			--j;
		} else if(dp[i][j] == dp[i - 1][j]) {
			--i;
		} else if(dp[i][j] == 1 + dp[i-1][j-1]) {
			s += b[j-1];
			--i; --j;
		}
	}
	reverse(s.begin(), s.end());
	cout << s << el;
}

int main() {
    int ccc = 1;
    // sc(ccc);
    while(ccc--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 35584
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007LL
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n,k, ans = 1;
    cin >> n >> k;
    rep(n){
        ans = min(ans*2, ans+k);
    }
    cout << ans;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+3;
vector<int> adj[N];
int par[N];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n,m;cin >> n >> m;
	for(int i=0;i<m;i++){
		int a,b;cin >> a >> b;a--,b--;
		adj[a].emplace_back(b);
		adj[b].emplace_back(a);
	}
	queue<int> nd;
	memset(par,-1,sizeof(par));
	par[0] = 0;
	nd.emplace(0);
	while(!nd.empty()){
		int nw = nd.front();
		nd.pop();
		for(auto it : adj[nw]){
			if(par[it] == -1){
				nd.emplace(it);
				par[it] = nw;
			}
		}
	}
	bool nfound = false;
	for(int i=0;i<n;i++)
		nfound |= (par[i] == -1);
	if(nfound){
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	for(int i=1;i<n;i++) cout << par[i]+1 << '\n';
}


Measured memory_bytes: 13308
#include<stdio.h>

int main(){
   int a,b,c;
    
    do{
     scanf("%d",&a);
    
    }while(a>100||a<0);
    
    do{
    
     scanf("%d",&b);

    }while(b>100||b<0);

    do{
    
     scanf("%d",&c);

    }while(c>100||c<0);


    if(b>a&&c>b){
       printf("Yes\n"); 
    }else {
       printf("No\n"); 
    }
return 0;
}

Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,m,H,M,k;
    cin>>h>>m>>H>>M>>k;
    m+=h*60;
    M+=H*60;
    cout<<M-m-k<<'\n';
}

Measured memory_bytes: 3652
#include <stdio.h>

int main(int argc, const char* argv[])
{
	long inputN, FizzBuzzSum = 0, aElement = 0;
	scanf("%ld", &inputN);

	// Looks inside iterator (i) for a number that has division remainder (remainder > 0). Then adds that remainder to FizzBuzzSum
	for (int i = 0; i < inputN; i++)
	{
		aElement++;
		if (aElement % 3 != 0 && aElement % 5 != 0)
		{
			FizzBuzzSum += aElement;
		}
	}

	printf("%ld \n", FizzBuzzSum);
}

Measured memory_bytes: 1732
using System;
using System.Linq;

class prog{
  
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    long[] lucas = new long[N + 1];
    
    lucas[0] = 2;
    lucas[1] = 1;
    for(int i = 2; i <= N; i++){
      lucas[i] = lucas[i - 1] + lucas[i - 2];
    }
    
    Console.WriteLine(lucas[N]);
  }
}

Measured memory_bytes: 11092
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	P mx = { -INF,-INF };
	rep(i, N) {
		int A, B;
		cin >> A >> B;
		P p = { A,B };
		mx = max(mx, p);
	}
	int ans = mx.first + mx.second;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int a,b,s=0,t;
	cin>>a;
	t=a;
	while(a!=0)
	{
		b=a%10;
		a=a/10;
		s+=b;
	}
	if(t%s==0)cout<<"Yes";else cout<<"No";
	return 0; 
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] array = new int[k];
        for (int i = 0; i < k; i++) {
            array[i] = sc.nextInt();
        }
        
        for (int i = n; i < 100000; i++) {
            boolean ok = true;
            
            String str = String.valueOf(i);
            for (int j = 0; j < k; j++) {
                if (str.contains(String.valueOf(array[j]))) {
                    ok = false;
                    break;
                }
            }
            
            if (ok) {
                System.out.println(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 34924
//  main.cpp
//  CppTest

#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    
    /////////////////////
    // Write code below /
    /////////////////////
    int numberOfPalindrome = 0;
    int A, B;
    cin >> A >> B;
    for (int currentNumber = A; currentNumber < B + 1; currentNumber++) {
        int x[5];
        int buf = currentNumber;
        for (int digit_i = 0; digit_i < 5; digit_i++) {
            x[digit_i] = buf % 10;
            buf /= 10;
        }
        
        int y[5];
        buf = currentNumber;
        for (int digit_i = 4; digit_i >= 0; digit_i--) {
            y[digit_i] = buf % 10;
            buf /= 10;
        }
        
        bool isPalindrome = true;
        for (int i = 0; i < 5; i++) {
            if (x[i] != y[i]) {
                isPalindrome = false;
            }
        }
        
        if (isPalindrome == true) {
            numberOfPalindrome++;
        }
    }
    
    cout << numberOfPalindrome << endl;
    
    return 0;
}


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

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

dp = [1000]

for i in range(N):

    now = dp[-1]
    for j in range(i):

        now = max(now , dp[j] % A[j] + dp[j]//A[j]*A[i])

    dp.append(now)

print (dp[-1])


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

int main()
{
	ll a, b, c, k;
	cin >> a >> b >> c >> k;

	ll score = 0;
	for (int i = 0; i < a; i++) {
		k--;
		if (0 <= k) score++;
		else {
			cout << score << endl;
			return 0;
		}
	}

	for (int i = 0; i < b; i++) {
		k--;
		if (0 <= k) score += 0;
		else {
			cout << score << endl;
			return 0;
		}
	}

	for (int i = 0; i < c; i++) {
		k--;
		if (0 <= k) score--;
		else {
			cout << score << endl;
			return 0;
		}
	}
	cout << score << endl;
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 1020304050

int main()
{
  int n;cin>>n;
  vector<int> t(n+1,0);
  int i,j;
  for(i=1;i<n;i++)cin>>t[i];
  int dp;
  vector<int> imin(n+1,INF);
  for(i=0;i<=n;i++)
  {
    imin[i]=t[i];
  }
  for(i=0;i<=n/2;i++)
  {
    int jmin=t[i];
    for(j=0;j<=n/2;j++)
    {
      dp=min(imin[j],jmin)+t[i+j];
      imin[j]=min(imin[j],dp);
      jmin=min(jmin,dp);
    }
  }
  cout<<dp<<endl;
}


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

bool check (vector<int> n) {
    int count = 0;
    for (int i = 0; i < n.size(); i++) {
        if (n[i] != 0) {
            count++;
        }
    }
    return count == 1 ? false : true;
}

int main ()
{
    int a, b;
    while (cin >> a >> b, (a || b)) {
        vector<int> n(a);
        int s  = 0;
        while (b || check(n)) {
            if (b > 0) {
                b--, n[s]++;
            } else {
                b += n[s], n[s] = 0;
            }
            if (!check(n) && !b) break;
            s = (s+1) % a;
        }
        cout << s  << endl;
    }

    return 0;
}

Measured memory_bytes: 1216
N, L = map(int, input().split())

t = []
for i in range(N):
    t.append(L + i)
    
real = sum(t)

diff = 1e10
ans = 0
for i in range(N):
    pred = sum(t) - t[i]
    if abs(pred - real) <= diff:
        diff = abs(pred - real)
        ans = pred
        
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll>a(n);
  rep(i,n)cin >> a[i];
  sort(a.begin(),a.end());
  ll ub = 2e18;
  ll lb = -2e18;
  while(ub-lb>1){
    ll mid = (ub+lb)/2;
    ll cnt = 0;
    rep(i,n-1){
      if(a[i]>0){
	if(a[n-1]*a[i]<=mid) cnt += (n-1)-(i+1)+1;
	else if(a[i+1]*a[i]>mid) continue;
	else{
	  ll ub2 = n-1;
	  ll lb2 = i+1;
	  while(ub2-lb2>1){
	    ll mid2 = (ub2+lb2)/2;
	    if(a[i]*a[mid2]<=mid) lb2=mid2;
	    else ub2=mid2;
	  }
	  cnt += ub2 - (i+1);	  
	}
      }
      else{
	if(a[i+1]*a[i]<=mid) cnt += (n-1)-(i+1)+1;
        else if(a[n-1]*a[i]>mid) continue;
        else{
	  ll ub2 = n-1;
          ll lb2 = i+1;
          while(ub2-lb2>1){
            ll mid2 = (ub2+lb2)/2;
            if(a[i]*a[mid2]>mid) lb2=mid2;
            else ub2=mid2;
          }
          cnt += (n-1) - lb2;
	}
      }
    }
    if(cnt<k) lb=mid;
    else ub = mid;
  }
  cout << ub << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include<vector>

using namespace std;

int main(){
	int n, y;
	cin >> n >> y;
	bool flag = false;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n-i; j++) {
			if (10000 * i + 5000 * j + 1000 * (n - i - j) == y) {
				flag = true;
				cout << i << " " << j << " " << n - i - j << endl;
				i = n+1;
			}
		}
	}
	if (flag == false) {
		cout << "-1 -1 -1" << endl;
	}
	return 0;
}

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


int main(){
  string s;
  cin >>s;
  char a=s.at(2);
  char b=s.at(3);
  char c=s.at(4);
  char d=s.at(5);
  if(a==b &&c==d){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }

}


Measured memory_bytes: 256
n,q = map(int,input().split())
#s=list(input())	
s = input()
index = -1
indexes = []
while True:
    index = s.find("AC", index + 1)
    if index == -1:
        break
    indexes.append(index)
dp = []

for i in range (n):
    dp.append(len(indexes))
    if len(indexes)> 0 and indexes[0] == i:
        indexes.pop(0)
for i in range(q):
    l,r = map(int,input().split())
    print(dp[l-1] - dp[r-1])



Measured memory_bytes: 7744
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif*/
}
int main()
{
	checkpoint1();
	ll n;
	cin>>n;
	ll op=1000;
	while(n>op)
		op+=1000;
	op-=n;
	cout<<op;
	return 0;
}

Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(1000000000)

def gcd(a: int, b:int):
    while b:
        a,b=b,a%b
    return a

def merge(a,us,vs):
    i,j,res=0,0,[]
    while i<len(us) and j<len(vs):
        if a[us[i]]>=a[vs[j]]:
            res.append(us[i])
            i+=1
        else:
            res.append(vs[j])
            j+=1
    return res+us[i:]+vs[j:]

def dfs(g,a,u,vis):
    vis[u]=True
    res=[]
    for v in g[u]:
        if not vis[v]:
            res=merge(a,res,dfs(g,a,v,vis))
    return [u]+res

while 1:
    try:
        n=int(input())
        a=sorted(map(int,input().split()))
    except: break

    g=[[] for _ in range(n)]
    for i in range(n):
        for j in range(i+1,n):
            if gcd(a[i],a[j])!=1:
                g[i].append(j)
                g[j].append(i)

    vis=[False]*n
    res=[]
    for u in range(n):
        if not vis[u]:
            res=merge(a,res,dfs(g,a,u,vis))
    print(' '.join(str(a[u]) for u in res))


Measured memory_bytes: 130012
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int div_cnt(ll k, ll div){
	int res = 0;
	while(k % div == 0){
		++res;
		k /= div;
	}
	return res;
}

ll toll(string s){
	string res;
	bool cnton = false;
	int nd = 9;
	rep(i,s.size()){
		if(s[i] == '.'){
			cnton = true;
		}else{
			if(cnton)--nd;
			res.push_back(s[i]);
		}
	}
	res += string(nd, '0');
	return atoll(res.c_str());
}

int main(){
	int N;
	string a;
	cin >> N;
	vector<P> A(N);
	vector<ll> Ks(N);
	vector<vector<ll>> tmp(64, vector<ll>(22, 0));
	vector<vector<ll>> sum(64, vector<ll>(23, 0));
	rep(i,N){
		cin >> a;
		ll k = toll(a);
		int t = div_cnt(k, 2);
		int f = div_cnt(k, 5);
		A[i] = make_pair(t,f);
		tmp[t][f]++;
		Ks[i] = k;
	}
	rep(i,64){
		rep(j,22){
			sum[i][j+1] = sum[i][j] + tmp[i][j];
		}
	}	
	//rep(i,20){
	//	printf("[%d] ", i);
	//	rep(j,20)cout << sum[i][j] << ' ';
	//	cout << endl;
	//}
	ll ans = 0;
	rep(i,N){
		int need_t = max(18-A[i].first, 0);
		int need_f = max(18-A[i].second, 0);
		if(need_t <= A[i].first && need_f <= A[i].second){
			--ans;
		}
		//int tmp_ans = 0;
		for(int j = need_t; j < 64; ++j){
			ans += sum[j][22] - sum[j][need_f];
			//tmp_ans += sum[j][22] - sum[j][need_f];
		}
		//printf("[%lld]->[need_t = %d, need_f = %d] && tmp_ans = %d && [cnt2:cnt5] = [%d, %d]\n", Ks[i], need_t, need_f, tmp_ans, A[i].first, A[i].second);
	}
	cout << ans/2 << endl;
	return 0;
}


Measured memory_bytes: 6328
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int n;
vector<bool> seen;
vector<vector<int>> graph;
map<pair<int, int>, int> color;
int deg = 0;

void dfs(int v,  int pv, int pc) {
  seen.at(v) = true;
  int nc = 1;

  for (auto &nv: graph.at(v)) {
    if (seen.at(nv)) continue;
    if (nc == pc) nc++;
    pair<int, int> p = make_pair(min(v, nv), max(v, nv));
    color[p] = nc;
    dfs(nv, v, nc);
    nc++;
  }
  deg = max(deg, (int)graph.at(v).size());
}

int main()
{ 
  cin >> n;
  seen.resize(n, false);
  graph.resize(n, vector<int>());
  vector<pair<int, int>> edges(n-1);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
    edges.at(i) = make_pair(a, b);
  }
  dfs(0, -1, -1);
  cout << deg << endl;
  for (auto &v : edges) {
    cout << color.at(v) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 17684
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long int a,b,asho,ar,bs,br,i,j,kotae=2019;
  cin>>a>>b;
  asho=a/2019;
  bs=b/2019;
  ar=a%2019;
  br=b%2019;
  if(asho!=bs){
    cout<<0;
  }else{
    for(i=ar;i<br;i++){
      for(j=i+1;j<=br;j++){
        kotae=min((i*j)%2019,kotae);
      }
    }
  cout<<kotae;
  }
}
  


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

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

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template <class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& p)
{
    return o << "(" << p.first << "," << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& vc)
{
    o << "sz = " << vc.size() << endl
      << "[";
    for (const T& v : vc)
        o << v << ",";
    o << "]";
    return o;
}
using ll = long long;
constexpr ll MOD = 1e9 + 7;

constexpr ll INF = 1e17;

template <typename T>
struct Edge {
    Edge(const std::size_t from_, const std::size_t to_, const T cost_) : from{from_}, to{to_}, cost{cost_} {}
    const std::size_t from;
    const std::size_t to;
    const T cost;
    bool operator<(const Edge<T>& e)
    {
        return cost != e.cost ? cost < e.cost : to < e.to;
    }
};

template <typename T>
class Graph
{
public:
    Graph(const std::size_t v) : m_v{v}
    {
        m_table.resize(v);
    }
    void addEdge(const std::size_t from, const std::size_t to, const T cost)
    {
        m_e++;
        m_table[from].push_back(Edge<T>{from, to, cost});
    }
    bool BellmanFord(const std::size_t s, std::vector<T>& d)
    {
        assert(s < m_v);
        assert(d.size() == m_v);
        for (std::size_t i = 0; i < m_v; i++) {
            d[i] = INF;
        }
        d[s] = 0;
        bool no_negative_loop = true;
        for (std::size_t i = 0; i < m_v; i++) {
            for (std::size_t v = 0; v < m_v; v++) {
                for (const auto& e : m_table[v]) {
                    if (d[e.to] > d[e.from] + e.cost) {
                        d[e.to] = d[v] + e.cost;
                        if (i == m_v - 1) {
                            d[e.to] = -INF;
                            no_negative_loop = false;
                        }
                    }
                }
            }
        }
        return no_negative_loop;
    }


private:
    const std::size_t m_v;
    std::size_t m_e;
    std::vector<std::vector<Edge<T>>> m_table;
};

int main()
{
    int N, M;
    cin >> N >> M;
    Graph<ll> g(N);
    rep(i, M)
    {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--, b--;
        g.addEdge(a, b, -c);
    }
    vector<ll> d(N);
    bool f = g.BellmanFord(0, d);
    if (d[N - 1] <= -INF) {
        cout << "inf" << endl;
    } else {
        cout << -d[N - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(){
    ll a;
    cin >> a;
    cout << 3*a*a << endl;
    return 0;
}


Measured memory_bytes: 256
import math
import itertools

ans = 0

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
root = [i for i in range(n)]
roots = list(itertools.permutations(root))
for i in roots:
    for j in range(1, n):
        ans += math.sqrt(((xy[i[j - 1]][0] - xy[i[j]][0]) ** 2 +  (xy[i[j - 1]][1] - xy[i[j]][1]) ** 2))


print(ans / len(roots))

Measured memory_bytes: 46960
QHSD = [int(i) for i in input().split()]
N = int(input())

ratio = [0]*4

ratio[0] = QHSD[0]*4
ratio[1] = QHSD[1]*2
ratio[2] = QHSD[2]
ratio[3] = QHSD[3]/2

res = 0

m_index = ratio.index(min(ratio))

if m_index == 3:
    res += int(N/2) * QHSD[3]
    N -= int(N/2) * 2


m_index = ratio[:3].index(min(ratio[:3]))

if m_index == 0:
    res += int(N/0.25) * QHSD[0]
elif m_index == 1:
    res += int(N/0.5) * QHSD[1]
elif m_index == 2:
    res += N * QHSD[2]


print(res)

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

int main(){
  ll h, w, k;
  cin >> h >> w >> k;
  vector<string> a(h);
  for(auto& i : a) cin >> i;
  ll cnt = 0;
  vector<vector<ll>> ans(h, vector<ll>(w));
  for(ll i = 0; i < h; i++) for(ll j = 0; j < w; j++) if(a[i][j] == '#'){
    ans[i][j] = ++cnt;
  }
  for(ll i = 0; i < h; i++) for(ll j = w - 2; j >= 0; j--) if(!ans[i][j]){
    ans[i][j] = ans[i][j + 1];
  }
  for(ll i = 0; i < h; i++) for(ll j = 1; j < w; j++) if(!ans[i][j]){
    ans[i][j] = ans[i][j - 1];
  }
  for(ll j = 0; j < w; j++) for(ll i = h - 2; i >= 0; i--) if(!ans[i][j]){
    ans[i][j] = ans[i + 1][j];
  }
  for(ll j = 0; j < w; j++) for(ll i = 1; i < h; i++) if(!ans[i][j]){
    ans[i][j] = ans[i - 1][j];
  }
  for(auto& i : ans){
    cout << i[0];
    for(ll j = 1; j < w; j++) cout << ' ' << i[j];
    cout << endl;
  }
}


Measured memory_bytes: 1664
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, q = map(int, input().split())
neighbor = [[] for _ in range(n)]
point = [0]*n

for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    neighbor[a].append(b)
    neighbor[b].append(a)

for i in range(q):
    p, x = map(int, input().split())
    point[p-1] += x


def dfs(now, past):
    for nv in neighbor[now]:
        if nv == past:
            continue
        point[nv] += point[now]
        dfs(nv, now)


dfs(0, -1)


print(*point)


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

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

typedef unsigned long long lu;
typedef long long li;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x = Sub(x - y); }
inline int Mul(int x, int y) { return (int)((lu)x * y % mod); }
inline int Mul(int x, int y, int z) { return (int)((lu)x * y % mod * z % mod); }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

int Inv(int x) { return Pow(x, mod - 2); }
template <class T> inline void Max(T &x, T y) { if (y > x) x = y; }
template <class T> inline void Min(T &x, T y) { if (y < x) x = y; }

// ----------------------------------------

const int maxn = 6000;

int n;
char s[maxn + 1];
int m;
string part[maxn];

string Solve(string s) {
  static int A[maxn], B[maxn];
  int len = s.length();
  int n = len / 2;
  int ca = 0, cb = 0;
  for (int i = 0; i < len; ++i) {
    if (s[i] == 'a') {
      A[ca++] = i;
    } else {
      B[cb++] = i;
    }
  }

  if (s[0] == 'a') {
    string ans = "";
    int last = -1;
    for (int i = 0; i < n; ++i) {
      if (A[i] > last) {
        ans += "ab";
        last = B[i];
      }
    }
    return ans;
  } else {
    string ans = "";
    static bool sel[maxn];
    for (int i = 0; i < n; ++i) {
      FILL(sel, len, 0);
      for (int j = i; j < n; ++j) {
        sel[A[j]] = sel[B[j]] = true;
      }
      string now = "";
      for (int j = 0; j < len; ++j) {
        if (sel[j]) now += s[j];
      }
      Max(ans, now);
    }
    return ans;
  }
}

int main(void) {
  scanf("%d", &n);
  scanf("%s", s);
  m = 0;
  int ca = 0, cb = 0, begin = 0;
  for (int i = 0; i < 2 * n; ++i) {
    ca += s[i] == 'a';
    cb += s[i] == 'b';
    if (ca == cb) {
      part[m++] = string(s + begin, s + i + 1);
      begin = i + 1;
    }
  }
  for (int i = 0; i < m; ++i) {
    part[i] = Solve(part[i]);
  }
  string ans = "";
  for (int i = m - 1; i >= 0; --i) {
    ans = max(ans, part[i] + ans);
  }
  cout << ans << endl;
  return 0;
}


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

#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

const int INF=1e9+7;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);	
        int n,k;cin>>n>>k;
        vi dp(n+1,INF);
        vi a(n+1);
        for(int i=1;i<n+1;i++)cin>>a[i];
        dp[1]=0;
        for(int i=1;i<n+1;i++){
            for(int j=i+1;j<i+k+1;j++){
              if(j<n+1){
                dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
              }
            }
        }
        cout<<dp[n]<<endl;
}


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

int main(){
  vector<int> n(3);
  rep(i,3){cin >> n[i];}
  int max = *max_element(n.begin(),n.end());
  cout << n[0]+n[1]+n[2]-max << endl;
}

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

int N;
bool p[100010] = {0};
int mem[100010] = {0};

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

    p[1] = true;
    for(int i = 2; i < 100010; i++)
    {
        if(!p[i])
        {
            for(int j = i + i; j < 100010; j += i)p[j] = true;
        }
    }

    for(int i = 2; i < 100010; i++)
    {
        if(!p[i] && i % 2 && !p[(i + 1) / 2])mem[i] = 1;
        mem[i] += mem[i - 1];
    }

    for(int i = 0; i < N; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        printf("%d\n",mem[b] - mem[a - 1]);
    }
    return 0;
}


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

template<class RandomAccessIterator>
void LSD_RadixSort(RandomAccessIterator first, RandomAccessIterator last,
		int maximum, int max_digit,
		::std::function<int(typename RandomAccessIterator::value_type, int)> get_digit){
	using value_type = typename RandomAccessIterator::value_type;

	::std::size_t size = ::std::distance(first, last);
	::std::vector<::std::vector<int>> bucket(maximum+1);
	::std::vector<value_type> v(first, last), tmp;

	int digit = 0;

	for(int digit = 0;digit < max_digit;digit++){
		for(int i = 0;i < size;i++){
			int x = get_digit(v[i], digit);
			bucket[x].push_back(i);
		}

		for(int i = 0;i <= maximum;i++){
			for(int j = 0;j < bucket[i].size();j++){
				tmp.push_back(v[bucket[i][j]]);
			}
			bucket[i].clear();
		}

		::std::swap(v, tmp);
		tmp.clear();
	}
	::std::move(v.begin(), v.end(), first);
}

/*

	

*/

/*

verify:https://beta.atcoder.jp/contests/abc088/submissions/3178401
*/

int get(int x, int dig){
	return x >> dig & 1;
}

int main(void){
	int n;
	::std::vector<int> v;
	std::cin >> n;
	v.resize(n);
	for(int i = 0;i < n;i++) std::cin >> v[i];

	LSD_RadixSort(v.begin(), v.end(), 2, 32,
			[](int x, int d){return x >> d & 1;});
	std::reverse(v.begin(), v.end());
	int res = 0;
	for(int i = 0;i < n;i++) res = res + v[i] * (i%2 ? -1 : 1);
	std::cout << res << std::endl;
	return 0;
}



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

int main() {
  int n, a;
  cin >> n >> a;
  if (n % 500 <= a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  for (int i=0; i<N; i++){
    int l;
    int r;
    cin >> l>> r;
    sum = sum + r - l + 1;
  }
  cout << sum<< endl;
}


Measured memory_bytes: 3592
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val str = sc.nextLine()
  val q = sc.nextLine()
  val cmds = List.fill(q.toInt)(sc.nextLine())
  val processor = makeProcessor
  cmds.foreach(cmdStr => processor(analysisCmdStr(cmdStr)))

  def makeProcessor: (List[String]) => Unit = {
    var result = str
    (cmd: List[String]) =>
      cmd.head match {
        case "replace" => result = result.pReplace(cmd(1).toInt, cmd(2).toInt, cmd(3))
        case "reverse" => result = result.pReverse(cmd(1).toInt, cmd(2).toInt)
        case "print" => result.pPrint(cmd(1).toInt, cmd(2).toInt)
        case _ =>
      }
  }

  def analysisCmdStr(line: String): List[String] = line.split(" ").toList

  implicit class StringExtends(val s: String) extends AnyVal {
    def pReplace(a: Int, b: Int, p: String): String = s.patch(a, p, b - a + 1)

    def pReverse(a: Int, b: Int): String = s.patch(a, s.substring(a, b + 1).reverse, b - a + 1)

    def pPrint(a: Int, b: Int): Unit = println(s.substring(a, b + 1))
  }

}

Measured memory_bytes: 47476
#include<iostream>
#include<math.h>
using namespace std;


bool is_sosu(long int x){
	int i;
	if(x<2) return false;
	for(i=2;i<=sqrt((float)x);i++){
		if(x%i==0) return false;
	}
	return true;
}

int main()
{
	long int a,d,n,i;	//a初項 d公差 n求める素数の順番

	cin>>a>>d>>n;
	while(a!=0 || d!=0 || n!=0){
		i=0;
		while(i!=n){
			if(is_sosu(a)==true) i++;
			a+=d;
		}
		cout<<a-d<<endl;
		cin>>a>>d>>n;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}


//for(int i = ; i < ; i++){}

int main(){
  int n;
  cin>>n;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int l,r;
    cin>>l>>r;
    ans+=r-l+1;
  }
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
 
main() {
  int array[100];
  int i, n;
   
  scanf("%d", &n);
   
   
  for (i = 0; i < n; i++) {
    scanf("%d", &array[i]);
  }
  for (i = n-1; i >= 0; i--) {
    printf("%d", array[i]);
    if (i != 0) {
      printf(" ");
    }
     
  }
  printf("\n");
  return 0; 
}

Measured memory_bytes: 600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	k := iScan()
	ans := 0.
	for i := 1; i <= n; i++ {
		x := 1. / float64(n)
		y := i
		for y < k {
			y *= 2
			x *= 0.5
		}
		ans += x
	}
	fmt.Println(ans)

}


Measured memory_bytes: 1772
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
static const int MAX = 50;
char A[MAX][MAX], B[MAX][MAX];
int n, m;

void solve(){
    bool res = false,tmp;
    for (int i = 0; i <= n - m; i++){
        for (int j = 0; j <= n - m; j++){
            tmp = true;
            for (int k = 0; k < m; k++){
                for (int l = 0; l < m; l++){
                    if (A[i + k][j + l] == B[k][l]) continue;
                    else {
                        tmp = false;
                        break;
                    }
                }
            }
            if (tmp) res = true;
        }
    }
    if (res) cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main(){
    sc(n) sc(m)
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < m; i++){
        for (int j = 0; j < m; j++){
            cin >> B[i][j];
        }
    }
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;
    if(x1==0)
        cout<<1;
    if(x2==0)
        cout<<2;
    if(x3==0)
        cout<<3;
    if(x4==0)
        cout<<4;
    if(x5==0)
        cout<<5;
    subt;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int count = 0;

  for (int i = 0; i < N; i++) {
    int l,r;
    cin >> l >> r;
    count += r - l + 1;
  }
 cout << count << endl;
}



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

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C=sc.nextInt();
        int D=sc.nextInt();
        System.out.println(Math.min(A, B)+Math.min(C, D));
    }

}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
using ll = long long;
using ull = unsigned long long;
ull mod = 1e9 + 7;
using namespace std;

vector<pair<ull, ull>> Factorize(ll n){
    vector<pair<ull, ull>> res;
    for(ull i = 2; i * i <= n; i++){
        if(n % i != 0)continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1)res.emplace_back(n, 1);
    return res;
}

vector< ull > divisor(ull n) {
  vector< ull > ret;
  for(ull i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){

    ull N; cin >> N;
    auto a = divisor(N);
    ull tmp = (int)sqrt((double)N);
    if(tmp * tmp == N){//もし平方数だったら
        cout << (tmp - 1) + (tmp - 1);
        return 0;
    }
    cout << (a[a.size() / 2 - 1] - 1) + (a[a.size() / 2] - 1);

}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n,i,c,d[100],o[100];
char s[100][11];
int cmp(const int *a,const int *b){
  c=strcmp(s[*a],s[*b]);
  if(c)return c;
  else return d[*b]-d[*a];
}
int main(){
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%d",s[i],&d[i]);
    o[i]=i;
  }
  qsort(o,n,sizeof(int),cmp);
  for(i=0;i<n;i++)printf("%d\n",o[i]+1);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define EPS 1e-9
#define MOD 1000000007
#define int long long
using namespace __gnu_pbds;
using namespace std;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ost;


int32_t main(){
	string s, t;
	cin >> s >> t;
	vector<vector<int>> v(s.size()+1,vector<int>(t.length()+1,0));
	int n = s.size(), m = t.size();
	for(int i = 0; i <= n; i++){
		v[i][0] = 0;
	}
	for(int i = 0; i <= m; i++){
		v[0][i] = 0;
	}
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= m; j++){
			if(i == 0 || j == 0)
				continue;
			if(s[i-1] == t[j-1]){
				v[i][j] = v[i-1][j-1]+1;
			}
			else
				v[i][j] = max(v[i-1][j],v[i][j-1]);
		}
	}
	
	string ans = "";
	int l = n, r = m;
	while(l > 0 && r > 0){
		if(s[l-1] == t[r-1]){
			ans += s[l-1];
			l--, r--;
		}
		else{
			if(v[l-1][r] > v[l][r-1])
				l--;
			else
				r--;
		}
	}
	reverse(ans.begin(),ans.end());
	cout << ans;


	return 0;
}

Measured memory_bytes: 70784
INFTY=2000000000+1

class Node:
    def __init__(self,key=INFTY):
        self.key=key
        self.parent=-1
        self.left=-1
        self.right=-1

root=-1
T=[]
commands=[]
preorderList=[]
inorderList=[]

def readinput():
    global commands

    n=int(input())
    for _ in range(n):
        s=input().split()
        command=s[0]
        if(len(s)>1):
            op=s[1]
        commands.append((command,int(op)))

def insert(op):
    global T
    global root

    #print('[{}]'.format(op))
    zidx=len(T)
    z=Node(op)
    T.append(z)

    yidx=-1
    xidx=root
    while(xidx != -1):
        x=T[xidx]
        yidx=xidx
        if(z.key<x.key):
            xidx=x.left
            #print('left: {} < {}'.format(z.key, x.key))
        else:
            xidx=x.right
            #print('right')
    z.parent=yidx

    if yidx==-1:
        root=zidx
        #print('root changed')
    elif z.key<T[yidx].key:
        T[yidx].left=zidx
    else:
        T[yidx].right=zidx

def bisearch(p,op):
    '''再帰を使わないバージョン
    '''
    global T

    x=p
    while(x != -1 and T[x].key != op):
        if (op < T[x].key):
            x=T[x].left
        else:
            x=T[x].right

    if x==-1:
        return False
    else:
        return True


def find(op):
    ans=bisearch(root,op)
    if(ans==True):
        print('yes')
    else:
        print('no')


def getPreorderList(id):
    global preorderList

    preorderList.append(id)
    node=T[id]
    if(node.left!=-1):
        getPreorderList(node.left)
    if(node.right!=-1):
        getPreorderList(node.right)

def getInorderList(id):
    global inorderList

    node=T[id]
    if(node.left!=-1):
        getInorderList(node.left)
    inorderList.append(id)
    if(node.right!=-1):
        getInorderList(node.right)

def printPreorderList():
    for i in preorderList:
        print(' '+str(T[i].key),end='')
    print('')

def printInorderList():
    for i in inorderList:
        print(' '+str(T[i].key),end='')
    print('')

def printT():
    global inorderList
    global preorderList

    inorderList=[]
    preorderList=[]
    
    getInorderList(root)
    printInorderList()
    getPreorderList(root)
    printPreorderList()
    #for node in T:
    #    print(node.key, node.parent, node.left, node.right)    

def main():
    global commands

    for command,op in commands:
        if(command=='insert'):
            insert(op)
        elif(command=='find'):
            find(op)
        elif(command=='print'):
            printT()

if __name__=='__main__':
    readinput()
    main()



Measured memory_bytes: 174428
from math import ceil


def minimization(N: int, K: int, A: list) -> int:
    return 1 + ceil((N - K) / (K - 1))


if __name__ == "__main__":
    N, K = map(int, input().split())
    A = [int(s) for s in input().split()]
    ans = minimization(N, K, A)
    print(ans)


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
vector<int> a,b;

vector<pair<int,int>> v;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    a.resize(n);
    b.resize(n);
    v.resize(n);
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }
    for (int i=0; i<n; i++) {
	cin>>b[i];
    }
    for (int i=0; i<n; i++) {
	v[i].first=a[i];
	v[i].second=b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    // Impossible even if we had infinite swaps
    for (int i=0; i<n; i++) {
	if (a[i]>b[i]) out("No");
    }

    // Permutations take at most n-1 swaps to sort.
    
    // We know that [..(a[i],b[i]),(a[i+1],b[i+1])..] and
    // [..(a[i+1],b[i]),(a[i],b[i+1])..] are both valid, which means
    // that we can sort up to 2 disjoint cycles which will take at most n-2 swaps.
    
    for (int i=0; i<n-1; i++) {
	if (a[i+1]<=b[i]) out("Yes");
    }


    
    // If perm has more than 1 disjoint cycle, it's possible
    sort(v.begin(), v.end(), [&](pair<int,int> p1, pair<int,int> p2) {
	    return p1.second<p2.second;
	});

    vector<int> perm(n, 0);
    for (int i=0; i<n; i++) {
	perm[i] = lower_bound(a.begin(), a.end(), v[i].first) - a.begin();
    }
    vector<int> viz(n, 0);
    for (int i=0, x=0; i<n; i++) {
	viz[x]=1;
	x=perm[x];
    }

    cout<<(std::count(viz.begin(),viz.end(),1)==n ? "No\n" : "Yes\n");
    
    
    return 0;
}


Measured memory_bytes: 5468
#include<stdio.h>
int main() {
 char s[3];
 int counta=0,countb=0;
  for(int i=0;i<3;i++){
    scanf("%c",&s[i]);
    if(s[i]=='A'){
      counta++;
    }else if(s[i]=='B'){
      countb++;
    }
  }
  
  if((counta>0)&&(countb>0)){
  	printf("Yes");
  }else{
  	printf("No");
  }
  
  return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  deque <ll> d;
  rep(i,n){
    ll now=lower_bound(d.begin(),d.end(),a[i])-d.begin();
    if (now==0)d.push_front(a[i]);
    else d[now-1]=a[i];
  }
  cout<<d.size();
}


Measured memory_bytes: 2428
import numpy as np
import sys

n, m, q = map(int, input().split())
ab = np.array(sys.stdin.read().split(), np.int)
a = ab[:m*2].reshape(m, 2)
b = ab[m*2:].reshape(q, 2)

x=np.zeros((501, 501), dtype=np.int)

np.add.at(x, (a[:, 0], a[:, 1]), 1)

np.cumsum(x, axis=0, out=x)
np.cumsum(x, axis=1, out=x)

for i in range(q):
    v1=b[i][0]
    v2=b[i][1]
    
    a1=x[v2, v2]
    a2=x[v2, v1-1]
    a3=x[v1-1, v2]
    a4=x[v1-1, v1-1]
    print(a1-a2-a3+a4)


Measured memory_bytes: 66896
<?php
declare(strict_types=1);

//引数を取得
list($s) = fscanf(STDIN, '%s');

//奇数と偶数の文字列配列を設定
$oddStringArray = ['R', 'U', 'D'];
$evenStringArray = ['L', 'U', 'D'];

//出力文字列を初期化
$outputString = 'Yes';

//入力文字列を配列化
$sArray = str_split($s);

//各文字列の条件を確認
foreach ($sArray as $key=>$value) {
  $checkStringArray = [];

  //インデックスが割り切れるなら奇数文字列とする
  if($key % 2 == 0) {
    $checkStringArray = $oddStringArray;
  }else {
    $checkStringArray = $evenStringArray;
  }

  //文字列の条件と合わなければ出力文字列をNoに変更
  if (!in_array($value, $checkStringArray)) {
    $outputString = 'No';
    break;
  }

}

//出力文字列を出力
echo $outputString;


Measured memory_bytes: 4728
from collections import Counter
n = int(input())
s = set()
lis = list(map(int,input().split()))
for i in range(n):
  s.add(lis[i])
if (len(lis)-len(s) )% 2 == 1:
  print(n-(len(lis)-len(s)+1))
else:
  print(n-(len(lis)-len(s)))

Measured memory_bytes: 14948