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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int count=0;
    bool flag=true;
    for(int i = 0; i < n; i++) {
        while(flag){
            if(a[i]%2==0){
                count++;
                a[i]/=2;
            }
            else flag=false;
        }
        flag=true;
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    int A[100010]={0};
    for(int i=1;i<=n;i++) cin>>A[i];
    int a=0;
    for(int i=0;i<=n;i++){
        a+=max(A[i]-A[i+1],A[i+1]-A[i]);
    }
    for(int i=1;i<=n;i++){
        int b=a;
        if(A[i-1]<A[i]&&A[i]>A[i+1]){
            b=b-2*(A[i]-max(A[i-1],A[i+1]));
        }
        if(A[i-1]>A[i]&&A[i]<A[i+1]){
            b=b-2*(min(A[i-1],A[i+1])-A[i]);
        }
        cout<<b<<endl;
    }
}

Measured memory_bytes: 1664
n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))

def dfs(N, M, i, f):
    if i == len(N):
        print(*M, sep='')
        exit()
    if f:
        dfs(N, M + [D[0]], i+1, 1)
    for d in D:
        if d == N[i]:
            dfs(N, M+[d], i+1, 0)
        elif d > N[i]:
            dfs(N, M+[d], i+1, 1)
            break
    if D[0] == 0:
        dfs(N, [D[1], D[0]], 1, 1)
    else:
        dfs(N, [D[0], D[0]], 1, 1)

dfs(N, [], 0, 0)

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

int main() {
	long long n;
	cin >> n;
	long long sum = 0;
	vector<long long>l;
	for (long long i = 0; i < n; i++){
		long long a;
		cin >> a;
		l.push_back(a);
	}
	sort(l.begin(), l.end());
	long long q = l.front();
	for (long long i = 1; i < n; i++){
		if (l[i] == q)sum++;
		else q = l[i];
	}
	if (sum % 2 == 1)sum++;
	cout << n - sum << endl;
	return 0;
}

Measured memory_bytes: 1400
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

//二叉搜索树插入操作的实现

struct Node {
    int key;
    Node *p, *l, *r;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->l = NIL;
    z->r = NIL;

/*    if ( x == NIL ) {
        cout << "yes" << endl;
    }
*/

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->l;
        } else {
            x = x->r;
        }
    }

    z->p = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->l = z;
        } else {
            y->r = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->l);
    cout << " " << u->key;
    inorder(u->r);
}

void preorder(Node *u) {
    if (u == NIL) return;
    cout << " " << u->key;
    preorder(u->l);
    preorder(u->r);
}

int main() {
    int n, k;
    cin  >> n;
    string com;
    for (int i = 0; i < n; i++) {
        cin >> com;
        if ( com == "insert" ) {
            cin >> k;
            insert(k);
        } else if ( com == "print" ) {
            inorder(root);
            cout << "\n";
            preorder(root);
            cout << "\n";
        }

    }

    return 0;
}



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

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

  int c = b / k ;

  if( a <= c * k && c * k <= b ) {
    cout << "OK" << endl ;
  }else {
    cout << "NG" << endl ;
  }
  
  return 0 ;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<vector<int>> data(2, vector<int>(100));
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> data.at(i).at(j);
    }
  }
  int result = 0;
  for (int i = 0; i < N; i++) {
    int total = 0;
    for (int j = 0; j <= i; j++) {
      total += data.at(0).at(j);
    }
    for (int j = i; j < N; j++) {
      total += data.at(1).at(j);
    }
    if (total > result) {
      result = total;
    }
  }
  
  cout << result << endl;
      
  return 0;
}

Measured memory_bytes: 3636
#15:35
h,w = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
mod = 10 ** 9 + 7
now = [1 for _ in range(w+1)]
for i in range(h):
  last = now
  now = [1]
  for j in range(w):
    if a[i] == b[j]:
      now.append((last[j+1]+now[-1])%mod)
    else:
      now.append((last[j+1]+now[-1]-last[j])%mod)
  #print(now)
print(now[-1])

Measured memory_bytes: 42588
#include <iostream>

using namespace std;


void selection_sort(char seq[100][2], int length) {
  char temp;
  int mini;
  for (int i = 0; i < length - 1; i ++) {
    mini = i;
    for (int j = i + 1; j < length; j ++) {
      if (seq[j][1] < seq[mini][1]) {
        mini = j;
      }
    }
    if (mini != i) {
      for (int j = 0; j < 2; j ++) {
        temp = seq[i][j];
        seq[i][j] = seq[mini][j];
        seq[mini][j] = temp;
      }
    }
  }
}


