akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdlib>
using namespace std;

struct Node_t{
	int key;
	Node_t *parent,*left,*right;
};

Node_t *root,*NIL;

void insert(int k);
void inPause(Node_t *u);
void prePause(Node_t *u);

int main(){
	int m; cin>>m;
	string command; int key;
	for(int i=0;i<m;i++){
		cin>>command;
		if(command=="insert"){
			cin>>key;
			insert(key);
		}else if(command=="print"){
			inPause(root);
			cout<<endl;
			prePause(root);
			cout<<endl;
		}
	}

}

void insert(int k){
	Node_t *x,*y,*z;
	y = NIL; x = root;
	z = (Node_t *)malloc(sizeof(Node_t));
	z->key = k;
	z->left = NIL; z->right = NIL;

	while(x!=NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}
	z->parent = y;

	if(y==NIL){
		root = z;
	}else{
		if(z->key < y->key){
			y->left = z;
		}else{
			y->right = z;
		}
	}
}

void inPause(Node_t *u){
	if(u==NIL) return;
	inPause(u->left);
	cout<<" "<<u->key;
	inPause(u->right);
}

void prePause(Node_t *u){
	if(u==NIL) return;
	cout<<" "<<u->key;
	prePause(u->left);
	prePause(u->right);
}

Measured memory_bytes: 26488
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n) for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n) for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;
/*ビットxにi番目のフラグが立っているかどうか
if(x & (1 << i))
↑ a << b == a*pow(b,2)
/*{0, 1, ..., n-1} の部分集合の全探索
for (int bit = 0; bit < (1 << n); ++bit)
*/

