akhauriyash/Code-Regression huggingface dataset:
from random import randint
from time import time
t1=time()

d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
	r=list(map(int,input().split()))
	s.append(r)

def score(T):
	last=[0]*26
	happy=0
	for i in range(d):
		last[T[i]-1]=i+1
		happy+=s[i][T[i]-1]
		for j in range(26):
			happy-=(i+1-last[j])*c[j]
	return happy

t=[]
for i in range(d):
	t.append(i%26+1)

t2=time()
while t2-t1<1.6:
	tt=t.copy()
	tt[randint(1,d)-1]=randint(1,26)
	if score(tt)>score(t):
		t=tt.copy()
	t2=time()
for x in t:
	print(x)


Measured memory_bytes: 81956
import sys
import decimal # 10進法に変換，正確な計算

def input():
    return sys.stdin.readline().strip()

def main():
    s = input()
    for i in range(len(s)):
        if (i+1) % 2 == 0:
            if s[i] == "R":
                print("No")
                return
        else:
            if s[i] == "L":
                print("No")
                return
    print("Yes")
    

    
    
main()

Measured memory_bytes: 5460
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    bool ok = false;
    for(int i = 1 ; i<=n ; i++){
        if((int)(i*1.08) == n){
            ok = true;
            cout<<i;
        }
    }
    if(!ok){
        cout<<":(";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define sc(x) scanf("%d", &x)
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ALL(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define ABS(x) ((x)>=0?(x):(-(x)))
#define fastio ios::sync_with_stdio(0),cin.tie(0)
template<class T>T gcd(T a, T b){return b?gcd(b, a%b):a;}
const int mod = 1e9+7;
const int maxn = 1e5+10;
char s[maxn];
ll dp[maxn][3][3];

ll qpow(ll a, ll n)
{
    ll ret = 1;
    while(n){
        if(n&1)ret = ret*a%mod;
        a = a*a%mod;
        n >>= 1;
    }
    return ret;
}

int main()
{
    scanf("%s", s+1);
    int n = strlen(s+1), cnt = 0;
    for(int i = 1; i <= n; i++){
        if(s[i] == 'A'){
            for(int j = 0; j < 3; j++)dp[i][0][0] += dp[i-1][j][0];
            for(int j = 0; j < 3; j++)dp[i][0][1] += dp[i-1][j][1];
            for(int j = 0; j < 3; j++)dp[i][0][2] += dp[i-1][j][2];
            dp[i][0][0] += qpow(3, cnt);
        }
        else if(s[i] == 'B'){
            for(int j = 0; j < 3; j++)dp[i][1][0] += dp[i-1][j][0];
            for(int j = 0; j < 3; j++)dp[i][1][1] += dp[i-1][j][1]+dp[i-1][j][0];
            for(int j = 0; j < 3; j++)dp[i][1][2] += dp[i-1][j][2];
        }
        else if(s[i] == 'C'){
            for(int j = 0; j < 3; j++)dp[i][2][0] += dp[i-1][j][0];
            for(int j = 0; j < 3; j++)dp[i][2][1] += dp[i-1][j][1];
            for(int j = 0; j < 3; j++)dp[i][2][2] += dp[i-1][j][2]+dp[i-1][j][1];
        }
        else{
            for(int j = 0; j < 3; j++)dp[i][0][0] += dp[i-1][j][0];
            for(int j = 0; j < 3; j++)dp[i][0][1] += dp[i-1][j][1];
            for(int j = 0; j < 3; j++)dp[i][0][2] += dp[i-1][j][2];
            for(int j = 0; j < 3; j++)dp[i][1][0] += dp[i-1][j][0];
            for(int j = 0; j < 3; j++)dp[i][1][1] += dp[i-1][j][1];
            for(int j = 0; j < 3; j++)dp[i][1][2] += dp[i-1][j][2];
            for(int j = 0; j < 3; j++)dp[i][2][0] += dp[i-1][j][0];
            for(int j = 0; j < 3; j++)dp[i][2][1] += dp[i-1][j][1];
            for(int j = 0; j < 3; j++)dp[i][2][2] += dp[i-1][j][2];
            dp[i][0][0] += qpow(3, cnt);
            for(int j = 0; j < 3; j++)dp[i][1][1] += dp[i-1][j][0];
            for(int j = 0; j < 3; j++)dp[i][2][2] += dp[i-1][j][1];
            cnt++;
        }
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                dp[i][j][k] %= mod;
                //printf("dp[%d][%d][%d]=%lld\n", i, j, k, dp[i][j][k]);
            }   
        }
    }
    printf("%lld\n", (dp[n][0][2]+dp[n][1][2]+dp[n][2][2])%mod);
    return 0;
}




Measured memory_bytes: 7424
//56
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main(){
  for(int r,c;cin>>r>>c,r|c;){
    int s[10][10000];
    for(int i=0;i<r;i++){
      for(int j=0;j<c;j++){
	cin>>s[i][j];
      }
    }
    int ms=0;
    for(int i=0;i<1<<r;i++){
      int sc[10][10000];
      memcpy(sc,s,sizeof(sc));
      for(int j=0;j<r;j++){
	for(int k=0;k<c;k++){
	  sc[j][k]^=!!(i&1<<j);
	}
      }
      int sum=0;
      for(int j=0;j<c;j++){
	int cn=0;
	for(int k=0;k<r;k++){
	  cn+=sc[k][j];
	}
	sum+=max(cn,r-cn);
      }
      ms=max(ms,sum);
    }
    cout<<ms<<endl;
  }
  return 0;
}
	

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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

