akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cassert>
#include<ctime>
#include<climits>
#include<queue>
#include<fstream>
#include<deque>
#include<iomanip>
#include<list>
#include<stack>
#include<sstream>
#include<string>
#include<cctype>
#include<cstdio>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<set>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-10
#define F first
#define S second
#define all(n) n.begin(),n.end()
#define pb push_back
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define INF (1<<27)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const int dx[4] = {-1,0,+1,0};
const int dy[4] = {0,-1,0,+1};
 
class Solve{
private:
  int d;
  int imap[110][110];
public:
 
  Solve(int n):d(n){}
  ~Solve(){}
 
  int Connect(P p){
    int cnt = 0;
    rep(i,4){
      int nx = p.F+dx[i],ny = p.S+dy[i];
      if(!(0<=nx && nx <d && 0<= ny && ny < d))continue;
      if(imap[ny][nx] == 1)cnt++;
    }
    return cnt;
  }
 
 
  void display(){
      cout << "--- in display ---" << endl;
      rep(i,d){
    rep(j,d){
      if(imap[i][j] == 1)cout << '#';
      else cout << ' ';
    }
    cout << endl;
      }
      cout << endl;
    }
 
 
  void run(){
    rep(i,d+1)rep(j,d+1)imap[i][j] = 0;
 
    rep(i,d){
      imap[0][i] = 1;
      imap[i][0] = 1;
      imap[i][d-1] = 1;
    }
 
   
 
 
    P pos = P(d-1,d-1);
    int dir = 0;
    int cnt = 0;
    bool fin = false;
    while(true){
 
      int nx,ny;
      nx  = pos.F,ny = pos.S;
      while(true){
    //cout << "nx = " << nx << ",ny = "<< ny << ",dir = " << dir << endl;
    //display();
 
 
    if(!(Connect(P(nx,ny)) == 2 || Connect(P(nx,ny)) == 1)){
      imap[ny-dy[dir]][nx-dx[dir]] = 0;
      //cout << "Lase nx = " << nx << ",ny = "<< ny << endl;
      //cout << "FIN! connnect = " << Connect(P(nx,ny)) << endl;
      fin = true;
      break;
    }
 
    if(imap[ny+dy[dir]][nx+dx[dir]] == 1){
      //cout << "IN nx = " << nx+dx[dir] << ",ny = " << ny+dy[dir] << endl;
      imap[ny][nx] = 0;
      cnt--;
      break;
    }
    imap[ny][nx] = 1;
    cnt++;  
 
 
    nx += dx[dir],ny += dy[dir];
      }
      //cout << "------ cnt = " << cnt << endl;
      if(fin){
    //cout << "dir = " << dir << endl;
    break;
      }
      if(cnt == 0)break;
      cnt =0;
 
      pos.F = nx-dx[dir],pos.S = ny-dy[dir];
      dir++;
      dir = dir%4;
    }
 
    rep(i,d){
      rep(j,d){
    if(imap[i][j] == 1)cout << '#';
    else cout << ' ';
      }
      cout << endl;
    }
     
 
  }
 
 
};
 
 
int main(){
  int T;
  cin >> T;
  while(T-- > 0){
    int _n;
    cin >> _n;
    Solve ans = Solve(_n);
    ans.run();
    if(T != 0)cout << endl;
  }
return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.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 pb emplace_back
typedef long long ll;
typedef pair<ll,ll> pint;

pair<pint,int> vx[200005],vy[200005];
vector<pint> g[400005];
ll d[400005];
ll INF=1000100010001000100;
int n,m;
int dijkstra(int st){
    priority_queue<pint,vector<pint>,greater<pint> > pq;
    rep(i,400005) d[i]=INF;
    d[st]=0;
    pq.push(make_pair(0,st));
    while(!pq.empty()){
        pint pi=pq.top();pq.pop();
        int t=pi.second;
        if(d[t]<pi.first) continue;
        for(vector<pint>::iterator it=g[t].begin();it!=g[t].end();++it){
            if(d[it->second]>d[t]+it->first){
                d[it->second]=d[t]+it->first;
                pq.push(make_pair(d[it->second],it->second));
            }
        }
    }
}
int main(){
    int k,xi,yi;
    cin>>m>>n>>k;
    FOR(i,1,k+1){
        cin>>xi>>yi;
        --xi,--yi;
        vx[i]={{xi,yi},i},vy[i-1]={{yi,xi},k+i+1};
        g[i].pb(1,k+i+1);g[i+k+1].pb(1,i);
    }
    vx[k+1]={{m-1,n-1},k+1},vy[k]={{n-1,m-1},k+k+2};
    g[k+1].pb(1,k+k+2);g[k+k+2].pb(1,k+1);
    sort(vx,vx+k+2);
    sort(vy,vy+k+1);
    rep(i,k+1){
        if(vx[i].first.first==vx[i+1].first.first){
            g[vx[i].second].pb(abs(vx[i+1].first.second-vx[i].first.second),vx[i+1].second);
            g[vx[i+1].second].pb(abs(vx[i+1].first.second-vx[i].first.second),vx[i].second);
        }
    }
    rep(i,k){
        if(vy[i].first.first==vy[i+1].first.first){
            g[vy[i].second].pb(abs(vy[i+1].first.second-vy[i].first.second),vy[i+1].second);
            g[vy[i+1].second].pb(abs(vy[i+1].first.second-vy[i].first.second),vy[i].second);
        }
    }
    dijkstra(0);
    ll ans=min(d[k+1],d[k+k+2]);
    if(ans==INF) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 59040
import numpy as np
n = int(input())
x = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
#一行で入力された数値をリストに
p = 0
x2 = np.power(x,2)

xsum = sum(x)
xsum2 = sum(x2)

p = -(-xsum//n)
p2 = xsum//n

print(min(xsum2 - 2*p*xsum + n*p*p,xsum2 - 2*p2*xsum + n*p2*p2))


Measured memory_bytes: 12508
#include<bits/stdc++.h>
using namespace std;
int n;
int a[2001];
int ans=0;
main(){
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			for(int k=j+1;k<=n;k++)
				if(a[i]+a[j]>a[k]) ans++;
				else break;
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
N, A, B, C = [int(i) for i in input().split()]
L = [int(input()) for i in range(N)]

def dfs(idx, a, b, c):

    if idx == N:
        if a == 0 or b == 0 or c == 0:
            return 1e9
        
        return abs(A - a) + abs(B - b) + abs(C - c)
    
    x = dfs(idx + 1, a, b, c)
    y = dfs(idx + 1, a + L[idx], b, c) + 10*(a != 0)
    z = dfs(idx + 1, a, b + L[idx], c) + 10*(b != 0)
    w = dfs(idx + 1, a, b, c + L[idx]) + 10*(c != 0)
    return min(x, y, z, w);

ans = dfs(0, 0, 0, 0);
print(ans)



Measured memory_bytes: 3064
# AOJ 0229 Big Hit !
# Python3 2018.6.25 bal4u

while 1:
	b, r, g, c, s, t = map(int, input().split())
	if (b|r|g|c|s|t) == 0: break
	ans = 100
	ans += 15*b+(15-2)*5*b
	t -= 5*b
	ans += 15*r+(15-2)*3*r
	t -= 3*r
	ans += 7*g
	ans += 2*c
	t -= s
	ans -= 3*t
	print(ans);


Measured memory_bytes: 5596
using System;
using System.Collections.Generic;

namespace B___Collatz_Problem
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = int.Parse(Console.ReadLine());
            var a = new List<int> { s };
            for (var i = 1; i < 1000000; i++)
            {
                if (a[i - 1] % 2 == 0)
                {
                    a.Add(a[i - 1] / 2);
                }
                else
                {
                    a.Add(3 * a[i - 1] + 1);
                }
                for (var j = 0; j < a.Count - 1; j++)
                {
                    for (var k = 1; k < a.Count; k++)
                    {
                        if (a[j] == a[k] && j < k)
                        {
                            Console.WriteLine(k + 1);
                            return;
                        }
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
  
  int N;
  cin >> N;
  cout << N / 3 << endl;

  return 0;
}

Measured memory_bytes: 3608
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = tuple(map(int, input().split()))

    ans = 0
    for i in range(n):
        ai = a[i]
        bi = b[i]
        if ai >= bi:
            ans += bi
        else:
            bi -= a[i]
            ans += a[i]

            aj = a[i+1]
            if aj >= bi:
                a[i+1] -= bi
                ans += bi
            else:
                a[i+1] = 0
                ans += aj
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18624
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
 
int main(){
  ll n,tmp = -9999999999,kai = 0,ans = 0;
  cin >> n;
  ll a[n];
  REP(i,n) {
    cin >> a[i];
  }
  SORT(a,n)
  REP(i,n) {
    if (a[i] < 0) {
      kai++;
      a[i] *= -1;
    }
  }
  SORT(a,n)
  if (kai % 2 == 1) {
    for(int i = 1; i < n;i++) {
      ans += a[i];
    }
    ans -= a[0];
  } else {
    for(int i = 0; i < n;i++) {
      ans += a[i];
    }
  }
  cout << ans;
}

Measured memory_bytes: 1024
// AOJ 2846: Slimming Plan
// 2017.11.24 bal4u@uu

#include <stdio.h>

int w[100001];
long long s[100001];

char buf[800000], *p;
int getint()
{
	int n = 0;
	if (*p == '-') {
		p++; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
		return -n;
	}
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int S, T, D, i;
	long long x, t, ans;
	
	fgets(p=buf, 30, stdin);
	S = getint(), p++, T = getint(), p++, D = getint();
	fgets(p=buf, sizeof(buf), stdin);
	for (i = 1; i <= D; i++) w[i] = getint(), p++;
	x = S, ans = -1;
	for (i = 1; i <= D; i++) {
		s[i] = x;
		x += w[i];
		if (x <= T) break;
	}
	if (i < D) { ans = i; goto done; }
	if (x >= S) goto done;
	ans = 1LL << 60;
	for (i = 1; i <= D; i++) {
		if (w[i] < 0) {
			t = (1 + (s[i]-T+w[i]-1)/(s[i]-x)) * D + i;
			if (t < ans) ans = t;
		}
		x += w[i];
	}
done: printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3440
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
double const PI=3.141592653589793;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int N;
int D[100];

int main(){
    cin>>N;
    rep(i,N){
        int d,e;
        cin>>d>>e;
        D[i]=d==e;
    }

    string ans="No";
    rep(i,N-2){
        if(D[i]&D[i+1]&D[i+2]==1){
            ans="Yes";
            break;
        }
    }

    cout<<ans<<endl;
}

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

typedef long long int ll;
vector<ll> len, patty;

ll recLength(ll n)
{
    return n == 0 ? 1 : recLength(n - 1) * 2 + 3;
}

ll recPatty(ll n)
{
    return n == 0 ? 1 : recPatty(n - 1) * 2 + 1;
}

ll calcPatty(ll x, ll n)
{
    if (x <= 0 && n == 0)
    {
        return 0;
    }
    else if (x > 0 && n == 0)
    {
        return 1;
    }
    else if (x <= len[n - 1] + 1)
    {
        return calcPatty(x - 1, n - 1);
    }
    else
    {
        return patty[n - 1] + 1 + calcPatty(x - len[n - 1] - 2, n - 1);
    }
}

int main()
{
    ll N, K;
    cin >> N >> K;

    for (ll i = 0; i < N; i++)
    {
        len.push_back(recLength(i));
        patty.push_back(recPatty(i));
    }
    cout << calcPatty(K, N) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
?????????????????£?????????
"""

while True:
    cards = input().strip()
    if cards == "-":
        break
    times = int(input().strip())
    for i in range(times):
        num = int(input().strip())
        cards = cards[num:] + cards[:num]
    print(cards)

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

int main()
{
  int64_t H, W, K, ans = 0;
  cin >> H >> W >> K;
  char c;
  vector<vector<bool>> Grid(H, vector<bool>(W, 0)); // 0: white. 1: black, 2: red
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> c;
      if (c == '#')
        Grid[i][j] = 1;
    }
  }
  for (int bith = 0; bith < (1 << H); bith++)
  {
    for (int bitw = 0; bitw < (1 << W); bitw++)
    {
      int cnt = 0;
      for (int i = 0; i < H; i++)
      {
        if (bith & (1 << i))
          continue;
        for (int j = 0; j < W; j++)
        {
          if (bitw & (1 << j))
            continue;
          if (Grid[i][j])
            cnt++;
        }
      }
      if (cnt == K)
        ans++;
    }
  }
  cout << ans << endl;
}

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

int main(){
    char c;
    rep(i, 9){
        cin >> c;
        if(i%4==0) cout << c;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


a,b,k = m()

if a-k < 0:
    print(0,max(b+a-k,0))
else:
    print(a-k,b)






Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
void file(){
    freopen("read.in","r",stdin);
    freopen("write.out","w",stdout);
}
const int N=500010;
inline int read(){
    int sym=0,res=0;char ch=0;
    while (!isdigit(ch))sym|=(ch=='-'),ch=getchar();
    while (isdigit(ch)) res=(res<<3)+(res<<1)+(ch^48),ch=getchar();
    return sym?-res:res;
}
int n,m;
int main(){
    n=read();m=read();
    if (n>9||m>9||n<1||m<1){
        printf("-1");
    }else{
        printf("%d",n*m);
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


/*桁数を判定*/
int digit(v) {
	int cnt = 1;
	while ((v /= 10) != 0) { //10で割った数が0になるまで続ける
		cnt++;
	}
	return cnt;
}

/*n桁目の数字を返す*/
int nketakazu(int a, int n) {
	for (int i = 1;i < n;i++)
		a /= 10;
	a %= 10;
	return a;
}

int main(void){
	int kai_suu = 0;
	int min, max;
	int i,j;

	scanf("%d%d", &min, &max);

	for(i=min;i<=max;i++){
		for (j = 1;j < digit(i);j++) {
			if (nketakazu(i, j) != nketakazu(i, digit(i) - j + 1)) {
				//printf(" %d  %d \n", i,j);
				break;
			}
		}
		if (j == digit(i)) {
			kai_suu++;
		}
	}

	printf("%d\n", kai_suu);


	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){int k;
cin>>k;cout<<a[k-1];
}

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

N = int(input())
schedule = []
for i in range(N):
    A, B = map(int, input().split())
    schedule.append((A, B))

schedule = sorted(schedule, key=lambda x: x[1])
ans = 0
end = 0

flg = True
for i in range(N):
    end += schedule[i][0]
    if end <= schedule[i][1]:                   # 重複がダメならば等号を消す
         continue
    flg = False

print("Yes" if flg else "No")

Measured memory_bytes: 98080
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

const ll mod=1e9+7;
const ll MAXN=2e5+5;
const ll inf=1e17;

vector<ll > fact(MAXN);

ll pwr(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

ll inv(ll a){
    return pwr(a, mod - 2);
}

ll comb(ll n, ll r){
    ll res = 1;
    for(int i = n; i > n - r; i--) res = (res * i) % mod;
    res = (res * inv(fact[r])) % mod;
    return res;
}

int main()
{
    fastio;
    fact[1] = 1;
    for(int i = 2; i < MAXN; i++){
        fact[i] = (i * fact[i - 1]) % mod;
    }
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = pwr(2, n);
    ans = (ans - comb(n, a) + mod) % mod;
    ans = (ans - comb(n, b) + mod) % mod;
    ans = (ans - 1) % mod;
    cout << ans << endl;
}


Measured memory_bytes: 1792
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 1000000007
#define M 2200000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}

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

	int a,b;
	cin>>a>>b;
	if(a<=b)cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;
	
}


Measured memory_bytes: 3656
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main()
{
  int k, x;
  cin >> k >> x;
  if(k * 500 >= x){
    cout << "Yes";
  }else{
    cout << "No"; 
  }
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
as = gets.chomp.split(" ").map(&:to_i)
dic = {}
sa = 0
as.each do |a|
	if dic[a]
		dic[a]+=1
	else
		dic[a] = 1
	end
end
dic.each do |k,v|
	if v >= k
		sa += v-k
	else
		sa += v
	end
end

puts sa

Measured memory_bytes: 15492
s = input()
i = 0
j = len(s) - 1
t1 = []
t2 = []

while True:
  #print(i,j)
  if(s[i] == "A"):
    t1.append(i)
    #print(t1)
  if(s[j] == "Z"):
    t2.append(j)
  if(len(t1) != 0 and len(t2) != 0):
    break
  i += 1
  j -= 1
  
print(t2[0]-t1[0] +1)
  

Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 
 
 
 
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 

// int n;
// cin>>n;
// vector<int>v(n);  map<int,vector<int>>m;
// for(int i=0;i<n;i++)
// {
//   cin>>v[i];
//   m[v[i]].push_back(i);
// }



// vector<int>x;
// if(m.find(1)==m.end())
// {
//   cout<<-1; return 0;
// }
// x.push_back(m[1][0]);

// for(int i=2;i<=n;i++)
// {
//   if(m.find(i)==m.end())break;
//   if(x.size()!=i-1)break;

//   for(int j=0;j<m[i].size();i++)
//   {
//     if(m[i][j]>x.back())
//     {
//       x.push_back(m[i][j]); break;
//     }
//   }
// }

// cout<<n-x.size()<<"\n";

int n;
cin>>n;

if(n%2==1)
{
  cout<<0; return 0;
}


int k=n/2;
 int cnt=0;
 int x=5;
 while(x<=k)
 {
   cnt+=k/x;
   x*=5;
 }

 cout<<cnt<<"\n";


}

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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acosl(-1)
#define ld long double
#define prime (1000000000 + 7)
#define INF 1000000000

using namespace std;

vl kmp(string &&s, string &r){
	vl vet(s.size() + 1, -1);
	ll t = -1;
	for(int i = 0; i < s.size(); ++i){
		while (t > -1 && s[i] != s[t]){
			t = vet[t];
		}
		vet[i+1] = ++t;
	}
	vl res;
	res.insert(res.begin(), vet.begin() + r.size() + 1, vet.end());
	res[0] = -1;
	return res;
}

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

	ll n, k;
	string s;
	cin >> n >> k >> s;
	s[k-1] = tolower(s[k-1]);
	cout << s << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  cout<<(N+110)/111*111<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};


int main(){
    int N;
    cin >> N;
    int P[N];
    int Q[N];
    int ord[N];
    rep(i,N) {
	cin >> P[i];
	ord[i] = i+1;
    }
    rep(i,N) {
	cin >> Q[i];
    }

    int a,b;
    int cnt = 0;
    do {
	bool fa = true;
	bool fb = true;
	
	rep(i,N) {
	    if(ord[i] != P[i]) fa = false;
	    if(ord[i] != Q[i]) fb = false;
	}
	if(fa) a = cnt;
	if(fb) b = cnt;
	cnt++;

	// for(auto itr : ord) cout << itr ;
	// cout << endl;
	// cout << cnt << endl;
    }while(next_permutation(ord,ord+N));

    cout << abs(a-b) << endl;
    
    return 0;
}



Measured memory_bytes: 3596
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    int n,h,w;
    cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

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

  if (n <= 599) {
    cout << "8" << endl;
  } else if (n <= 799) {
    cout << "7" << endl;
  } else if (n <= 999) {
    cout << "6" << endl;
  } else if (n <= 1199) {
    cout << "5" << endl;
  } else if (n <= 1399) {
    cout << "4" << endl;
  } else if (n <= 1599) {
    cout << "3" << endl;
  } else if (n <= 1799) {
    cout << "2" << endl;
  } else {
    cout << "1" << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
N,K=map(int,input().split())
X=N-K+1
Y=1
if X==0:
    print(Y)
else:
    Y=(N-K+2)*(N-K+2)*(K-1)+(N-2*K+3)*(N-K+2)*(N-K+3)/2-(N-K+2)*(N-K+3)*(2*N-2*K+5)/6+N-K+2
    print(int(Y%(1000000007)))


Measured memory_bytes: 61908
import sys
input = sys.stdin.readline

def gcd(a, b):
    while a > 0:
        if a < b:
            a, b = b, a
        a = a % b
    return b

def main():
    n, x = map(int, input().split())
    town = map(int, input().split())

    distance = map(lambda y: abs(x-y), town)
    res = next(distance)
    for d in distance:
        if d % res != 0:
            res = gcd(res, d)

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 11468
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <complex>
#include <iterator>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i, a, cont, next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i, a, b, step) repfn(i, a, i < b, i + step)
#define repab(i, a, b) repby(i, (a), (b), 1)
#define rep(i, n) repab(i, 0, (n))
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  int a, b, c, d, e, f;
  double x, y;
  while (cin >> a >> b >> c >> d >> e >> f) {
    y = (double)(d*c - a*f) / (b*d - a*e);
    x = (c - b*y) / a;
    printf("%.3f %.3f\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <cmath>
 
using namespace std;
 
// typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<string> vs;
 
// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
// repetition
#define FOR(i,m,n) for (ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for (ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)
 
// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl
 
//constant
const double    EPS     = 1e-10;
const double    PI      = acos(-1.0);
const int       INFTY   = (1<<21);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

ll c[51][51];

void init() {
    REP(i, 51) {
        REP(j, 51) {
            c[i][j] = -1;
        }
    }
}

ll combi(ll n, ll r) {
    if (c[n][r] != -1) return c[n][r];
    if (r == 0 || r == n) return c[n][r] = 1;
    else return c[n][r] = combi(n-1, r) + combi(n-1, r-1);
}

int main() {
    init();
    ll n, a, b; cin >> n >> a >> b;
    vll v;
    REP(i, n) {
        ll e; cin >> e;
        v.push_back(e);
    }
    SORT(v);

    bool is_same = true;
    ll e = v[n-1];
    RFOR(i, n, n-a) {
        if (e != v[i]) {
            is_same = false;
            break;
        }
    }

    if (is_same) {
        e = v[n-1];
        ll border = n - 1;
        while (true) {
            if (border < 0 || e != v[border]) break;
            border--;
        }
        border = n - 1 - border;
        ll m = min({b, border});
        ll ans = 0;
        FOR(i, a, m + 1) {
            ans += combi(border, i);
        }
        cout << e << endl;
        cout << ans << endl;
    } else {
        e = v[n-a];
        ll l = n-a, r = n-a; 
        while(true) {
            if (l < 0 || v[l] != e) break;
            l--;
        }
        l++;
        while(true) {
            if (r >= n || v[r] != e) break;
            r++;
        }

        ll ans = combi(r - l, r - (n - a));
        long double e_d = 0.0;
        FOR(i, n - a, n) {
            e_d += v[i];
        }
        e_d /= a;
        cout.precision(20);
        cout << fixed << e_d << endl;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys

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

if __name__ == "__main__":
    a, b = map(int, input().split())

    count = 0
    for i in range(a, b+1):
        s = str(i)
        if s[0] == s[-1] and s[1] == s[-2]:
            count += 1

    print(count)


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

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

  int B[M];
  int A[N][M];

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

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

  int ans = 0;

  for(int i = 0; i < N; i++){
    int cal = 0;
    
    for(int j = 0; j < M; j++){
      cal += A[i][j] * B[j];
    }

    if(cal + C > 0) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
     
    using namespace std;
     
    int a,b,c;
     
    template<typename Drake>
    void read(Drake &x){
    	x=0;char ch=getchar();bool f=1;
    	while(!isdigit(ch)){
    		if(ch=='-')f^=1;
    		ch=getchar();
    	}
    	while(isdigit(ch)){
    		x=(x<<1)+(x<<3)+(ch^48);
    		ch=getchar();
    	}
    	x*=(2*f-1);
    }
     
    template<typename Drake>
    void write(Drake x){
    	if(x<0){x=-x;putchar('-');}
    	if(x>9)write(x/10);
    	putchar(x%10+'0');
    }
     
    template<typename Drake>
    void writeln(Drake x){
    	write(x);
    	puts("");
    }
     
    void init(){
    	read(a);read(b);read(c);
    }
     
    int main(){
    	init();
    	int cnt=0,opt1=0,opt2=0,Max;
    	opt1=(a&1)+(b&1)+(c&1);
    	opt2=3-opt1;
    	if(opt1*opt2==2){
    		if(opt1>opt2){
    			if(a&1)a++;
    			if(b&1)b++;
    			if(c&1)c++;
    		}
    		else if(opt1<opt2){
    			if(!(a&1))a++;
    			if(!(b&1))b++;
    			if(!(c&1))c++;
    		}
    		cnt++;
    	}
    	Max=max(a,max(b,c));
    	cnt+=(Max-a)/2+(Max-b)/2+(Max-c)/2;
    	cout<<cnt<<endl;
    	return 0;
    }

Measured memory_bytes: 256
const main = (input) => {
  input = input.trim().split('\n')
  const data = input.map(n => Number(n))
  const arr = [1, 2, 3]
  const [result] = arr.filter(num => data.indexOf(num) === -1)
  console.log(result)
  
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500
import java.math.BigDecimal
import java.util.*

fun main() {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()

    val a: MutableList<BigDecimal> = mutableListOf()
    repeat(n) {
        val ai = sc.nextBigDecimal()
        if (ai == BigDecimal.ZERO) {
            println("0")
            return
        }
        a.add(ai)
    }

    val max = BigDecimal("1000000000000000000")

    var answer: BigDecimal = BigDecimal.ONE
    a.forEach {
        answer *= it
        if (answer > max) {
            println("-1")
            return
        }
    }

    println(answer)
}


Measured memory_bytes: 68684
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

typedef long long ll;

ll gcd(ll m, ll n){
	return n ? gcd(n, m%n) : m;
}

int main(){
	int n, p;
	while (cin >> p >> n, p|n){
		vector<tuple<double, int, int>> v;
		double rp = sqrt(double(p));
		for (int i = 1; i <= n; ++i){
			int x = i*rp;
			for (int j = x - 3; j <= x + 3; ++j){
				if (j <= 0 || j > n) continue;
				if (gcd(i, j) != 1) continue;
				v.push_back(make_tuple((double)j/i, j, i));
			}
		}
		sort(ALL(v));
		int it = upper_bound(ALL(v), make_tuple(rp, 0, 0))-v.begin();
		auto pr = [v](int i){cout << get<1>(v[i]) << "/" << get<2>(v[i]); };

		pr(it);
		cout << " ";
		pr(it-1);
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 2040
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, k, d;
    cin >> x >> k >> d;
    ll cnt = 0, ans = 0;
    if(x < 0){
        cnt = (-x) / d;
    }
    else{
        cnt = x / d;
    }
    if(cnt >= k){
        if(x < 0) ans = x + d*k;
        else ans = x - d*k;
        if(ans < 0) ans *= (-1);
        cout << ans << endl;
        return 0;
    }
    if(x < 0){
        x = x + cnt * d;
    }
    else{
        x = x - cnt * d;
    }
    k -= cnt;
    if(k%2 == 0) ans = x;
    else{
        if(x < 0) ans = x + d;
        else ans = x - d;
    }
    if(ans < 0) ans *= (-1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
N = int(input())
A = list(map(int,input().split()))

M = max(A)
Mi = A.index(M)
m = min(A)
mi = A.index(m)

cnt = 0
ans = []

if M > 0 and m < 0:
    if abs(m) <= abs(M):
        for i in range(N):
            if Mi == i:
                continue
            x = Mi
            y = i
            A[y] += A[x]
            ans.append((x, y))
            cnt += 1
    else:
        for i in range(N):
            if mi == i:
                continue
            x = mi
            y = i
            A[y] += A[x]
            ans.append((x, y))
            cnt += 1

M = max(A)
m = min(A)

if m >= 0:
    for i in range(N-1):
        x = i
        y = i+1
        A[y] += A[x]
        ans.append((x, y))
        cnt += 1
else:
    for i in range(N-1, 0, -1):
        x = i
        y = i-1
        A[y] += A[x]
        ans.append((x, y))
        cnt += 1

print(cnt)
for x, y in ans:
    print(x+1, y+1)

Measured memory_bytes: 3064
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

ant = [a,b,c,d,e]
for i in range(1,5):
    for j in range(0,i):
        if ant[i] - ant[j] > k:
            print(':(')
            exit()
print('Yay!')


Measured memory_bytes: 3060
using System;

namespace AtCoder
{
    static class Solver
    {
        static IO io = new IO();

        public static void Solve()
        {
            io.ReadSplit();
            int H = io.Int();
            int W = io.Int();

            string[] str = new string[H];
            for (int i = 0; i < H; ++i)
            {
                io.Read();
                str[i] = io.String();
            }

            string str_header = new string('#', W + 2);

            io.WriteLine(str_header);
            for (int i = 0; i < H; ++i)
            {
                io.WriteLine(string.Format("#{0}#", str[i]));
            }
            io.WriteLine(str_header);
        }
    }
}
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver.Solve();
        }
    }
    class IO
    {
        private string[] _Inputs;
        private int _Index;
        public void Read()
        {
            _Inputs = new string[1];
            _Inputs[0] = Console.ReadLine();
            _Index = 0;
        }
        public void ReadSplit()
        {
            _Inputs = Console.ReadLine().Split(' ');
            _Index = 0;
        }
        public string String()
        {
            return _Inputs[_Index++];
        }
        public string[] String(int xCount)
        {
            string[] rv = new string[xCount];
            Array.Copy(_Inputs, _Index, rv, 0, xCount);
            _Index += xCount;
            return rv;
        }
        public int Int()
        {
            return int.Parse(_Inputs[_Index++]);
        }
        public int[] Int(int xCount)
        {
            int[] rv = new int[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = int.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public long Long()
        {
            return long.Parse(_Inputs[_Index++]);
        }
        public long[] Long(int xCount)
        {
            long[] rv = new long[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = long.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public void Write(string xStr)
        {
            Console.Write(xStr);
        }
        public void WriteLine(string xStr)
        {
            Console.WriteLine(xStr);
        }
    }
}

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

int main(){
    int N;
    cin >> N;
    int A[N];

    int ans[N];

    for(int i=0; i<N; i++){
        cin >> A[i];
        ans[A[i]-1]=i+1;
    }

    for(int i=0; i<N; i++){
        if(i!=0) cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1536
S=input()

f=int(S[:2])
l=int(S[2:])

if(f==0 and l==0):
	print("NA")
	exit()
if(f==0 and l<=12):
	print("YYMM")
	exit()
if(f<=12 and l==0):
	print("MMYY")
	exit()
if(f==0 and l>12):
	print("NA")
	exit()
if(f>12 and l==0):
	print("NA")
	exit()


if(f>12 and l<=12):#年はありえない
	print("YYMM")
if(f<=12 and l>12):
	print("MMYY")
if(f<=12 and l<=12):
	print("AMBIGUOUS")
if(f>12 and l>12):
	print("NA")



Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
char c[2][3];
int main(){
  for(int i=0; i<2; i++)
    for(int j=0; j<3; j++)
  cin >> c[i][j];
  bool flag = true;
  for(int i=0; i<2; i++){
    for(int j=0; j<3; j++){
      if(c[i][j] != c[1-i][2-j])
        flag = false;
      }
    }
  if(flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
  }

Measured memory_bytes: 256
n,m=map(int,input().split())
s=list(map(int,input().split()))

s.sort()
term=[]
if n >= m:
    print(0)
else:
    for i in range(m-1):
        term.append(s[i+1]-s[i])

    term.sort()

    for i in range(n-1):
        del term[-1]
    
    print(sum(term))

Measured memory_bytes: 13964
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000009
int n,m,com;
int a[1009],bit[1009];
ll memo[1009][4500];

ll dp(int k,int bits){
  if(memo[k][bits]!=-1)return memo[k][bits];
  if(k==m){
    if(bits==com)return 0;
    else return INF;
  }
  ll rec=dp(k+1,bits);
  rec=min(rec,dp(k+1,bits|bit[k])+a[k]);
  return memo[k][bits]=rec;
}

int main(){
  memset(memo,-1,sizeof(memo));
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int b;
    cin>>a[i]>>b;
    for(int j=0;j<b;j++){
      int c;
      cin>>c;
      c--;
      bit[i]|=(1<<c);
    }
  }
  for(int i=0;i<n;i++){
    com+=(1<<i);
  }

  ll ans=dp(0,0);
  if(ans>=INF){
    cout<<-1<<endl;
  }
  else{
    cout<<ans<<endl;
  }
  return(0);
}


Measured memory_bytes: 35712
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000
#define MAX_N 21
#define MAX_Q 210

int n, q;
int a[MAX_N], m[MAX_Q];

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

  cin >> n;
  rep(i, 0, n) cin >> a[i];
  cin >> q;
  rep(i, 0, q) cin >> m[i];

  map<int, bool> canCreate;

  for(int mask = 0; mask < 1 << n; ++mask) {
    int sum = 0;
    rep(j, 0, n) {
      if(mask & (1 << j)) sum += a[j];
    }
    canCreate[sum] = true;
}

  rep(i, 0, q) {
    if (canCreate[m[i]]) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}



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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	int A, B, C; cin >> A >> B >> C;
	bool flag = false;
	if(A == B and A != C) flag = true;
	else if(B == C and A != B) flag = true;
	else if(A == C and A != B) flag = true;

	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n,greater<int>());
    int ans=a[0];int idx=1;
    if(n&1)
    {
        for(int i=2;i<n-1;i+=2)
        {
            ans+=2*a[idx];
            idx++;
        }
        ans+=a[idx];
    }
    else
    {
        for(int i=2;i<n;i+=2)
        {
            ans+=2*a[idx];
            idx++;
        }
    }
    cout<<ans<<nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

int main() {
	string S;
	cin >> S;
	string T = S.substr(0, (S.size() - 1) / 2);
	string RS = S, RT = T;
	reverse(RS.begin(), RS.end()), reverse(RT.begin(), RT.end());
	if (RS == S && RT == T) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
x = int(input())

if 400 <= x < 600:
    a = 8
elif 600 <= x < 800:
    a = 7
elif 800 <= x < 1000:
    a = 6
elif 1000 <= x < 1200:
    a = 5
elif 1200 <= x < 1400:
    a = 4
elif 1400 <= x < 1600:
    a = 3
elif 1600 <= x < 1800:
    a = 2
else:
    a = 1
print(a)

Measured memory_bytes: 9056
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,MOD = [int(i) for i in readline().split()]

SIZE=3001; #MOD=10**9+7 #998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE # fac[j] = j! mod MOD
finv = [0]*SIZE# finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
    inv[i] = MOD -(MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0


"""
make the table of Sterling numbers of the second kind
Sterling[ball][box]

SIZE = n
Sterling2 = [[0]*(SIZE+1) for _ in range(SIZE+1)]
Sterling2[0][0] = Sterling2[1][1] = 1
for i in range(2,SIZE+1):
    for k in range(1,i+1):
        Sterling2[i][k] = (Sterling2[i-1][k-1] + k*Sterling2[i-1][k])%MOD
"""





SIZE = n+1
f = [[0]*(SIZE) for _ in range(SIZE)]
f[0][0] = 1
for i in range(1,SIZE):
    f[i][0] = 1
    for k in range(1,i+1):
        f[i][k] = (f[i-1][k] + f[i-1][k-1] + k*f[i-1][k])%MOD

#print(f)

#pow(2,n-s,MOD-1)
pp = [1]*SIZE
for i in range(1,SIZE):
    pp[i] = 2*pp[i-1]%(MOD-1)

def size(s):
    """
    for b in range(n+1):
        res += f[s][b]*pow(2,b*(n-s),MOD)
    """
    res = 0
    p = 1
    e = pow(2,(n-s),MOD)
    for b in range(SIZE):
        res += f[s][b]*p
        p *= e
        p %= MOD
    return res*pow(2,pp[n-s],MOD)%MOD

#for i in range(n+1):
#    print(size(i))

ans = 0
sgn = 1
for j in range(n+1):
    ans += sgn*choose(n,j)*size(j)
    ans %= MOD
    sgn *= -1

print(ans)








Measured memory_bytes: 114268
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    int a, b; cin >> a >> b;
    out(a * b);



    return 0;
}









Measured memory_bytes: 3632
X = int(input())
  
# 順に素数判定を行えばよい
def is_prime(x):
  if x <= 1:
    return False
  for i in range(2, x):
    if x % i == 0:
      return False
  return True
 
p = X
while not is_prime(p):
  p += 1
  
print(p)

Measured memory_bytes: 9164
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
data = list(map(int,read().split()))

def calc_g(x,k):
    while(x>=k):
        if(x%k==0):
            return x//k
        fn = x//k
        x1 = x - (fn + 1)
        x2 = fn*k + (x%k)%(fn+1)
        x = min(x1,x2)
    return 0

grundy = 0
it = iter(data)
for a,k in zip(it,it):
    grundy = grundy ^ calc_g(a,k)

if(grundy==0):
    print('Aoki')
else:
    print('Takahashi')

Measured memory_bytes: 66992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int x = b*10+c;
  if (x%4==0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    char s[4];
    scanf("%s", s);
    if (s[1] == s[2])
    {
        if (s[0] == s[1] || s[2] == s[3])
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128