int main(){
  string s;  cin >> s;
  rep0(i,s.size()){
    if(i % 2 == 0){
      if(s[i]=='L'){
        cout << "No";
        return 0;
      }
    }else{
      if(s[i]=='R'){
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
}


Measured memory_bytes: 256
import java.util.*;

class Main{
public static void main(String[] args){
 Scanner sc = new Scanner(System.in);

int A=sc.nextInt();
int B=sc.nextInt();
  if((B%A)==0){
System.out.println(A+B);
  }else{
  System.out.println(B-A);
  }
}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include<cmath>
using namespace std;
int main(void)
{
    int s[2];
    int t[2];
    cin >> s[0]>>s[1]>>t[0]>>t[1];
    for (int i = 0; i < t[0] - s[0]; i++)
    {
        cout << "R";
    }

    for (int i = 0; i < t[1] - s[1]; i++)
    {
        cout << "U";
    }
    for (int i = 0; i < t[0] - s[0]; i++)
    {
        cout << "L";
    }

    for (int i = 0; i < t[1] - s[1]; i++)
    {
        cout << "D";
    }
    cout<<"D";
    for (int i = 0; i < t[0] - s[0]; i++)
    {
        cout << "R";
    }
    cout <<"R";
    for (int i = 0; i < t[1] - s[1]; i++)
    {
        cout << "U";
    }
    cout<<"ULU";
    for (int i = 0; i < t[0] - s[0]; i++)
    {
        cout << "L";
    }
    cout<<"L";
    for (int i = 0; i < t[1] - s[1]; i++)
    {
        cout << "D";
    }
    cout<<"DR";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, m, cnt = 0;
int f[N];

int32_t main()
{
	IOS;
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		int l, r;
		cin >> l >> r;
		f[l]++;
		f[r + 1]--;
	}
	for(int i = 1; i <= n; i++)
	{
		f[i] += f[i - 1];
		if(f[i] == m)
			cnt++;
	}
	cout << cnt;
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        cout << "a > b"
             << "\n";
    } else if (a < b) {
        cout << "a < b"
             << "\n";

    } else if (a == b) {
        cout << "a == b"
             << "\n";
    }
    return 0;
}



Measured memory_bytes: 3064
import collections
n = int(input())
dic = []
for i in range(n):
    dic.append(collections.Counter(input()))
alp = [chr(i) for i in range(97,97+26)]
ans = ""
for x in alp:
    num = float("inf")
    for i in range(n):
        num = min(num,dic[i][x])
    ans += str(x)*num
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int a; cin>>a;
    cout << (a ^ 1) << '\n';
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int D;
  int S;
  int T;
  cin>>D>>T>>S;
  int a= D/S;
  if(D%S!=0){
    a++;}
  if(a<=T){
    cout<<"Yes"<<endl;}
  else if(a>T){
    cout<<"No"<<endl;}
}
   

Measured memory_bytes: 3628
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int X, N, ans = 1000, dif = 1000 ;
  cin >> X >> N ;
  int P[N], num[102] ;
  for(int i=0;i<102;i++){
    num[i] = i ;
  }
  for(int i=0;i<N;i++){
    cin >> P[i] ;
    num[P[i]] = -1 ;
  }
  for(int i=0;i<102;i++){
    if(num[i] >= 0){
      if(X>i){
        if(dif > (X - i) ){
          ans = i ;
          dif = X - i ;
        }
        else{
          break ;
        }
      }
      else{
        if(dif > (i - X) ){
          ans = i ;
          dif = i - X ; 
        }
      }
    }
  }
  cout << ans << endl ;
  return 0 ;
}  

Measured memory_bytes: 3636
import math
HL,ML,h,m=(int(x) for x in input().split())
HW=float((60*h+m)/2)
MW=float(6*m)

if HW > MW:
    if HW-MW>180:
        w=360-(HW-MW)
    else:
        w=HW-MW
    print(math.sqrt(HL*HL+ML*ML-2*HL*ML*math.cos(math.radians(w))))
else:
    if HW-MW>180:
        w=360-(HW-MW)
    else:
        w=HW-MW
    print(math.sqrt(HL*HL+ML*ML-2*HL*ML*math.cos(math.radians(-w))))

Measured memory_bytes: 9444
#include <stdio.h>

int main(){
  int a, b;

  scanf("%d %d", &a, &b);

  if(a < b){
    printf("a < b\n");

  }else if(a > b){
    printf("a > b\n");

  }else{
    printf("a == b\n");

  }

  return 0;
}

Measured memory_bytes: 580
#include <stdio.h>
  
#define LEN 25000
 int main(){
  char ascii[LEN];
  int i, len, det;
  int sum = 0, alt = 0, pl = 0, stk = 0;
  int height[LEN] = {0}, ex[LEN] = {0};
 
  scanf("%s", ascii);
  for(len = 0; ; len++){
    height[len] = alt;
    if(ascii[len] == '/'){
      alt++;
    }
    if(ascii[len] == '\\'){
      alt--;
    }
    if(ascii[len] == '\0'){
      break;
    }
  }
 
  while(pl < len){
    while(ascii[pl] != '\\' && pl < len){
      pl++;
    }
    det = pl+1;
    while(det <= len && height[det] != height[pl]){
      det++;
    }
    if(det <= len){
      ex[stk++] = Terrain(ascii, len, pl, det);
      pl = det;
    }else{
      pl++;
    }
  }
 
  for(i = 0; i < stk; i++){
    sum += ex[i];
  }
 
  printf("%d\n%d", sum, stk);
 
  for(i = 0; i < stk; i++){
    printf(" %d", ex[i]);
  }
  printf("\n");
 
  return 0;
}
int Terrain(char* ascii, int len, int p, int q){
  int depth = 0, i;
  double b = 0;
 
  for(i = p; i < q; i++){
    if(ascii[i] == '/'){
      b += (double)depth - 0.5;
      depth--;
    }
    if(ascii[i] == '\\'){
      b += (double)depth + 0.5;
      depth++;
    }
    if(ascii[i] == '_'){
      b += depth;
    }
  }
  return b;
}
  

Measured memory_bytes: 772
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
/*---------------------------------------------------------------------*/
const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    string s,k;
    cin>>s>>k;
    int a,b;
    string aa;
    cin>>a>>b>>aa;
    if(aa==s)
    {
        cout<<a-1<<" "<<b<<nl;
    }
    else
    {
        cout<<a<<" "<<b-1<<nl;
    }
    return 0;
}


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

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=998244353;
const int M=200009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int nxt[M+5];
int dp[M+7];
int n;
inline int ad(int x,int y)
{
    int ret=(x%mod)+(y%mod);
    if(ret<0)ret+=mod;
    ret=ret%mod;
    return ret;
}
int solve(int pos)
{
    if(pos>=n)return 1;
    int &ret=dp[pos];
    if(ret!=(-1))return ret;
    ret=ad(solve(pos+1),solve(nxt[pos]));
    return ret;
}
 main()

{
    fast
    cin>>n;
    vector<pi>s;
    f(i,1,n)
    {
        int x,d;
        cin>>x>>d;
        s.pb(mp(x,x+d-1));
    }
    sort(s.begin(),s.end());
    rf(i,n-1,0)
    {
        int j=i+1;
        while(j<n && s[j].fi<=s[i].si)
        {
            j=nxt[j];
        }
        nxt[i]=j;
    }
    memset(dp,-1,sizeof dp);
    cout<<solve(0)<<endl;
















    return 0;

}