llint my_binary_search(llint ary[], llint key, llint left, llint right) {
	llint middle;
	if (right < left) {
		return -(INF64);
	} else {
		middle = left + (right - left) / 2;
		if (ary[middle] > key) {
			return my_binary_search(ary, key, left, middle - 1);
		} else if (ary[middle] < key) {
			return my_binary_search(ary, key, middle + 1, right);
		} else {
			return middle;
		}
	}
}

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for(int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main (void)
{
	//INPUT
	llint A,B,M;
	cin >> A >> B >> M;
	llint mina=1000000;
	llint minb=1000000;
	vector<llint> a(A);
	vector<llint> b(B);
	vector<pair<llint,llint> > P(M);
	vector<llint> c(M);
	rep(i,0,A) {
		cin >> a[i];
		if (mina > a[i]) mina = a[i];
	}
	rep(i,0,B) {
		cin >> b[i];
		if (minb > b[i]) minb = b[i];
	}

	rep(i,0,M) {
		cin >> P[i].F >> P[i].S >> c[i];
	}

	//SOLVE
	llint ans=mina+minb;
	llint bufans;
	rep(i,0,M) {
		bufans = a[P[i].F-1] + b[P[i].S-1] - c[i];
		// cout << P[i].F << "   " << P[i].S << endl;
		ans = min(ans,bufans);
	}


	//OUTPUT
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
typedef long long ll;
using namespace std;
int measure(int x, int y)
{	
	int z = y;
	while(x%y!=0)
	{
		z = x%y;
		x = y;
		y = z;	
	}
	return z;
}
int gy3(int a,int b,int c){
	int x[3];
	x[0]=a;x[1]=b;x[2]=c;
	sort(x,x+3);
	int z=measure(x[0],x[1]);
	z=measure(z,x[2]);
	return z;
}
int main(){
	int k,a,b,c,ans;
	ll res=0;
	cin>>k;
	for(a=1;a<=k;a++){
		for(b=1;b<=k;b++){
			for(c=1;c<=k;c++){
				ans=gy3(a,b,c);
				res+=ans;
			}
		}
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a=1,b=2;
    ll q,x;
    for(int i=0;i<n;i++){
        cin>>q>>x;
        if(q==1){
            a*=x;
            b*=x;
        }
        else if(q==2){
            a+=x;
            b+=x;
        }
        else{
            a-=x;
            b-=x;
        }
    }
    cout << b-2*a<<" "<<b-a<<endl;

    return 0;
}




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

using namespace std;
using int64 = long long;

constexpr string_view ANSWER = "";

constexpr int kMaxL = 128;

constexpr int DEBUG = 0;

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

int EditDistance(const string& s, const string& t) {
  int n = s.length();
  int m = t.length();
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1E9));
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (i == 0 && j == 0) {dp[i][j] = 0; }
      else if (i == 0) { dp[i][j] = j; }
      else if (j == 0) { dp[i][j] = i; }
      else if (s[i - 1] == t[j - 1]) { dp[i][j] = dp[i - 1][j - 1]; }
      else {
        UpdateMin(dp[i][j], dp[i - 1][j - 1] + 1);
        UpdateMin(dp[i][j], dp[i - 1][j] + 1);
        UpdateMin(dp[i][j], dp[i][j - 1] + 1);
      } 
    }
  }
  return dp[n][m];
}

int Query(const string& q) {
  cout << "? " << q << endl;
  if (ANSWER.length() > 0) {
    return EditDistance(q, string(ANSWER));
  } else {
    int x;
    cin >> x;
    return x;
  }
}

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

  string cs;
  for (char c = 'a'; c <= 'z'; c++) {
    cs.push_back(c);
  }
  for (char c = 'A'; c <= 'Z'; c++) {
    cs.push_back(c);
  }
  for (char c = '0'; c <= '9'; c++) {
    cs.push_back(c);
  }

  auto compare_state = [](const string& s1, const string& s2) {
    return s1.length() > s2.length();
  };
  priority_queue<string, vector<string>, decltype(compare_state)>
      pq(compare_state);
  int length = 0;
  for (char c : cs) {
    int x = Query(string(kMaxL, c));
    if (kMaxL - x > 0) {
      pq.push(string(kMaxL - x, c));
      length += kMaxL - x;
    }
  }

  while (pq.size() >= 2) {
    string s1 = pq.top();
    pq.pop();
    string s2 = pq.top();
    pq.pop();
    if (DEBUG) cout << "s1: " << s1 << endl;
    if (DEBUG) cout << "s2: " << s2 << endl;

    string t = s1;
    int c = 0;
    for (int k = 0; k < s2.length(); k++) {
      while (c <= t.length()) {
        string u = t;
        u.insert(c, 1, s2[k]);
        int x = Query(u);
        if (x + u.length() == length) {
          t = u;
          c++;
          break;
        } else {
          c++;
        }
      }
    }

    if (DEBUG) cout << "t: " << t << endl;
    pq.push(t);
  }
  cout << "! " << pq.top() << endl;
}

Measured memory_bytes: 3804
#include <iostream> 
#include <math.h>



using namespace std;



