akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>

using namespace std;


#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int h,w,ch,cw,dh,dw;
    cin >> h >> w >> ch >> cw >> dh >> dw;
    ch--; cw--; dh--; dw--;
    int dist[h][w];
    char s[h][w];
    const int INF = 1000000000;
    rep(i,h) rep(j,w){
        dist[i][j] = INF;
        cin >> s[i][j];
    }
    deque<P> que;
    dist[ch][cw] = 0;
    que.emplace_front(P(ch,cw));
    while(!que.empty()){
        int y = que.front().first;
        int x = que.front().second;
        que.pop_front();
        int d = dist[y][x];
        rep(i,4){
            int yi = y + my4[i];
            int xi = x + mx4[i];
            if(yi < 0 || xi < 0 || xi >= w || yi >= h) continue;
            if(dist[yi][xi] <= d) continue;
            if(s[yi][xi] == '#') continue;
            dist[yi][xi] = d;
            que.emplace_front(P(yi,xi));
        }
        for(int i = -2; i <= 2; ++i){
            for(int j = -2; j <= 2; ++j){
                int yi = y + i;
                int xi = x + j;
                if(yi < 0 || xi < 0 || yi >= h || xi >= w) continue;
                if(dist[yi][xi] <= d+1) continue;
                if(s[yi][xi] == '#') continue;
                dist[yi][xi] = d+1;
                que.emplace_back(P(yi,xi));
            }
        }
    }
    int ans = dist[dh][dw];
    if(dist[dh][dw] == INF) ans = -1;
    cout << ans << endl;
}



Measured memory_bytes: 8492
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int k = in.nextInt();
        in.nextLine();
        final int[] array = Arrays.stream(in.nextLine().split(" "))
                                  .mapToInt(Integer::parseInt)
                                  .sorted()
                                  .toArray();
        int p = 0;
        for (int i = 0; i < k; i++) {
            p += array[i];
        }
        System.out.println(p);
    }
}


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

#define loop(i,a,b) for(int i = a ; i< b ; i ++)