Measured memory_bytes: 13548
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		String s = scan.next();

		int ans = 0;

		for(int i = 1; i < n; i++) {
			String s1 = "";
			String s2 = "";
			for(int j = 0; j < s.length(); j++) {
				if(j < i) {
					s1 += s.charAt(j);
				} else {
					s2 += s.charAt(j);
				}
			}
			ans = c(ans, b(s1, s2));
		}

		System.out.println(ans);
	}

	static int c(int a, int b) {
		if(a > b) return a;
		return b;
	}

	static int b(String s1, String s2) {
		int count = 0;
		char ans[] = new char[100];

		for(int i = 0; i < s1.length(); i++) {
			for(int j = 0; j < s2.length(); j++) {
				char c = s2.charAt(j);
				if(s1.charAt(i) == c) {
					for(int k = 0; k <= count; k++) {
						if(ans[k] == c) break;
						if(k == count) {
							ans[count] = c;
							count++;
							break;
						}
					}
				}
			}
		}
		return count;
	}
}


Measured memory_bytes: 26196
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

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

int main() {
	ll a,b;
	cin >> a >> b;
	auto ma = prime_factor(a);
	auto mb = prime_factor(b);

	int ans = 1;
	for (auto i = ma.begin(); i != ma.end(); i++){
		for (auto k = mb.begin(); k != mb.end(); k++){
			if(i -> first == k -> first)
				ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
typedef long long ll;
ll x[200005],y[200005];
int main(void)
{
	ll n,d;
	scanf("%lld%lld",&n,&d);
	ll cnt=0;
	for(ll i=0;i<n;i++)
	{
		scanf("%lld%lld",&x[i],&y[i]);
		if(x[i]*x[i]+y[i]*y[i]<=d*d) cnt++;
	}
	printf("%lld\n",cnt);
}

Measured memory_bytes: 6948
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
S = sum(A)
Q = int(input())

dict = Counter(A)
for i in range(Q):
    l = list(map(int, input().split()))
    d = l[1] - l[0]
    cnt = dict[l[0]]
    dict[l[1]] += dict[l[0]]
    dict.pop(l[0], None)
    S += d*cnt
    print(S)

Measured memory_bytes: 91060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mujin
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			var x = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray();
			long count = 1;
			var list = new Stack<int>();
			var mod = (long)(1000000007);
			for (int i = 0; i < N; i++)
			{
				list.Push(x[i]);
				if (x[i] < 2 * list.Count - 1)
				{
					count *= list.Count;
					list.Pop();
					count %= mod;
				}
			}
			for (int i = 0; i < list.Count; i++)
			{
				count *= i + 1;
				count %= mod;
			}
			Console.WriteLine(count);
		}
	}
}

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

#define ll long long
#define ull unsigned long long
#define PI 6.28318530717958623200

int main()
{
//	const double PI = 6.28318530717958623200;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	cout << PI*n;
}

Measured memory_bytes: 3804
#include <iostream>
#include <cctype>
#include <cstdio>
using namespace std;

int main(){
    string s;
    cin >> s;
    
    int pr = 700;

    for (int i = 0; i < 3; i++) 
        if (s[i] == 'o') pr += 100;

    cout << pr << endl;

}

Measured memory_bytes: 256
# stack.py
class Cell:
    def __init__(self, value, name):
        self.name = name
        self.value = value
        self.next = None


class Queue:
    def __init__(self):
        self.front = None
        self.rear = None

    def Enqueue(self, d,name):
        new = Cell(d,name)
        if self.front is None:
            self.front = new
            self.rear = self.front
        else:
            self.rear.next = new
            self.rear = new

    def Dequeue(self):
        if self.front is None:
            print('Queue Under Flow!')
            return
        else:
            res = self.front
            nex = self.front.next
            del self.front
            self.front = nex
            return res

    def is_empty(self):
        return self.front==None


n,q = map(int,input().split())
que = Queue()
for i in range(n):
    name,val = input().split()
    que.Enqueue(int(val),name)

t = 0
while not que.is_empty():
    a = que.Dequeue()
    if a.value>q:
        que.Enqueue(a.value-q,a.name)
        t+=q
    else:
        t+=a.value
        print(a.name,t)



Measured memory_bytes: 16948
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

template <class T>
void printVector(const vector<T>& v) {
    for (auto value : v) {
        cout << value << " ";
    }
    cout << endl;
}