int main() 
{
    int a, b, c, t;

    cin >> a >> b >> c;
    
    t = floor(b/a);
    if (t>c) 
    {
        cout << c;
    }
    else
        cout << t;

    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: u64, k: u64,
        a: [usize; n],
    }
    // annotate for rust-analyzer
    let n: u64 = n;
    let mut k: u64 = k;
    let a: Vec<usize> = a;

    let mut ans = 0;
    let mut v = vec![0; n as usize];

    if k > n as u64 {
        let mut i: u64 = 0;
        loop {
            ans = a[ans] - 1;
            i += 1;

            if v[ans] != 0 {
                k = (k - i) % (i - v[ans]);
                break;
            } else {
                v[ans] = i;
            }
        }
    }

    for i in 0..k {
        ans = a[ans] - 1;
    }

    println!("{}", ans + 1);
}


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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

ll a, b, c;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> a >> b >> c;
  cout << min((a & 1) * b * c, min((b & 1) * a * c, (c & 1) * a * b)) << "\n";
}


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

using namespace std;

const int MOD = 1e9 + 7;


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

    int n, m, xmax = -1, ymin = 1e9+1;
    cin >> n >> m;

    for(int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        if (x > xmax) {
            xmax = x;
        }
        if (y < ymin) {
            ymin = y;
        }
    }

    int sol = ymin - xmax + 1;
    if (sol < 0)
        cout << 0;
    else cout << sol;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n, f=0, a=0;
  scanf("%d", &n);
  
  for(int i=1; i<=n; i++){
    if((int)(i*1.08) == n){
      a=i;
      f=1;
      break;
    }
  }
  if(f==0) printf(":(");
  else printf("%d", a);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int N;
	string S;
	cin >> N >> S;

	int w = 0, b = 0;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '.') w++;
	}

	int W = w;
	int ans = INT_MAX;
	for (int i = 0; i < S.size(); i++) {
		char c = S[i];
		if (c == '.') w--;
		if (c == '#') b++;
		ans = min(ans, w + b);
	}
	ans = min(ans, W);

	cout << ans << endl;
}

Measured memory_bytes: 3756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int sideA = sc.nextInt();
		int sideB = sc.nextInt();
		int angleC = sc.nextInt();

		// 高さを求める
//		double h = sideB * Math.sin(angleC);
//		// 面積を求める
//		double area = sideB * h / 2;
//		System.out.println(h);
//		System.out.println(area);

		// 角度をラジアンで指定
		double radianC = Math.toRadians(angleC);

//		double area = sideA * sideB / 2;
		double sideC = Math.sqrt(Math.pow(sideA, 2) + Math.pow(sideB, 2) - 2 * sideA * sideB * Math.cos(radianC));
//		System.out.println(area);
		double length = sideA + sideB + sideC;
		// ヘロンの公式を使って面積を計算
//		double area = length / 2;
		double area = 0.5 * sideA * sideB * Math.sin(radianC);
		System.out.println(area);
		System.out.println(length);
//		double height = sideB;
		// b*sinCを求めるためにbとa
		double height = sideB * Math.sin(radianC);
		System.out.println(height);

		sc.close();

	}

}


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

int main()
{

int K , A , B , n;

cin >> K >> A >> B ;

n=(B/K);

n=n*K;

if(n>=A){
cout << "OK" << endl;}
else{
cout << "NG"<< endl;
}



return 0;
}


Measured memory_bytes: 3636
# import bisect
from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, m  = list(map(int,ipti().split()))
    ctr = Counter(list(map(int,ipti().split())))

    for i in range(m):
        b, c = list(map(int,ipti().split()))
        ctr[c] += b

    ctr_list = list(ctr.items())
    ctr_list.sort(key=itemgetter(0), reverse=True)

    rem = n
    ans = 0
    l = len(ctr_list)

    for i in range(l):
        num = ctr_list[i][0]
        count = ctr_list[i][1]
        if count >= rem:
            ans += num * rem
            print(ans)
            sys.exit()
        else:
            ans += num * count
            rem -= count

    print(ctr_list)

if __name__ == '__main__':
    main()

Measured memory_bytes: 91544
n = int(input())
a = list(map(int, input().split()))
l = [0]*(10**5+1)
all_sum = sum(a)
for i in a:
    l[i] += 1
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    cnt = l[b]
    l[c] += cnt 
    all_sum += cnt * (c-b)
    l[b] = 0
    print(all_sum)


Measured memory_bytes: 84368
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a = I()
b = I()
c = I()
d = I()
e = I()
lst = [a,b,c,d,e]
ans = inf
for i in permutations(range(5)):
    time = 0
    for j in i:
        if time % 10 == 0:
            time += lst[j]
        else:
            time += (10 - time % 10)
            time += lst[j]
    ans = min(ans,time)
print(ans)

Measured memory_bytes: 38384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    x = II()
    if x < 1200:
        return 'ABC'
    return 'ARC'

print(main())


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

