akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<bitset>
#include<queue>
#include<stack>
#include<deque>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define il inline
#define rg register
#define rep(i,st,ed) for(int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(int i=(ed);i>=(st);--i)
#define rep0(i,n) for(int i=0;i<(n);++i)
#define lch(i) ((i)<<1)
#define rch(i) ((i)<<1^1)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il void getmin(T &x,const T &y){if(y<x) x=y;}
template<typename T> il void getmax(T &x,const T &y){if(y>x) x=y;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;

struct sta{
	int a,b,c;
	
	sta(){}
	sta(int x,int y,int z):a(x),b(y),c(z){} 
	
	il bool operator <(const sta &t)const{
		if(a!=t.a) return a<t.a;
		if(b!=t.b) return b<t.b;
		return c<t.c;
	}
};

set<sta> all;

int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	all.insert(sta(a,b,c));
	if((a&1)||(b&1)||(c&1)) return puts("0"),0;
	for(int i=1;;++i){
		int na=b+c>>1,nb=a+c>>1,nc=a+b>>1;
		sta ns(na,nb,nc); 
		if(all.find(ns)!=all.end()){
			return puts("-1"),0;
		}
		all.insert(ns);
		a=na,b=nb,c=nc;
		if((a&1)||(b&1)||(c&1)) return printf("%d\n",i),0;
	}
}

Measured memory_bytes: 256
import random

n = int(input(""))
Taro = 0
Hanako = 0
get_point_w = 3
get_point_d = 1

def judge(card_a, card_b, get_point_w, get_point_d, point_a, point_b):
    win_card = max(card_a, card_b)
    if card_a == card_b:
        point_a += get_point_d
        point_b += get_point_d
    elif win_card == card_a:
        point_a += get_point_w
    elif win_card == card_b:
        point_b += get_point_w
    else:
        print("bad input!")  
    
    return point_a, point_b
    
if n <= 1000:
    for i in range(n):
        card_Taro_Hanako = input()
        card_Taro = card_Taro_Hanako.split(" ")[0]
        card_Hanako = card_Taro_Hanako.split(" ")[1]
        if len(card_Taro) <= 100 and len(card_Hanako) <= 100:
            Taro, Hanako = judge(card_Taro, card_Hanako, get_point_w, get_point_d, Taro, Hanako)
        else:
            print("animal name string length > 100, bad input!")
else:
    print("n > 1000, bad input!")
print(Taro, Hanako)



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

#define inRange(x,a,b) (a <= x && x < b)
int di[8] = {0,0,1,-1,1,1,-1,-1};
int dj[8] = {1,-1,0,0,1,-1,1,-1};