int main() {
    int d;
    ll g, ans = INF;  // scoreがg点以上
    cin >> d >> g;
    vector<int> p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];
    rep(i, 1 << d) {
        vector<int> used_bits;
        debug(" ");
        debug(i);
        ll score = 0, cnt = 0;
        rep(j, d) {
            if (i >> j & 1) {
                score += 100 * (j + 1) * p[j] + c[j];
                cnt += p[j];
                if (cnt == p[j]) {
                    debug(cnt, p[j]);
                    used_bits.push_back(j);
                }
            }
        }
        debug(i, score, abs(score - g), cnt);
        if (score < g) {
            debug("足し算");
            rrep(j, d) {
                if (find(used_bits.begin(), used_bits.end(), j) !=
                    used_bits.end()) {
                    debug(p[j], "continue");
                    continue;
                }
                rep(k, p[j]) {
                    score += 100 * (j + 1);
                    cnt++;
                    debug(j, score, 100 * (j + 1), p[j], cnt);
                    debug(g, k);
                    if (score >= g) {
                        debug(cnt, "break");
                        break;
                    };
                }
                if (score >= g) {
                    ans = min(ans, cnt);
                    break;
                };
            }
        } else {
            ans = min(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3168
#include<iostream>
#define N_MAX 200
int P[N_MAX];
int main(){
    int N, X;
    std::cin >> X >> N;
    for(int i=0; i<N; i++){
        int tmp;
        std::cin >> tmp;
        P[tmp] = 1;
    }
    for(int i=0;i<=100; i++){
        if(X-i>=0 && P[X-i] == 0){
            printf("%d\n", X-i);
            break;
        }else if(X-i<=100 && P[X+i] == 0){
            printf("%d\n", X+i);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    string S;
    const string dates[7]={"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};
    cin>>S;
    int num;
    rep(i, 7){
        if(dates[i]==S) num=i;
    }
    int count=0;
    switch(num){
        case 6: count++;
        case 0: count++;
        case 1: count++;
        case 2: count++;
        case 3: count++;
        case 4: count++;
        case 5: count++;
        default: cout<<count<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define eall(a) a.begin()+1, a.end()
#define show(ans)  cout << ans << endl;

long dp[100001];
long broken[100001];
int main(){
long N, M, tmp;
cin >> N >> M;
erep(i, M){
    cin >> tmp;
    broken[tmp] = 1;
}
dp[0] = 1;
if(broken[1] == 1) dp[1] = 0;
if(broken[1] == 0) dp[1] = 1;
for(long i = 2; i <= N; i++){
    if(broken[i] == 1) dp[i] = 0;
    if(broken[i] == 0){
        dp[i] = dp[i-2] + dp[i-1];
        dp[i] = dp[i] % MOD;
    }
}
show(dp[N]);


return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long[][] input = new long[3][n];
        for (int i = 0; i < n; i++) for (int k = 0; k < 3; k++) input[k][i] = scanner.nextInt();
        long[][] dp = new long[3][n];
        for (int i = 0; i < 3; i++) dp[i][0] = input[i][0];
        for (int i = 1; i < n; i++)
            for (int k = 0; k < 3; k++)
                for (int p = 0; p < 3; p++)
                    if (p != k) dp[k][i] = Math.max(dp[k][i], input[k][i] + dp[p][i - 1]);
        System.out.println(Math.max(dp[0][n - 1], Math.max(dp[1][n - 1], dp[2][n - 1])));

    }


}


Measured memory_bytes: 97560
#include <iostream>
using namespace std;
#define MOD 1000000007
int h, w;
char grid[1100][1100];
long long dp[1100][1100];
int main () {
	cin >> h >> w;
	for (int i=1; i<=h; i++) {
		for (int j=1; j<=w; j++) {
			cin >> grid[i][j];
		}
	}
	dp[1][1] = 1;
	for (int i=1; i<=h; i++) {
		for (int j=1; j<=w; j++) {
			if (i == 1 && j == 1) continue;
			if (grid[i][j] == '.') dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
		}
	}
	cout << dp[h][w] << endl;
}

Measured memory_bytes: 13264
#include <iostream>
#include <array>

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

    long long int n;

    while (std::cin >> n, n) {
        std::array<long long int, 7> arr{{}};
        int age;
        for (; n--;) {
            std::cin >> age;
            age = (age < 60 ? age : 60);
            ++arr[age / 10];
        }

        for (const auto& cnt : arr) {
            std::cout << cnt << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
    int arr[103]={0};
    int b,i,j,t;
    cin>>b;
    for(i=1;i<=b;i++)
        cin>>arr[i];
    for(i=1;i<=b-1;i++)
    {
        for(j=1;j<=b-1;j++)
        {
            if(arr[j]<arr[j+1])
            {
                t=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=t;
            }
        }
    }
    int sum1=0;
    int sum2=0;
    if(b%2==1)
        b=b+1;
    b=b/2;
    for(i=1;i<=b;i++)
    {
        sum1=sum1+arr[2*i-1];
    }
    for(i=1;i<=b;i++)
    {
        sum2=sum2+arr[2*i];
    }
    sum2=sum2-sum1;
    cout<<abs(sum2)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

// えびちゃんの make_vector (ここから)
template <typename Tp, size_t N>
std::vector<Tp> make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N == 1), const Tp&>::type x) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector_detail(std::vector<size_t>& sizes, typename std::enable_if<(N > 1), const Tp&>::type x) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector_detail<Tp, N-1>(sizes, x))>(size, make_vector_detail<Tp, N-1>(sizes, x));
}

template <typename Tp, size_t N>
auto make_vector(const size_t(&sizes)[N], const Tp& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return make_vector_detail<Tp, N>(s, x);
}
// えびちゃんの make_vector (ここまで)

signed main(){
    
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    vector<pair<int, int> > p(m);

    for(int i = 0; i < m; i++){
        int b, c; cin >> b >> c;
        p[i].first = c;
        p[i].second = b;
    }
    
    sort(p.rbegin(), p.rend());
    for(int i = 0; i < m; i++) cerr << p[i].first << " " << p[i].second << endl;

    int idx = 0;

    for(int i = 0; i < m; i++){
        if(idx == n) break;

        int c = p[i].first;
        int b = p[i].second;
        for(int j = 0; j < b; j++){
            if(idx == n) break;
            if(a[idx] < c){
                a[idx] = c;
                idx++;

            }else{
                idx = n;
                break;
            }
        }
    }
    
    for(int i = 0; i < n; i++) cerr << a[i] << " ";
    cerr << endl;

    int ans = 0;
    for(int i = 0; i < n; i++) ans += a[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;


int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	int a[6][6];
	int n, m, k; cin >> n >> m >> k;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j) {
			char c; cin >> c;
			a[i][j] = c=='#';
		}
	int ans = 0;
	for (int mask1 = 0; mask1 < 1<<n; ++mask1) {
		for (int mask2 = 0; mask2 < 1<<m; ++mask2) {
			int ct = 0;
			for (int i = 0; i < n; ++i)
				for (int j = 0; j < m; ++j)
					ct += a[i][j] == 1 && !((mask1>>i)&1) && !((mask2>>j)&1);
			ans += ct == k;
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <queue>
using namespace std;
typedef long long ll;

ll min(ll a, ll b) {
  return a < b ? a : b;
}

int main(void) {
  ll i, j, k, n, ans = 0, now;
  scanf("%lld", &n);
  ll p, d[n * n];
  bool flg[n * n];
  for(i = 0; i < n * n; ++i) d[i] = min(min(i % n, n - 1 - i % n), min(i / n, n - 1 - i / n)), flg[i] = false;
  for(k = 0; k < n * n; ++k) {
    queue<ll> q;
    scanf("%lld", &p), --p;
    flg[p] = true;
    ans += d[p];
    q.push(p);
    p--;
    while(q.size()) {
      now = q.front(), q.pop();
      if(now % n && d[now - 1] == d[now] + 2) q.push(now - 1), d[now - 1]--;
      if(n - 1 - now % n && d[now + 1] == d[now] + 2) q.push(now + 1), d[now + 1]--;
      if(now / n && d[now - n] == d[now] + 2) q.push(now - n), d[now - n]--;
      if(n - 1 - now / n && d[now + n] == d[now] + 2) q.push(now + n), d[now + n]--;
      if(flg[now]) {
        if(now % n && d[now - 1] == d[now] + 1) q.push(now - 1), d[now - 1]--;
        if(n - 1 - now % n && d[now + 1] == d[now] + 1) q.push(now + 1), d[now + 1]--;
        if(now / n && d[now - n] == d[now] + 1) q.push(now - n), d[now - n]--;
        if(n - 1 - now / n && d[now + n] == d[now] + 1) q.push(now + n), d[now + n]--;
      }
    }
  }
  printf("%lld", ans);
  return 0;
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;

inline int in() {int x; scanf("%d",&x); return x;}
inline ll lin() {ll x; scanf("%lld",&x); return x;}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

char s[N];
string T;


int main(){
    scanf("%s",s + 1);
    int len = strlen(s + 1);

    int i, l;
    for(i = len; i >= 5; ){
        if(i < 5) break;
        if(s[i] == 'm'){
            l = i - 4;
            T = "";
            for(int j = l;j <= i; j++){
                T += s[j];
            }
            if(T == "dream"){
                i = l - 1;
            }else {
                break;
            }
        }else if(s[i] == 'e'){
            int l = i - 4;
            T = "";
            for(int j = l;j <= i; j++){
                T += s[j];
            }
            if(T == "erase"){
                i = l - 1;
            }else {
                break;
            }
        }else if(s[i] == 'r'){
            l = i - 5;
            if(l < 1) break;
            T = "";
            for(int j = l;j <= i; j++){
                T += s[j];
            }
            if(T == "eraser"){
                i = l - 1;
                continue;
            }
            l = i - 6;
            if(l < 1) break;
            T = "";
            for(int j = l;j <= i; j++){
                T += s[j];
            }
            if(T == "dreamer"){
                i = l - 1;
                continue;
            }
            break;
        }else {
            break;
        }
    }

    puts(i < 1 ? "YES" : "NO");
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	map<int, int> mp;
	for (int i = 1; i < N; i++) {
		cin >> A[i];
		A[i]--;
		mp[A[i]]++;
	}
	for (int i = 0; i < N; i++) {
		cout << mp[i] << endl;
	}
}

Measured memory_bytes: 17228
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, const char *> R;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int P;

int modpow(int x, int k) {
  int a = 1;
  while (k > 0) {
    if (k & 1) a = (1LL*a*x) % P;
    x = (1LL*x*x) % P;
    k >>= 1;
  }
  return a;
}

int inv(int x) {
  return modpow(x, P-2);
}

bool failed;
R expr(const char *s);
R number(const char *s) {
  int x = 0;
  while ('0' <= *s && *s <= '9') {
    x = 10*x + (*s-'0');
    s++;
  }
  return R(x, s);
}

R factor(const char *s) {
  if (*s != '(') return number(s);
  s++;
  R r = expr(s);
  return R(r._1, r._2+1);
}

R term(const char *s) {
  int val = 1;
  do {
    bool div = false;
    if (*s == '*' || *s == '/') {
      if (*s == '/') div = true;
      s++;
    }
    R r = factor(s);
    int t = r._1;
    s = r._2;
    if (div) {
      if (r._1 == 0) {
        failed = true;
        t = 0;
      }
      else {
        t = inv(r._1);
      }
    }

    val = (1LL*val*t) % P;
    s = r._2;
  }
  while (*s == '*' || *s == '/');
  return R(val, s);
}

R expr(const char *s) {
  int val = 0;
  do {
    bool minus = false;
    if (*s == '+' || *s == '-') {
      if (*s == '-') minus = true;
      s++;
    }
    R r = term(s);
    int t = r._1;
    s = r._2;
    if (minus) t = (P-t) % P;

    val = (val+t) % P;
    s = r._2;
  }
  while (*s == '+' || *s == '-');
  return R(val, s);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  while (getline(cin, s)) {
    int i;
    P = 0;
    for (i=0; i<s.length(); i++) {
      if (s[i] == ':') break;
      P = 10*P + (int)(s[i]-'0');
    }
    if (P == 0) break;
    i++;
    string t = "";
    for (; i<s.length(); i++) {
      if (s[i] == ' ') continue;
      t += s[i];
    }
    failed = false;
    int val = expr(t.c_str())._1;
    if (failed) cout << "NG\n";
    else cout << t << " = " << val << " (mod " << P << ")\n";
  }
  return 0;
}

Measured memory_bytes: 3252
/*! path: src/contest/atcoder/abc173/c.ts */!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";(function(e){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.main=t.calcBitRemaining=void 0;const o=r(n(2)),i=n(3);function u(e,t,n){let r=0;for(let o=0;o<n.length;o++)for(let i=0;i<n[o].length;i++){"#"===n[o][i]&&r++;const u=(1<<o&e)>0,c=(1<<i&t)>0;u&&"#"===n[o][i]&&r--,c&&"#"===n[o][i]&&r--,u&&c&&"#"===n[o][i]&&r++}return r}function c(e){const t=i.getNext(e),n=parseInt(t()),r=parseInt(t()),o=parseInt(t()),c=[];for(let e=0;e<n;e++)c.push(t());const l=function({H:e,W:t,K:n,B:r}){let o=0;for(let i=0;i<1<<e;i++)for(let e=0;e<1<<t;e++)u(i,e,r)===n&&o++;return o}({H:n,W:r,K:o,B:c});console.log(l)}if(t.calcBitRemaining=u,t.main=c,n.c[n.s]===e){c(o.default.readFileSync("/dev/stdin","utf8"))}}).call(this,n(1)(e))},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t){e.exports=require("fs")},function(e,t,n){"use strict";function*r(e){const t=e.split(/\s+/);for(const e of t)yield e}Object.defineProperty(t,"__esModule",{value:!0}),t.getNextBigInt=t.getNextInt=t.getNext=t.getIteratorWithParser=t.getIterator=void 0,t.getIterator=r,t.getIteratorWithParser=function*(e,t){const n=e.split(/\s+/);for(const e of n)yield t(e)},t.getNext=function(e){const t=r(e);return()=>t.next().value},t.getNextInt=function(e){const t=r(e);return()=>parseInt(t.next().value)},t.getNextBigInt=function(e){const t=r(e);return()=>BigInt(t.next().value)}}]);

Measured memory_bytes: 32772
### main

n = gets.strip.to_i
m = gets.strip.to_i

n2 = n * 2
cards = (1..n2).to_a

m.times do
  k = gets.strip.to_i

  if k == 0
    c0 = []
    for i in (0...n)
      c0[2 * i] = cards[i]
      c0[2 * i + 1] = cards[n + i]
    end
    cards = c0
  else
    c0 = cards[0...k]
    c1 = cards[k...n2]
    cards = c1 + c0
  end
end

for c in cards
  puts c
end

Measured memory_bytes: 7364
N ,K = map(int,input().split())
S = input()
list = []
for i in range(N):
    list.append(S[i])
if list[K-1] == "A":
    list[K-1] = "a"
if list[K-1] == "B":
    list[K-1] = "b"
if list[K-1] == "C":
    list[K-1] = "c"
S_ans = "".join(list)
print(S_ans)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] arg) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int count = Integer.parseInt(str);
		for (int i = 0; i < count; i++) {
			str = br.readLine();
			String[] datasetstr = str.split(" ", 3);
			int[] datasetint = new int[3];
			for (int j = 0; j <= 2; j++) {

				datasetint[j] = Integer.parseInt(datasetstr[j]);
			}
			for (int k = 0; k <= 1; k++) {
				for (int l = k + 1; l <= 2; l++) {
					if (datasetint[k] < datasetint[l]) {
						int temporary = datasetint[k];
						datasetint[k] = datasetint[l];
						datasetint[l] = temporary;
					}
				}
			}
			int cc = datasetint[0] * datasetint[0];
			int aa = datasetint[1] * datasetint[1];
			int bb = datasetint[2] * datasetint[2];
			Boolean isRight = cc == (aa + bb);
			if (isRight) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 25996
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
long long int A[101][101],B[101][101];
int n,m,l;
scanf("%d %d %d",&n,&m,&l);
for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
		scanf("%lld",&A[i][j]);
	}
}
for(int i=0;i<m;i++){
	for(int j=0;j<l;j++){
		scanf("%lld",&B[i][j]);
	}
}
long long int c;
for(int i=0;i<n;i++){
	for(int j=0;j<l;j++){
		c=0;
		for(int k=0;k<m;k++){
			c+=A[i][k]*B[k][j];
		}
		if(j>0)printf(" ");
		printf("%lld",c);
	}
	printf("\n");
}

return 0;
}


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

using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
//const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p;//<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main()
{
	int n;
	cin >> n;
	vl a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vl sum(n + 1);
	map<ll, ll> cnt;
	cnt[0] = 1;
	ll res = 0;
	rep(i, n) {
		sum[i + 1] = sum[i] + a[i];
		res += cnt[sum[i + 1]];
		cnt[sum[i + 1]]++;
	}
	cout << res << endl;
}



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

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define INF 1e9



int main(){
    int n; cin >> n;
    string s,t;
    cin >> s >> t;
    string ans;
    
    rep(i,n){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    
    

}




 


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
lis=[[]for _ in range(n)]
for _ in range(m):
	s,t=map(int,input().split())
	lis[s].append(t)
	lis[t].append(s)
from collections import deque as dq
queue=dq([])
cnt=0
k=0
color=[-1]*n
while True:
	while k<n:
		if color[k]!=-1:
			k+=1
		else:
			break
	try:
		p=color[k:].index(-1)+k
	except:
		break
	queue.append(p)
	while queue:
		r=queue.popleft()
		color[r]=cnt
		for i in range(len(lis[r])):
			if color[lis[r][i]]==-1:
				queue.append(lis[r][i])
				color[lis[r][i]]=cnt
	cnt+=1
q=int(input())
for _ in range(q):
	s,t=map(int,input().split())
	if color[s]==color[t]:
		print("yes")
	else:
		print("no")




Measured memory_bytes: 24596
const main = (input) => {
  let [x, k, d] = input.trim().split(' ').map(Number)
  x = x >= 0 ? x : x*-1

  const m = Math.min(k, Math.floor(x/d))
  x = x - (m*d)
  k -= m

  if (k % 2 === 0) return console.log(x)
  else return console.log(Math.min(Math.abs(x+d), Math.abs(x-d)))
}

process.env.MYTEST ? test() : main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29660
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;

signed main(){
	int N;
	cin>>N;
	vector<int>a(N);
	rep(i,0,N)cin>>a[i];
	sort(all(a));
	int mid = N/2;
	if(a[mid-1]==a[mid])cout<<0<<endl;
	else cout<<a[mid]-a[mid-1]<<endl;
}


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

const int INF = 1001001001;
const int NV=100100;

int main() {
  int A,B,M,min_a=100100,min_b=100100;
  cin>>A>>B>>M;
  int a[A],b[B],m[M+1];
  for(int i=0;i<A;i++){
    cin>>a[i];
    min_a=min(min_a,a[i]);
  }
  for(int i=0;i<B;i++){
    cin>>b[i];
    min_b=min(min_b,b[i]);
  }
  int x,y,c,min_m;
  m[0]=min_a+min_b;
  min_m=m[0];
  for(int i=1;i<=M;i++){
    cin>>x>>y>>c;
    m[i]=a[x-1]+b[y-1]-c;
    min_m=min(min_m,m[i]);
  }
//  printf("%d,%d,%d,%d\n",min_a,min_b,m[0],m[1]);
  cout<<min_m<<endl;
}

Measured memory_bytes: 1408
num=input()
for i in range(2**3):
    total=int(num[0])
    ans_str=str(num[0])
    for k in range(0,3):
        if (i>>k)&1:
            total+=int(num[k+1])
            ans_str+='+'+num[k+1]
        else:
            total-=int(num[k+1])
            ans_str+='-'+num[k+1]
    #print(ans_str)
    #print(total)
    if total==7:
        ans_str+='=7'
        print(ans_str)
        break

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,l;
	cin >> n;
	vector<ll> a(n);
	vector<ll> ans(n);

	for(int i = 0; i < n; i++) {
		cin >> l;
		a[i] = l * 2;
	}
	ll x = a[0];
	for(int i = 1; i < n - 1; i++) {
		if (i % 2 == 1){
			x -= a[i];
		}
		else{
			x+= a[i];
		}
	}
	x += a[n - 1];
	ans[0] = x/2;

	ll tmp = ans[0];
	for(int i = 1; i < n; i++) {
		tmp = a[i - 1] - tmp;
		ans[i] = tmp; 
	}
	for(int i = 0; i < n; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;

	return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a+b>c+d) {
    cout << "Left" << endl;
  }
  if(a+b==c+d) {
    cout << "Balanced" << endl;
  }
  if(a+b<c+d){
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
/*input
10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 1e6+1;
int a[N];
int n,k;

bool check(int x){
	int whAt = 0;
	RE(i,n){
		whAt += (a[i]-1)/x;
	}
	return (whAt<=k);
}

void solve(){
  	cin >> n >> k;
  	RE(i,n){
  		cin >> a[i];
  	}
  	int lo = 1;
  	int hi = 1e9;
  	while(lo < hi){
  		int mid = (lo+hi)/2;
  		if(check(mid))hi = mid;
  		else lo = mid+1;
  	}
  	cout << lo;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans;
    ll a, b, c, d, e;
    if((A-B)%2==0) {
        a = (max(A,B)-min(A,B))/2;
        b = N-min(A,B);
        c = max(A,B)-1;
        ans = min(min(a,b),c);
    }
    else{
        b = N-min(A,B);
        c = max(A,B)-1;
        d = (A+B-1)/2;
        e = (2*N-A-B+1)/2;
        ans = min(min(b,d),min(d,e));
    }
    cout << ans << endl;
    return 0;
}


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

i=1
tmp=0
while 1:
    tmp=tmp+26**i
    if tmp>=n:
        tmp-=26**i
        break
    i+=1
n-=tmp+1

#print(n)

ans=[]

for j in range(i):
    cnt=i-j-1
    #print(cnt)
    ans.append(n//(26**cnt))
    n=n-(n//(26**cnt))*(26**cnt)
#print(ans)
result=""
for item in ans:
    result+=(chr(97 + item))

print(result)








Measured memory_bytes: 61800
arr = Array[]
size = gets.chomp.to_i

i = 0
while i < size
	command, number = gets.chomp.split(' ')
	if command == "insert"
		arr.unshift(number)
	elsif command == "delete"
		if arr.index(number) != nil
			arr.delete_at(arr.index(number).to_i)
		end
	elsif command == "deleteFirst"
		arr.shift
	elsif command == "deleteLast"
		arr.pop
	end
#	p arr
	i = i + 1
end

puts arr.join(" ")

Measured memory_bytes: 99240