int main(){
    int n; cin >> n;
    vector <int> a(n);
    rep(i, n) cin >> a.at(i);
    vector <int> cnt(n + 1, -1);
    cnt.at(1) = 0;
    int now = 1;
    while(cnt.at(2) == -1){
        int next = a.at(now - 1);
        if(cnt.at(next) != -1){
            cout << -1 << endl;
            return 0;
        }
        cnt.at(next) = cnt.at(now) + 1;
        now = next;
    }
    cout << cnt.at(2) << endl;
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define ll long long
#define eb emplace_back
#define all(c) (c).begin(), (c).end()
#define vi vector<int>


int op(int a, int b) { return max(a, b); }

int e() { return -1; }

int v;

bool f(int x) { return x < v; }

int main() {
	int n, q, x, ans;
	int t, l, r;
	cin >> n >> q;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		a.eb(x);
	}

	segtree<int, op, e> seg(a);

	for (int i = 0; i < q; i++) {
		cin >> t;
		if (t == 1) {
			cin >> x >> v;
			x--;
			seg.set(x, v);
		}
		else if (t == 2) {
			cin >> l >> r;
			l--;
			ans = seg.prod(l, r);
			cout << ans << endl;
		}
		else if (t == 3) {
			cin >> x >> v;
			x--;
			ans = seg.max_right<f>(x) + 1;
			cout << ans << endl;
		}
	}
}


Measured memory_bytes: 6236
#include <bits/stdc++.h>
#define REP(i, x, y) for(int i = (int)x; i <= (int)y; i ++)
#define FOR(i, x, y) for(int i = (int)x; i <  (int)y; i ++)
#define PER(i, x, y) for(int i = (int)x; i >= (int)y; i --)
#define fi first
#define se second
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long LL;
const	int N = 200005;
const	int P = 1e9 + 7;

int n, X[N], V[N], id[N], A[N], B[N];

int cmp(const int &a, const int &b){
	return X[a] < X[b];
}

int sum[N << 2], Sum[N << 2];
int qx, ql, qr, qv;
bool qf;
void Add(int x, int L, int R){
	if(L == R){
		Sum[x] += qv;
		return;
	}
	int md = (L + R) >> 1;
	if(qx <= md) Add(x + x, L, md);
	else Add(x + x + 1, md + 1, R);
	Sum[x] = Sum[x + x] + Sum[x + x + 1];
}

void S(int x, int L, int R){
	if(qf) return;
	if(ql <= L && R <= qr){
		qf |= bool(Sum[x]);
		return;
	}
	int md = (L + R) >> 1;
	if(ql <= md) S(x + x, L, md);
	if(md <  qr) S(x + x + 1, md + 1, R);
}

void add(int x, int val){
	qx = x, qv = val;
	Add(1, 1, n);
}

int check(int l, int r){
	if(l > r) return 1;
	int P = A[l - 1] , Q = B[r + 1];
	if(P > Q) return 1;
	ql = P, qr = Q, qf = 0;
	S(1, 1, n);
	return !qf;
}

int Val[N];



int main(){
	scanf("%d", &n);
	REP(i, 1, n) scanf("%d%d", X + i, V + i);
	REP(i, 1, n) Val[i] = V[i];
	sort(Val + 1, Val + n + 1);
	REP(i, 1, n) V[i] = lower_bound(Val + 1, Val + n + 1, V[i]) - Val;
	REP(i, 1, n) id[i] = i;
	sort(id + 1, id + n + 1, cmp);
	REP(i, 1, n){
		int u = id[i];
		A[i] = max(A[i - 1], V[u]);
	}
	B[n + 1] = 1 << 30;
	PER(i, n, 1){
		int u = id[i];
		B[i] = min(B[i + 1], V[u]);
	}
	int x = n + 1;
	B[n + 1] = n;
	sum[x] = 1;
	PER(i, n, 0){
		if(i < n)
			add(V[id[i + 1]], 1);
		while(!check(i + 1, x - 1)){
			add(V[id[x - 1]], -1);
			x --;
		}
		int tmp = (sum[i + 1] - sum[x + 1] + P) % P;
		if(!i){
			printf("%d\n", tmp);
			return 0;
		}
		sum[i] = (sum[i + 1] + tmp) % P;
	}
	return 0;
}


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

int main() {
  int D;
  cin >> D;
  
  if (D == 25) {
    cout << "Christmas" << endl;
  } else if (D == 24) {
    cout << "Christmas Eve" << endl;
  } else if (D == 23) {
    cout << "Christmas Eve Eve" << endl;
  } else if (D == 22) {
    cout << "Christmas Eve Eve Eve" << endl;
  } 
        
}

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

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false);
	ll x;
	cin >> x;
	ll y = (x / 11) * 2;
	if(x % 11 > 0){ ++y; }
	if(x % 11 > 6){ ++y; }
	cout << y << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*

fun shuffle(cards: String, h: Int)= cards.drop(h) + cards.take(h)

fun shuffle(cards: String, vararg h: Int): String =
    if (h.isEmpty()) cards else
        shuffle(shuffle(cards, h.first()), *h.drop(1).toIntArray())

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val answers = mutableListOf<String>()
    while (true) {
        val cards = scanner.next()
        if (cards == "-") {
            break
        }
        val m = scanner.nextInt()
        val list = mutableListOf<Int>()
        (1..m).forEach {
            list.add(scanner.nextInt())
        }
        answers.add(shuffle(cards, *list.toIntArray()))
    }
    answers.forEach { println(it) }
}



Measured memory_bytes: 34584
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  vi a(3);
  rep(i,3)cin >>a[i];
  sort(rng(a));
  if(a[0]+a[1]!= a[2])cout<<"No"<<endl;
  else cout<<"Yes"<<endl; 
  return 0;
}

