akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

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



}


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

int main(){
  string a;
  C(a);

  while(1){
    a.erase(a.size() - 1 );
    
    if(a.size() %2 == 1)
      continue;
    
    int j=a.size()/2;
    
    string mae = "";
    string usi = "";

    rep(i,0,j){
      mae += a[i];
      usi += a[j+i];
    }
    
    if(mae == usi){
      P(a.size());
      break;
    }
  }

  ret 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7


from functools import lru_cache


def main(): 
    S = SI()

    # 桁DP
    dp_table = [[0 for _ in range(13)] for _ in range(len(S))]

    # 最初の桁を見る。
    if S[0] == '?':
        for i in range(10):
            dp_table[0][i] = 1
    else:
        dp_table[0][int(S[0])] = 1

    # 以降の桁を見ていく。
    for digit in range(1, len(S)):
        if S[digit] == '?':
            for prev_res, comb in enumerate(dp_table[digit-1]):
                for x in range(10):
                    res = (prev_res*10+x)%13
                    dp_table[digit][res] = (dp_table[digit][res] + comb)%MOD

        else:
            for prev_res, comb in enumerate(dp_table[digit-1]):
                res = (prev_res*10+int(S[digit]))%13
                dp_table[digit][res] = (dp_table[digit][res] + comb)%MOD

    print(dp_table[len(S)-1][5])





main()

Measured memory_bytes: 65884
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

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

	if (n%k != 0) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
class Node
  attr_accessor :key, :left, :right
  def initialize key
    @key = key
  end
 
  def inorder
    left.inorder if left
    print " ", key
    right.inorder if right
  end
 
  def preorder
    print " ", key
    left.preorder if left
    right.preorder if right
  end
end
 
def insert
  z = Node.new $key.to_i
  x = $root
  while x
    y = x  # // x??????
    x = z.key < x.key ? x.left : x.right  #??????????????§????/??????????????§????
  end
 
  unless y  #y???nil??????´???
    $root  = z
  else
    z.key < y.key ? y.left = z : y.right = z  #z???y?????????????????????/z???y?????????????????????
  end
end
 
n = gets.to_i
n.times do
  command, $key = gets.split
  if command == "insert"
    insert
  else
    $root.inorder
    puts
    $root.preorder
    puts
  end
end

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

bool ok(const vector<int> &p, const int k) {
    for (int i = 0; i < p.size(); ++i) {
        for (int j = 0; j < p.size(); ++j) {
            if (abs(p[j] - p[i]) > k) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    vector<int> p(5);
    for (int i = 0; i < p.size(); ++i) {
        cin >> p[i];
    }
    int k; cin >> k;
    if (ok(p, k)) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline

#複数入力
a,b=(int(x) for x in input().split())

def factorize(n):
    b = 2
    #本当は[]
    fct = [1]
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

#len(list(itertools.combinations(set(factorize(a))&set(factorize(b)),2)))
if len(set(factorize(a))&set(factorize(b)))==1:
    print(1)
else:
    print(len((set(factorize(a))&set(factorize(b)))))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define M 200010
#define MOD 1000000007
#define ULL unsigned long long
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while('0'<=ch&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int d[M];
struct Edge{
	int u,v,Next;
} G[M];
int head[M],tot;
inline void add(int u,int v){
	G[++tot]=(Edge){u,v,head[u]};
	head[u]=tot;
}
int st, ban;
bool vis[100010];
bool flag;
inline void dfs(int x,int fa){
	vis[x]=1;
	for(int i=head[x];i!=-1;i=G[i].Next){
		if(G[i].v==fa)continue;
		if(G[i].v==ban)continue;
		if(G[i].v==st){
			flag=1;
		}
		if(vis[G[i].v])continue;
		dfs(G[i].v,x);
	}
}
int main() {
	int n=read(),m=read();
	memset(head,-1,sizeof(head));
	rep(i,1,m){
		int u=read(),v=read();
		add(u,v),add(v,u);
		++d[u],++d[v];
	}
	int cnt4=0,cnt6=0;
	rep(i,1,n){
		if(d[i]==4)++cnt4;
		if(d[i]==6)++cnt6;
		if(d[i]&1){
			return puts("No"),0;
		}
	} 
	if(cnt6||cnt4>=3)return puts("Yes"),0;
	if(cnt4==2){
		rep(i,1,n)if(d[i]==4){
			if(ban)st=i;
			else ban=i;
		}
		dfs(st,0);
		if(flag)puts("Yes");
		else puts("No");
		return 0;
	}
	puts("No");
}

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

int main() {
  vector<int> s(5);
  for(int i=0; i<5; i++) cin>>s[i];
  int k;
  cin>>k;
  for(int i=0; i<5; i++){
    for(int j=0; j<5; j++){
      int dist = abs(s[i]-s[j]);
      if(dist>k) {
        cout<<":(";
        return 0;
      }
    }
  }
  cout<<"Yay!";
}


Measured memory_bytes: 384
#!/usr/bin/env python3
import math
n = int(input())
# n 以下の素数を全部列挙
def eratosthenes(n):
    prime = [2]
    for i in range(2,n+1):
        for j in range(2,math.ceil(i**1/2)+1):
            if i % j == 0: break
            if j == math.ceil(i**1/2): 
                prime.append(i)
    return prime
prime = eratosthenes(n)
#print(prime)
# その素数に対して、n を割っていく
ans = 1
for i in prime:
    div = i
    cnt_div = 0
    while div <= n:
        cnt_div += n // div
        div *= i

    #print(i,cnt_div)
    ans = ans * (1+cnt_div) % (10**9+7)
print(ans%(10**9+7))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
long long x[1000001],xx[1000001],w[1000001],i,j,k,l,r,s,t,n,m,c;
int main(){
    scanf("%lld%lld%lld",&n,&l,&t);    
    for(register int i=1;i<=n;++i)
        scanf("%lld%lld",&x[i],&w[i]);
    for(register int i=1;i<=n;++i)
    {
        if (w[i]==2) w[i]=-1;
        r=x[i]+w[i]*t;
        if (r>0) (c+=r/l)%=n;
        else if (r<0) (c+=(r+1)/l-1)%=n;
        xx[i]=(r%l+l)%l;
    }
    std::sort(xx+1,xx+n+1);
    c=(c+n)%n;
    for(register int i=c+1;i<=n;++i)printf("%d\n",xx[i]);
    for(register int i=1;i<=c;++i)printf("%d\n",xx[i]);
}

Measured memory_bytes: 10112
s = input()

if len(s)%2 == 0:
    s1 = s[:int(len(s)/2)]
    s2 = ''.join(list(reversed(s[int(len(s)/2):])))
else:
    s1 = s[:int((len(s)-1)/2)]
    s2 = ''.join(list(reversed(s[int((len(s)+1)/2):])))

count = 0
for i in range(len(s1)):
    if s1[i] != s2[i]:
        count += 1
    
print(count)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define ll long long

const int MOD = 1e9 + 7;

int main() {
    int a, b, n;
    cin >> a >> b;
    if(a == 2 || b == 2)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>

#include<iostream>

#include<cstring>

#include<algorithm>

#include<string>

#define LL long long

using namespace std;

string s;

LL k,num=0,ans=0,last=0;

LL vis=0,viss=0,check=0;

int main(){

	cin>>s>>k;

	if(s.length()==1){

		cout<<k/2<<endl;

		return 0;

	}	

	for(int i=0;i<s.length();i++){

		if(s[i]==s[0]) vis++;

		else break;

	}

	if(vis==s.length()){

		cout<<(k*s.length())/2;

		return 0;

	}

	for(int i=s.length()-1;i>=0;i--){

		if(s[i]==s[s.length()-1]) viss++;

		else break;

	}

	for(int i=0;i<s.length()-1;i++){

		if(s[i]==s[i+1])s[i+1]='-',num++;

	}

	if(s[0]==s[s.length()-1]){

		last=1;

		if((vis+viss)%2==1) check=1;

	}

	if(check){

		cout<<num*k<<endl;

		return 0;

	}

	else ans=(num*k+last*(k-1));

	cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<iterator>
#include<algorithm>
#include<string>
//#include<Windows.h>
#include<map>
#include<vector>
using namespace std;

int main() {
	//RECT rc;
	//GetClientRect(GetConsoleWindow(), &rc);
	//SetWindowPos(GetConsoleWindow(), HWND_TOP, 700, 200, rc.right , rc.bottom, 0x0040);
	
	int n;
	cin >> n;
	bool y = 1;
	int cou = 0;
	int a;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (a % 2 == 1)
			cou++;
	}
	if (cou % 2 == 1)
		y = 0;


	if (y)
		cout << "YES";
	else
		cout << "NO";
	cout << endl;
	
	return 0;
}


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

using namespace std;

int main(){

string s;
  cin >> s;
  
  int res=0;
  
  for(int i=0;i<s.length();i++){
   if(s[i]=='+')
     res++;
   else
     res--;
  
  }
  
  cout << res << endl;

}

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

using namespace std;

int main(void) {
	int a[3] = { 0 }, n[3], i;
	for (i = 0; i < 3; i++)
		cin >> n[i];
	if (n[0] == n[1] && n[1] == n[2]) {
		if (n[0] & 1)
			printf("0\n");
		else
			printf("-1\n");
	}
	else {
		for (i = 0; i < 3; i++) {
			while ((n[i] & 1) == 0) {
				a[i]++;
				n[i] >>= 1;
			}
		}
		i = min(min(a[0], a[1]), a[2]);
		if (a[0] == a[1] && a[1] == a[2])
			i++;
		printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int isPrime(const int N) {
    if(N == 2) return 1;
    if(N < 2 || N % 2 == 0) return 0;
    for(int i = 3; i * i <= N; i += 2) {
        if(N % i == 0) return 0;
    }
    return 1;
}

int main() {
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        int a;
        scanf("%d", &a);
        isPrime(a) && cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 2084
object Main extends App{
    val n = scala.io.StdIn.readInt
    val x = scala.io.StdIn.readLine.split(" ").map(_.toInt).sorted
    val output = (x.head to x.last).map(e => (for(count <- x) yield (e-count)*(e-count)).sum).min
    println(output)
}


Measured memory_bytes: 27200
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
key_dict = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for i in range(n):
    key = input()
    key_dict[key] += 1

print("AC x " + str(key_dict["AC"]))
print("WA x " + str(key_dict["WA"]))
print("TLE x " + str(key_dict["TLE"]))
print("RE x " + str(key_dict["RE"]))

Measured memory_bytes: 9204
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false ll_MAX ll_MIN insert erase clear pop push compare ll64_MAX ll64_MIN  reverse replace stringstream string::npos length substr front priority_queue

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define conutBits(n)	__builtin_popcount(n)
#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	ll x, y, z;
	cin >> x >> z >> y;
	// douzle tmp = (x * 1.0) / y;
	if (x <= z * y) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 3636
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a_copy = a.copy()
biggest = max(a)
a_copy.remove(biggest)
second_biggest = max(a_copy)

for j in range(n):
    if a[j] == biggest:
        print(second_biggest)
    else:
        print(biggest)

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

int main(){
    int a,b;
    cin >> a >> b;
    if((a+b)%2==0){
        cout << (a+b)/2 << '\n';
    }
    else{
        cout << (a+b)/2+1 << '\n';
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int c[5];
  char cm;
  while(cin>>c[0]>>cm>>c[1]>>cm>>c[2]>>cm>>c[3]>>cm>>c[4]){
    int card[14];
    for(int i=0;i<14;i++)
      card[i] = 0;
    bool fourcard = false;
    bool threecard = false;
    bool twopair = false;
    bool onepair = false;
    bool fullhouse = false;
    for(int i=0;i<5;i++){
      card[c[i]]++;
      switch(card[c[i]]){
      case 2:
	if(threecard)
	  fullhouse = true;
	else if(onepair)
	  twopair = true;
	else
	  onepair = true;
	break;
      case 3:
	if(twopair)
	  fullhouse = true;
	else
	  threecard = true;
	break;
      case 4:
	fourcard = true;
	break;
      default:
	break;
      }
    }
    if(fullhouse){
      cout<<"full house"<<endl;
      continue;
    }
    if(fourcard){
      cout<<"four card"<<endl;
      continue;
    }
    if(threecard){
      cout<<"three card"<<endl;
      continue;
    }
    if(twopair){
      cout<<"two pair"<<endl;
      continue;
    }
    if(onepair){
      cout<<"one pair"<<endl;
      continue;
    }
    bool straight = false;
    for(int i=1;i<10;i++)
      if(card[i]&&card[i+1]&&card[i+2]&&card[i+3]&&card[i+4])
	straight = true;
    if(card[10]&&card[11]&&card[12]&&card[13]&&card[1])
      straight = true;
    if(straight)
      cout<<"straight"<<endl;
    else
      cout<<"null"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
    
using namespace std;
    
#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)
    
int main(){
    int N,K;
    int x[101];
    
    scanf("%d%d",&N,&K);
    
    REPI(N){
        scanf("%d",&x[i]);
    }
    
    int res = 0;
    int mid = K/2;
    
    REPI(N)
    {
        if(x[i]<=mid)
            res+=2*x[i];
        else
            res+=2*(K-x[i]);        
    }
    
    printf("%d\n",res);
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }
    for (int i = n - 1; i > 0; i--) {
      System.out.print(a[i] + " ");
    }
    System.out.println(a[0]);
  }
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main()
{
	int a, b, t;
	cin >> a >> b >> t;

	cout << (t/a)*b << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

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

int main(){
    int N;
    ll ANS=0,Lz=2,Lo=1;
    cin>>N;
    if(N==1){
        ANS=1;
        cout<<ANS<<endl;
        return 0;
    }

    for(int i=2;i<=N;i++){
        ANS=Lz+Lo;
        Lz=Lo,Lo=ANS;
    }
    cout<<ANS<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
n,k=map(int,input().split())
x=list(map(int,input().split()))
ans=float("inf")
for i in range(n-k+1):
    sm=x[i]
    sp=x[i+k-1]
    if sp<0:
        ans=min(-sm,ans)
    elif 0<sm:
        ans=min(ans,sp)
    else:
        ans=min(ans,min(sm*-2+sp,sp*2-sm))
print(ans)

Measured memory_bytes: 20080
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <limits>
using namespace std;

int main(void){
    int h, w;
    cin >> h >> w;
    string str[h];
    for(int i = 0; i < h; i++)
        cin >> str[i];
    int count = 0;
    for(int i = 1; i < h-1; i++){
        for(int j = 1; j < w-1; j++){
            if(str[i][j] == '#' && str[i][j-1] != '#' && str[i][j+1] != '#'&& str[i-1][j] != '#' && str[i+1][j] != '#'){
                count++;
            }
        }
    }
    if(count == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author indy256
 */

#include <bits/stdc++.h>

using namespace std;

void solve(istream &in, ostream &out) {
    int n, k;
    in >> n >> k;

    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        in >> a[i];
        a[i] = (a[i] - 1 + k) % k;
    }

    long long res = 0;
    map<int, int> m;
    m[0] = 1;
    int s = 0;
    int s1 = 0;
    for (int i = 0; i < n; ++i) {
        if (i == k - 1) {
            --m[0];
        }
        if (i >= k) {
            s1 += a[i - k];
            s1 %= k;
            --m[s1];
        }
        s += a[i];
        s %= k;
        res += m[s];
        ++m[s];
    }

    out << res  << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solve(in, out);
}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  ll a[3];
  rep(i, 3) cin >> a[i];
  sort(a, a + 3);
  cout << a[2] - a[0] << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
A = sum(a)
x = A - 2*a[0]
ll = [x]

for i in range(1,n-1):
    x = x-2*a[i]
    ll.append(x)

for i in range(len(ll)):
    ll[i] = abs(ll[i])
    
print(min(ll))

Measured memory_bytes: 26060
#include<bits/stdc++.h>
#define rep(i,n,k) for(long long int i=k; i<n; ++i)
#define drep(i,n,k) for(long long int i=n-1; i>=k; --i)
using namespace std;

int main(){
  long long int n;
  cin >> n;
  vector<tuple<long long int, long long int>> a;
  rep(i, n, 0){
    long long int c;
    cin >> c;
    a.push_back(tie(c, i));
  }
  sort(a.begin(), a.end());
  rep(i, n, 0){
    long long int p, q;
    tie(p, q) = a[i];
    cout << q+1 << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2544
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let p: Vec<usize> = s.take(n).map(|a| a.parse().unwrap()).collect();
	let mut ans = 0;
	let mut i = 0;
	while i < n {
		if p[i] == i + 1 {
			i += 2;
			ans += 1;
		} else {
			i += 1;
		}
	}
	println!("{}", ans);
}


Measured memory_bytes: 3496
# -*- coding: utf-8 -*-


def main():
    from collections import deque

    n, q = map(int, input().split())
    graph = [[] for _ in range(n)]

    # KeyInsight
    # 直線のグラフとみなす
    # 累積和の考え方を応用

    # 隣接リストを作成
    for i in range(n - 1):
        ai, bi = map(int, input().split())
        graph[ai - 1].append(bi - 1)
        graph[bi - 1].append(ai - 1)

    values = [0 for _ in range(n)]

    for j in range(q):
        pi, xi = map(int, input().split())
        values[pi - 1] += xi

    # 木の持ち方
    d = deque()
    d.append(0)
    visited = [False for _ in range(n)]
    visited[0] = True

    # bfs
    while d:
        di = d.popleft()

        for g in graph[di]:
            if not visited[g]:
                visited[g] = True
                values[g] += values[di]
                d.append(g)

    print(' '.join(map(str, values)))


if __name__ == '__main__':
    main()


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

int w, h;
int maze[55][55];

void dfs(int y, int x){
	maze[y][x] = 0;
	//search8deg
	for(int i=-1; i<=1; i++){
		for(int j=-1; j<=1; j++){
			int nx = x - j;
			int ny = y - i;
			if(0 <= nx and nx < w and 0 <= ny and ny < h and maze[ny][nx] == 1){
				dfs(ny, nx);
			}
		}
	}
}

int main(){
while(1){	
	
	
	cin >> w >> h;
	if(w == 0 and h == 0) break;
	
	for(int i=0; i < h; i++){
		for(int j=0; j < w; j++){
			cin >> maze[i][j]; 
		}
	}
	
	int ans = 0;
	for(int i=0; i < h; i++){
		for(int j=0; j < w; j++){
			if(maze[i][j] == 1){
				dfs(i, j);
				ans += 1;
			}
		}
	}
	
	cout << ans << endl;
	
	
}//END
	return 0;
}


Measured memory_bytes: 3288
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    vector<double> v;
    for (int i = 0; i < n; i++)
    {
        double num;
        cin >> num;
        v.push_back(num);
    }

    double ans = 0;
    for (int i = 0; i < n-1; i++)
    {
        double min = 10001;
        int minIndex = 0;
        double preMin = 10001;
        int preMinIndex = 0;
        for (int j = 0; j < v.size(); j++)
        {
            if (v[j] < min)
            {
                preMin = min;
                preMinIndex = minIndex;
                min = v[j];
                minIndex = j;
            }
            else if (v[j] < preMin)
            {
                preMin = v[j];
                preMinIndex = j;
            }
        }

        double calcNum = ((min + preMin) / 2.0);
        ans = calcNum;
        v[minIndex] = calcNum;
        v.erase(v.begin() + preMinIndex);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 1000

int main(){

	int N;
	scanf("%d",&N);

	vector<int> V;
	int tmp;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&tmp);
		V.push_back(tmp);
	}

	V.erase(unique(V.begin(),V.end()),V.end());

	printf("%d",V[0]);
	for(int i = 1; i < V.size(); i++){
		printf(" %d",V[i]);
	}
	printf("\n");

	return 0;
}




Measured memory_bytes: 3496
function Main(input){ 
  var D = parseInt(input,10);
  if(D == 25){
  console.log("Christmas");    
  }else if(D == 24){
    console.log("Christmas Eve");
  }else if(D == 23){
    console.log("Christmas Eve Eve");
  }else if(D == 22){
    console.log("Christmas Eve Eve Eve");
  }
}
    Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define N 1010
ll x,y,z,k,a[N],b[N],c[N];
ll t[N][N];
struct qry{
  ll i,j,cost;
  bool operator<(const qry&key)const{
    return this->cost<key.cost;
  }
};
qry qrys(ll ii,ll jj,ll costt){
    qry gen;gen.i=ii,gen.j=jj,gen.cost=costt;
    return gen;
  }
int main(){
  cin>>x>>y>>z>>k;
  for(int i=0;i<x;i++)cin>>a[i]; sort(a,a+x);
  for(int i=0;i<y;i++)cin>>b[i]; sort(b,b+y);
  for(int i=0;i<z;i++)cin>>c[i]; sort(c,c+z);
  priority_queue<qry> Q;
  for(int i=0;i<x;i++)for(int j=0;j<y;j++){
    t[i][j]=z-2;
    Q.push(qrys(i,j,a[i]+b[j]+c[z-1]));
  }
  while(k--){
    qry cur=Q.top();
    Q.pop();
    cout<<cur.cost<<endl;
    ll i=cur.i,j=cur.j;
    if(t[i][j]<0)continue;
    Q.push(qrys(i,j,a[i]+b[j]+c[t[i][j]]));
    t[i][j]--;
  }
    return 0;
}



Measured memory_bytes: 33128
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;

ll Pow(ll x, ll n)
{
  if(n == 0) return 1;
  if(n % 2 == 0) return Pow(x*x % 1000000007, n/2);
  else return x * Pow(x,n-1) % 1000000007;
}

ll n,k;
ll gcd[100005];
ll sum;

int main()
{
	cin>>n>>k;
	for(ll i=1;i<=k;i++)
	{
		gcd[i]=Pow(k/i,n);
	}
	for(ll i=k/2;i>0;i--)
	{
		for(ll j=2*i;j<=k;j+=i)
		{
			gcd[i]-=gcd[j];
		}
	}
	for(ll i=1;i<=k;i++)
	{
		gcd[i]=i*gcd[i]%1000000007;
		sum+=gcd[i]%1000000007;
	}
	
	cout<<sum%1000000007;
	return 0;
}

Measured memory_bytes: 4400
import java.util.Scanner;

public class Main {
	
	public static void main(String []args) {
		Scanner sc = new Scanner(System.in);
		
		int h = Integer.parseInt(sc.next());
		int w = Integer.parseInt(sc.next());
		
		if(h % 3 == 0 || w % 3 == 0) {
			System.out.println(0);
			return;
		}
		long min = (long)(Math.min(h, w));
		int H = h % 2 == 0? h/2 : (h-1)/2;
		for(int i = 1 ; i < w ;i++) {
			long temp = Math.max((long)(w-i)*h,(long)(h-H)*i) - Math.min((long)(w-i)*h,(long)H*i);
			min = Math.min(min, temp);
		}
		
		int W = w % 2 == 0 ? w/2 : (w-1)/2;
		for(int i = 1 ; i < h ;i++) {
			long temp = Math.max((long)(h-i)*w, (long)(w-W)*i) - Math.min((long)(h-i)*w, (long)W*i);
			min = Math.min(temp, min);
		}
		
		System.out.println(min);
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
//---------------------------

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N,K; cin>>N>>K;
  ll count=0;
  // for(ll b=K+1; b<=N; b++) {
  //   for(ll c=K; c<b; c++) {
  //     count += (N - c) / b;
  //     if(c!=0)count++;
  //   }
  //   // count += (b - K)*N / b - (b-1+K)*(b-K) / (2*b);
  // }

  for(int b=K+1; b<N+1; b++) {
    int p= N / b;
    int r= N % b;
    count += p*max(0, b-K) + max(0,r-K+1);
  }
  if(K==0)count -= N;
  P(count);
  return 0;
}


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

using namespace std;

int main(){
    int N,M;
    cin>>N>>M;

    vector<pair<long,long>> nowp(N);
    for(auto &x:nowp){
        cin>>x.first>>x.second;
    }

    vector<int> minpoint(N);
    vector<pair<long ,long>> checkp(M);
    for(auto &x:checkp){
        cin>>x.first>>x.second;
    }

    for(int i=1;i<M;++i){
        for(int k=0;k<N;++k){
            if(abs(checkp[i].first-nowp[k].first)+abs(checkp[i].second-nowp[k].second)<abs(checkp[minpoint[k]].first-nowp[k].first)+abs(checkp[minpoint[k]].second-nowp[k].second)){
                minpoint[k]=i;
            }
        }
    }


    for(auto &x:minpoint){
        cout<<x+1<<endl;
    }

}

Measured memory_bytes: 256
use std::collections::{BTreeMap, BTreeSet};

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let l: usize = sc.read();
    let mut trie = TrieNode::new();
    for _ in 0..n {
        let s: Vec<usize> = sc
            .chars()
            .into_iter()
            .map(|c| c as usize - '0' as usize)
            .collect();
        trie.add(&s, 0);
    }

    let mut result = vec![];
    trie.get_count(0, &mut result);

    let mut grundy: u64 = 0;
    for &r in result.iter() {
        let height = l - r;
        let g = 1 << (height as u32).trailing_zeros();
        grundy ^= g;
    }
    println!("{}", if grundy != 0 { "Alice" } else { "Bob" });
}

struct TrieNode {
    child: [Option<Box<TrieNode>>; 2],
}

impl TrieNode {
    fn new() -> Self {
        TrieNode {
            child: [None, None],
        }
    }

    fn add(&mut self, s: &[usize], pos: usize) {
        if s.len() == pos {
            return;
        }
        if self.child[s[pos]].is_none() {
            self.child[s[pos]] = Some(Box::new(TrieNode::new()));
        }
        self.child[s[pos]].as_mut().unwrap().add(s, pos + 1);
    }

    fn get_count(&self, height: usize, result: &mut Vec<usize>) {
        let count = self.child.iter().filter(|c| c.is_none()).count();
        if count == 1 {
            result.push(height);
        }
        for child in self.child.iter() {
            match child.as_ref() {
                Some(child) => child.get_count(height + 1, result),
                None => {}
            }
        }
    }
}

fn grundy(h: usize, map: &mut BTreeMap<usize, u32>) -> u32 {
    match map.get(&h) {
        Some(&v) => v,
        None if h == 1 => 1,
        None => {
            let mut set = BTreeSet::new();
            for remove in 1..(h + 1) {
                let mut g = 0;
                for i in 1..remove {
                    g ^= grundy(h - i, map);
                }
                set.insert(g);
            }
            let g = (0..).skip_while(|i| set.contains(&i)).next().unwrap();
            map.insert(h, g);
            g
        }
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 9468
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

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

P move(char** stage){
	set<P> visited;
	int c=1;
	int x=0,y=0;

	visited.insert(P(x,y));

	while(1){
		if(stage[y][x] == '>') x++;
		else if(stage[y][x] == '^') y--;
		else if(stage[y][x] == '<') x--;
		else if(stage[y][x] == 'v') y++;
		else if(stage[y][x] == '.') break;

		visited.insert(P(x,y));
		if(++c != visited.size()) return P(-1,-1);
	}

	return P(x,y);
}

int main(){

	string str;
	int h,w;
	while(getline(cin,str)){
		sscanf(str.c_str(),"%d %d",&h,&w);
		if(h==w && h==0) break;

		char** stage = new char*[h];
		for(int i=0;i<h;i++) stage[i] = new char[w];

		for(int y=0;y<h;y++){
			getline(cin,str);
			for(int x=0;x<w;x++){
				stage[y][x] = str[x];
			}
		}

		P pos = move(stage);

		if(pos.first == -1 && pos.second == -1) cout << "LOOP" << endl;
		else printf("%d %d\n",pos.first,pos.second);

		for(int i=0;i<h;i++) delete[] stage[i];
		delete[] stage;
	}
}

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

int main() {
	char a, b;
	cin >> a >> b;
	int a2, b2;
	if (a == 'H') {
		a2 = 1;
	} else {
		a2 = -1;
	}
	if (b == 'H') {
		b2 = 1;
	} else {
		b2 = -1;
	}

	char ans;
	if (a2 * b2 == 1) {
		ans = 'H';
	} else {
		ans = 'D';
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int main(int argc,char const* argv[])
{
  string s;
  cin >> s;
  string news;
  int n=int(s.size());
  ll ans=0;
  for(int i=0;i<n;i++)
    {
      if(s[i]=='B' && s[i+1]=='C')
	{
	  news.push_back('D');
	  i++;
	}
      else
	{
	  news.push_back(s[i]);
	}

    }
  //cout << news << endl;
  int m=int(news.size());
  int nowachain=0;
  for(int i=0;i<m;i++)
    {
      if(news[i]=='A') 
	{
	  nowachain++;
	}
      else if(news[i]=='D')
	{
	  ans+=nowachain;
	}
      else
	{
	  nowachain=0;
	}
    }
  cout << ans << endl;
}


Measured memory_bytes: 776
// -*- coding:utf-8-unix -*-

use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
use std::convert::TryInto;
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//abc128-C

#[fastout]
fn main() {
    //     input! {
    //         n: u8,
    //         m: u8,
    //         sk: [[u8]; n],
    //         ps: [u8; m]
    //     }

    //     println!(
    //         r#"
    // n: {},
    // m: {},
    // sk: {:?},
    // ps: {:?}
    //         "#,
    //         n, m, sk, ps
    //     );

    let n: usize = read();
    let m: usize = read();
    let mut s: Vec<Vec<usize>> = vec![vec![]; m];
    let mut p: Vec<usize> = vec![];

    for i in 0..m {
        let k = read();
        for _ in 0..k {
            s[i].push(read());
        }
    }

    for _ in 0..m {
        p.push(read());
    }
    let mut ans = 0;

    let mut sstate = vec![false; n];

    for switch_state in 0..(2u64.pow(n.try_into().unwrap())) {
        for i in 0..n {
            sstate[i] = (switch_state >> i) % 2 == 0
        }

        let mut is_ok = true;
        for i in 0..m {
            let mut sum = 0;
            for s in &s[i] {
                sum += if sstate[s - 1] { 1 } else { 0 }
            }

            if sum % 2 != p[i] {
                is_ok = false;
            }
        }

        if is_ok {
            ans += 1;
        }
    }

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


Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,m=0,n=0,max=0;
    cin>>a;
    int b[a],c[a];
    for(int i=0;i<a;i++){cin>>b[i];}
    for(int i=0;i<a;i++) cin>>c[i];
    for(int i=0;i<a;i++){
        m+=b[i];
        int w=m;
        for(int j=0;j<a-i;j++){
            w+=c[n+j];
        }
        n++;
        if(max<w) max=w;
        if(max<m) max=m;
    }
    cout<<max<<endl;
}


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

typedef long long ll;
typedef unsigned long long ull;

void getpost(int n, int *pre, int *in, int *post){
    int m;
    for(int i=0;i<n;i++){
        if(in[i]==pre[0]){
            m=i;
            break;
        }
    }
    post[n-1]=pre[0];
    if(m>0) getpost(m, pre+1, in, post);
    if(m<n-1) getpost(n-1-m, pre+m+1, in+m+1, post+m);
}

int main(){
    int n;
    cin >> n;
    int pre[40], in[40], post[40];
    for(int i=0;i<n;i++) cin >> pre[i];
    for(int i=0;i<n;i++) cin >> in[i];
    
    getpost(n, pre, in ,post);
    cout << post[0];
    for(int i=1;i<n;i++) cout << ' ' << post[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 3108
/*
𝓐𝓾𝓽𝓱𝓸𝓻:-

╭━━━┳━━━┳╮╱╭┳━━━┳━━━┳━━╮╭╮╱╭╮
┃╭━╮┃╭━╮┃┃╱┃┃╭━╮┃╭━╮┃╭╮┃┃┃╱┃┃  
┃╰━━┫┃╱┃┃┃╱┃┃╰━╯┃┃╱┃┃╰╯╰┫╰━╯┃
╰━━╮┃╰━╯┃┃╱┃┃╭╮╭┫╰━╯┃╭━╮┃╭━╮┃
┃╰━╯┃╭━╮┃╰━╯┃┃┃╰┫╭━╮┃╰━╯┃┃╱┃┃
╰━━━┻╯╱╰┻━━━┻╯╰━┻╯╱╰┻━━━┻╯╱╰╯  

*/

#include <bits/stdc++.h> 
using namespace std; 
#define int long long int
#define REDBULL ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define endl "\n"


int32_t main()
{
	REDBULL
	int n;
	cin>>n;
	int a[n];
	int sum2=0;
	for(int i=0;i<n;i++)
		{
			cin>>a[i];
			sum2+=a[i];
		}
	int sum[n];
	sum[0]=a[0];
	for(int i=1;i<n-1;i++)
		sum[i]=a[i]+sum[i-1];
	set<int> set;
	for(int i=0;i<n-1;i++)
	{
		int check=abs(sum2-sum[i]);
		set.insert(abs(check-sum[i]));
	}
	// cout<<endl;
	auto f=set.begin();
	cout<<*f<<endl;
	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()

#define MAX_N 110

int N, K;
int table[MAX_N];
// offset: 0 ~ MAX_N
// A, B: 0 ~ 2
int cache[MAX_N][3][3];

bool invalid(int x) {
  return x != 0 && x != 1 && x != 2;
}

bool isConst(int offset) {
  return !invalid(table[offset]);
}

// (offset) A B ? ...
int solve(int offset, int A, int B) {
  // cout << "solve(" << offset <<", " << A <<", " << B <<")" << '\n';
  // | x y ? [wall]
  if (offset + 2 >= N) return 1; // goal
  if (offset >= 0 && cache[offset][A][B] != -1) return cache[offset][A][B];

  int ans = -1;
  // A B C ...
  // shift
  if (isConst(offset+2)) {
    int next = table[offset+2];
    // check
    if (A == B && B == next) return 0;
    ans = solve(offset+1, B, table[offset+2]);
  }

  // A B ? ...
  else {
    // x x [^x] ...
    if (A == B) {
      int a, b = -1;
      if (A == 0) { a = 1; b = 2; }
      if (A == 1) { a = 0; b = 2; }
      if (A == 2) { a = 0; b = 1; }
      ans = solve(offset+1, B, a) + solve(offset+1, B, b);
    }
    // x y (any) ...
    else {
      ans = solve(offset+1, B, 0) + solve(offset+1, B, 1) + solve(offset+1, B, 2);
    }
  }
  ans = ans % 10000;
  if (offset >= 0) cache[offset][A][B] = ans;
  return ans;
}



int main() {
  cin >> N >> K;
  rep(i, MAX_N) table[i] = -1;
  rep(i, MAX_N)
    rep(a, 3)
      rep(b, 3)
        cache[i][a][b] = -1;
  // input
  rep(i, K) {
    int a, b;
    cin >> a >> b;
    table[a-1] = b-1;
  }

  // rep(i, N) cout << " "<<(table[i]==-1?"?":str(table[i]));
  // main
  cout << solve(-2, -11, -12) << '\n';
  return 0;
}

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

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

const int INF = 1000000007;

int main(){
	int a,b;
	cin>>a>>b;
	if(a<=8 && b<=8) cout<< "Yay!" <<endl;
	else cout<< ":(" <<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cassert>
using namespace std;

int S[366][4][4] = {};
int vis[366][3][3][7][7][7][7] = {};
int dx[9] = {-1,0,1,0,-2,0,2,0,0},dy[9] = {0,-1,0,1,0,-2,0,2,0};

struct state{
    int x = 1,y = 1;
    int d = 1;
    int rest[4][4] = {};
    bool in(){
        return 0<=x && x<=2 && 0<=y && y<=2;
    }
    void update(){
        for(int i=0;i<4;i++) for(int j=0;j<4;j++) rest[i][j]++;
        for(int i=0;i<2;i++) for(int j=0;j<2;j++) rest[x+i][y+j] = 0;
    }
    bool ok(){
        if(!in()) return false;
        for(int i=0;i<2;i++) for(int j=0;j<2;j++) if(S[d][x+i][y+j]==1) return false;
        return true;
    }
    bool ok2(){
        for(int i=0;i<4;i++) for(int j=0;j<4;j++) if(rest[i][j]==7) return false;
        return true;
    }
};
int main(){
    int N;
    while(cin >> N && N){
        for(int d=1;d<=N;d++) for(int i=0;i<4;i++) for(int j=0;j<4;j++) cin >> S[d][i][j];
        for(int d=0;d<=N;d++) for(int i=0;i<3;i++) for(int j=0;j<3;j++) 
        for(int a=0;a<7;a++) for(int b=0;b<7;b++)
        for(int c=0;c<7;c++) for(int e=0;e<7;e++) vis[d][i][j][a][b][c][e] = 0;
        queue<state> Q;
        state init;
        init.update();
        if(!init.ok()){
            cout << 0 << endl;
            continue;
        }
        Q.push(init);
        int complete = 0;
        while(!Q.empty()){
            state now = Q.front(); Q.pop();
            if(now.d==N){
                complete = 1;
                break;
            } 
            for(int i=0;i<9;i++){
                state ne = now;
                ne.x += dx[i]; ne.y += dy[i];
                ne.d++;
                if(!ne.ok()) continue;
                ne.update();
                if(ne.ok2() && !vis[ne.d][ne.x][ne.y][ne.rest[0][0]][ne.rest[0][3]][ne.rest[3][0]][ne.rest[3][3]]){
                    vis[ne.d][ne.x][ne.y][ne.rest[0][0]][ne.rest[0][3]][ne.rest[3][0]][ne.rest[3][3]] = 1;
                    Q.push(ne);
                }
            }
        }
        cout << complete << endl;
    }
}


Measured memory_bytes: 34028
def main():
    N,*A=map(int, open(0).read().split())
    L,C={},{}
    for i,a in enumerate(A):
        if a in C:
            C[a]+=1
        else:
            C[a]=1
            L[a]=i
    Z=[0]*N
    B=sorted(C,reverse=True)
    l=N-1
    cnt=0
    for b,c in zip(B,B[1:]+[0]):
        l=min(l,L[b])
        cnt+=C[b]
        Z[l]+=(b-c)*cnt
    print(*Z, sep="\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 29768
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	string ans = "";
	while (n > 0) {
		n -= 1;
		int rem = (n) % 26;
		ans += ('a' + rem);
		n /= 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
}



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

int main(void){
    int i, j, n, r, S[13], H[13], C[13], D[13];
    char s[2];
    cin >> n;
    for (i=0; i<13; i++){ 
        S[i]=i+1;
        H[i]=i+1;
        C[i]=i+1;
        D[i]=i+1;
    }
    for (i=0; i<n; i++){
        cin >> s >> r;
        if(s[0]=='S') S[r-1] = 0; 
        if(s[0]=='H') H[r-1] = 0; 
        if(s[0]=='C') C[r-1] = 0; 
        if(s[0]=='D') D[r-1] = 0; 
    }
    for (i=0; i<4; i++){
        for (j=0; j<13; j++){
            if(i==0 && S[j]!=0) cout << "S" << " " << S[j] << endl;
            if(i==1 && H[j]!=0) cout << "H" << " " << H[j] << endl;
            if(i==2 && C[j]!=0) cout << "C" << " " << C[j] << endl;
            if(i==3 && D[j]!=0) cout << "D" << " " << D[j] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3104
def dis(p1, p2):
    return abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])

N,M = map(int, input().split())
a = []
for i in range(N):
    a.append(list(map(int, input().split())))

b = []
for i in range(M):
    b.append(list(map(int, input().split())))

for s in a:
    max_d = 1e9
    cp = 0
    for k,v in enumerate(b):
        tmp_d = dis(s, v)
        if(tmp_d < max_d):
            max_d = tmp_d
            cp = k
    print(cp+1)


Measured memory_bytes: 3064
import sys

n, q = map(int, input().split())
lines = sys.stdin.readlines()
links = [set() for _ in range(n)]
for line in lines[:n - 1]:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
adds = [0] * n
for line in lines[n - 1:]:
    p, x = map(int, line.split())
    p -= 1
    adds[p] += x
ans = [-1] * n
q = [(0, 0)]
while q:
    v, a = q.pop()
    a += adds[v]
    ans[v] = a
    for u in links[v]:
        if ans[u] == -1:
            q.append((u, a))

print(*ans)


Measured memory_bytes: 118632
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 2000010;

int n,m,T;
int main()
{
    char a[10];
    cin>>a;
    char b[10];
    int n=strlen(a);
    for(int i=n-1;i>=0;i--)
        b[i]=a[n-i-1];
        int flag=1;
    for(int i=0;i<n;i++)
        if(a[i]==b[i]);
    else flag=0;
    if(flag)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
import math

def sign(x):
    if x >= 0:
        return True
    else:
        return False

n = int(input())
while n != 0:
    a = []
    for i in range(n):
        a.append(int(input()))
    b = []
    b.append(a[0])
    for i in range(1,len(a)):
        if b[len(b)-1] > 0 and a[i] > 0:
            b[len(b)-1] = b[len(b)-1] + a[i]
        else:
            b.append(a[i])

    ans = b[0]
    for i in range(len(b)):
        S = 0
        for j in range(i,len(b)):
            S = S + b[j]
            ans = max(S, ans)
    print(ans)
    n = int(input())



Measured memory_bytes: 5772
main = do
  s <- getLine
  let n = read s :: Int
  if n == 0 then
    return ()
  else do
    getLine >>= (putStrLn . show . stddev . map read . words)
    main

stddev :: [Int] -> Double
stddev xs = let n=fromIntegral(length xs)
                ave = (fromIntegral (sum xs)) / n in
  sqrt ((sum $ map ( (^ 2).(flip (-) ave).fromIntegral) xs) / n)

Measured memory_bytes: 4944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string N;
    cin >>N;
    
    rep(i,3){
        if(N[i]=='1'){
            cout<<"9";
        }else{
            cout<<"1";
        }
    }
    cout<<endl;
 


    return 0;
    

}

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

#define rep(i,a,b)     for(int i=a;i<(b);i++)
typedef long long                ll;
const int mod = 1e9 + 7;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    string s, t;
    cin >> s >> t;

    int n = s.length();
    int m = t.length();
    ll ans = INT_MAX, c;

    rep(i, 0, n - m + 1)
    {   c = 0;
        rep(j, 0, m)
        {
            if (s[i + j] != t[j])
                c++;
        }
        ans = min(ans, c);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3628
while gets do
  max = $_.to_i

  prime_list = [false, false] + [true] * (max - 1)

  loop_max = (max**0.5)

  (2..loop_max).each do |i|
    next unless prime_list[i]
    limit = ((max.to_f/i.to_f) - i.to_f).truncate
    base = (i*i)
    (0..limit).each do |j|
      prime_list[base + i*j] = false
    end
  end

  puts prime_list.select{ |p| p }.count
end

Measured memory_bytes: 29724