void buble_sort(char seq[100][2], int length) {
  char temp;
  for (int i = 0; i < length; i ++) {
    for (int j = length - 1; j > i; j --) {
      if (seq[j][1] < seq[j-1][1]) {
        for (int k = 0; k < 2; k ++) {
          temp = seq[j][k];
          seq[j][k] = seq[j-1][k];
          seq[j-1][k] = temp;
        }
      }
    }
  }
}


int main(){
  int N, count;
  char seq[100][2];
  char seq2[100][2];
  bool flag = true;
  cin >> N;
  for (int i = 0; i < N; i ++) {
    cin >> seq[i];
    seq2[i][0] = seq[i][0];
    seq2[i][1] = seq[i][1];
  }
  selection_sort(seq, N);
  buble_sort(seq2, N);

  for (int k = 0; k < N; k ++)
    cout << seq2[k][0] << seq2[k][1] << ((k == N-1) ? "" : " ");
  cout << endl << "Stable" << endl;


  for (int k = 0; k < N; k ++) {
    cout << seq[k][0] << seq[k][1] << ((k == N-1) ? "" : " ");
    if (seq2[k][0] != seq[k][0]) flag = false;
  }
  cout << endl;
  if (flag)
    cout  << "Stable" << endl;
  else
    cout  << "Not stable" << endl;

}



Measured memory_bytes: 3100
from bisect import bisect
import sys

n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())

#r[i][j]: jから(2**i)日で行ける右端
r = [[i for i in range(n)] for _ in range(18)]
for j in range(n):
	r[0][j] = bisect(x, x[j]+l) - 1
for i in range(1, 18):
	for j in range(n):
		r[i][j] = r[i-1][r[i-1][j]]

def search(x, y):
	res = 0
	cur = x
	i = 17
	while True:
		if i == 0 and r[i][cur] >= y:
			return res+1
		if r[i][cur] < y:
			cur = r[i][cur]
			res += 1 << i
			continue
		i -= 1

for _ in range(q):
	a, b = map(int, sys.stdin.readline().strip().split())
	print(search(min(a, b)-1, max(a, b)-1))

Measured memory_bytes: 78940
#include <stdio.h>

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

Measured memory_bytes: 128
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
   string s; cin>>s;
   int count=00;
   if(s[0]=='R'){
       count++;
       if(s[1]=='R'){
           count++;
           if(s[2]=='R'){
               count++;
           }
       }
   }
    else {
           if(s[1]=='R'){
               count++;
              if(s[2]=='R')count++;
           }
           else{
               if(s[2]=='R') count++;;
           }
       }
   cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main(void){
	int x,y,tmp;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0)break;
		if(x>y){
			tmp=x;
			x=y;
			y=tmp;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 600
#!/usr/bin/env python
n = int(input())
s = input()
ans = float('inf')
E_total = s.count('E')
W_total = s.count('W')
cnt = {'E': 0, 'W': 0}
for i in range(n):
    turn = cnt['W'] + (E_total - cnt['E'])
    if s[i] == 'E':
        turn -= 1
    ans = min(ans, turn)
    cnt[s[i]] += 1
print(ans)


Measured memory_bytes: 3700
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    l=[]
    for i in range(n):
        ans=sum(l1[:i+1])+sum(l2[i:])
        l.append(ans)
    print(max(l))
resolve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define MAX_V 100005

using namespace std;
typedef long long ll;

const int mod = 1e9 + 7;

int cannot_setfoot[MAX_V];
int dp[MAX_V];
int n, m;

int backtrack(int i)
{
    if (i > n)
        return 0;
    else if (i == n)
        return 1; 
    else if (cannot_setfoot[i])
        return 0;
    else if (dp[i] != -1)
        return dp[i];
    return (dp[i] = (backtrack(i+1) + backtrack(i+2)) % mod);
}

int main()
{
    FAST_IO;
    cin >> n >> m;
    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < m; i++) {
        int x;
        cin >> x;
        cannot_setfoot[x] = 1;
    }
    cout << backtrack(0) << endl;
    return 0;
}