int main(void){
  int d;
  while(cin>>d){
    long long int sum =0;
    loop(i,1,600/d)
      sum+=i*i*d*d*d;
    cout<<sum<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll N, K, S;
    cin >> N >> K >> S;
    rep(i, K) {
        cout << S << " ";
    }
    if (S == 1000000000) {
        rep(i, N-K) {
            cout << 1 << " ";
        }
    } else {
        rep(i, N-K) {
            cout << S+1 << " ";
        }
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


class Player():

    A = 0
    B = 1
    C = 2

    def __init__(self, data, op_list):
        self.data = data
        self.op_list = op_list
        self.move_history = ["X"] * len(self.op_list)
        self.key = 0
        self.ans = "Yes" # "Yes" or "No"
        self.flg_out = False
        self.flg_foresight = False
        s = sum(data)
        if s == 2:
            self.flg_foresight = True
        elif s == 0:
            self.ans = "No"
            self.flg_out = True

    def has_next_op(self):
        if self.key + 1 < len(self.op_list):
            return True
        else:
            return False

    def play(self):
        for key, op in enumerate(op_list):
            #print('self.data') # debug
            #print(self.data) # debug
            if self.flg_out:
                break
            self.key = key
            self.read_op(op)

    def read_op(self, op):
        if op == "AB":
            self.do(self.A, self.B)
        if op == "AC":
            self.do(self.A, self.C)
        if op == "BC":
            self.do(self.B, self.C)

    def do(self, x, y):
        if self.data[x] < self.data[y]:
            self.move(y, x)
        elif self.data[x] > self.data[y]:
            self.move(x, y)
        else: # same
            if self.flg_foresight:
                if self.is_next_used(x):
                    self.move(y, x)
                else:
                    self.move(x, y)
            else:
                self.move(x, y) # which is ok

    def move(self, frm, to):
        self.move_history[self.key] = self.num_to_char(to)
        self.data[frm] -= 1
        self.data[to] += 1
        if self.data[frm] < 0:
            self.ans = "No"
            self.flg_out = True

    @staticmethod
    def num_to_char(z):
        chars = ['A', 'B', 'C']
        return chars[z]

    def is_next_used(self, z):
        if not self.has_next_op():
            return False
        next_op = self.op_list[self.key + 1]
        if self.num_to_char(z) in next_op:
            return True
        else:
            return False

    def print_ans(self):
        print(self.ans)
        if self.ans == "No":
            return
        for h in self.move_history:
            print(h)




if __name__ == '__main__':
    n, a, b, c = list(map(int, input().split()))
    data = [a, b, c]
    #print('data') # debug
    #print(data) # debug
    op_list = [""] * n
    for i in range(n):
        op_list[i] = input()
    #print('op_list') # debug
    #print(op_list) # debug

    p = Player(data, op_list)
    p.play()
    p.print_ans()


    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 78140
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;


/*void printvec(vector<int> v) {
	int a = v.size();
	for (int i = 0; i < a; i++) {
		printf("%d ", v[i]);
	}
	printf("\n");
}*/
int mae(int a) {
	int b=a;
	while (b >= 10) {
		b /= 10;
	}
	return b;
}

int ushiro(int a) {
	return a % 10;
}

int keta(int a) {
	int b=0,c=a;
	while (c) {
		c /= 10;
		b++;
	}
	return b;
}

int rui(int a, int b) {//a^b=c
	int c=1;
	for (int i = 0; i < b; i++) {
		c *= a;
	}
	return c;
}

int keshi(int a) {
	int b=a,c=mae(a)*(rui(10,keta(a)-1));
	b -= c;
	return b;
}

int val(int i, int N) {
	int f = mae(i), b = ushiro(i),count=0;
	int k = keta(N);
	if (b < mae(N) && b) {
		for (int j = 0; j < k; j++)
			count += rui(10, j)/10;
	}
	if (b > mae(N)) {
		for (int j = 0; j < k - 1; j++)
			count += rui(10, j)/10;
	}
	if (b == mae(N)) {
		for (int j = 0; j < k - 1; j++)
			count += rui(10, j)/10;
		//cout << "count=" << count;
		count += keshi(N) / 10 +(f <= ushiro(N));
		//cout << " keshi=" << keshi(N) << " ";
	}
	count += f==b;
	return count;
}

int main(){
	int N,count=0,d=0;
	cin >> N;
	
	for (int i = 1; i <= N; i++) {
		d = val(i, N);
		if (d) {
			//cout << "i=" << i << " d=" <<d<< endl;
		}
		count += d;
		d = 0;
	}
	count -= !(N / 10);
	cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<double> x(n),y(n);
  rep(i,n) cin >> x[i] >> y[i];

  vector<int> v;
  rep(i,n){
    v.push_back(i);
  }

  double cnt=0;
  double sum=0;
  do{
    double tmp=0;
    rep(i,n-1){
      tmp += sqrt((x[v[i]]-x[v[i+1]])*(x[v[i]]-x[v[i+1]])+(y[v[i]]-y[v[i+1]])*(y[v[i]]-y[v[i+1]]));
    }
    sum += tmp;
    cnt++;
  }while(next_permutation(v.begin(), v.end()));

  sum /= cnt;

  printf("%.7f\n", sum);
  
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import heapq
n,m,s,t = map(int, input().split())
e = [[] for _ in range(n+1)]
for _ in range(m):
    v,u,a,b = map(int, input().split())
    e[v].append((u,(a,b)))
    e[u].append((v,(a,b)))


inf = 10**18
def dijkstra(s,cu):
    d = [inf]*(n+1)
    d[s] = 0

    q = [(d[s],s)]
    heapq.heapify([q])
    while len(q)>0:
        _,v = heapq.heappop(q)
        for u,ud in e[v]:
            if d[v]+ud[cu]>=d[u]:
                continue
            d[u] = d[v] + ud[cu]
            heapq.heappush(q, (d[u],u))
    return d


da = dijkstra(s,0)
db = dijkstra(t,1)
res = [0]*n
res[n-1] = da[n]+db[n]
for i in range(n-2,-1,-1):
    res[i] = min(res[i+1], da[i+1]+db[i+1])

for r in res:
    print(10**15 - r)

Measured memory_bytes: 68824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n)     for (ll i = 0; i < (n); ++i)
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)  (x).begin(), (x).end()    //昇順
#define rall(x) (x).rbegin(), (x).rend()  //降順
#define yes     out("Yes");
#define no      out("No");

int main() {
    in(n);
    vector<bool> d(n);
    rep(i, n) {
        in(x);
        in(y);
        if (x == y) {
            d[i] = true;
        } else {
            d[i] = false;
        }
    }
    rep(i, n - 2) {
        if (d[i] && d[i + 1] && d[i + 2]) {
            yes;
            return 0;
        }
    }
    no;
}

Measured memory_bytes: 3624
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if max(L[i],L[j],L[k]) < L[i]+L[j]+L[k]-max(L[i],L[j],L[k]) and L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
                ans += 1
print(ans)

Measured memory_bytes: 9160
# include "cmath"
# include "queue"
# include "cstdio"
# include "cstring"
# include "iostream"
# include "algorithm"
# define Maxn 100
# define fi first
# define se second
# define P pair<int,int>
# define rep(i,x,y) for(int i=x;i<=y;i++)
# define rep_d(i,x,y) for(int i=x;i>=y;i--)
# define rep_t(u) for(int i=head[u];i;i=f[i].next)
using namespace std;
typedef long long ll;
inline int read()
{
	int ok=1,k=0;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
		ok=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		k=k*10+c-'0';
		c=getchar();
	}
	return ok*k;
}
char s[Maxn],ss[Maxn];
int main()
{
	scanf("%s %s",s,ss);
	int n=strlen(s)-1,ans=0;
	rep(i,0,n)
	if(s[i]==ss[i])
	ans++;
	cout<<ans<<endl;
	return 0;
}


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

int main()
{
    double a,b,c,d;
    cin>>a>>b>>c>>d; // health and strength
    if(ceil(a/d)<ceil(c/b))
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3684
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')
# ----------------------------------------------------------- #

n = I()
A = LI()
absmin = INF
minus = 0
for a in A:
    absmin = min(absmin, abs(a))
    if a < 0:
        minus += 1

ans = sum([abs(a) for a in A])
if minus % 2 == 0:
    print(ans)
else:
    print(ans - absmin*2)


Measured memory_bytes: 89708
def gcd(x,y):
    if x>y:
        x,y=y,x
    if y%x==0:
        return x

    return gcd(x,y%x)

def lcm(x,y):
    return (x*y)//(gcd(x,y))

A,B,C,D=list(map(int,input().strip().split(' ')))

ans1=(A-1)//C+(A-1)//D-(A-1)//(lcm(C,D))
ans2=(B)//C+(B)//D-(B)//(lcm(C,D))

ans3=(B-A+1)-(ans2-ans1)
print(ans3)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    set<int> st;
    vi A(n);
    rep(i,n) {
        int a;
        cin >> a;
        A[i] = a;
        st.insert(a);
    }
    if (A.size() == st.size()) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
}



Measured memory_bytes: 10368
/*betaでやろう*/
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <iterator>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = (ll)(1<<30)*10000;
const ll NEGA=-INF*10000; 


ll ans = 0;
int cnt=0;

ll a[200000];
int used[1001];
ll dp[1001][1001];
ll sumx,sumy,sumz;
ll sx,sy,sz;
int main() 
{
  double n,m,d;
  cin>>n>>m>>d;
  double ppap=1;
  if(d) ppap=2;
  cout<<std::fixed;
  cout<< std::setprecision(10)<<((m-1)*ppap/n)*((n-d)/n)<<endl;
}



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

ll n, w;
ll wt[110], val[110];
bool vis[102][100002];
ll dp[102][100002];

ll func( int pos, int weightLeft ) {
  if ( pos > n ) return 0;
  if (vis[pos][weightLeft])  return dp[pos][weightLeft];
  vis[pos][weightLeft] = 1;

  ll x = 0, y = 0;
  if ( weightLeft - wt[pos] >= 0 ) 
    x = val[pos] + func( pos + 1, weightLeft - wt[pos] );
  y = func( pos + 1, weightLeft );

  return dp[pos][weightLeft] = max(x, y);
}


int main() {

  cin >> n >> w;
  for (int i = 1; i <= n; ++i) cin >> wt[i] >> val[i];
  cout << func(1, w) << endl;

  return 0;
}

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

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

    long long res = 0;
    res += 1000 * (x / 500);
    x %= 500;
    res += 5 * (x / 5);

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3584
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> ss(n); cin >> ss;
    vector<int> ts(m); cin >> ts;
    vector<vector<int>> dp(2, vector<int>(m + 1, 1));
    for(int i = 0; i < n; i++){
        int i1 = i & 1, i2 = !i1;
        dp[i2][0] = 1;
        for(int j = 0; j < m; j++){
            int& num = dp[i2][j + 1];
            num = dp[i2][j] + dp[i1][j + 1] - dp[i1][j];
            if(num >= M){
                num -= M;
            }else if(num < 0){
                num += M;
            }
            if(ss[i] == ts[j]){
                num += dp[i1][j];
                if(num >= M){
                    num -= M;
                }
            }
        }
    }
    printde(dp);
    cout << dp[n & 1][m] << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
const ll mod = 1e9+7;
const ll INF = 2e9;
const double PI = 3.1415926535;

int h, w;
int c[10000];
int m[100][100];

int main(void){
    int n; cin >> h >> w >> n;
    int now = 0;
    for(int i = 1;i <= n;i++){
        int a; scanf("%d", &a);
        while(a > 0){
            c[now] = i;
            now++;
            a--;
        }
    }
    for(int i = 0;i < h;i++){
        if(i%2 == 0){
            for(int j = 0;j < w;j++)printf("%d ", c[i*w+j]);
            printf("\n");
        }else{
            for(int j = w-1;j >= 0;j--)printf("%d ", c[i*w+j]);
            printf("\n");
        }
    }

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <map>
#include <utility>

using namespace std;
typedef pair<int, int> facePair;

class Dice{
public:
    Dice(int labels[]);
    void rotate(char);
    void rotate(string);
    void spinClockwise();
    int getTop(){return t;};
    int getFront(){return s;};
    int getRight(){return e;};

private:
    int t, s, e, w, n, b;
    void rotate(int &direction, int &opposite);
};

Dice::Dice(int labels[]){
    t = labels[0];
    s = labels[1];
    e = labels[2];
    w = labels[3];
    n = labels[4];
    b = labels[5];
}

void Dice::rotate(char direction){
    if(direction == 'N') rotate(n, s);
    if(direction == 'E') rotate(e, w);
    if(direction == 'S') rotate(s, n);
    if(direction == 'W') rotate(w, e);
}

void Dice::rotate(int &direction, int &opposite){
    int old = direction;
    direction = t;
    t = opposite;
    opposite = b;
    b = old;
}

void Dice::rotate(string directions){
    for(auto ch : directions) rotate(ch);
}

void Dice::spinClockwise(){
    int old = n;
    n = w;
    w = s;
    s = e;
    e = old;
}

class DiceFaceFinder{
public:
    DiceFaceFinder(Dice &diceref);
    int queryTopFrontToRight(int top, int south);
private:
    map<facePair, int> map_topfront2right;
    Dice &dice;
    void initMap();
};

DiceFaceFinder::DiceFaceFinder(Dice &diceref):dice(diceref){
    initMap();
}

void DiceFaceFinder::initMap(){
    string directions("EEESEE");
    for(auto dir : directions){
        dice.rotate(dir);
        for(int i = 0; i < 4; ++i){
            dice.spinClockwise();
            facePair key (dice.getTop(), dice.getFront());
            map_topfront2right[key] = dice.getRight();
        }
    }
}

int DiceFaceFinder::queryTopFrontToRight(int top, int south){
    facePair key (top, south);
    return map_topfront2right[key];
}


int main(){
    int labels[6] = {};
    for(auto &face : labels){
        cin >> face;
    }
    Dice dice(labels);
    DiceFaceFinder dff(dice);
    int q;
    cin >> q;
    for (auto i = 0; i < q; ++i){
        int top_num, front_num;
        cin >> top_num >> front_num;
        cout << dff.queryTopFrontToRight(top_num, front_num) << endl;
    }
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    set<string> secrets;
    rep(i, 10){
        int pos1 = s.find(to_string(i));
        if(pos1 == string::npos || pos1 > n-3) continue;
        string substr1 = s.substr(pos1+1);
        rep(j, 10){
            int pos2 = substr1.find(to_string(j));
            if(pos2 == string::npos || pos2 > n-2) continue;
            string substr2 = substr1.substr(pos2+1);
            rep(k, 10){
                if(substr2.find(to_string(k)) != string::npos){
                    secrets.insert(to_string(i) + to_string(j) + to_string(k));
                }
            }
        }
    }
    cout << secrets.size() << endl;
}


Measured memory_bytes: 3864
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
const int N=1001;
int f[N+1];
int main()
{
	f[0]=1, f[1]=2;
	REP(i, 2, N+1) f[i] = (f[i-1] + f[i-2]) % N;

	int v, d;
	while (cin >> v >> d) {
		vector<int> a;
		REP(i, 1, v+1) a.push_back(f[i]);
		sort(a.begin(), a.end());
		int k = -1000000;
		int res = 0;
		rep(i, a.size()) {
			if (a[i] - k >= d) res++;
			k = a[i];
		}
		cout << res << endl;
	}

	return 0;
}

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

ullong L = 1000000007;

ullong power(ullong m, ullong n) {
    if (n == 0) {
        return (ullong) 1; 
    }

    ullong res = power(m, n / 2);
    if (n % 2 == 0) {
        res = (res * res) % L;
    } else {
        res = (((res * res) % L) * m) % L;
    }

    return res;
}

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

    cout << power(m, n) << endl;

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define fin(x) cout << x << endl;

using namespace std;
using ll = long long;

int main(void) {
  int n;
  cin >> n;
  if (n < 105) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (int num = 1; num <= n; num++) {
    int tmp = 0;
    if (num % 2 == 0) {
      continue;
    }
    for (int j = 1; j <= num; j++) {
      if (num % j == 0) {
        tmp++;
      }
    }
    if (tmp == 8) {
      ans++;
    }
  }
  cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
  char a[2];
  char b[2];
  cin >> a[0] >> a[1] >> a[2];
  cin >> b[0] >> b[1] >> b[2];
  if (a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    for(int i=0; i<n; ++i)
        cin >> a[i] >> b[i];

    long long ans = 0;
    for(int i=0; i<30; ++i){
        if(i != 0 && !(k & (1 << i)))
            continue;

        int x = k;
        if(i != 0){
            x &= ~((1 << (i+1)) - 1);
            x |= ((1 << i) - 1);
        }
        long long sum = 0;
        for(int j=0; j<n; ++j){
            if(!(a[j] & ~x))
                sum += b[j];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
n,m = map(int,input().split())
mp = [False]*(n+1)
for i in range(m):
    a=int(input())
    mp[a]=True
mod = 10**9 + 7

dp = [[0]*2 for i in range(n+1)]
dp[0][0] = 1

for i in range(0,n):
    if(mp[i]):
        continue
    for j in range(2):
        if(dp[i][j]==0):
            continue
        if(not mp[i+1]):
            dp[i+1][0] += dp[i][j]
            dp[i+1][0] %= mod
        if(i==(n-1)):
            continue
        if(not mp[i+2]):
            dp[i+2][1] += dp[i][j]
            dp[i+2][1] %= mod

ans = (dp[-1][0]+dp[-1][1])%mod

print(ans)

Measured memory_bytes: 24692
# -*- encoding: UTF-8 -*-
a, b = map(int, input().split())

c1 = a + b
c2 = a - b
c3 = a * b

tmp = 0
if c1 > c2 :
  tmp = c1
else :
  tmp = c2
  
if c3 > tmp :
  tmp = c3

print(tmp)

Measured memory_bytes: 3060
n, m = map(int, input().split())
mod = 10**9 + 7
def fact(n, mod=10**9 + 7):
  val = 1
  for i in range(2, n+1):
    val = val * i % mod
  return val

if n == m:
  print(2*fact(n)*fact(m) % mod)
elif n == m+1 or n+1 == m:
  print(fact(n)*fact(m) % mod)
else:
  print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a;
  cin >> N;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      a = 4*i + 7*j;
      if(a == N) {       
        cout << "Yes" << endl;
           goto label;
      }
    }
  }
  cout << "No" << endl;
  label:
  ;
}
  

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
cost = 0
for i in range(n):
    t = cnt = 0
    x = a.index(b[i])
    while x != i:
        y = a.index(b[x])
        a[x], a[y] = b[x], b[i]
        cnt += 1
        t += b[x] + b[i]
        x = y
    if cnt:
        cost += min(t, (b[i] + b[0]) * 2 + t - (b[i] - b[0]) * cnt)
print(cost)


Measured memory_bytes: 5628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    if(N%10 == 3){
        cout << "bon" << enld;
    }else if(N%10 == 0 or N%10 == 1 or N%10 == 6 or N%10 == 8){
        cout << "pon" << enld;
    }else{
        cout << "hon" << enld;
    }
    return 0;
}


Measured memory_bytes: 3592
import sys
stdin = sys.stdin
from collections import deque

 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, q = na()
a, b = [0]*n, [0]*n
G = [[] for i in range(n)]
for i in range(n-1):
        a, b = na()
        G[a-1].append(b-1)
        G[b-1].append(a-1)

counter = [0] * n
for i in range(q):
        p, x = na()
        counter[p-1] += x

visit = [False] * n
visit[0] = True
que = deque([0])

while que:
        parent = que.popleft()
        for child in G[parent]:
                if visit[child]:
                        None
                else:
                        visit[child] = True
                        counter[child] += counter[parent]
                        que.append(child)

print(*counter)

Measured memory_bytes: 64856
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

string angou,zumi;

int main(){
	cin>>angou;
	for(int i=0;i<angou.size();i++){
		if(angou[i]=='A'){angou[i]='X';} 
		else if(angou[i]=='B') {angou[i]='Y';} 
		else if(angou[i]=='C') {angou[i]='Z';}
		else {angou[i]-=3;}
	}
	cout<<angou<<endl; 
	return 0;
}

Measured memory_bytes: 1184
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a - b == b - c)
    {
        cout << "YES" << endl;
    }else
    {
        cout << "NO" << endl;
    }
    
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    string s;
    int k;cin>>s>>k;
    int now=0;
    while(1){
        if(s[now]!='1')break;
        now++;
    }
    if(now>=k)cout<<1<<endl;
    else cout<<s[now]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void AGC038A()
{
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	vector<vector<int> > grid(H, vector<int>(W));
	for (int i = 0; i < B; ++i)
	{
		for (int j = 0; j < A; ++j)
		{
			grid[i][j] = 1;
		}
	}
	for (int i = B; i < H; ++i)
	{
		for (int j = A; j < W; ++j)
		{
			grid[i][j] = 1;
		}
	}

	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
		{
			cout << grid[i][j];
		}
		cout << endl;
	}
	return;

}
int main()
{
	AGC038A();
	return 0;
}