// H*W*4*N = 3.6e7
int main(){
    int h, w, n;
    cin >> h >> w >> n;
    n++;
    char mat[h][w];
    int pi[n], pj[n], si, sj;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
            if(mat[i][j] == 'S')    pi[0] = i, pj[0] = j;
            if(inRange(mat[i][j], '1', '9'+1))  pi[mat[i][j]-'0'] = i, pj[mat[i][j]-'0'] = j;
        }
    }
    int ans = 0;
    for(int i = 0; i+1 < n; i++){
        vector<vector<int>> dis(h, vector<int>(w,-1));
        queue<pair<pair<int,int>,int>> q;
        q.push({{pi[i], pj[i]},0});
        while(!q.empty()){
            auto p = q.front(); q.pop();
            int x = p.first.first, y = p.first.second, d = p.second;
            if(dis[x][y] != -1) continue;
            dis[x][y] = d;
            if(x == pi[i+1] && y == pj[i+1]){
                ans += d;
                break;
            }
            for(int k = 0; k < 4; k++){
                int ni = x+di[k], nj = y+dj[k];
                if(inRange(ni,0,h)&&inRange(nj,0,w)&&mat[ni][nj]!='X'&&dis[ni][nj]==-1){
                    q.push({{ni,nj},d+1});
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7896
#include <iostream>
#include <cstdio>

#define MAX 10000
#define NIL -1

struct Node {
	int parent;
	int left;
	int right;
};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u,int d)
{
	if(u == NIL) {
		return;
	}
	D[u] = d;

	setDepth(T[u].left, d + 1);
	setDepth(T[u].right, d + 1);
}


int setHeight(int u) 
{
	int h1, h2;
	h1 = h2 = 0;

	if (T[u].left != NIL) {
		h1 = setHeight(T[u].left) + 1;
	}
	if (T[u].right != NIL) {
		h2 = setHeight(T[u].right) + 1;
	}

	return H[u] = (h1 > h2) ? h1 : h2;
}

int getSibling(int u)
{
	if (T[u].parent == NIL) {
		return NIL;
	}

	if (T[T[u].parent].left != u && T[T[u].parent].left != NIL) {
		return T[T[u].parent].left;
	}

	if (T[T[u].parent].right != u && T[T[u].parent].right != NIL) {
		return T[T[u].parent].right;
	}


	return NIL;
}

void print(int u)
{
	printf("node %d: ",u);
	printf("parent = %d, ", T[u].parent);
	printf("sibling = %d, ", getSibling(u));

	int deg = 0;

	if (T[u].left != NIL) {
		deg++;
	}
	if (T[u].right != NIL) {
		deg++;
	}

	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ", H[u]);
	
	if (T[u].parent == NIL) {
		printf("root\n");
	}
	else if (T[u].left == NIL && T[u].right == NIL) {
		printf("leaf\n");
	}
	else {
		printf("internal node\n");
	}
}


int main(void)
{
	int v, l, r, root = 0;
	scanf("%d",&n);

	for (int i = 0; i < n; i++) {
		T[i].parent = NIL;
	}

	for (int i = 0; i < n; i++) {

	}

	for (int i = 0; i < n; i++) {
		scanf("%d %d %d",&v,&l,&r);
		T[v].left = l;
		T[v].right = r;
		if (l != NIL) {
			T[l].parent = v;
		}
		if (r != NIL) {
			T[r].parent = v;
		}
	}

	for (int i = 0; i < n; i++) {
		if (T[i].parent == NIL) {
			root = i;
			break;
		}
	}

	setDepth(root, 0);
	setHeight(root);

	for (int i = 0; i < n; i++) {
		print(i);
	}

	return 0;

}

Measured memory_bytes: 3204
import java.math.BigInteger;
import java.util.Scanner;


public class Main {
    public static int gcd(int a,int b)
    {
        if(b==0)
             return a;
        else
            return gcd(b,a%b);
    }

    public static void main(String[] args) {

     Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
     long  sum=0;
     for(int i = 1; i<=n; i++)
     {
         for(int j=1;j<=n;j++)
         {
             for(int k=1;k<=n;k++)
                  sum+=gcd(i,gcd(j,k));
         }

     }

     System.out.println(sum);

    }
}


Measured memory_bytes: 35748
def ex_dice(n):
    n = int(n)
    a = n*(n+1) / 2
    return a / n


n, k = list(map(int, input().split()))
dices = list(map(ex_dice, input().split()))
exp = 0
for i in range(k):
    exp += dices[i]

max_val = exp

for i in range(n - k):
    first_val = dices[i]
    next_val = dices[i+k]
    exp = exp + next_val - first_val
    max_val = max(max_val, exp)

print(max_val)    

Measured memory_bytes: 23716
n, m = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(m)]

sum_n = sum([i for i in range(n + 1)])

all_route = []
def dfs(i, r, o):
  route = r
  o_v = o
  route.append(i)
  o_v.append(i)
  v_num = [v[1] for v in a if v[0] == i and v[1] not in o_v]
  v_num += [v[0] for v in a if v[1] == i and v[0] not in o_v]
  if len(v_num) == 0:
    all_route.append(route[:])
    
  else:
    for v in v_num:
      dfs(v, route[:],o_v[:])    

dfs(1, [], [])
all_route_scores = [sum(route) for route in all_route]
r = all_route_scores.count(sum_n)

print(r)
  

Measured memory_bytes: 3828
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    string n;
    int i;
    cin >> n;
    for (i = 0 ; i<3; i++){
      if (n[i] == '1'){
        n[i] = '9';
      }
      else{
        n[i] = '1';
      }
    }
    cout << n << endl;
}

Measured memory_bytes: 256
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor, gcd
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10

    a,b = LMIIS()
    print(a*b)

    
main()

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

long long gcd(long long a,long long b){
	long long r=a%b;
	while (r>0){
		a=b;b=r;r=a%b;
	}
	return b;
}
int main(){
	long long m,n,ans=1;
	cin >> m >> n;
	long long x=gcd(m,n);
	long long N=x;
	for(long long i=2;i*i<=N;i++){
		if(x%i==0){
			ans++;
			while(x%i==0)
				x/=i;
		}
	}
	if(x>1) ans++;
	cout << ans;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define  _(x)  cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v)  (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;


int main() {

    int r;
    cn r;
    

    printf("%.10f", 2*PI*r);nl;

    return 0;
}


Measured memory_bytes: 3764
a[10],b[2];main(n,i,j,k){
	for(scanf("%d",&n);n--;){
		for(i=0;i<10;i++)scanf("%d",a+i);
		for(j=0;j<1024;j++){
			for(*b=b[1]=i=0;i<10;i++){
				k=(j>>i)&1;
				if(b[k]>a[i])break;
				b[k]=a[i];
			}
			if(i==10){puts("YES");break;}
		}
		if(j==1024)puts("NO");
	}
}

Measured memory_bytes: 0
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

const int N = 100500;

int c[300][300];
int n;
int a[300][300];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    forn(i, n) forn(j, n) cin >> a[i][j], c[i][j] = a[i][j];
    forn(k, n) forn(i, n) forn(j, n)
    {
        if (c[i][k] + c[k][j] < c[i][j])
        {
            c[i][j] = c[i][k] + c[k][j];
        }
    }
    forn(i, n) forn(j, n)
    {
        if (a[i][j] != c[i][j])
        {
            cout << -1;
            return 0;
        }
    }
    ll ans = 0;
    forn(i, n) forn(j, n)
    {
        if (i >= j) continue;
        int t = 0;
        forn(k, n)
        {
            if (k != i && k != j && a[i][k] + a[k][j] == a[i][j]) t = 1;
        }
        if (t == 0)
            ans += a[i][j];
    }
    cout << ans;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 1024
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

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

    ll tmp = 100;
    ll cnt = 0;
    while(tmp<x){
        cnt++;
        ll t = 0.01*tmp;
        tmp += t;
        //dump(tmp);
    }
    cout << cnt << endl;

    return 0;
}


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

table = [[[0]*10 for i in range (0,3)] for k in range (0,4)]


for i in range(n):
    b, f, r, v = map(int, input().split())
    table[b-1][f-1][r-1] +=v


for i in range(4):
   
    for k in range(3):
        for l in range(10):
            print (" %d" %(table[i][k][l]), end="")
        print()
    if i < 3: print("#"*20, end="\n")


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

int r, p, s;

int opnum(char x) {
    if (x == 's') {
        return (r);
    }
    if (x == 'r') {
        return (p);
    }
    if (x == 'p') {
        return (s);
    }
    return 0;
}
char op(char x) {
    if (x == 's') {
        return ('r');
    }
    if (x == 'r') {
        return ('p');
    }
    if (x == 'p') {
        return ('s');
    }
    return 0;
}

int main() {
    long a, b, n, k, q, ans = 0;
    cin >> n >> k >> q;
    vector<long> as(q + 1);
    k = k - q;
    vector<long> player(n + 1, k);
    for (int i = 1; i <= q; i++) {
        cin >> as[i];
        player[as[i]]++;
    }
    for (int i = 1; i <= n; i++) {
        if (player[i] > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 2176
import heapq
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
BC = [list(map(int, input().split())) for _ in range(m)]
BC.sort(key=lambda x: -x[1])

tank = []

idx = 0
while (len(tank) < n + 1) and (idx < m):
  for _ in range(BC[idx][0]): 
    heapq.heappush(tank, -BC[idx][1])
  idx +=  1

# print(A)
# print(BC)
# print(tank)

ans = 0
p = -heapq.heappop(tank)
for a in A:
  if p > a:
    ans += p
    if tank:
      p = -heapq.heappop(tank)
    else:
      p = - 10 ** 9
  else:
    ans += a

print(ans)
    
    

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

#define ll long long
#define pii pair<int, int>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<set<int>> st(n);
    for (int i = 0; i < m; i++) {
        int pos, val;
        cin >> pos >> val;
        st[pos - 1].insert(val);
    }
    string s;
    s.resize(n);
    if (st[0].size() == 1 && *st[0].begin() == 0) {
        if (n == 1) {
            cout << 0;
            return 0;
        } else {
            cout << -1;
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (st[i].size() > 1) {
            cout << -1;
            return 0;
        } else if (st[i].size() == 1)s[i] = (char) (*st[i].begin() + (int) '0');
        else if (i == 0 && n > 1)s[i] = '1';
        else s[i] = '0';
    }
    cout << s;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
	int n; cin >> n;
	Graph G(n);
	for (int i = 0; i < n-1; ++i) {
		int a, b; cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<ll> c(n);
	for (int i = 0; i < n; ++i) cin >> c[i];
	sort(c.begin(), c.end(), greater<ll>());

	queue<int> q;
	q.push(0);
	vector<ll> ans(n, -1);
	ans[0] = c[0];
	int j = 1;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (auto v : G[u]) {
			if (ans[v] != -1) continue;
			ans[v] = c[j];
			++j;
			q.emplace(v);
		}
	}

	ll sum = 0;
	q.push(0);
	set<int> se;
	se.insert(0);
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (auto v : G[u]) {
			if (se.count(v) != 0) continue;
			sum += min(ans[u], ans[v]);
			q.push(v);
			se.insert(v);
		}
	}

	cout << sum << endl;
	for (int i = 0; i < n; ++i) {
		cout << ans[i];
		if (i != n - 1) cout << " ";
		else cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define COUNT(i,n) for(int i=1;i<=(n);i++)
// repeat for accumulational summention
#define Acu(i,n,m) for(int i=(n);i<=(m);i++)
#define DownREP(i,n) for(int i=(n);i>0;i--)
#define ll long long
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int MAX=1e9;
int MOD=1e9+7;


int main(){
  ll N,ANS=0;cin>>N;
  for(int i=0;i<9;i++){
    ll X=i;
    if(X>N)continue;
    int SUM=i;
    while(X*10+9<=N){
      X=X*10+9;
      SUM+=9;
    }
    ANS=max(ANS,(ll)SUM);
  }
  cout<<ANS<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <utility>
#include <algorithm>
#include <set>
#include <cmath>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b+1;i++)
#define Per(i,b,a) for(int i=b;i>=a;i--)
int main(){
    string S;
    cin>>S;
    if(S.size()%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    rep(i,S.size()/2){
        if(S[2*i]!='h' ||S[2*i+1]!='i'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

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

ll a[100010][3];

ll dp[10010][3];

int main(){
    int n;
    cin>>n;
    rep(i,n)rep(j,3)cin>>a[i][j];

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j!=k)chmax(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
    ll ans=0;
    for(int i=0;i<3;i++)chmax(ans,dp[n][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 6152
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n;
	string s; cin >> n >> s;
	
	rep(it, 4){
		string t; 
		vi ans(n, -1);
		ans[0] = it & 1;
		ans[1] = it / 2;
		rep(i, n){
			int v = ans[i] ^ (s[(i + 1) % n] == 'x') ^ ans[(i + 1) % n];
			if(ans[(i + 2) % n] >= 0 && v != ans[(i + 2) % n]){
				goto FAIL;
			}
			ans[(i + 2) % n] = v;
		}
		rep(i, n) t += ans[i] ? 'W' : 'S';
		cout << t << endl;
		return 0;
		FAIL:;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 1096
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
//		long start = System.currentTimeMillis();
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			int q = scanner.nextInt();
			// init
			int[] sankasha = new int[n];
			for (int i = 0; i < n; i++) {
				sankasha[i] = k;
			}

			// calc
			for (int i = 0; i < q; i++) {
				int index = scanner.nextInt();
				sankasha[index-1]++;
			}

			for (int i = 0; i < n; i++) {
				System.out.println((sankasha[i] - q) > 0 ? "Yes" : "No");
			}
//			long end = System.currentTimeMillis();
//			System.out.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 62340
A, B = gets.split().map(&:to_i)
common_divisors = []

def is_prime_number(num)
  (2..num**0.5).each do |i|
    return false if num % i == 0
  end
  return true
end

def divisors(num)
  return [1] if num == 1
  div = []
  (1..num**0.5).each do |i|
    if num % i == 0
      div.push(i) if is_prime_number(i)
      div.push(num/i) if is_prime_number(num/i)
    end
  end
  div
end

divisors(A).each do |i|
  common_divisors.push(i) if B % i == 0
end

puts common_divisors.count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n, h, w;
    scanf("%d%d%d", &n, &h, &w);
    vector<int> s(n*w, 1);
    rep(i, n){
        int x;
        scanf("%d", &x);
        int l = i*w, r = (i+1)*w;
        For(j, l, r) --s[j];
        if(i%2 == 0) l+=x, r+=x;
        else l-=x, r-=x;
        For(j, l, r) ++s[j];
    }
    int ans = 0;
    rep(i, n*w) ans += h * (s[i] == 0);
    printf("%d\n", ans);
}


Measured memory_bytes: 3268
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] gcnt = new int[100001];
		int[] kcnt = new int[100001];
		int gmax = 0;
		int gmax2 = 0;
		int gid = 0;
		int gid2 = 0;
		int kmax = 0;
		int kmax2 = 0;
		int kid = 0;
		int kid2 = 0;
		for(int i = 0; i < n; i++){
			int tmp = sc.nextInt();
			if(i%2==0){
				gcnt[tmp]++;
				if(gmax <= gcnt[tmp]){
					if(tmp != gid){
						gmax2 = gmax;
						gid2 = gid;
					}
					gmax = gcnt[tmp];
					gid = tmp;
				}
				if(tmp == gid2){
					gmax2++;
				}
			}else{
				kcnt[tmp]++;
				if(kmax <= kcnt[tmp]){
					if(tmp != kid){
						kmax2 = kmax;
						kid2 = kid;
					}
					kmax = kcnt[tmp];
					kid = tmp;
				}
				if(tmp == kid2){
					kmax2++;
				}
			}
		}
		if(gid != kid){
			System.out.print(n-gmax-kmax);
		}else{
			if(gmax+kmax==n){
				System.out.print(n/2);
			}else if(n-gmax-kmax2 > n-gmax2-kmax){
				System.out.print(n-gmax2-kmax);
			}else{
				System.out.print(n-gmax-kmax2);
			}
		}
	}
}


Measured memory_bytes: 56396
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int ll;
#define MOD (1e9+7);
#define INF (2e9)

long long int c(int x, int y) {//xCyを返す関数
    long long int a = 1;
    for (int i = 1; i <= y; i++) {
        a *= x + 1 - i;//x,x-1,・・・,x-y+1 がaにかけられる
        a /= i;//1,2,・・・,y　をaから割る
    }
    return a;
}

int main(void) {
    int n, a, b;
    cin >> n >> a >> b;
    long long int *v = new long long int[n];
    for (int i = 0; i<n; i++) {
        cin >> v[i];
    }

    sort(v, v + n);
    reverse(v, v + n);//降順ソート

    long long int min = v[a - 1];
    //min = 価値平均が最大となるように選んだ品物のうち、
    //     一番価値の低いものの価値　　→

    long long int ans = 0;//答え（場合の数）
    double ans_max = 0;//答え（最大値）

    if (v[0] == min) {//A番目まですべて同じ価値なら
        ans_max = min;// 答え
        int i;
        for (i = 0; i<n; i++) {
            if (v[i] != min) {//{min,min,・・・,min,no,・・・} ならばnoを指して止まる
                break;
            }
        }
        //i = min と同じ価値の品物の個数
        while (a <= b && a <= i) {//i個のうちa個選ぶ、a+1個選ぶ、・・・・、min(b,i)個選ぶ
            ans += c(i, a);
            a++;
        }
    }
    else {
        for (int k = 0; k<a; k++) {//A番目までの商品の平均値
            ans_max += v[k];
        }
        ans_max /= a;

        int minp, minm;
        for (minp = a - 1; v[minp] == min && minp<n; minp++) {}//minより小さい値を見つけたらstop
        for (minm = a - 1; v[minm] == min && minm >= 0; minm--) {}//minより大きい値を見つけたらstop
        int kosu = minp - minm - 1; // minと同じ価値の商品のkosu

        ans = c(kosu, a - (minm + 1));
        //選ぶa個のうち、　minm + 1 は確定してるので、
        //minと同じ価値の商品　から　a - (minm + 1)　個選ぶ


    }
    cout << fixed<<ans_max << endl << ans << endl;
    return 0;
}

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

w = [0]
e = [0]

tmp_w = 0
tmp_e = 0

for i in range(1, n):

    j = (n - 1) - i

    if (s[i-1] == 'W'):
        w.append(tmp_w + 1)
        tmp_w += 1
    else:
        w.append(tmp_w)

    if (s[j+1] == 'E'):
        e.append(tmp_e + 1)
        tmp_e += 1
    else:
        e.append(tmp_e)

e.reverse()

ans = 10 ** 6 
for i in range(n):
    ans = w[i] + e[i] if w[i] + e[i] < ans else ans

print(ans)

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


public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
                
                long A = scan.nextLong();
                long B = scan.nextLong();
                long N = scan.nextLong();
                
                long k;
                long u;
                long l;
                long p;
                
                long ans;
                long preans;
                
                k = (A*(B-1))/B;
                u = (B-1)/B;
                
                ans = k-A*u;
                     
                p = (A*N)/B;
                l = N/B;
                     
                preans = p;
                System.out.println(Math.min(ans,preans));
        }
}

Measured memory_bytes: 35836
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>

using namespace std;

/*
  let's try computer shogi!!!
 */

int N;
vector<int> X;
vector<int> W;
vector<vector<int> > P;
const int Xmax = 114514;

bool dfs(int id){
  //cerr<<id<<"(id)"<<endl;
  int total = 0;
  bool oks[Xmax];
  bool toks[Xmax];
  for(int i=0;i<Xmax;++i){
    oks[i] = false;
    toks[i] = false;
  }
  oks[0]=true;
  for(int i=0;i<P[id].size();++i){
    //cerr<<id<<","<<P[id][i]<<" id,child"<<endl;
    if (!dfs(P[id][i])){
      return false;
    }
    for(int k=0;k<Xmax;++k){
      if(oks[k]){
	toks[k+X[P[id][i]]] = true;
	toks[k+W[P[id][i]]] = true;
      }
    }
    for(int k=0;k<Xmax;++k){
      oks[k] = toks[k];
    }
    total += X[P[id][i]] + W[P[id][i]]; 
  }
  //cerr<<total<<"(total) oks : ";
  bool possible = false;
  for(int i=0;i<=total;++i){
    //cerr<<oks[i]<<",";
    if(oks[i] && total - i <= X[id]){
      W[id] = i;
      possible = true;
      break;
    }
  }
  //cerr<<"result "<<possible<<endl;
  return possible;
}

int main(){
  cin >> N;
  
  X.resize(N);
  P.resize(N);
  W.resize(N);
    
  for(int i=0;i<N-1;++i){
    int p;
    cin >> p;
    P[p-1].push_back(i+1);
  }

  for(int i=0;i<N;++i){
    cin >> X[i];
  }

  cout<<( dfs(0) ? "POSSIBLE" : "IMPOSSIBLE")<<endl;
  
}

Measured memory_bytes: 96000
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[N];
		double sum = 0;
		int x = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			sum += A[i];
		}
		for(int i = 0; i < N; i++) {
			if(A[i] >= sum/4/M)
				x++;
		}
		System.out.println(x >= M ? "Yes" : "No");
	}

}


Measured memory_bytes: 21844
a,b,c,d=gets.split.map(&:to_i)
e=b-a+1

if c<a
  c_min= a%c==0 ? a : a+c-a%c
else
  c_min=c
end
c_max=b-b%c

if d<a
  d_min= a%d==0 ? a : a+d-a%d
else
  d_min=d
end
d_max=b-b%d

cd_lcm=[c,d].inject(:lcm)
if cd_lcm<a
  cd_min= a%cd_lcm==0 ? a : a+cd_lcm-a%cd_lcm
else
  cd_min=cd_lcm
end
cd_max=b-b%cd_lcm

c_num=(c_max-c_min)/c+1
d_num=(d_max-d_min)/d+1
cd_num=(cd_max-cd_min)/cd_lcm+1
puts e-c_num-d_num+cd_num


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a==5&&b==5&&c==7)||(b==5&&c==5&&a==7)||(c==5&&a==5&&b==7)) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <complex>
#include <iomanip>
#include <queue>
#include <bitset>
#include <numeric>
//定数
#define MOD 1000000007
//マクロ
#define loop()      while(1)
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin(), (v).end());

typedef unsigned long long int ull;
typedef long long lint;

using namespace std;




int main(){
    int A, B;

    //入力
    cin >> A >> B;
    lint ai=A, bi=B;
    while(ai!=bi) {
        if(ai>bi) bi += B;
        else      ai += A;
    }
    
    cout << ai << endl;
    return 0;
}

Measured memory_bytes: 256
"""
8:30:00
"""

from collections import defaultdict
def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    if n < 2:
        raise ValueError("N >= 2")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]

def factorization(n):
    factors = defaultdict(int)
    primes = getprime(int(n**0.5))
    for prime in primes:
        while n % prime == 0:
            factors[prime] += 1
            n //= prime
            # print(factors,n)
    if n != 1:
        factors[n] += 1
    return factors


def modconb(n,k,mod):
    # テーブルを作る
    fac = [0]*(n+1)
    finv = [0]*(n+1)
    inv = [0]*(n+1)  

    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1

    for i in range(2,n+1):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] % mod

    if n<k: return 0
    if n<0 or k<0: return 0
    return(fac[n]*(finv[k]*finv[n-k]%mod)%mod)