Measured memory_bytes: 4096
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    a, b, c, d = list(map(int, input().rstrip('\n').split()))
    cd = b // c - (a - 1) // c
    dd = b // d - (a - 1) // d
    gcd = c * d // fractions.gcd(c, d)
    gcdd = b // gcd - (a - 1) // gcd
    print(b - a + 1 - cd - dd + gcdd)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 63980
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int, input().split())
uni = UnionFind(N)

for _ in range(M):
    a,b = map(int, input().split())
    uni.union(a-1,b-1)

print(uni.group_count()-1)


Measured memory_bytes: 12936
#include <stdio.h>
int main(void)
{
  char a[128], b[128], c[128], ch;
  int i;
  char *p;
  scanf("%s %s %s", a, b, c);
  for(i=0; a[i]!='\0'; ++i){
    ch=a[i];
  }
  if(ch != b[0]){
    p="NO";
  } else {
    for(i=0; b[i]!='\0'; ++i){
      ch=b[i];
    }
    if(ch != c[0]){
      p="NO";
    } else {
      p="YES";
    }
  }
  printf("%s\n", p);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int A, B;
    cin >> A >> B;
    FOR(X, 1, 10001) {
        if (8 * X / 100 == A && 10 * X / 100 == B) {
            cout << X << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
};

Measured memory_bytes: 256
package main

import "fmt"

func abs(a int) int {
	if a > 0 {
		return a
	}
	return (-1) * a
}

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)

	if abs(x-a) < abs(x-b) {
		fmt.Println("A")
	} else {
		fmt.Println("B")
	}
}


Measured memory_bytes: 1768
// At Corder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <algorithm>
#include <iostream>
using namespace std;
#include <vector>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using p = pair<int, int>;//<key,value>
#include <math.h>
int main()
{
ll x;


cin>>x;
for (int a= -1000; a < 1000; ++a)
	for (int b= -1000; b < 1000; ++b){

if(pow(a,5)-pow(b,5)==x)
	{cout<<a<<" "<<b<<endl;
return 0;}
}

	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント:
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 4024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define vv vector
#define ff first
#define ss second
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
typedef pair<ll,ll> pll;
typedef vv<ll> vll;
// #define dbg

int main(){
	fastio;
	ll n,k;
	cin>>k>>n;
	ll a[n];
	for(ll i=0; i<n; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	ll mx = -1;
	for(ll i=0; i<n-1; i++){
		mx = max(mx, abs(a[(i+1)] - a[i]));
	}
	mx = max(mx, (a[0] + k- a[n-1]));
	cout<<k - mx;
}

Measured memory_bytes: 1792
#!/usr/local/bin/ruby
rec,dia=0,0
while line=gets
  arr=line.split(",").map(&:to_i)
  a=arr[0].to_i
  b=arr[1].to_i
  c=arr[2].to_i
  if a==b
    dia+=1
  elsif a**2+b**2==c**2
    rec+=1
  end
end
puts "#{rec}"
puts "#{dia}"

Measured memory_bytes: 6104
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n + 1];
		for (int i = 0; i < n + 1; i++) {
			a[i] = sc.nextInt();
		}
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			b[i] = sc.nextInt();
		}
		long sum = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] < b[i]) {
				sum += a[i] + Math.min(a[i + 1], b[i] - a[i]);
				a[i + 1] = Math.max(0, a[i + 1] - (b[i] - a[i]));
			} else {
				sum += b[i];
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 65600
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,X,a;cin>>N>>M>>X;
  vector<int>A(M);
  for(int i=0;i<M;i++)cin>>A.at(i);
  a=upper_bound(A.begin(),A.end(),X)-A.begin();
  cout<<min(a,M-a)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>

typedef struct {
	char mark;
	int number;
} card;

card L[50002] = {0};
card R[50002] = {0};

void showM(card A[], int n) {
	int i;
	for(i = 0; i < n; ++i) {
		printf("%c %d\n", A[i].mark, A[i].number);
	}
	return;
}

int partition(card A[], int p, int r) {
	int x, i, j;
	card tmp;
	x = A[r].number;
	i = p - 1;

	for (j = p; j < r; ++j) {
		if (A[j].number <= x) {
			++i;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	tmp = A[i+1];
	A[i+1] = A[r];
	A[r] = tmp;
	return i + 1;
}

void quicksort(card A[], int p, int r) {
	int q;
	if (p < r) {
		q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q+1, r);
	}
}

void Merge(card A[], int left, int mid, int right) {
	int n1, n2;
	int i, j, k;
	n1 = mid - left;
	n2 = right - mid;
//	printf("A\n");
//	showM(A,right);
	for (i = 0; i < n1; ++i) {
		L[i] = A[left + i];
	}
	for (i = 0; i < n2; ++i) {
		R[i] = A[mid + i];
	}
	/* printf("L\n"); */
	/* showM(L, n1); */
	/* printf("R\n"); */
	/* showM(R, n2); */
	L[n1].number = INT_MAX;
	R[n2].number = INT_MAX;
	i = 0;
	j = 0;
	
	for (k = left; k < right; ++k) {
		if (L[i].number <= R[j].number) {
			A[k] = L[i];
			++i;
		} else {
			A[k] = R[j];
			++j;
		}
	}
	return;
}

void MergeSort(card A[], int left, int right) {
	int mid;
//	showM(A, right);
	if (left + 1 < right) {
		mid = (left + right) / 2;
		MergeSort(A, left, mid);
		MergeSort(A, mid, right);
		Merge(A, left, mid, right);
	}
	return;
}

int main(void) {
	int i, n;
	int flag = 0;
	card A[100000] = {0};
	card B[100000] = {0};
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf(" %c %d", &A[i].mark, &A[i].number);
		B[i] = A[i];
	}

	
	quicksort(A, 0, n-1);
	MergeSort(B, 0, n);
	
	for (i = 0; i < n; ++i) {
		if (A[i].mark != B[i].mark) {
			flag = 1;
			break;
		}
	}
	if (flag) {
		printf("Not stable\n");
	} else {
		printf("Stable\n");
	}
	
	for (i = 0; i < n; ++i) {
		printf("%c %d\n", A[i].mark, A[i].number);
	}
	return 0;
}

Measured memory_bytes: 2960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);


