akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll x;
/******* define variable end *******/
int solve() {
	cin >> x;
	ll money = 100;
	for(ll i = 1;; i++){
		money *= 1.01;
		if(money >= x){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long int lli;
int c[30],x[30000];
lli dp[30000][256];

int sq(int x) {
    return x*x;
}
int add(int x, int y) {
    return max(0, min(255, x+y));
}
int main(void) {
    while(1) {
        int n,m;
        scanf("%d%d",&n,&m);
        if(!n) break;
        memset(dp, 0x3F, sizeof(dp));

        for(int i=0; i<m; i++)
            scanf("%d",&c[i]);
        for(int i=0; i<n; i++)
            scanf("%d",&x[i]);

        dp[0][128] = 0;

        for(int i=0; i<n; i++)
            for(int j=0; j<256; j++)
                for(int k=0; k<m; k++)
                    dp[i+1][add(j,c[k])] = min(dp[i+1][add(j,c[k])], dp[i][j] + sq(x[i]-add(j,c[k])));

        lli res=0xFFFFFFFFFFFF;
        for(int j=0; j<256; j++)
            res = min(res, dp[n][j]);

        printf("%lld\n", res);

    }
    return 0;
}

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


int n, w;
int weight[110], value[110];
ll dp[110][100100];

int main() {
  cin >> n >> w;
  rep(i,n) cin >> weight[i] >> value[i];
  for(int i = 0; i <= w; i++) dp[0][i] = 0;
  rep(i,n) {
    for(int j = 0; j <= w; j++) {
      if(weight[i]<=j) dp[i+1][j] = max(dp[i][j],dp[i][j-weight[i]]+value[i]);
      else dp[i+1][j] = dp[i][j];
    }
  }
  cout << dp[n][w] << endl;
  return 0;
}

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

int main() {
	string a, b, ab;
	cin >> a >> b;
	ab = a + b;
	int c = stoi(ab);
	int e = sqrt(c);
	int d = pow(e, 2);
	if (c==d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}	
	return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

z = []
for i in range(3):
    a,b = inpl()
    z.append(a)
    z.append(b)
c = Counter(z)
for key in c.keys():
    if c[key] > 2:
        print('NO')
        break
else:
    print('YES')


Measured memory_bytes: 38384
N,K = map(int,input().split())
P=list(map(lambda x:int(x)-1,input().split()))
C=list(map(int,input().split()))

ans=-float("inf")

for start in range(N):
    cur=P[start]
    scores=[C[cur]]
    for _ in range(K):
        if cur==start:
            break
        cur = P[cur]
        scores.append(C[cur]+scores[-1])

    for goal in range(len(scores)):
        no_loop_sum=scores[goal]
        remain_hops=K-goal-1

        if scores[-1]>0:
            loops=remain_hops//len(scores)
        else:
            loops=0
        ans=max(ans,no_loop_sum+scores[-1]*loops)
print(ans)


Measured memory_bytes: 78144
import scala.io.Source

object Main{
  def main(args: Array[String]){
    val lines = for{
      in <- Source.stdin.getLines.toList
    }yield in

    recStrArrange(lines(0), lines.drop(2))
  }

  def recStrArrange(s: String, ops: List[String]): String ={
    if(ops == Nil){
      s
    }
    else if(ops.head.split(" ").toList.head != "print"){
      val opnow = ops.head.split(" ").toList
      val res = opnow.head match{
        case x if(x == "replace") => replaceStr(s, opnow.tail)
        case x if(x == "reverse") => reverseStr(s, opnow.tail)
        case _ =>
      }

      recStrArrange(res.toString, ops.tail)
    }
    else{
      val opnow = ops.head.split(" ").toList
      println(s.drop(opnow.tail.head.toInt).dropRight(s.length - opnow.last.toInt - 1))
      recStrArrange(s, ops.tail)
    }
  }

  def replaceStr(s: String, list: List[String]): String ={
    s.patch(list.head.toInt, list.last, list.last.length)
  }

  def reverseStr(s: String, list: List[String]): String ={
    val t1 = s.substring(list.head.toInt, list.last.toInt + 1).reverse.patch(0, s.dropRight(s.length - list.head.toInt), 0)
    t1 + s.drop(t1.length)
  }
}

Measured memory_bytes: 45656
#include <iostream>
using namespace std;
int main(void){
  int a,b;
  cin >> a >> b;
  
  int n = 1;
  
  if(a != 0){
    for(int i=0;i<a;i++){
    n = n * 100;
    }
  }
  
  if(b != 100)
  cout << n * b << endl;
  else
    cout << n * (b+1) << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
a=int(input())
x=[]
for i in range(a):
	s=str(input())
	x.append(s)
b=int(input())
y=[]
for i in range(b):
	s=str(input())
	y.append(s)
m=0
for i in range(a):
	a=x.count(x[i])-y.count(x[i])
	if(a>m):
		m=a
print(m)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

int main(){
	int N, W; cin >> N >> W;
	vector<vector<int>> dp(N+1,vector<int>(W+1,0));
	vector<pair<int,int>> items;
	for (int i=0;i<N;i++){
		int v,w; cin >> v >> w;
		items.push_back(pair<int,int>(v,w));
	}
	for (int i = 0;i < N;i++){
		for(int w = 0; w < W+1; w++){
			if (w >= items[i].second) dp[i+1][w] = max(dp[i+1][w-items[i].second] + items[i].first, dp[i][w]);
			else dp[i+1][w] = dp[i][w];
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}




Measured memory_bytes: 6820
// 第六回 ドワンゴからの挑戦状 予選 A.cpp

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	int n, index, answer = 0;
	string x;
	cin >> n;
	vector<string> s(n);
	vector<int> t(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i] >> t[i];
	}
	cin >> x;

	for (int i = 0; i < n; i++) {
		if (s[i] == x) {
			index = i + 1;
			break;
		}
	}

	for (; index < n; index++) {
		answer += t[index];
	}

	cout << answer << endl;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n:u32 = iter.next().unwrap().parse().unwrap();
    let s = iter.next().unwrap();
    for c in s.chars() {
        print!("{}", std::char::from_u32(((c as u32 - 'A' as u32) + n) % 26 + ('A' as u32)).unwrap())
    }
    println!();
}


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<int, PI> V;
typedef vector<int> VE;
const ll mod = 10000000007; //10^9+7


int main(){
  int n,z,w;
  ll a[2002];
  cin>>n>>z>>w;
  REP(i,n)cin>>a[i];
  if(n==1){print(abs(a[0]-w));return 0;}
  ll ans=max(abs(a[n-1]-w),abs(a[n-2]-a[n-1]));
  print(ans);
}

Measured memory_bytes: 256
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

//s.find_by_order(index);
//s.order_of_key(value);
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define why         (ll)1000000007
//#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod){
    ll result=1;
    while(power){
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod){
    return fast_power(base,mod-2,mod);
}

void solve() {
    ll n; cin>>n;
    vector<string> a = {"AC","WA","TLE","RE"};
    map<string,ll> m;
    lp(i,0,n){
        string p; cin>>p;
        m[p]++;
    }
    lp(i,0,4){
        cout<<a[i]<<" "<<"x"<<" "<<m[a[i]]<<dl;
    }
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}  

Measured memory_bytes: 3660
#include <stdio.h>

int main(void)
{
    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: 1928
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K, x, a = 0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x > K - x)
      a += (K - x) * 2;
    else
      a += x * 2;
  }
  
  cout << a;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

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

const ll INF = 1e18;

int main() {
    ll n;
    cin >> n;
    VL a(3), b(3);
    REP(i,3) a[i] = in();
    REP(i,3) b[i] = in();

    VL dp(n + 1, -INF);
    dp[0] = 0;
    REP(i,n){
        if (dp[i] == -INF) continue;
        REP(j,3){
            if (i + a[j] > n) continue;
            chmax(dp[i + a[j]], dp[i] + b[j]);
        }
    }
    ll ma = -INF;
    REP(i,n+1){
        chmax(ma, n - i + dp[i]);
    }

    VL dp2(ma + 1, -INF);
    dp2[0] = 0;
    REP(i,ma){
        if (dp2[i] == -INF) continue;
        REP(j,3){
            if (i + b[j] > ma) continue;
            chmax(dp2[i + b[j]], dp2[i] + a[j]);
        }
    }
    ll ans = -INF;
    REP(i,ma+1){
        chmax(ans, ma - i + dp2[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 195584
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int h, w;
int a[505][505];
vector<vector<int>> v(4);

int main() {
    cin >> h >> w;
    rep(i, h) {
        rep(j, w) {
            cin >> a[i+1][j+1];
        }
    }

    int x = 1, y = 1;
    int nx, ny;
    int cnt = 0;
    while (cnt < h*w) {
        if (y % 2 == 1) {
            if (x < w) nx = x+1, ny = y;
            else nx = x, ny = y+1;
        } else {
            if (x > 1) nx = x-1, ny = y;
            else nx = x, ny = y+1;
        }

        if (a[y][x] % 2 == 1 && ny <= h) {
            a[y][x]--;
            a[ny][nx]++;
            v[0].pb(y);
            v[1].pb(x);
            v[2].pb(ny);
            v[3].pb(nx);
        }
        y = ny;
        x = nx;
        cnt++;
    }

    int n = v[0].size();
    cout << n << endl;
    rep(i, n) {
        cout << v[0][i] << " " << v[1][i] << " " << v[2][i] << " " << v[3][i] << endl;
    }
}


Measured memory_bytes: 5220
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
    int n,x[101],y[101],xy;
    double ans1,ans2,ans3,ans4;
    ans1 = 0;ans2 = 0;ans3 = 0;ans4 =0;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> x[i];
    }
    for(int i = 1; i <= n; i++){
        cin >> y[i];
    }
    for(int i = 1; i <= n; i++){
        xy = fabs(x[i] - y[i]);
        ans1 += xy;
        ans2 += pow(xy,2);
        ans3 += pow(xy,3);
        if(ans4 < xy) ans4 = xy;
    }
    printf("%f\n%f\n%f\n%f\n",ans1,sqrt(ans2),cbrt(ans3),ans4);
    return 0;
    
}



Measured memory_bytes: 3376
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
n,q = map(int,readline().split())
ABPX = list(map(int,read().split()))
AB = iter(ABPX[:n+n-2])
PX = iter(ABPX[n+n-2:])

graph = [[] for _ in range(n+1)]
for a, b in zip(AB, AB):
    graph[a].append(b)
    graph[b].append(a)

val = [0] * (n+1)
for p, x in zip(PX, PX):
    val[p] += x

stack = [1] #queue的なやつ
parent = [0] * (n+1)
while stack:
    x = stack.pop() #根を引っこ抜く
    for y in graph[x]: #木を見る
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)
        val[y] += val[x]
        
print(' '.join(map(str, val[1:])))

Measured memory_bytes: 90672
p=print
b=0
for e in iter(input,'0 0'):
 if b:p()
 b=f=1;s,t=map(int,e.split())
 for y in range(s,t+1):
  if(y%4==0)*(y%100)or y%400==0:p(y);f=0
 if f:p('NA')


Measured memory_bytes: 5716
ppl = [[],[],[],[]]
for i in range(4):
    for j in range(3):
        tmp = []
        for k in range(10):
            tmp.append(0)
        ppl[i].append(tmp)
n = int(input())
for i in range(n):
    vals = list(map(int,input().split()))
    ppl[vals[0]-1][vals[1]-1][vals[2]-1] += vals[3]
for i in range(4):
    for j in range(3):
        for k in range(10):
            print (" ", end="")
            print (ppl[i][j][k], end="")
        print ()
    if i != 3:
        for j in range(20):
            print ("#", end="")
        print ()


Measured memory_bytes: 5640
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j, k;

  //input
  
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i = 1; i < n+1; i++) scanf("%d",&A[i]);

  //countingsort

  k = VMAX;

  for(i = 0; i < k+1; i++) C[i] = 0;

  for(j = 1; j < n+1; j++) C[A[j]]++;

  for(i = 1; i < k+1; i++) C[i] = C[i] + C[i-1];
  
  for(j = n; j > 0; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  
  //output
  
  for(i = 1; i < n; i++) printf("%d ",B[i]);
  printf("%d\n",B[i]);

  free(A);
  free(B);
  
  return 0;
}



Measured memory_bytes: 9116
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int N=2500,MAXN=100000+10;
int v[N+10];ll p[N+10],cnt;
ll a[MAXN];map<ll,int> m;set<pair<ll,ll> >s;

void init(void)
{
	for(int i=2;i<=N;++i)
	{
		if(!v[i]) v[i]=i,p[++cnt]=i;
		for(int j=1;j<=cnt;++j)
		{
			if(p[j]>v[i]||p[j]>N/i) break;
			v[i*p[j]]=p[j];
		};
	};
	// for(int i=1;i<=cnt;++i) printf("%lld ",p[i]);
}

void work(ll num)
{
	ll lim=pow(num,1.0/3)+5,x=1,y=1;
	for(int i=1;p[i]<=lim;++i)
	{
		int c=0;
		while(num%p[i]==0) num/=p[i],++c;
		c%=3;if(c){x*=c==1?p[i]:p[i]*p[i];y*=c==1?p[i]*p[i]:p[i];}
	};
	x*=num;
	if(num>1)
	{
		ll sq=sqrt(num);
		if(sq*sq==num) y*=sq; else y*=num*num;
	};
	++m[x];s.insert(make_pair(min(x,y),max(x,y)));
}

int main()
{
	init();
	int n;scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%lld",&a[i]);
	for(int i=1;i<=n;++i) work(a[i]);
	int ans=0;
	for(set<pair<ll,ll> >::iterator i=s.begin();i!=s.end();++i)
		ans+=i->first==1?1:max(m[i->first],m[i->second]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 19840
t = [0]
x = [0]
y = [0]
n = int(input())
for i in range(n):
    ti, xi, yi = map(int, input().split())
    t.append(ti)
    x.append(xi)
    y.append(yi)
    
flg=True
for i in range(1, n+1):
    if((x[i]-x[i-1])+(y[i]-y[i-1])>(t[i]-t[i-1])):
        flg=False
    elif(((x[i]-x[i-1])+(y[i]-y[i-1]))%2!=(t[i]-t[i-1])%2):
        flg=False
if(flg):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 11816
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int P[N];
  int Min = N+1,answer=0;
  for(int i=0;i<N;i++){
    cin >> P[i];
    if(Min > P[i]) answer++;
    Min = min(Min,P[i]);
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 1024
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxk = 5005;

int K, d[mxk], td[mxk];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
/*
It's easier to count the complement of answer.
If we ensure a[j]-a[j-1]<m (by x%=m and d[j-1]%=m), a[j]<a[j-1] iff a[j] crosses/touches multiple of m. ==> floor(a[n-1]/m).
a[j]==a[j-1] iff d[j-1]%m==0. a[j]>a[j-1] = n-1-(a[j]==a[j-1])-(a[j]<a[j-1])
*/
    cin >> K >> Q;
    for (int i = 0; i < K; i++) {
        cin >> d[i];
    }
    while (Q--) {
        int n, x, m;
        cin >> n >> x >> m;
        ll stxd = x%m, std = 0;
        int o = (n-1)%K;
        for (int i = 0; i < K; i++) {
            td[i] = d[i]%m;
            if (!td[i]) td[i] = m;  // instead of counting d[j]==0 cases, changed it so that it contributes 1 instead 0.
            std += td[i], stxd += (i < o ? td[i] : 0);
        }
        stxd += std*((n-1)/K);//bug(stxd);
        cout << n-1-(stxd/m) << '\n';
    }
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
ll n,q,dp[(1<<9)+2][100002], mid=9;
pi store[(1<<9)+2];
pi A[MAXN];
int main(){
	FAST
	cin>>n;
	FOR(i,1,n)cin>>A[i].f>>A[i].s;
	FOR(i,1,(1<<min(n,mid))-1){
		DEC(w,1e5,0){
			dp[i][w]=dp[i/2][w];
			if(w >= A[i].s) dp[i][w]=max(dp[i][w], dp[i/2][w-A[i].s]+A[i].f);
		}
	}
	cin>>q;
	while(q--){
		ll v, l;
		cin>>v>>l;
		ll lvl = ll(log2l(v)) + 1;
		vector<ll> stuff;
		while(lvl > mid) {
			stuff.eb(v);
			v /= 2, -- lvl;
		}
		ll ans=0;
		for(auto&i:store)i=pi(0,0);
		FOR(i,0,(1<<siz(stuff))-1){
			ll total=0, sum=0;
			if(i){
				ll lsb=__builtin_ctz(i);
				store[i].f=store[i - (1<<lsb)].f+A[stuff[lsb]].f;
				store[i].s=store[i - (1<<lsb)].s+A[stuff[lsb]].s;
				total=store[i].s, sum=store[i].f;
			}
			if(total > l) continue;
			ans = max(ans, sum + dp[v][l-total]);
		}
		cout<<ans<<'\n';
	}
}


Measured memory_bytes: 406992
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int ipow(int x, int y)
{
	int z = 1;
	for (int i = 0; i < y; i++) {
		z *= x;
	}

	return z;
}

void arnext(int x, bool* ar)
{
	for (int i = 0; i < 6; i++) {
		if (x % 2) {
			ar[i] = true;
		} else {
			ar[i] = false;
		}
		x = x >> 1;
	}
}


int main()
{
	int h, w, k;
	cin >> h >> w >> k;
	bool row[6];
	bool line[6];
	int maxh = ipow(2, h);
	int maxw = ipow(2, w);
	vector<vector<bool>> dp(h, vector<bool>(w, false));

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char tmp;
			cin >> tmp;
			if (tmp == '#') {
				dp[i][j] = true;
			}
		}
	}
	
	int sum = 0;
	int ans = 0;
	for (int i = 0; i < maxh; i++) {
		arnext(i, line);
		for (int j = 0; j < maxw; j++) {
			arnext(j, row);
			for (int ki = 0; ki < h; ki++) {
				if (line[ki])continue;
				for (int kj = 0; kj < w; kj++) {
					if (row[kj])continue;
					if (dp[ki][kj])sum++;
				}
			}
			if (sum == k)ans++;
			sum = 0;
		}
	}

	printf("%d", ans);


	return 0;
}


Measured memory_bytes: 3704
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        ipt_s: chars,
    }
    let even: bool = (n % 2 == 0);
    let right: bool = (&ipt_s[0..n/2] == &ipt_s[n/2..n]);
    let ans = if even && right {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <queue>
 
class Baseball{
	int score, out_count;
	std::queue<bool> runners;
public:
	Baseball() : score(), out_count(){}
	void hit();
	void homerun();
	void out();
	int get_score() {return score;}
	int get_out() {return out_count;}
};

void Baseball::hit(){
	runners.push(true);
	if(runners.size() == 4){
		++score;
		runners.pop();
	}
}

void Baseball::homerun(){
	score += runners.size() + 1;
	while(!runners.empty()){
		runners.pop();
	}
}

void Baseball::out(){
	++out_count;
}

int main(){
	int inning;
	std::cin >> inning;
	//inningの回数だけループ
	for(int i = 0; i < inning; ++i){
		Baseball game;
		while(game.get_out() != 3){
			std::string event;
			std::cin >> event;
			if(event == "HIT"){
				game.hit();
			}
			else if(event == "HOMERUN"){
				game.homerun();
			}
			else if(event == "OUT"){
				game.out();
			}
		}
		std::cout << game.get_score() << std::endl;
	}
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
int N,M,A;
string s[111];
int dp[111][111][4][11][11];
bool in(int y,int x){
  return 0<=y&&y<N&&0<=x&&x<M;
}
int P(int d){
  if(d&1) return (d+1)%4;
  return (d+3)%4;
}
int Q(int d){
  if(d&1) return (d+3)%4;
  return (d+1)%4;
}
struct st{
  int y,x,d,p,q;
  st(){}
  st(int y,int x,int d,int p,int q):y(y),x(x),d(d),p(p),q(q){}
};
signed main(){
  cin>>N>>M>>A;
  for(int i=0;i<N;i++) cin>>s[i];
  int ans=A*2+1;
  int sy,sx;
  for(int i=0;i<N;i++)
    for(int j=0;j<M;j++)
      if(s[i][j]=='S') sy=i,sx=j;
  memset(dp,-1,sizeof(dp));
  int ax[]={0,1,0,-1};
  int ay[]={-1,0,1,0};
  deque<st> dq;
  dq.push_back(st(sy,sx,2,0,0));
  dp[sy][sx][2][0][0]=0;
  while(!dq.empty()){
    st r=dq.front();dq.pop_front();
    int y=r.y,x=r.x,d=r.d,p=r.p,q=r.q;
    //cout<<y<<" "<<x<<" "<<d<<" "<<p<<" "<<q<<endl;
    if(p+q>=ans) break;
    if(s[y][x]=='G'){
      ans=min(ans,p+q);
      break;
    }
    if(s[y][x]=='S'&&d==0) continue;
    {
      int ny=y+ay[d],nx=x+ax[d],nd=d;
      if(in(ny,nx)&&s[ny][nx]!='#'){
	if(dp[ny][nx][nd][p][q]<0||
	   dp[ny][nx][nd][p][q]>dp[y][x][d][p][q]){
	  dp[ny][nx][nd][p][q]=dp[y][x][d][p][q];
	  dq.push_front(st(ny,nx,nd,p,q));
	}
      }
    }
    if(s[y][x]!='S'&&p<A){
      int nd=P(d);
      int ny=y+ay[nd],nx=x+ax[nd];
      if(in(ny,nx)&&s[ny][nx]!='#'){
	if(dp[ny][nx][nd][p+1][q]<0||
	   dp[ny][nx][nd][p+1][q]>dp[y][x][d][p][q]+1){
	  dp[ny][nx][nd][p+1][q]=dp[y][x][d][p][q]+1;
	  //cout<<p+1<<" "<<q<<endl;
	  dq.push_back(st(ny,nx,nd,p+1,q));
	}
      }
    }
    if(s[y][x]!='S'&&q<A){
      int nd=Q(d);
      int ny=y+ay[nd],nx=x+ax[nd];
      if(in(ny,nx)&&s[ny][nx]!='#'){
	if(dp[ny][nx][nd][p][q+1]<0||
	   dp[ny][nx][nd][p][q+1]>dp[y][x][d][p][q]+1){
	  dp[ny][nx][nd][p][q+1]=dp[y][x][d][p][q]+1;
	  dq.push_back(st(ny,nx,nd,p,q+1));
	}
      }
    }
  }
  cout<<(ans>A*2?-1:ans)<<endl;
  return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int mm,dd;
    cin>>mm>>dd;
    int ans=0;
    for (int m = 1; m <= mm; m++)
    {
        for (int d = 1; d <= dd; d++)
        {
            int d1 = d%10;
            int d10 = d/10;
            if(d1>=2 && d10>=2 && d1*d10==m)
            {
                ans++;
            }
        }
        
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 768
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#define pb push_back
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  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;
  }
}
using namespace Header_Template;

const int N = 2e5 + 10;
const li inf = 1e18;
int n, a[N];

int main(void) {
  read(n);
  for (int i = 1; i <= n; ++i) read(a[i]);
  
  li ans = inf;
  li x = a[1], y = 0, u = a[2] + a[3], v = 0;
  int l = 1, r = 3;
  for (int i = 4; i <= n; ++i) v += a[i];
  for (int i = 2; i <= n - 2; ++i) {
    y += a[i], u -= a[i];
    while (l + 1 < i && min(x, y) < min(x + a[l + 1], y - a[l + 1])) {
      x += a[l + 1], y -= a[l + 1];
      ++l;
    }
    while (r + 1 < n && min(u, v) < min(u + a[r + 1], v - a[r + 1])) {
      u += a[r + 1], v -= a[r + 1];
      ++r;
    }
    li mn = min(min(x, y), min(u, v));
    li mx = max(max(x, y), max(u, v));
    Min(ans, mx - mn);
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 896
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

s = ''.join(sorted(input()))
if s == 'abc':
    print('Yes')
else:
    print('No')



Measured memory_bytes: 5680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_169
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long n = ReadLong();
            List<long[]> factors = PrimeFactors(n);
            int res = 0;
            for(int i = 0; i < factors.Count; i++)
            {
                long remain = factors[i][1];
                long minus = 1;
                while (minus <= remain)
                {
                    remain -= minus;
                    minus++;
                    res++;
                }
            }
            WriteLine(res);
        }

        static List<long[]> PrimeFactors(long n)
        {
            var res = new List<long[]>();
            long tmp = n;

            for (long i = 2; i * i <= n; i++)
            {
                if (tmp % i == 0)
                {
                    res.Add(new long[2] { i, 0 });
                    while (tmp % i == 0)
                    {
                        tmp /= i;
                        res[res.Count - 1][1]++;
                    }
                }
            }
            if (tmp != 1) res.Add(new long[2] { tmp, 1 });//最後の素数も返す

            return res;
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27836
/* ?????????????????????????????£??????????????¨???????????§?????????
????????????????????§?¨????0???????§???????*/
#include <stdio.h>

int main(void)
{
	int map[21][21];
	int N,P,x,y,M,w,get,i,j;
	char c,a,exa;
	
	while(1){
		get = 0;
		for(i = 0;i < 21;i++){
			for(j = 0;j < 21;j++){
				map[i][j] = 0;
			}
		}
		scanf("%d",&N); // ??????????????°
		if(N == 0) break;
		P = N;
		while(P > 0){
			scanf("%d %d",&x,&y); // ???????????§?¨??????????
			map[y][x] = 1;
			P--;
		}
		x = 10;
		y = 10;
		scanf("%d",&M); // ??????????????????????????????????????°
		while(M > 0){
			scanf("%c",&exa); // ???????????§??????????????????\n?????????
			scanf("%c %d",&c,&w); // ?????????????????????????§?????????????
			
			switch(c){
				case 'N': //??????y+?????????
					while(w > 0){
						y++;
						if(map[y][x] == 1){
						get++;
						map[y][x] = 0;
						}
						w--;
					}
					break;
				case 'E':
					while(w > 0){
						x++;
						if(map[y][x] == 1){
						get++;
						map[y][x] = 0;
						}
						w--;
					}
					break;
				case 'S':
					while(w > 0){
						y--;
						if(map[y][x] == 1){
						get++;
						map[y][x] = 0;
						}
						w--;
					}
					break;
				case 'W':
					while(w > 0){
						x--;
						if(map[y][x] == 1){
						get++;
						map[y][x] = 0;
						}
						w--;
					}
					break;
			}
			M--;
			
		}
		if(get == N) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

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

int main(){
	int h,w,k; cin>>h>>w>>k;
	vector<string> C(h);
	rep(i, h) cin>>C[i];
	int ans = 0;
	rep(bit, 1<<(h+w)){
		int c = 0;
		rep(i,h)
			if(bit>>(w+i) & 1)
				rep(j,w) if(bit>>j & 1 && C[i][j] == '#') c++;
		if(c == k) ans++;
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 3596
//Problem A
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;ll x,y;
char str[200005];
int main(){
	scanf("%s",str);n=strlen(str);
	for(int i=0;i<n;i++){
		if(str[i]=='B')++x;else y+=x;
	}
	printf("%lld",y);
	return 0;
}

Measured memory_bytes: 384
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


# サイズが大きいとdefaultdictが早い(for文を書かなくて済む)
from collections import defaultdict
n = int(input())
ns = defaultdict(set)
for _ in range(n-1):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].add(v)
    ns[v].add(u)

def is_bip(ns):
    start = 0
    q = [start]
    cs = [None]*n
    cs[start] = 1
    while q:
        u = q.pop()
        c = cs[u]
        cc = int(not c)
        for v in ns[u]:
            if cs[v] is None:
                cs[v] = cc
                q.append(v)
            elif cs[v]==c:
                return False, None
    return True, cs
_, cs = is_bip(ns)
v1, v0 = 0, 0
for num in cs:
    if num==0:
        v0 += 1
    else:
        v1 += 1
num0 = [i for i in range(1,n+1) if i%3==0]
num1 = [i for i in range(1,n+1) if i%3==1]
num2 = [i for i in range(1,n+1) if i%3==2]
if v0<=len(num0) or v1<=len(num0):
    if v0<=len(num0):
        val = 0
    else:
        val = 1
    for i in range(n):
        if cs[i]==val:
            cs[i] = num0.pop()
        else:
            if num1:
                cs[i] = num1.pop()
            elif num2:
                cs[i] = num2.pop()
            else:
                cs[i] = num0.pop()
else:
    if v0<=v1:
        val = 0
    else:
        val = 1
    for i in range(n):
        if cs[i]==val:
            if num1:
                cs[i] = num1.pop()
            else:
                cs[i] = num0.pop()
        else:
            if num2:
                cs[i] = num2.pop()
            else:
                cs[i] = num0.pop()
write(" ".join(map(str, cs)))

Measured memory_bytes: 198628
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int n, a, b, i, j, k, m;
int str[100];
int main() {
	for (i = 1; i <= 9; i++) {
		for (j = 1; j <= 9; j++) {
			str[i * j] = 1;
		}
	}
	scanf("%d", &a);
	if (str[a] == 1)
		printf("Yes\n");
	else
		printf("No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


long gcd(int A, int B) {
	if (A % B == 0) return B;
	return gcd(B,A%B);
}

long lcm(long A, long B) {
	return (A/gcd(A,B))*B;	
}
int main(int argc, char *argv[]) {

	long A,B; cin >> A >> B;
	long C,D; cin >> C >> D;

	long ans = 0;

	ans += (B / C);
	ans -= ((A-1) / C);
	ans += (B / D);
	ans -= ((A-1) / D);

	ans += ((A-1) / lcm(C,D));
	ans -= (B / lcm(C,D));

	cout << (B - A + 1) - ans << endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

from bisect import bisect_left, bisect_right

def main():
    N,C,K = map(int, input().split())
    Ti = list(int(input()) for _ in range(N))
    Ti.sort()
    i = 0
    ret = 0
    while i<N:
        ret += 1
        s = i
        Ts = Ti[i]
        while i<N and Ti[i]<=(Ts+K) and (i-s)<C:
            i += 1

    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 7396
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  if (a <= c && b <= c) {
    ans = c * 10 + a + b;
  } else if (a <= b && c <= b) {
    ans = b * 10 + a + c;
  } else {
    ans = a * 10 + b + c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3184
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
const int maxx=100100;
vector<int> A[maxx];
int color[maxx];
int c=1;

void dfs(int u){
	if(color[u]!=-1) return ;//当该节点已经属于某一联通分量时，不需要染色
	color[u]=c;
	int si=A[u].size();
	for(int i=0;i<si;i++){
		if(color[A[u][i]]==-1){//注意是对A[u][i]进行染色
			dfs(A[u][i]);
		}
	}
	return ;
}

int main(){
	int n,q,a,b;//这里有个问题，n如果放在global里定义的话会出现问题，只能在main里定义，不知道为什么
	cin>>n>>q;
	for(int i=0;i<=maxx;i++) color[i]=-1;
	for(int i=1;i<=q;i++){
		cin>>a>>b;
		A[a].push_back(b);
		A[b].push_back(a);
	}
	for(int i=0;i<n;i++){
		dfs(i);
		c++;
	}
	cin>>q;
	for(int i=1;i<=q;i++){
		cin>>a>>b;
		if(color[a]==color[b]) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}


Measured memory_bytes: 12080
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;


Int dp[108000][13];

int main(){
    string s;
    cin >> s;
    dp[0][0] = 1;
    for(int i = 0;i < s.size();i++){
        for(int j = 0;j < 13;j++){
            if(s[i] == '?'){
                for(int d = 0;d < 10;d++){
                    (dp[i+1][(j*10+d)%13] += dp[i][j]) %= MOD;
                }
            }
            else{
                int d = s[i] - '0';
                (dp[i+1][(j*10+d)%13] += dp[i][j]) %= MOD;
            }
        }
    }
    cout << dp[s.size()][5] << endl;
    return 0;
}

Measured memory_bytes: 10752
package main

import "fmt"

func main() {
	var N,cnt int
	fmt.Scan(&N)
	
	for i := 1; i <= N; i++ {
		//もし奇数なら約数の数を調べる
		if i % 2 != 0 {
			divcnt := 0
			for j := 1;  j <= i; j++ {
				if i % j == 0 {
					divcnt++
				}
			}
			//約数の数が8個のものの個数をカウント
			if divcnt == 8 {
				cnt++
			}
		}
	}
	fmt.Println(cnt)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i, n, t, a, b;
    scanf("%d %d", &n, &t);
    vector <int> v;
    for(i = 0; i < n; i++)
    {
        scanf("%d %d", &a, &b);
        if(b <= t)
            v.push_back(a);
    }
    if(!v.size())
    {
        printf("TLE");
        return 0;
    }
    sort(v.begin(), v.end());
    printf("%d", v[0]);
}

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int L; cin >> L;
	V<ll> a(L+1,0);
	for(int i = 1; i <= L; ++i) cin >> a[i];
	V<V<ll>> dp(L+1,V<ll>(5,(ll)1e15));
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[0][2] = 0;
	dp[0][3] = 0;
	dp[0][4] = 0;
	for(int i = 1; i <= L; ++i){
		dp[i][0] = dp[i-1][0] + a[i];
		dp[i][1] = min({dp[i-1][0],dp[i-1][1]}) + (a[i]!=0?a[i]%2:2);
		dp[i][2] = min({dp[i-1][0],dp[i-1][1],dp[i-1][2]}) + 1-a[i]%2;
		dp[i][3] = min({dp[i-1][0],dp[i-1][1],dp[i-1][2],dp[i-1][3]}) + (a[i]!=0?a[i]%2:2);
		dp[i][4] = min({dp[i-1][0],dp[i-1][1],dp[i-1][2],dp[i-1][3],dp[i-1][4]}) + a[i];
	}
	cout << min({dp[L][0],dp[L][1],dp[L][2],dp[L][3],dp[L][4]}) << endl;
	
	return 0;
}


Measured memory_bytes: 15872
#include<cstdio>
#include<algorithm>
struct aff{
	int id,w;
	friend bool operator <(aff a,aff b){return a.w<b.w;}
}a[200005];
int ans[200005];
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i].w),a[i].id=i;
	std::sort(a+1,a+n+1);
	for(int i=1;i<=n/2;i++) ans[a[i].id]=a[n/2+1].w,ans[a[i+n/2].id]=a[n/2].w;
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 4480
from collections import defaultdict
import sys
N=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
L=[0]*N
for i in range(N):
    L[A[i]]+=1
if N%2==0:
    for i in range(1,N,2):
        if L[i]!=2:
            print(0)
            sys.exit()
    print(pow(2,N//2,mod))
else:
    if L[0]!=1:
        print(0)
        sys.exit()
    for i in range(2,N,2):
        if L[i]!=2:
            print(0)
            sys.exit()
    print(pow(2,N//2,mod))        

Measured memory_bytes: 52972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#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 fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll,ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

void solve(){
    int x,y;
    cin>>x>>y;
    if(x==1&&y==1){
        cout<<1000000;
        return;
    }
    int a=4-x,b=4-y;
    if(4-x<0)a=0;
    if(4-y<0)b=0;

    cout<<a*100000+b*100000<<endl;
}

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

Measured memory_bytes: 256
l, r = gets.chomp.split.map(&:to_i)
size = r - l + 1

if size > 2019
  p 0
  exit
end

tmp = []
(l..r).to_a.combination(2) do |a, b|
  tmp.push((a * b) % 2019)
end
p tmp.sort[0]


Measured memory_bytes: 50296
#include <bits/stdc++.h>
 #include <string> 
 #include <math.h>
 #include <bitset>
 #include <numeric>
 #include <stdio.h>
 #include <algorithm>

 using namespace std;

 int main(){
    string S, T;
    int i, j;
    int l_S, l_T;
    int tmp_ans = 0;
    int ans = 1200;
    cin >> S >>T;

    l_S = S.size();
    l_T = T.size();

    for (i=0; i<l_S-l_T+1; i++){
        for (j=0; j<l_T; j++){
            if (T[j]!=S[i+j]){
                tmp_ans = tmp_ans + 1;
            }
            }
        if (tmp_ans < ans)
            ans = tmp_ans;
        tmp_ans = 0;
        }

    cout << ans << endl;

    return 0;
 }
 


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(){
	int A,B;
	cin >>A>>B;
	if (A - B * 2 > 0) {
		cout << A - B * 2 << endl;
	}
	else {
		cout << 0 << 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;

int main()
{
    int N, K;
    cin >> N >> K;
    int ans = 1, ans1, ans2;
    rep(i, N)
    {
        ans1 = ans;
        ans2 = ans;
        ans1 += K;
        ans2 *= 2;
        ans = min(ans1, ans2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
long long mmin(long long &a,long long b) {
	a = min(a, b);
	return a;
}
long long mmax(long long &a,long long b) {
	a = max(a, b);
	return a;
}
int nibu(vector<int> &v, int tan) {
	int up = v.size()-1;
	int lo = 0;
	if (tan <= v[0]) {
		return 0;
	}
	while (up - lo > 1) {
		int mi = (up + lo) / 2;
		if (tan <= v[mi]) {
			up = mi;
		}
		if (v[mi] < tan) {
			lo = mi;
		}
	}
	return up;
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	vector<int> te(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		int to = 0;
		while (a[to] > x) {
			to++;
		}
		te[to]++;
	}
	int ans = 0;
	int mo = 0;
	for (int i = 0; i < n; i++) {
		if (mo < te[i]) {
			ans = i;
			mo = te[i];
		}
	}
	cout << ans+1 << endl;
}


Measured memory_bytes: 3132
from collections import defaultdict
N,S = open(0).read().split()
N = int(N)
ldic = defaultdict(int)
rdic = defaultdict(int)
L = S[:N]
R = S[N:][::-1]
for i in range(2**N):
  la = ''
  lb = ''
  ra = ''
  rb = ''
  for j in range(N):
    if i%2==1:
      la += L[j]
      ra += R[j]
    else:
      lb += L[j]
      rb += R[j]
    i >>= 1
  ldic[(la,lb)] += 1
  rdic[(ra,rb)] += 1
ans = sum(rdic[k]*ldic[k] for k in ldic.keys())
print(ans)


Measured memory_bytes: 192372