Measured memory_bytes: 256
(N,),X,(M,K),A=$<.map{|l|l.split.map &:to_i};*s=(t=*0..N-2,0);A.map{|a|t[a+1],t[a]=t[a-=2,2]};99.times{|i|K[i]>0&&s.map!{|b|t[b]};t=t.map{|b|t[b]}};x,=X;N.times{|i|p x;x+=X[1+r=s[i]]-X[r]}

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

int main() {

  int N,K, sum=0;
  cin >> N >> K;
  
  vector<int> vec(N);
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }

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

  for (int i=0; i<K; i++){
    sum += vec.at(i);
  }
  cout << sum << endl;  
}

Measured memory_bytes: 256
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n,a,b=parseMap(split(readline()))
    println(ifelse((b-a)%2==0,"Alice","Borys"))
end
main()

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

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

/* solve */

int main(){
    ll a,b;
    cin >> a >> b;
    if(a*b%2==1){
        cout << "Yes";
    }else
        cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	int w,angle;
	double x=0.0,y=0.0, prev_angle=90.0;
	while( (scanf("%d,%d",&w,&angle)) != EOF){
		if(w==0 && angle==0) break;
		double radian_angle = prev_angle * M_PI / 180.0;
		x += w*cos(radian_angle);
		y += w*sin(radian_angle);
		
		prev_angle -= (double)angle;
	}
	printf("%d\n%d\n",(int)x,(int)y);
	return 0;
}

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

int main(){
  int a,b,c,d;
  cin>>a>>b;
  c=1000000000;
  vector<vector<int>> av(a,vector<int>(2));
  vector<vector<int>> bv(b,vector<int>(2));
  for(int i=0;i<a;i++)
    cin>>av.at(i).at(0)>>av.at(i).at(1);
  for(int i=0;i<b;i++)
    cin>>bv.at(i).at(0)>>bv.at(i).at(1);
  for(int i=0;i<a;i++){
    c=1000000000;
    for(int j=0;j<b;j++){
      if(c>abs(av.at(i).at(0)-bv.at(j).at(0))+abs(av.at(i).at(1)-bv.at(j).at(1))){
        c=abs(av.at(i).at(0)-bv.at(j).at(0))+abs(av.at(i).at(1)-bv.at(j).at(1));
        d=j+1;
      }
      if(j==b-1)
        cout<<d<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;
ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

std::vector<int> Eratosthenes( const int N )
{
  std::vector<bool> is_prime( N + 1, true );
  std::vector<int> P;
  for( int i = 2; i <= N; i++ ){
    if( is_prime[ i ] ){
      for( int j = 2 * i; j <= N; j += i ){
          is_prime[ j ] = false;
      }
      if( (i & 1) && is_prime[(i + 1) / 2] ){
        P.emplace_back( i );
      }
    }
  }
  return P;
}

int main(){
  int q;
  cin >> q;
  vector<int> l(q);
  vector<int> r(q);
  rep(i, q) cin >> l[i] >> r[i];

  vector<int> sieve = Eratosthenes(1e5);
  vector<int> ans;
  for(int i = 0; i < q; ++i){
    auto ritr = upper_bound(sieve.begin(), sieve.end(), r[i]);
    auto litr = lower_bound(sieve.begin(), sieve.end(), l[i]);
    ans.push_back((int)(ritr - litr));
  }
  for(auto itr : ans){
    cout << itr << endl;
  }
  return 0;
}

Measured memory_bytes: 1932
#include<bits/stdc++.h>
 
using namespace std;
#define ll  long long
#define ld  long double
 
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN=1e5 + 5;
int main() {
int n;
cin>>n;
vector<int> v;
int sum=0;
 
while(n--)
{
 int a;
 cin>>a;
 v.push_back(a);
 sum+=a;
}
sort(v.begin(),v.end());
if (sum%10!=0){
    cout<<sum<<endl;
    return 0;
}
for(int i=0;i<(int)v.size();i++)
{
    if(v[i]%10!=0)
    return cout<<sum-v[i],0;
    
}
cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
fact = factorization(n)

ans = 0
for i in fact:
    if i[1] > 2:
        tmp = 1
        while True:
            i[1] -= tmp
            tmp += 1
            if i[1] < 0:
                break
            ans += 1
    else:
        ans += 1

if n == 1:
    ans = 0
    
print(ans)

Measured memory_bytes: 9524
n = int(input())
steps = list(map(int,input().split()))
dp = []

def frog(list,n,max):
    global dp
    if n == 0:
        dp.append(0)
    else:
        temp1 = abs(list[n] - list[n-1]) + dp[n-1]

        if n == 1:
            dp.append(temp1)
        else:
            temp2 = abs(list[n] - list[n-2]) + dp[n-2]
            if temp1 >= temp2:
                dp.append(temp2)
            else:
                dp.append(temp1)
for i in range(n):
    frog(steps,i,n)
print(dp[n-1])


Measured memory_bytes: 13980
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 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; }

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int a,b;
  cin >> a >> b;

  cout << (a<9&&b<9 ? "Yay!" : ":(");
  return 0;
} 

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod = 7 + 1e9;
string s; int d , dp[10000][100][2];
int f( int i = 0 , int sum = 0 , bool pp=0 )
{
    if( i == s.size() )
        if( sum == 0 )
            return 1;
        else
            return 0;
    int &dp = :: dp[i][sum][pp];
    if( dp != -1 )
        return dp;
    dp = 0;
    if( pp )
    {
        for(char c = '0';c<s[i];++c)
        {
            dp+= f(i+1,(sum+c-'0')%d)%mod;
            dp%=mod;
        }
        dp+= f(i+1,(sum+s[i]-'0')%d,1)%mod;
        dp%=mod;
    }
    else
        for(int c=0;c<=9;++c)
        {
            dp+= f(i+1,(sum+c)%d)%mod;
            dp%=mod;
        }
    return dp%=mod;
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin >> s >> d;
    int ans = f(0,0,1)-1;
    cout << ( ans == -1 ? 1000000006 : ans );
}

Measured memory_bytes: 8832
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto n = readln.chomp.to!size_t;

  auto cards = new bool[](52);
  foreach (_; 0..n) {
    auto c = readln.chomp;
    cards[cardStoI(c)] = true;
  }

  foreach (int i, c; cards)
    if (!c) writeln(cardItoS(i));
}

int cardStoI(string s)
{
  auto rd = s.split;
  auto suite = rd[0], rank = rd[1].to!int;
  return suiteStoI(suite) * 13 + rank - 1;
}

string cardItoS(int s)
{
  return suiteItoS(s / 13) ~ " " ~ (s % 13 + 1).to!string;
}

const auto suites = ["S", "H", "C", "D"];

int suiteStoI(string s)
{
  return suites.countUntil!(a => a == s).to!int;
}

string suiteItoS(int s)
{
  return suites[s];
}

Measured memory_bytes: 2440
while line = gets do
  h, w = line.split.map(&:to_i)
  if h == 0 && w == 0 then break end
  h.times do |i|
    w.times do  |j|
      if i == 0 || i== h -1 || j == 0 || j == w - 1
        print "#"
      else 
        print "."
      end
    end
    print "\n"
  end
  print "\n"
end

Measured memory_bytes: 8888
import java.io.PrintWriter

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val  (n, p) = readLongList()
    val prime = primeFactor(p)
    var ans = 1L
    for (e in prime) {
        var tmp = 1L
        for (i in 0 until (e.value / n)) {
            tmp *= e.key
        }
        ans *= tmp
    }
    println(ans)
}