"""
1 * 1 * 1のどこに素因数をかけるか
3^3だとして
どこかで3回3をかけないといけない
a + b + c = 3 //重複組合せ
3*3-1C3
こいつをかけ合わせると答えになる
modconbいる
"""

mod = 10**9 + 7
n, m = map(int, input().split())
if m == 1:
    print(1)
    exit()
factors = factorization(m)
ans = 1
for k in factors.keys():
    x = factors[k]
    ans *= modconb(x+n-1,x,mod)
    ans %= mod
print(ans)


Measured memory_bytes: 16808
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 30;
int N;
int p[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> p[i];
    }

    int ret = 0;

    for (int i = 2; i <= N-1; i++) {
        if (p[i-1] < p[i] && p[i] < p[i+1]) {
            ret++;
        } else if (p[i+1] < p[i] && p[i] < p[i-1]) {
            ret++;
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

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

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 RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  ll x, y; cin >> x >> y;
  if(abs(x - y) > 1) {
    cout << "Alice" << endl;
  } else {
    cout << "Brown" << endl;
  }

}
























Measured memory_bytes: 256
package main

import "fmt"

func main() {
	H := make([]int, 0)
	W := make([]int, 0)
	for {
		var h, w int
		fmt.Scan(&h, &w)
		if h == 0 && w == 0 {
			break
		}
		H = append(H, h)
		W = append(W, w)
	}
	for i := 0; i < len(H); i++ {
		for h := 0; h < H[i]; h++ {
			for w := 0; w < W[i]; w++ {
				if (0 < h && h < H[i]-1) && (0 < w && w < W[i]-1) { // 内部にあれば.を出力する
					fmt.Print(".")
				} else {
					fmt.Print("#")
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}



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

namespace AtCoder
{
    public class Program
    {
        /// <summary>
        /// 偶数個の数列からひとつ除いたときの中央値
        /// </summary>
        /// <returns></returns>]
        /// <remarks>
        /// 数列をソートして、中央の左と右をleft、rightに保存。
        /// 左以下を除いたときの中央値は常にright、
        /// 右以上を除いたときの中央値は常にleft。
        /// </remarks> 
        /// <example>
        /// 6
        /// 6 5 4 3 2 1
        /// のとき、以下のように分かれ、3以下が除かれるときは常に4、
        /// 4以上が除かれるときは常に3が中央値となる。
        /// 
        /// ←―― ――→
        /// 1 2 3 | 4 5 6 
        /// 
        /// </example>

        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            //xをyにコピー（xの保存）
            int[] y = new int[n]; 
            for (int i = 0; i < n; i++)
                y[i] = x[i];

            //xを昇順ソート
            Array.Sort(x);

            //偶数の中央値のもとになる２つの値を、leftとrightに代入（奇数なら配列のN/2番目が中央値）
            int left = x[(n / 2) - 1];
            int right = x[n / 2];
            
            //iがleft以下なら中央値はright、逆も然り。
            for (int i = 0; i < n; i++)
            {
                if (y[i] <= left)
                    Console.WriteLine(right);
                else
                    Console.WriteLine(left);
            }
            Console.Read();

            //return 0;



            //Console.WriteLine(result.Remove(0, 1));
            
        }
    }
}

Measured memory_bytes: 38236
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String s = new Scanner(System.in).nextLine();
        long count = s.chars().filter(c -> c == 'R').count();
        if (count == 2) {
            if (s.charAt(1) == 'S') {
                count = 1;
            }
        }
        System.out.println(count);
    }
}


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

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

  cin >> a >> b >> c;

  if (a == '7' || b == '7' || c == '7') {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

int main(){
	string W;
	cin>>W;
	string T,tmp;
	int ans=0;
	while(cin>>tmp){
		if(tmp=="END_OF_TEXT")break;
		for(int i=0;i<tmp.length();++i){
			if(tmp[i]>='A' && tmp[i]<='Z')tmp[i]+=0x20;
		}
		if(tmp==W)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3156
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

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


int main(){
	FIO
	
	int a, b;
	cin >> a >> b;
	cout << ceil((a + b) / 2.0) << '\n';
	return 0; 
}


Measured memory_bytes: 256
# k = int(input())
K = input()
k = int(K)
# if k%2 == 0:
#     print(-1)
#     exit()

# r7 = 7%k
r = 0
for i in range(1,k*10):
    r = (r*10 + 7)%k

    # print('r {} i {}'.format(r,i))
    if r == 0:
        print(i)
        exit()
    # print(n)
print(-1)


Measured memory_bytes: 9132
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
	int h, w, d;
	scanf("%d%d%d", &h, &w, &d);
	map<int, pair<int, int>> mp;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int a;
			scanf("%d", &a);
			mp[a] = {i, j};
		}
	}
	vector<int> dist(h * w);
	for (int i = d; i < h * w; i++) {
		dist[i] = dist[i - d] + abs(mp[i + 1].first - mp[i + 1 - d].first)
		          + abs(mp[i + 1].second - mp[i + 1 - d].second);
	}
	int q;
	scanf("%d", &q);
	while (q--) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%d\n", dist[r - 1] - dist[l - 1]);
	}
	return 0;
}

Measured memory_bytes: 7040
#include<stdio.h>
#include<string.h>
#define MAX 2*10*10*10*10*10+1
int main(){
    char s[MAX], t[MAX];
    int  c = 1;
    int count =0;
    scanf("%s", s);
    scanf("%s", t);
    for(int i=0; i<strlen(s);i++){
        while(1){
            if(s[i]!=t[i]){
                t[i]++;
                if(c==1){
                     count++;
                     c = 0;
                }
            }
            c = 1;
            break;
        }
    }
    printf("%d\n", count);
}

Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
//const long long INF = 1LL << 60;

const int mod = 1e9 + 7;
const int INF = 100000;
int h,w;
int main() {
    string maze[51];
    int dist[51][51];//座標(i,j)までの最短距離
    queue<pair<int, int> > q;//2次元のqueue
    //移動方向の組み合わせ
    int dx[4] = {-1, 0, 1, 0};
    int dy[4] = {0, -1, 0, 1};

    // 入力
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> maze[i];
    q.push(make_pair(0, 0));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            dist[i][j] = INF;
        }
    }
    dist[0][0] = 1;//0-オリジン、でスタート位置に0
    
    while (!q.empty()) {//queueが空になるまで
        int y = q.front().first;
        int x = q.front().second;
        q.pop();//qの先頭に格納されている座標に訪問
        for (int i = 0; i < 4; i++) {
            //上下左右行けるか調べる
            int nx = x + dx[i];
            int ny = y + dy[i];
            if ( !(nx >= 0 && nx < w && ny >= 0 && ny < h)) continue;
            if(maze[ny][nx] == '#') continue;
            if(dist[ny][nx] == INF) {
                //次の訪問場所をqueueに格納
                q.push(make_pair(ny, nx));//make_pairは2個セットで格納
                dist[ny][nx] = dist[y][x] + 1;//現在の場所から1の距離
            }
        }
    }
    int ans=dist[h-1][w-1];
    int cnt = 0;
    rep(i,h) rep(j,w) {
      //ans = min(ans,dist[i][j]);
      if(maze[i][j] == '#') cnt++;
      }
     // cout <<cnt << " "<<ans << endl;
    
    cout << ((dist[h-1][w-1] == INF) ? (-1) : ((h*w-cnt) - ans)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define deb(x) cerr<<#x<<" "<<x<<"\n"
typedef long long ll;
typedef unsigned long long ull;
class solution{
public:
	void solve(){
		int n;
		cin>>n;
		map<string,int> v;
		string temp;
		for(int i=0;i<n;i++){
			cin>>temp;
			//s.insert(temp);
			v[temp]++;
		}
		//sort(v.rbegin(),v.rend());
		int max = 0;
		for(auto it : v){
			if(it.s > max){
				max = it.s;
			}
		}
		vector<string> se;
		for(auto it : v){
			if(it.s == max){
				se.pb(it.f);
			}
		}
		sort(se.begin(),se.end());
		for(auto it : se){
			cout<<it<<"\n";
		}
		
	}

};

int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}