Measured memory_bytes: 5120
n = int(input())
A = list(map(int,input().split()))
A.sort()
t = 0
S = []
k = 0
for i in range(n):
    k += A[i]
    S.append(k)
for i in range(n-1):
    if 2*S[i] < A[i+1]:
        t = i+1
print(n-t)

Measured memory_bytes: 14320
#1, g stock=0. : g       point 0
#2. g stock>0 :  p          +1
#2 p stock=0 : g         -1
#4 p stck>0 : p           0

s = str(input())

point = 0
stock = 0

for i in range(len(s)):
  if s[i] == 'g':
    if stock == 0:
      stock+=1
    elif stock>0:
      stock-=1
      point+=1
  elif s[i] == 'p':
    if stock == 0:
      stock+=1
      point-=1
    elif stock>0:
      stock-=1
print(int(point))

Measured memory_bytes: 3316
a = int(input())
b = ["3","5","7"]
c = []

for i1 in b:
    for i2 in b:
        for i3 in b:
            tmp = i1+i2+i3
            if "3" in tmp and "5" in tmp and "7" in tmp and int(tmp) <= a:
                c.append(tmp)
            for i4 in b:
                tmp = i1+i2+i3+i4
                if "3" in tmp and "5" in tmp and "7" in tmp and int(tmp) <= a:
                    c.append(tmp)
                for i5 in b:
                    tmp = i1+i2+i3+i4+i5
                    if "3" in tmp and "5" in tmp and "7" in tmp and int(tmp) <= a:
                        c.append(tmp)
                    for i6 in b:
                        tmp = i1+i2+i3+i4+i5+i6
                        if "3" in tmp and "5" in tmp and "7" in tmp and int(tmp) <= a:
                            c.append(tmp)
                        for i7 in b:
                            tmp = i1+i2+i3+i4+i5+i6+i7
                            if "3" in tmp and "5" in tmp and "7" in tmp and int(tmp) <= a:
                                c.append(tmp)
                            for i8 in b:
                                tmp = i1+i2+i3+i4+i5+i6+i7+i8
                                if "3" in tmp and "5" in tmp and "7" in tmp and int(tmp) <= a:
                                    c.append(tmp)
                                for i9 in b:
                                    tmp = i1+i2+i3+i4+i5+i6+i7+i8+i9
                                    if "3" in tmp and "5" in tmp and "7" in tmp and int(tmp) <= a:
                                        c.append(tmp)

    