/**
O(n^(1/2)) // n * n <= Long.MAX_VALUE n <= 10^8 or more
if n == 1, return emptyMap
 */
fun primeFactor(n: Long): Map<Long, Long> {
    val factorMap = mutableMapOf<Long, Long>()
    var target = n
    var i = 2L
    while (i * i <= target) {
        while (target % i == 0L) {
            factorMap[i] = factorMap.getOrElse(i) { 0L } + 1L
            target /= i
        }
        i++
    }

    if (target != 1L) { factorMap[target] = 1 }
    return factorMap
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 36556
#include <cstdio>
#include <utility>
#include <vector>
#include <complex>
#include <cmath>

using namespace std;

static const double EPS=1e-12;
static const double INF=1e24;

using Point=complex<double>;
using Plane=vector<Point>;

bool operator<(const Point &a, const Point &b) {
    return real(a)!=real(b)? real(a)<real(b) : imag(a)<imag(b);
}

double cross_prod(const Point &a, const Point &b) {
    return imag(conj(a)*b);
}

double dot_prod(const Point &a, const Point &b) {
    return real(conj(a)*b);
}

struct Line: public vector<Point> {
    Line() {}
    Line(const Point &a, const Point &b) {
        push_back(a);
        push_back(b);
    }
};

struct Circle {
    Point p;
    double r;
    Circle() {}
    Circle(const Point &p, const double r): p(p), r(r) {}
};

enum {
    CROSSES,
    ORTHOGONAL,
    PARALLEL,
};

int rel_lines(const Line &l, const Line &m) {
    if (abs(dot_prod(l[1]-l[0], m[1]-m[0])) < EPS) {
        return ORTHOGONAL;
    } else if (abs(cross_prod(l[1]-l[0], m[1]-m[0])) < EPS) {
        return PARALLEL;
    } else {
        return CROSSES;
    }
}

int main() {
    size_t q;
    scanf("%zu", &q);
    for (size_t i=0; i<q; ++i) {
        double x, y;
        scanf("%lf %lf", &x, &y);
        Point p0(x, y);

        scanf("%lf %lf", &x, &y);
        Point p1(x, y);

        scanf("%lf %lf", &x, &y);
        Point p2(x, y);

        scanf("%lf %lf", &x, &y);
        Point p3(x, y);

        Line l(p0, p1), m(p2, p3);
        printf("%d\n", rel_lines(l, m));
    }

    return 0;
}

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

int main() {
    int a, b, t;
    char op;
    while (1) {
        cin >> a >> op >> b;
        if (op == '+') t = a + b;
        else if (op == '-') t = a - b;
        else if (op == '*') t = a * b;
        else if (op == '/') t = a / b;
        else if (op == '?') break;
        cout << t << "\n";
    }
    return 0;
}

Measured memory_bytes: 3096
use std::io::{BufRead};

fn get_stdin(numlines:usize)->Vec<Vec<String>>{
    let mut ret:Vec<Vec<String>> = vec![];
    let stdin = std::io::stdin();
    for (ii,line) in stdin.lock().lines().enumerate() {
        let s:String = line.unwrap().trim_right().to_owned();
        if s.len() > 0{
            let vvec:Vec<String> = s.split_whitespace().map(|m|m.to_string()).collect();
            ret.push(vvec);
        }
        if ii+1 == numlines{
            break;
        }
    }
    return ret;
}

fn main() {
    let vvec:Vec<Vec<i64>> = get_stdin(2).iter().map(|m|m.iter().map(|m|m.parse::<i64>().unwrap()).collect()).collect();
    let mut ret:i64 = 0;
    for i in 0..vvec[1].len(){
        for j in (i+1)..vvec[1].len(){
       		//println!("{} {} ",vvec[1][i],vvec[1][j]);
            ret += vvec[1][i]*vvec[1][j];
        }
    }
    println!("{}",ret);
}


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

int main () {
    int n, x, y;
    cin >> n >> x >> y;

    vector<int> ans(n, 0);

    for (int i=1; i<=n; i++) {
        for (int j=i+1; j<=n; j++) {

            int d = j-i;
            d = min(d, abs(i-x)+1+abs(j-y));
            d = min(d, abs(i-y)+1+abs(j-x));

            ans[d]++;
        }
    }

    for (int i=1; i<n; i++) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 256
// Problem : B - Fennec vs Monster
// Contest : Virtual Judge - atcoders
// URL : https://vjudge.net/contest/390808#problem/B
// Memory Limit : 1048 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n,k;
	cin>>n>>k;
	vi a(n);
	loop(i,n)
	cin>>a[i];
	sort(all(a),greater<int>());

	ll ans=0;
	l00p(i,min(k,n),n)
	{
		ans+=a[i];
	}
	cout<<ans<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3964
#include <iostream>
#include <cmath>

using namespace std;

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

    int min_digit = 10 ^6;
    for (int i = 1; i <= sqrt(n); ++i) {
        if ((n % i) != 0) {
            continue;
        }
        long long int j = n / i;
        int max_digit = max(to_string(i).length(), to_string(j).length());
        min_digit = min(min_digit, max_digit);
    }

    cout << min_digit << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

const ll mod = 998244353;
ll fac[maxn],inv[maxn],ans,tot,pow2[maxn];
int n,k;

inline ll power(ll x,ll y){
	ll res = 1;
	while ( y ){
		if ( y & 1 ) res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
inline ll C(int n,int m){
	if ( n < m ) return 0;
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
void init(){
	fac[0] = inv[0] = pow2[0] = 1;
	rep(i,1,4000){
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = power(fac[i],mod - 2);
		pow2[i] = pow2[i - 1] * 2 % mod;
	}
	tot = C(n + k - 1,k - 1);
}

int main(){
	scanf("%d %d",&k,&n);
	init();
	rep(i,2,2 * k){
		ans = 0;
		if ( i & 1 ){
			int a = (min(i - 1,k) - max(1,i - k) + 1) / 2,b = k - a * 2;
		//	cout<<i<<" "<<a<<" "<<b<<endl;
			ll res = 0;
			rep(j,0,a){
				res = (res + C(a,j) * C(n + b - 1,a + b - j - 1) % mod * pow2[a - j]) % mod;
			}
			ans = (ans + res) % mod;
		}
		else{
			int a = (min(i - 1,k) - max(1,i - k) + 1) / 2,b = k - a * 2 - 1;
		//	cout<<i<<" "<<a<<" "<<b<<endl;
			ll res = 0;
			rep(j,0,a){
				res = (res + C(a,j) * (C(n + b - 1,a + b - j - 1) + C(n + b - 2,a + b - j - 1)) % mod * pow2[a - j]) % mod;
			}
				ans = (ans + res) % mod;
		}
		printf("%lld\n",ans);
	}
}



Measured memory_bytes: 384
n, m = map(int, input().split())
py = []
mli = [0]*n
li = [""]*m

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

py.sort(key=lambda x: x[1])

for p,y,i in py:
    mli[p-1] += 1
    pi = str(p).zfill(6)
    yi = str(mli[p-1]).zfill(6)
    li[i] = pi+yi

for i in li:
    print(i)

Measured memory_bytes: 32176
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PGC
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var S = Console.ReadLine().Split().Select(int.Parse).ToArray();

			var q = int.Parse(Console.ReadLine());
			var T = Console.ReadLine().Split().Select(int.Parse).ToArray();

			var set = new HashSet<int>(S);
			System.Console.WriteLine(T.Where(t => set.Contains(t)).Count());
		}
	}
}



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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    int s=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s^=a[i];
    }
    for(int i=0;i<n;i++){
        int ans=s^a[i];
        cout<<ans<<endl;
    }
}

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