Measured memory_bytes: 25584
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
int main()
{
	int n,i,j,k;
	cin>>n;
	int a[n],b[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
		{
			b[a[i]]=i+1;
		}
	for(i=1;i<n+1;i++)
		cout<<b[i]<<" ";
}


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

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

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

	if (a > b) {
		tmp = a;
		a = b;
		b = tmp;
	}//b > a
	if (a > c) {
		tmp = a;
		a = c;
		c = tmp;
	}//c > a
	if (b > c) {
		tmp = b;
		b = c;
		c = tmp;
	}

	printf("%d\n", (c - b) + (b - a));

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)

ll gcd(ll i,ll j){
        if(j == 0) return i;
        return gcd(j,i%j);
}

ll lcm(ll i,ll j){
        return i / gcd(i,j) * j;
}

 
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  ll k = 1;
  rep(i,n) k = lcm(k,a.at(i));
  cout << k << endl;
}



Measured memory_bytes: 256
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
cnt = 0
for i in 0..a
  for j in 0..b
    for k in 0..c
      if x==500*i+100*j+50*k
        cnt += 1
      end
    end
  end
end
puts cnt

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

long H[100000];

int main(){
  long N;
  cin >> N;
  for(long i=0; i<N; i++){
    cin >> H[i];
  }
  long len=0;
  long max=0;
  for(long i=0; i<N-1; i++){
    if(H[i]>=H[i+1]){
      len++;
    }
    else if(H[i] < H[i+1]){
      if(max < len) max = len;
      len=0;
    }
  }
  if(max < len) max = len;
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
int m[11][11];
int main()
{
  int n,i,j,k;
  for(;;){
    scanf("%d",&n);
    if(n==0) break;
    memset(m,0,sizeof(m));
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	scanf("%d",&m[i][j]);
	m[i][n] += m[i][j];
	m[n][j] += m[i][j];
	m[n][n] += m[i][j];
      }
      scanf("\n");
    }
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	printf("%5d",m[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

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

const int N = 2005;
const int M = 2005;
const int mod = 1e9 + 7;

int n, m;
int A[N], B[M], R[M];
int dp[N][M];

signed main(){
  
  cin>>n>>m;
  
  for(int i=0;i<n;i++) cin>>A[i];
  
  for(int i=0;i<m;i++) cin>>B[i];
  
  for(int i=0;i<n;i++){
    
    int sum = 0;
    
    for(int j=0;j<m;j++){
      
      if( A[i] == B[j] ){
	dp[i][j] = sum + 1;
	dp[i][j] %= mod;
      }
      
      sum += R[j];
      sum %= mod;
      
    }
    
    for(int j=0;j<m;j++){
      
      if( A[i] == B[j] ){
	R[j] += dp[i][j];
	R[j] %= mod;
      }
      
    }
    
  }
  
  int sum = 0;

  for(int i=0;i<m;i++){
    sum += R[i];
    sum %= mod;
  }
  
  int ans = ( sum + 1 ) % mod;
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 31488
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=1e9+7;
const ll maxn=5*1e5+10;
const ll inf=99999999999;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<int> uid(l, r); return uid(rng); }
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << "(" << a.F << ", " << a.S << ")"; }
template <class A> ostream& operator << (ostream& out, const vector<A> &v) { 
out << "["; for (int i=0;i<v.size();i++) { if(i) out << ", "; out << v[i]; } return out << "]"; } 
	


void solve(){
	
	
	string s;
	cin>>s;
	for (int i=0;i<=2;i++) cout<<s[i];
	
		
	return;
}
 
int main(){ 
    
    #ifndef ONLINE_JUDGE
		//freopen("input.txt", "r", stdin);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
 
 	
	//T{ solve(); }
	solve();
	
	return 0;
}

Measured memory_bytes: 3664