int main()
{
	int n,i,ans=0;
	sc(n);
	vector<int>v(100001,0);
	rep(i,n)
	{
		int m;
		sc(m);
		v[m]++;
	}
	rep1(i,100000)
	{
		int t=0;
		t+=v[i-1];
		t+=v[i];
		t+=v[i+1];
		ans=max(ans,t);
	}
	cout << ans << endl;
	return 0;
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

long long gcd(long long m, long long n) {
    return n != 0 ? gcd(n, m % n) : m;
}

int main() {
    ll n, x;
    cin >> n >> x;
    ll y = n - x;
    ll t = n;
    ll q, r;
    while (x > 0 && y > 0) {
        if (x > y) {
            q = x / y;
            r = x % y;
        } else {
            q = y / x;
            r = y % x;
        }
        t += min(x, y) * 2 * q;
        if (r == 0) {
            t -= min(x, y);
        }
        if (x > y) {
            x = y;
            y = r;
        } else {
            y = x;
            x = r;
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

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

	int ans = 0;
	for (int i = 1; i <= n; i += 2) {
		int num = 0;
		for (int j = 1; j <= i; j++) {
			if (i % j == 0) {
				num++;
			}
		}
		if (num == 8) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
K=int(input())
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[K-1])

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

int main () {
    int n, check_n, max_n = 0, count, max_count = 0; cin >> n;
    for (int i = 1; i <= n; i++) {
        check_n = i; count = 0;
        while (check_n > 0) {
            check_n /= 2;
            count++;
        }
        if (count > max_count) {
            max_n = i;
            max_count = count;
        }
    }
    cout << max_n << endl;
    return 0;
}

Measured memory_bytes: 256
def f(n):
    return n // 2 if n % 2 == 0 else n * 3 + 1
    
s = int(input())

count = 1
while True:
    if s == 1 or s == 2 or s == 4:
        print(count + 3)
        break
    else:
        s = f(s)
    count += 1


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

int main(void){
    int A, B, C, K;
    
    cin >> A >> B >> C;
    cin >> K;
    
    for (int i = 0; i < K; i++){
        if (A >= B) B *= 2;
        else if (B >= C) C *= 2;
        else break;
    }
    
    if(A < B && B < C) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	string S;
	cin >> S;
	int i;
	int A = 0;
	//01010101ver.
	for (i = 0; i < S.size(); i++) {
		if (i % 2 == 0 && S.at(i) !='0'){
			A++;
		}
		else if (i % 2 == 1 && S.at(i) != '1'){
			A++;
		}
	}
	int B = 0;
	//10101010ver.
	for (i = 0; i < S.size(); i++) {
		if (i % 2 == 0 && S.at(i) != '1'){
			B++;
		}
		else if (i % 2 == 1 && S.at(i) != '0') {
			B++;
		}
	}
	cout << min(A, B);
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,m;
map<int,int> mp1;
map<int,int> mp2;

int main() {
    cin >> n;
    vector<int> d(n);
    REP(i,n){
        cin >> d[i];
    }
    cin >> m;
    vector<int> t(m);
    REP(i,m){
        cin >> t[i];
    }
    //map<int,int> m;
    REP(i,n){
        auto itr = mp1.find(d[i]);
        if(itr==mp1.end()){
            mp1[d[i]]=1;
        }else{
            mp1[d[i]]++;
        }
    }
    REP(i,m){
        auto itr = mp2.find(t[i]);
        if(itr==mp2.end()){
            mp2[t[i]]=1;
        }else{
            mp2[t[i]]++;
        }
    }
    REP(i,m){
        auto itr = mp1.find(t[i]);
        if(itr==mp1.end()){
            put("NO");
            return 0;
        }else{
            if(mp1[t[i]]==0){
                put("NO");
                return 0;
            }else{
                mp1[t[i]]--;
            }
        }
    }
    put("YES");
    return 0;
}


Measured memory_bytes: 20608
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

int g[N];

signed main(){
    IOS;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        g[i] = a;
    }
    int slow = 1, fast = 1;
    do {
        slow = g[slow];
        fast = g[g[fast]];
    } while (slow != fast);
    int extra = 0;
    fast = 1;
    while (fast != slow) {
        fast = g[fast];
        slow = g[slow];
        extra++;
    }
    int len = 0;
    int start = slow;
    do {
        slow = g[slow];
        len++;
    } while (slow != fast);
    if (k <= extra) {
        start = 1;
        while (k--) {
            start = g[start];
        }
        cout << start << endl;
    }
    else {
        k -= extra;
        k %= len;
        while (k--) {
            start = g[start];
        }
        cout << start << endl;
    }
    return 0;
}

Measured memory_bytes: 5216
#include "bits/stdc++.h"
using namespace std;
 
#define nl '\n'
#define ll long long 
#define ull unsigned long long
#define debug(x)       { cerr << #x << " = " << x << endl; } 
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
 
const int Max = (int)2e5+5;
 
//functions
ll lcm(ll a,ll b) {if(a==0 || b==0){return 0;}else{return (a*b)/__gcd(a,b);}}
 
//direction arry
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
//____________________________________________________________________________________________________
void solve()
{
    int n;
    cin>>n;
    ll sum = 0;
    for(int i=1;i<=n;i++)      
    {
        if((i%3==0 && i%5==0))
            continue;
        if(i%3==0)
            continue;
        if(i%5==0)
            continue;
        sum+=i; 
    }
    cout<<sum<<endl;
}
int main()
{
    fastread;
    int tc=1;
    // cin>>tc;
    while(tc--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
// typedef pair<int,int> P;
const int MAX = 1000000;
int n;
vector<int> a(MAX);

int main(){
    int n;
    cin >> n;
    // ll ans=0;
    vector<int> a(n+1),t(n+1,-1);
    rrep(i,n){
        cin >> a[i];
        if(i*2>n){
            t[i] = a[i];
        }
    }
    for(int i = n;i>0;i--){
        // int k = 2;
        // if(t[i]!=-1)continue;
        int s =0;
        // while(i*k<n){
        //     s+=t[i*k];
        //     ++k;
        // }
        for(int j = i*2;j<=n;j+=i){
            s^=t[j];
        }
        t[i] = s^a[i];
    }
    // rrep(i,n){
    //     ans+=t[i];
    // }
    // cout << ans << endl;
    // rrep(i,n)if(t[i])cout << i <<endl;
    // return 0;

    vector<int> ans;
    rrep(i,n)if(t[i])ans.push_back(i);
    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        printf("%d%c",ans[i],i+1==ans.size()?'\n':' ');
    }
    return 0;

}

Measured memory_bytes: 7032
#include<stdio.h>
#include<string.h>
//20000桁のマージソート(1単語10文字以下)
char c[101][101];
int sort(int a,int b,char s[][101]){
  if(a==b)
    return 0;
  sort(a,(a+b)/2,s);
  sort((a+b)/2+1,b,s);
  int i=a,j=(a+b)/2+1,k=a;
  while(k<=b){
    if(i<(a+b)/2+1 && j<b+1){
      if(strcmp(s[i],s[j])<0){
        strcpy(c[k],s[i]);
        i++;
      }
      else{
        strcpy(c[k],s[j]);
        j++;
      }
    }
    else if(j>b){
      strcpy(c[k],s[i]);
      i++;
    }
    else{
      strcpy(c[k],s[j]);
      j++;
    }
    k++;
  }
  for(i=a;i<=b;i++)
    strcpy(s[i],c[i]);
  return 0;
}

int main(){
  int n,l,i;
  scanf("%d%d",&n,&l);
  char s[n][101];
  for(i=0;i<n;i++)
    scanf("%*c%s",s[i]);
  sort(0,n-1,s);
  for(i=0;i<n;i++)
    printf("%s",s[i]);
  puts("");
  return 0;
}

Measured memory_bytes: 1696
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define i_inf int(1e9)
#define i_half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 1000000007;

const int max_n = i_half_inf;
ll n, a[max_n], b[max_n];

void solve() {
    ll ans = 0, n_add = 0;
    repr(i, n) {
        a[i] += n_add;
        ll temp = a[i] % b[i] == 0 ? 0 : b[i] - a[i] % b[i];
        n_add += temp, ans += temp;
    }
    cout << ans << endl;
}

int main() {
    cin >> n;
    rep(i, n) cin >> a[i] >> b[i];
    solve();
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
ostream& operator << (ostream& out, vector<int>& v) {
	for (auto& x: v) out << x << ' ';
	return out;
}

ostream& operator << (ostream& out, pii& v) {
	out << v.fi << ", " << v.se;
	return out;
}

istream& operator >> (istream& in, pii& a) {
	in >> a.fi >> a.se;
	return in;
}

const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

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



signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	vector<int> goo (n);
	cinv (goo);
	auto moo = goo;
	sort (all (moo));
	int ans = 0;
	fr (i, n) {
		auto it = lower_bound (all (moo), goo[i]) - moo.begin ();
		ans += i % 2 != it % 2;
	}
	cout << (ans + 1) / 2 << '\n';







}

Measured memory_bytes: 4796
import java.util.Scanner;


public class Main {


    static void solve() {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        if(Character.isLowerCase(s.charAt(0))) {
            System.out.println('a');
        }else{
            System.out.println('A');
        }
//        for (int i = 0; i < t; i++) {
//            int a = scan.nextInt();
//            scase();
//        }
    }


//    static void solveCase(int t, int x, String s) {
//
//    }

    static void scase() {

    }


    public static void main(String[] args) {

        solve();
        //        Main m = new Main();
        //        Scanner scan = new Scanner(System.in);

        //        long n = scan.nextLong();
        //        long r = scan.nextLong();
        //        List<Long> list = new ArrayList<>();
        ////        int[] arr = new int[n];
        //        for (long i=0;i<n;i++){
        //            list.add(scan.nextLong());
        //        }
//            System.out.println(ch);
        //        solve(n, arr);
        //        scan.close();
    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }


//    static class TreeNode {
//        int val;
//        TreeNode left;
//        TreeNode right;
//
//        TreeNode(int x) {
//            val = x;
//        }
//    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

}

Measured memory_bytes: 26980
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int h = Integer.parseInt(sc.next());
    int a = Integer.parseInt(sc.next());
    pw.println(
      h / a + (h % a == 0 ? 0 : 1)
    );
  }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    char W[1500]={0};
    int i;
    scanf("%[^\n]",W);
    for(i=0;i<strlen(W);i++){
        if(W[i]=='p'&&W[i+1]=='e'&&W[i+2]=='a'&&W[i+3]=='c'&&W[i+4]=='h'){W[i]='a';W[i+1]='p';W[i+2]='p';W[i+3]='l';W[i+4]='e';}
        else if(W[i]=='a'&&W[i+1]=='p'&&W[i+2]=='p'&&W[i+3]=='l'&&W[i+4]=='e'){W[i]='p';W[i+1]='e';W[i+2]='a';W[i+3]='c';W[i+4]='h';}
    }
    for(int j=0;j<i;j++){
        cout<<W[j];
    }
    puts("");
    return 0;
}

Measured memory_bytes: 1108
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll;
typedef double db;
const int maxn = 45000 + 5;
const int mod = 1e9 + 7;

int a[4], b[4];

int main(){
    for(int i = 1; i <= 3; i++)
        cin >> a[i] >> b[i];
    int p, q;
    int flag = 0;
    for(int i = 1; i <= 3; i++){
        for(int j = 1; j <= 3; j++){
            if(a[i] != a[j] && a[i] != b[j] && b[i] != a[j] && b[i] != b[j]){
                p = i;
                q = j;
                flag = 1;
                break;
            }
        }
    }
    if(!flag){
        printf("NO\n");
        return 0;
    }
    int k;
    for(int i = 1; i <= 3; i++)
        if(i != p && i != q) k = i;
    if(a[k] == a[p] || a[k] == b[p]){
        if(b[k] == a[q] || b[k] == b[q]){
            printf("YES\n");
        }
        else printf("NO\n");
    }
    else if(a[k] == a[q] || a[k] == b[q]){
        if(b[k] == a[p] || b[k] == b[p]){
            printf("YES\n");
        }
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, k) = scan!(usize, usize);
    let hs = scan!(i64;;);

    let mut dp = vec![0; n];
    dp[0] = 0;
    for i in 1..dp.len() {
        dp[i] = (1..k + 1)
            .map(|j| {
                if i >= j {
                    dp[i - j] + (hs[i] - hs[i - j]).abs()
                } else {
                    1 << 60
                }
            })
            .min()
            .unwrap()
    }
    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 6396
#include <iostream>
#include <vector>
using namespace std;
 
class Dice{
public:
    long r[6];
    Dice(){};
    void roll(long a, long b, long c, long d){swap(r[a], r[b]);swap(r[b], r[c]);swap(r[c], r[d]);}
    void spin(char c){if (c == 'W') roll(0, 2, 5, 3); else roll(0, 1, 5, 4);}
};

bool check(Dice d1, Dice d2){
    int ans = 6;
    for (int i = 0; i < 6; i++) if (d1.r[i] == d2.r[i]) ans--;
    if (ans) return 0; else return 1;
}
 
int main(){
    char SWS[8]={"NNNWNNN"};
    int n;
    cin >> n;
    vector<Dice> D(n);
    for (int i = 0; i < n ; i++) for (int j = 0; j < 6; j++) cin >> D[i].r[j];
    for (int i = 0; i < n - 1; i++){
        for (int j = i + 1; j < n; j++){
            for (int k = 0; k < 8; k++){
                if (D[i].r[1] == D[j].r[1]) break;
                D[j].spin(SWS[k]);
            }
            for (int k = 0; k < 4; k++){
                int ans = 0;
                for (int l = 0; l < 6; l++) if (D[i].r[l] == D[j].r[l]) ans++;
                if (ans == 6){cout << "No" << endl; return 0;}
                D[j].spin('W');
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

int main(){
	int n;
	llong d;
	cin>>n>>d;
	d=d*d;
	
	int ans=0;
	REP(i,n){
		llong x,y;
		cin>>x>>y;
		if(x*x+y*y<=d) ans++;
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

const int SIZE=100005;
const int INF=100000005;

vector<int> mp[SIZE];
int id[SIZE],L[SIZE],R[SIZE];
bool ok=true;

void solve(int v,int p){
    if(id[v]==-1){
        L[v]=-INF;
        R[v]=INF;
    }
    else{
        L[v]=R[v]=id[v];
    }
    for(int i=0;i<mp[v].size();i++){
        int to=mp[v][i];
        if(to==p) continue;
        solve(to,v);
        if(L[to]<-INF/2) continue;
        if(!(L[v]<-INF/2)){
            if(L[to]%2==L[v]%2){
                ok=false;
                return;
            }
        }
        L[v]=max(L[to]-1,L[v]);
        R[v]=min(R[to]+1,R[v]);
        if(L[v]>R[v]){
            ok=false;
            return;
        }
    }
}

void make(int v,int p){
    for(int i=0;i<mp[v].size();i++){
        int to=mp[v][i];
        if(to==p) continue;
        if(id[to]==-1){
            if(L[to]<=id[v]+1 && id[v]+1<=R[to]) id[to]=id[v]+1; else id[to]=id[v]-1;
        }
        make(to,v);
    }
}

int main(){
    int n,k;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        a--;
        b--;
        mp[a].push_back(b);
        mp[b].push_back(a);
        id[i]=-1;
    }
    id[n-1]=-1;
    scanf("%d",&k);
    for(int i=0;i<k;i++){
        int v,p;
        scanf("%d%d",&v,&p);
        v--;
        id[v]=p;
    }
    solve(0,-1);
    if(!ok) puts("No");
    else{
        puts("Yes");
        id[0]=L[0];
        make(0,-1);
        for(int i=0;i<n;i++) printf("%d\n",id[i]);
    }
    return 0;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    ll n;
    cin>>n;
    cout<<1000*(n/500) + 5*((n%500)/5);
    return 0;
}



Measured memory_bytes: 256
my $s = <STDIN>;
chomp $s;
my ($n, $a, $b) = split ' ', $s;
if ($a == 0) {
    print "0\n";
}
else {
    my $c = $a + $b;
    my $div = int($n / $c);
    my $res = $n - $div * $c;
    my $ans = $div * $a;
    $ans += ($res > $a) ? $a : $res;
    print "$ans\n";
}

Measured memory_bytes: 512
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections
import numpy

H, W, K = map(int, sys.stdin.readline().rstrip().split(" "))
gamemap = numpy.array([
    list(map(lambda s: s == "#", sys.stdin.readline().rstrip()))
    for _ in range(H)
])

strawberry_index = 0
result = []
for line in gamemap:
    resultline = []
    strawberrys = numpy.where(line)[0]
    current_pos = -1
    for i, pos in enumerate(strawberrys):
        strawberry_index += 1
        for _ in range(pos-current_pos):
            resultline.append(strawberry_index)
        current_pos = pos
        if i == (len(strawberrys)-1):
            for _ in range(W-current_pos-1):
                resultline.append(strawberry_index)
    result.append(resultline)

fillline = [x for x in result if len(x) > 0][0]
for i, line in enumerate(result):
    if len(line) > 0:
        assert len(line) == W
        fillline = line
    print(" ".join(map(str, fillline)))

has_strawberry = gamemap.any(axis=1)
exit(0)


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


def inpl():
    return list(map(int, input().split()))


def main():
    N, K = inpl()
    P = sorted(inpl())
    print(sum(P[:K]))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

string x;
int main(){
	cin >> x;
	stack<char> st;
	rep(i,0,x.size()){
		char c = x[i];
		if(st.size() == 0 )
			st.push(c);
		else if( st.top() == 'S' && c == 'T' )
			st.pop();
		else{
			st.push(c);
		}
	}

	P(st.size());

	ret 0;
}

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

int dp[1001][1001];

int lcs(string x, string y)
{
	fill(dp[0], dp[0] + x.length() * y.length(), 0);
	for (int i = 0; i < x.length(); ++i)
	{
		for (int j = 0; j < y.length(); ++j)
		{
			if (x[i] == y[j])dp[i + 1][j + 1] = dp[i][j] + 1;
			else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
		}
	}
	return dp[x.length()][y.length()];
}

int main()
{
	string s1, s2;
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> s1 >> s2;
		cout << lcs(s1, s2) << endl;
	}
	return 0;
}


Measured memory_bytes: 7088
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()


int main(){
  int n,x; cin >> n >> x;
  if(x == 1 || x == 2*n-1){
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  if(n == 2){
    rep(i,3) cout << i+1 << endl;
    return 0;
  }

  vi ans(2*n-1,-1);
  vector<bool> used(2*n,false);
  if(x > 2){
    ans[n-2] = 1;
    used[1] = true;
    ans[n-1] = x;
    used[x] = true;
    ans[n] = x+1;
    used[x+1] = true;
    ans[n+1] = 2;
    used[2] = true;
  }
  else{
    ans[n-2] = x+2;
    used[x+2] = true;
    ans[n-1] = x;
    used[x] = true;
    ans[n] = x-1;
    used[x-1] = true;
    ans[n+1] = x+1;
    used[x+1] = true;
  }

  int num = 1;
  rep(i,2*n-1) {
    if(ans[i] != -1) continue;
    while(used[num]) num++;
    ans[i] = num;
    used[num] = true;
  }

  rep(i,2*n-1) cout << ans[i] << endl;

}

Measured memory_bytes: 2304
s=input()
t=input()
ans=999999
def check(x,y):
    ret=0
    for i in range(len(x)):
        if x[i]!=y[i]:
            ret+=1
    return ret
for i in range(len(s)-len(t)+1):
    ans=min(check(s[i:i+len(t)],t),ans)
print(ans)


Measured memory_bytes: 9116
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(b<c){
			printf("Yes\n");
		}else {
			printf("No\n");
		}
	}else {
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580