print(len(c))

Measured memory_bytes: 5040
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    
    if(N == 1){
        cout << "Yes" << endl;
        return 0;
    }
    
    int* H = new int[N + 1];
    H[0] = 0;
    for(int i=1; i<=N; i++){
        cin >> H[i];
        if(H[i-1] < H[i]){
            H[i] -= 1;
        }
        
        if(H[i] < H[i-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
	int n; cin >> n;
	int l; cin >> l;
	int sum_taste = 0;
	vector<int> taste_a(n);
	for (int i = 1; i <= n; ++i) {
		taste_a[i - 1] = l + i - 1;
		sum_taste += taste_a[i - 1];
	}
	int diff = 0;
	int min_diff = INF;
	int ans = 0;
	for (unsigned int i = 0; i < taste_a.size(); ++i) {
		int cnt = 0;
		for (unsigned int j = 0; j < taste_a.size(); ++j) {
			if (j != i) {
				cnt += taste_a[j];
			}
		}
		diff = abs(cnt - sum_taste);
		if (diff < min_diff) {
			min_diff = diff;
			ans = cnt;
		}
	}
	cout << ans << endl;
    return;
}

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



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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

typedef bitset<2000005> B;
int main() {
	int N;
	cin >> N;
	B b(1);
	int sum = 0;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		b = b | (b << a);
		sum += a;
	}
	for (int i : range((sum + 1) / 2, sum+1)) {
		if (b[i]) {
			cout << i << endl; return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main(){
  int n = 0;
  scanf("%d\n",&n);
  int a[n];
  int i = 0;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  i = 0;
  int num = 0;
  while(i<n){
    if(a[i]%2==0){
      a[i] = a[i] / 2;
      num++;
    }else{
      i++;
    }
  }
  printf("%d\n",num);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    rep(i, (int)S.length()-1) {
        if (S[i] == S[i+1]) {
            cout << i+1 << " " << i+2 << endl;
            return 0;
        }
    }
    rep(i, (int)S.length()-2) {
        if (S[i] == S[i+2]) {
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;

    return 0;
}


Measured memory_bytes: 512
/****************************************************************
# @Author:      iLovePKU_zbtxdy
# @DateTime:    2020-01-27 10:36:08
# @Description: You build it. You run it
# @More: Once lots of AC, try Brute-force,dynamic programming
****************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define eps 1e-8
typedef long long ll;
const int maxn = 1e6+10;
const int INF = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
string s[maxn];int n , l ;
int main()
{
    cin >> n >> l;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }sort(s , s+n);
    string ans = "";
    for(int i = 0; i < n; i++){
        ans.append(s[i]);
    }cout << ans << endl;
    //system("pause");
}
/***************************************************************************
*stuff you should look for
*int overflow, array bounds
*special cases (n=1?), set tle
*do smth instead of nothing and stay organized
***************************************************************************/

Measured memory_bytes: 8064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 2000;

/* typedef */

/* global variables */

int n, t;
string rng;
double dp[2][MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> t;
    if (n == 0) break;

    cin >> rng;

    double max_p = 0;
    
    int cur = 0, nxt = 1;
    for (int i = 0; i < n; i++) dp[0][i] = (rng[i] == 'R') ? 1 : 0;

    for (int ti = 0; ti < t; ti++) {
      for (int i = 0; i < n; i++) dp[nxt][i] = 0;

      for (int i = 0; i < n; i++) {
	for (int d = 1; d <= 6; d++) {
	  dp[nxt][i] += dp[cur][(i + d) % n] / 6;
	}
      }

      cur ^= 1;
      nxt ^= 1;
    }

    for (int i = 0; i < n; i++)
      if (max_p < dp[cur][i]) max_p = dp[cur][i];

    printf("%.8lf\n", max_p);
  }

  return 0;
}

Measured memory_bytes: 1280
-- Repetitive Processing - Print Test Cases

import Control.Applicative

main :: IO ()
main = do
  xs <- takeWhile (/= "0") . words <$> getContents
  mapM_ putStrLn [mes i x | (i, x) <- zip [1 ..] xs]
    where mes i x = "Case " ++ (show i) ++ ": " ++ x



Measured memory_bytes: 4956
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
template<class T> bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	string S;
	cin >> S;
	K--;
	S[K] += 'a' - 'A';
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n,m,mas[1001]={0},eye[1001]={0},count,place;
	while(1){
		count=0;
		cin>>n>>m;
		if(n==0 && m==0){
			break;
		}
		for(int i=0;i<n;++i){
			cin>>mas[i];
		}
		for(int i=0;i<m;++i){
			cin>>eye[i];
		}
		count=0;place=0;
		while(1){
			if(place>=n-1){
				break;
			}
			place+=eye[count];
			place+=mas[place];
			count++;
		}
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
n=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))  
C=list(map(int, input().split()))
point = 0
for i in range(n):
    r = A[i]
    point += B[r-1]
    
for i in range(n-1):
  if A[i]+1 == A[i+1]:
    point += C[A[i] - 1]
    
print(point)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)return false;
		return true;
	}
	static void solve(){
		int res = 0;
		while(n >= 5){
			res += n/5;
			n = n/5;
		}
		System.out.println(res);
	}
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I_1000000007 (1000000007)
#define I_998244353   (998244353)
#define I_INF             (1<<28)
#define L_INF           (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;
  using Graph = vector<vector<int> >;

  int N, M, parent[100010];
  Graph G;

  void init() {
    cin >> N >> M;
    G.resize(N);
    int a, b;
    rep(i, M) {
      cin >> a >> b;
      a--;
      b--;
      G[a].push_back(b);
      G[b].push_back(a);
    }
  }

  void bfs() {
    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    while(!que.empty()) {
      auto pr = que.front(); que.pop();
      int s = pr.first, p = pr.second;
      if(parent[s] >= 0) continue;
      parent[s] = p;
      for(const auto& t : G[s]) {
        if(parent[t] >= 0) continue;
        else {
          que.push(make_pair(t, s));
        }
      }
    }
  }

  void solve() {
    memset(parent, -1, sizeof parent);
    bfs();
    cout << "Yes" << "\n";
    REP(i, 1, N) {
      cout << parent[i]+1 << "\n";
    }
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

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

int main() {
    int N, M;
    ll ans = 0;
    cin >> N >> M;
    vector<pair<ll, ll>> ab(N);
    for(int i = 0; i < N; ++i)
        cin >> ab[i].first >> ab[i].second;
    sort(ab.begin(), ab.end());
    int item = M;
    for(int i = 0; i < N; ++i) {
        if(item <= ab[i].second) {
            ans += item * ab[i].first;
            break;
        }
        item -= ab[i].second;
        ans += ab[i].first * ab[i].second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int m,n;
    while (cin>>m>>n) {
        if (m==0) {
            break;
        } else {
            int count=0;
            for (int i=m;i<=n;i++) {
                int tmp=i;
                if (tmp%2==0) {
                    while (tmp%2==0) {
                        tmp=tmp/2;
                    }
                    while (tmp%3==0) {
                        tmp=tmp/3;
                    }
                    while (tmp%5==0) {
                        tmp=tmp/5;
                    }
                    if (tmp==1) {
                        count++;
                    }
                } else {
                    while (tmp%3==0) {
                        tmp=tmp/3;
                    }
                    while (tmp%5==0) {
                        tmp=tmp/5;
                    }
                    if (tmp==1) {
                        count++;
                    }
                }
            }
            cout<<count<<endl;
        }
    }
}


Measured memory_bytes: 3056
<?php
$a = [];
for ($i = 1; $i <= 9; $i++) {
    for ($j = 1; $j <= $i; $j++) {
        $a[$i * $j] = 1;
    }
}
fscanf(STDIN, "%d", $N);
echo isset($a[$N]) ? "Yes" : "No";


Measured memory_bytes: 4604
// Small and Large Integers

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

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

    // a = 3, b = 20, k = 5のとき
    // i = 3, 4, 5, 6, 7 ,  16, 17, 18, 19, 20

    for (int i = a; i <= b; i++) {
        if (i < a + k || b -k < i) {
            cout << i << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256