using namespace std;

using ll = long long;

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

    int x, y, z;
    cin >> x >> y >> z;

    int n = x / (y + z);
    if (z <= x - n * (y + z)) cout << n << endl;
    else cout << n - 1 << endl;

    return 0;
}
 


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a;
  string s;
  cin >> a;
  cin >> s;
  if (a >= 3200) {
    cout << s << endl;
  } else {
    cout << "red" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#define ll long long
using namespace std;

int main() 
{
    ll k, a = 100, b, t = 0;
    cin >> k;

    while(a < k) {
        a = (ll)(a * 1.01);
        t++;
    }

    cout << t << endl;
}

Measured memory_bytes: 3632
<?php
fscanf(STDIN, "%d", $t);
for ($j = 0; $j < $t; $j++) {
    $list = explode(" ",trim(fgets(STDIN)));
    $a = 0;
    $b = 0;
     for ($i = 0; $i < 10; $i++) {
        if($list[$i] > $a) {
            $a = $list[$i];
        } else if($list[$i] > $b) {
            $b = $list[$i];
        } else {
            break;
        }
     }
    echo $i === 10 ? 'YES' : 'NO';
    echo PHP_EOL;
}

 
// fscanf(STDIN, '%d', $n);
// for ($count = 0; $count < $n; $count++) {
//     $a = explode(' ', trim(fgets(STDIN)));
//     $b = 0;
//     $c = 0;
//     for ($i = 0; $i < 10; $i++) {
//         if ($a[$i] > $b) {
//             $b = $a[$i];
//         } elseif ($a[$i] > $c) {
//             $c = $a[$i];
//         } else {
//             break;
//         }
//     }
 
//     echo $i === 10 ? 'YES' : 'NO';
//     echo PHP_EOL;
// }


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

using namespace std;

int n,a,i,j,k,cnta[55][2505],cntb[55][2505],val[55];

void solve(int id, int lim, int pick, int now, int (&A)[55][2505]){
	if(id == lim){
		A[pick][now]++;
		return;
	}
	solve(id + 1, lim, pick + 1, now + val[id], A);
	solve(id + 1, lim, pick, now, A);
}

int main(){
	
	scanf("%d%d", &n, &a);
	for(i = 0; i < n; i++)
	scanf("%d", &val[i]);
	
	int mid = n / 2;
	solve(0, mid, 0, 0, cnta);
	solve(mid, n, 0, 0, cntb);
	
	long long ans = 0;
	
	for(i = 0; i <= mid; i++){
		for(j = 0; j <= 2500; j++){
			for(k = i; k <= n; k++){
				long long target = k * a - j;
				if(target < 0) continue;
				if(k == 0) continue;
				ans += (long long)cnta[i][j] * cntb[k - i][target];
			}
		}
	}
	
	printf("%lld\n", ans);
}


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

int main()
{
    int n;
    scanf("%d", &n);
    ll K;
    scanf("%lld", &K);
    int q;
    scanf("%d", &q);
    map<int, int> a;
    for (int i=0; i<q; i++)
    {
        int player;
        scanf("%d", &player);
        a[player]++;
    }

    for (int i=1; i<=n; i++)
    {
        if (K - q  + a[i] <= 0) printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 5376
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

typedef struct{
  short x,y;
  int cost;
  short ch;
}mouse;

short maxch[1000][1000];
char ku[1000][1000];
mouse t;
short cx,cy,nx,ny,ch,nch,h,w,n;
int cost;

main(){
  scanf("%d%d%d",&h,&w,&n);

  rep(i,h)scanf("%s",ku[i]);


  rep(i,h)rep(j,w){
    if(ku[i][j]=='S')cx=i,cy=j;
    maxch[i][j]=-1;
  }

  queue<mouse> Q;

  Q.push((mouse){cx,cy,0,0});
  maxch[cx][cy]=0;

  while(!Q.empty()){
    //cout<<Q.size()<<endl;
    t=Q.front();Q.pop();
    cx=t.x,cy=t.y,cost=t.cost;
    ch=t.ch;

    rep(i,4){
      nx=cx+dx[i],ny=cy+dy[i];
      if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
	 if(ku[nx][ny]=='X')continue;
	 nch=ch;
	 if(ku[nx][ny]<='9' && ku[nx][ny]>='1' && ku[nx][ny]-'0'==t.ch+1){
	   nch=ch+1;
	 }

	 if(maxch[nx][ny]>=nch)continue;
	 if(nch==n){
	   printf("%d\n",cost+1);
	   return 0;
	 }
	 maxch[nx][ny]=nch;
	 Q.push((mouse){nx,ny,cost+1,nch});
    }
  }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   ll n;cin >>n;
   vector<ll>a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    sort(all(a));
    cout <<a[n-1]-a[0]<<endl;
   return 0;
}

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

int main()
{
  int a,b,c,d;
  string s;
  cin>>s;
  a=s[0]-'0';
  b=s[1]-'0';
  c=s[2]-'0';
  d=s[3]-'0';


  if(a+b+c+d==7)
    printf("%d+%d+%d+%d=7",a,b,c,d);
  else if(a+b+c-d==7)
    printf("%d+%d+%d-%d=7",a,b,c,d);
  else if(a+b-c+d==7)
    printf("%d+%d-%d+%d=7",a,b,c,d);
  else if(a-b+c+d==7)
    printf("%d-%d+%d+%d=7",a,b,c,d);
  else if(a+b-c-d==7)
    printf("%d+%d-%d-%d=7",a,b,c,d);
  else if(a-b+c-d==7)
    printf("%d-%d+%d-%d=7",a,b,c,d);
  else if(a-b-c+d==7)
    printf("%d-%d-%d+%d=7",a,b,c,d);
  else if(a-b-c-d==7)
    printf("%d-%d-%d-%d=7",a,b,c,d);

    cout<<endl;


  //main();


}





Measured memory_bytes: 384
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll A, B;
    cin >> A >> B;

    if(B%A==0){
        p(A+B);
    }else{
        p(B-A);
    }
    
    return 0;
}

Measured memory_bytes: 256