akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
  int n;cin>>n;
  vector<int>a(n,0);
  fol(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  int k = a.front();
  while(a.size()!=1){
    for(int i=1;i<a.size();i++){
      a[i] %= k;
    }
    sort(a.begin(),a.end());
    auto itr = upper_bound(a.begin(),a.end(),0);
    a.erase(a.begin(),itr);
    k = a.front();
  }
  cout << k << endl;
  return 0;
}


Measured memory_bytes: 640
/******************************************
    > File Name: Aoj_0033.cpp
    > Author: universal42
    > Mail: universal42@163.com 
    > Created Time: 2019年05月03日 星期五 16时38分31秒
 ******************************************/

#include<bits/stdc++.h>
#define ll long long int
#define inf 0x3f3f3f3f
#define LOCALa
using namespace std;
const int maxn=1e5+5;
int n;
int arr[10],a[10],b[10];
int flag=0;
void dfs(int i,int j){
	if(flag){
		return;
	}
	if(i+j==10){
		for(int p=0;p<i-1;p++){
			if(a[p]>a[p+1]){
				return;
			}
		}
		for(int p=0;p<j-1;p++){
			if(b[p]>b[p+1]){
				return;
			}
		}
		flag=1;
		return;
	}
	a[i]=arr[i+j];
	dfs(i+1,j);
	b[j]=arr[i+j];
	dfs(i,j+1);
}
void solve(){
	scanf("%d",&n);
	while(n--){
		flag=0;
		for(int i=0;i<10;i++){
			scanf("%d",&arr[i]);
		}
		dfs(0,0);
		if(flag){
			puts("YES");
		}
		else{
			puts("NO");
		}
	}
}
int main(){
#ifdef LOCAL
    freopen("in.in","r",stdin);
#endif
    solve();
    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

using namespace std;

map<int, vector<int>> g;
vector<int> color;
vector<int> depth;

void func(int v, int d, int c) {
    if (!color[v]) {
        color[v] = c;
    }
    if (d == 0 || depth[v] >= d ) {
        return;
    }
    depth[v] = d; 
    FOE(u, g[v]) {
        func(u, d - 1, c);
    }
}

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

    FOR(_, 0, M) {
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int Q;
    cin >> Q;
    vector<int> v(Q, 0), d(Q, 0), c(Q, 0);
    FOR(i, 0, Q) {
        cin >>  v[Q - i - 1] >> d[Q - i - 1] >> c[Q - i - 1];
    }

    color = vector<int>(N + 1, 0);
    depth = vector<int>(N + 1, 0);

    FOR(i, 0, Q) {
        func(v[i], d[i], c[i]);
    }

    FOR(i, 1, N + 1) {
        cout << color[i] << endl;
    }

    return 0;
}

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

int main() {
    string s; cin >> s;
    int na, nz;
    for (int i=0; i<s.size(); ++i) {
        if (s[i] == 'A') {
            na = i;
            break;
        }
    }
    for (int i=s.size()-1; i>=0; --i) {
        if (s[i] == 'Z') {
            nz = i+1;
            break;
        }
    }
    cout << nz - na << endl;
}

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

int main(int argc, char *argv[])
{
  int A, B, C, D, P;
  int Xcost, Ycost;

  cin >> A >> B >> C >> D >> P;

  Xcost = A*P;

  if (C >= P) {
    Ycost = B;
  }
  else {
    int sub = P - C;
    int extra = sub*D;
    Ycost = B + extra;
  }

  cout << min(Xcost, Ycost) << endl;
  
  return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;



int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int x = tx - sx;
  int y = ty - sy;
  string ans = "";
  rep(i, y) ans += 'U';
  rep(i, x) ans += 'R';
  rep(i, y) ans += 'D';
  rep(i, x+1) ans += 'L';
  rep(i, y+1) ans += 'U';
  rep(i, x+1) ans += 'R';
  rep(i, 1) ans += 'D';
  rep(i, 1) ans += 'R';
  rep(i, y+1) ans += 'D';
  rep(i, x+1) ans += 'L';
  rep(i, 1) ans += 'U';
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/




int N, L; string S[1010];
//--------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> L;
    rep(i, 0, N) cin >> S[i];

    map<string, int> cnt;
    rep(i, 0, N) cnt[S[i]]++;

    vector<pair<string, string>> v;
    vector<string> pan;
    fore(p, cnt) {
        // ??????????????????
        int ispand = 1;
        rep(i, 0, L / 2 + 1) if (p.first[i] != p.first[L - 1 - i]) ispand = 0;

        if (ispand) {
            while (2 <= p.second) {
                v.push_back({ p.first, p.first });
                p.second -= 2;
            }
            if (p.second) pan.push_back(p.first);
        } else {
            string rev = p.first;
            reverse(rev.begin(), rev.end());

            if (p.first > rev) continue;
            int n = min(p.second, cnt[rev]);
            rep(i, 0, n) v.push_back({ p.first, rev });
        }
    }

    string ans = "";
    int n = v.size();
    rep(i, 0, n) ans += v[i].first;
    if (0 < pan.size()) ans += pan.front();
    rrep(i, n - 1, 0) ans += v[i].second;
    cout << ans << endl;
}

Measured memory_bytes: 3420
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace mitsui2019_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            int V = 0;
            var ans = 0;
            while (V <= 999)
            {
                var Vstr = V.ToString();
                if (V < 10)
                {
                    Vstr = "00" + V.ToString();
                }
                else if (V < 100)
                {
                    Vstr = "0" + V.ToString();
                }

                var p1 = 0;
                for (int i = 0; i < N; i++)
                {

                    if (S[i] == Vstr[p1])
                    {
                        if (p1 == 2)
                        {
                            ans++;
                            break;
                        }
                        p1++;
                        continue;
                    }
                }
                V++;
            }
            Console.WriteLine(ans);
        }

    }
}


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

int main() {
  string s;
  cin >> s;
  bool ans = false;
  if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) ans = true;
  if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) ans = true;
  if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) ans = true;
  if (ans) puts("Yes");
  else puts("No");
  return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define MP make_pair
#define PB push_back

const int MAX = 3e5+10;
const int MOD = 1e9+10;

int N;
vii cs;

bool check() {
    ll endAt = 0;
    REP (i, N) {
        endAt += cs[i].second;
        if (endAt > cs[i].first) {
            return false;
        }
    }
    return true;
}

int main() {
    cin >> N;
    REP (i, N) {
        ll a, b;
        cin >> a >> b;
        cs.PB(MP(b, a));
    }
    sort(cs.begin(), cs.end());

    if (check()) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#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 fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define PI 3.1415926535897
#define EPS (1e-10)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


struct NUMS {
	int x[10];
	int s;
	int p;
	NUMS(){
		repe(i, 1, 9) x[i] = 0;
		s = p = 0;
	}
	NUMS(const NUMS& n){
		repe(i, 1, 9) x[i] = n.x[i];
		s = n.s;
		p = n.p;
	}
	void insert(int y, int z){
		x[y] += z;
		s += z;
		p += x[y]*y;
	}
	int size(){
		return s;
	}
	bool operator<(NUMS& n){
		reper(i, 9, 1)
			if(x[i] < n.x[i]) return true;
			else if(x[i] > n.x[i]) return false;
		return true;
	}
};


int N, M;
SI A;
int c[10] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
NUMS dp[10010];


void makeDP(){
	dp[0] = NUMS();
	rep(i, 0, N){
		if(i != 0 && SIZE(dp[i]) == 0) continue;
		for(int x : A){
			int y = c[x];
			repif(j, 1, i+y*j <= N){
				if(SIZE(dp[i+y*j]) < SIZE(dp[i])+j){
					NUMS n = dp[i];
					n.insert(x, j);
					dp[i+y*j] = n;
				}
				else if(SIZE(dp[i+y*j]) == SIZE(dp[i])+j){
					NUMS n = dp[i];
					n.insert(x, j);
					if(dp[i+y*j] < n) dp[i+y*j] = n;
				}
			}
		}
	}
}


string solve(){
	VI v;
	repe(i, 1, 9)
		if(dp[N].x[i]) v.pb(i);
	sort(ALL(v), greater<int>());
	string ans;
	for(int i : v)
		rep(j, 0, dp[N].x[i]) ans.pb(i+'0');
	return ans;
}


signed main(){
	cin >> N >> M;
	rep(i, 0, M){
		int a;
		cin >> a;
		A.insert(a);
	}

	makeDP();

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 768
def flip(c):
    if c=='S':
        return 'W'
    else:
        return 'S'

def judge():
    found=False
    ret = -1
    for i in xrange(N):
        #print r
        if r[i]=='S':
            if s[i]=='o':
                if i==0:
                    r[i-1]=r[i+1]
                elif i==N-1:
                    if r[0]==r[i-1]:
                        found=True
                elif i==N-2:
                    if r[i+1]!=r[i-1]:
                        break;                    
                else:
                    r[i+1]=r[i-1]
            else:
                if i==0:
                    r[i-1]=flip(r[i+1])
                elif i==N-2:
                    if r[i+1]!=flip(r[i-1]):
                        break;                    
                elif i==N-1:
                    if r[0]==flip(r[i-1]):
                        found=True
                else:
                    r[i+1]=flip(r[i-1])
        else: # W
            if s[i]=='x':
                if i==0:
                    r[i-1]=r[i+1]
                elif i==N-1:
                    if r[0]==r[i-1]:
                        found=True
                elif i==N-2:
                    if r[i+1]!=r[i-1]:
                        break;                    
                else:
                    r[i+1]=r[i-1]
            else:
                if i==0:
                    r[i-1]=flip(r[i+1])
                elif i==N-1:
                    if r[0]==flip(r[i-1]):
                        found=True
                elif i==N-2:
                    if r[i+1]!=flip(r[i-1]):
                        break;                    
                else:
                    r[i+1]=flip(r[i-1])
                
        if found:
            ret = ''.join(r)

    return ret
    
N=input()
s=list(raw_input())


ptn=[['S','S'],['S','W'],['W','S'],['W','W']]

ret = None
for p in ptn:
    r = [None]*N
    r[0]=p[0]
    r[1]=p[1]
    ret = judge()
    if ret != -1:
        break
print ret



Measured memory_bytes: 5252
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2005;
char s[MAX][MAX];
int ile[MAX];
int32_t main()
{
  BOOST;
  int n,m;
  cin>>n>>m;
  for (int i=0;i<n;i++)for (int j=0;j<m;j++)cin>>s[i][j];
  int ans=0;
  ans=max({n,m});
  for (int i=0;i<n;i++){
  	for (int j=0;j<m-1;j++) if (i && !(s[i][j]^s[i-1][j]^s[i][j+1]^s[i-1][j+1]))ile[j]++;
  	else ile[j]=1;
  	vi q;
  	q.clear();
  	q.pb(-1);
  	for (int j=0;j<m;j++){
  		while (sz(q)>1 && ile[q.back()]>=ile[j]){
  			int ele=q.back();
  			q.pop_back();
  			ans=max(ans,ile[ele]*(j-q.back()));
  		}
  		q.pb(j);
  	}
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 7560
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner in=new Scanner(System.in);
        int a=in.nextInt(),b=in.nextInt(),c=in.nextInt();
        long k=in.nextLong();
        if(k%2==0){
            System.out.println(a-b);
        }else{
            System.out.println(b-a);
        }
    }
}

Measured memory_bytes: 21844
import math


def calc1():
    if x >= V_div2:
        r = math.degrees(math.atan(2 * (V - x) / (a * a * a)))
        print(r)
    else:
        r = math.degrees(math.atan((a * b * b) / (2 * x)))
        # r = math.degrees(math.atan(2 * x / (a * a * a)))
        print(r)


def calc2():
    if x >= V_div2:
        r = math.degrees(math.atan(2 * (V - x) / (a * a * a)))
        # r = math.degrees(math.atan((a * b * b) / (2 * (V - x))))
        print(r)
    else:
        r = math.degrees(math.atan((a * b * b) / (2 * x)))
        print(r)


a, b, x = map(int, input().split())
V = a * a * b
V_div2 = V / 2

if a <= b:
    calc1()
    exit()
else:
    calc2()
    exit()


Measured memory_bytes: 3064
import sys

readline = sys.stdin.readline

def main():
    N, M = map(int, readline().split())
    sw = []
    for _ in range(M):
        k, *S = map(int, readline().split())
        sw.append(S)
    p = list(map(int, readline().split()))

    cnt = 0
    for i in range(2**N):
        jtmp = []
        flag = True
        for j in range(N):
            if (i>>j)&1:
                jtmp.append(j+1)
        
        for k in range(M):
            setj = set(jtmp)
            settmp = set(sw[k])
            if len(setj&settmp)%2 != p[k]:
                flag = False
                break
        if flag:
            cnt += 1

    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};
 



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Timer TM;

    
    ll n;
    cin>>n;
    vll v(n);
    rep(i,n){
        cin>>v[i];
    }
    ll ans=0;
    rep2(i,1,n-1){
        if(v[i-1]<v[i]&&v[i]<v[i+1]) ans++;
        else if(v[i+1]<v[i]&&v[i]<v[i-1]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int n,A[50];

int solve(int i,int m){
    if(m == 0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(){
    int q,M,i;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
        scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&M);
    if(solve(0,M)){
        printf("yes\n");
    }
    else{
        printf("no\n");
    }
    }

    return 0;


}


Measured memory_bytes: 2040
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <list>

using namespace std;
list <long> L;
int main(){
	long n; scanf("%ld",&n);
	while (n--){
		char tmp[20]; scanf("%s",&tmp);
		string a; a = tmp;
		if (a == "insert" || a == "delete"){
			long b; scanf("%ld", &b);
			if (a == "insert"){
				L.push_front(b);
			}
			else{
				list <long>::iterator Lite;
				for (Lite = L.begin(); Lite != L.end(); Lite++){
					if (*Lite == b){
						L.erase(Lite); break;
					}
				}
			}
		}
		else if (a == "deleteFirst"){
			L.pop_front();
		}
		else if (a == "deleteLast"){
			L.pop_back();
		}
	}
	list <long>::iterator Lite;
	for (Lite = L.begin(); Lite != L.end(); Lite++){
		if (Lite != L.begin()) printf(" ");
		printf("%ld", *Lite);
	}
	printf("\n");
}

Measured memory_bytes: 32404
#include<stdio.h>
#include<string.h>

#define M 1000000
#define NIL -1
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
  long long key,i,h;

  key=getKey(str);

  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0) return 0;

  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;

  key=getKey(str);

  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0) return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 16388
#if 1
#include <iostream>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    int a, b;
    std::cin >> a >> b;
    if (b < a) {
        std::swap(a, b);
    }
    if (a != 1) {
        std::cout << 1 << '\n';
    } else if (b == 3) {
        std::cout << 2 << '\n';
    } else {
        std::cout << 3 << '\n';
    }
    return 0;
}
#endif

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int p = sc.nextInt();
		
		int x = a*3+p;
		int y = x/2;
		
		System.out.println(y);
	
	}
		
}

Measured memory_bytes: 20820
#include <stdio.h>

int main(void)
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if (x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2112
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll A, B;
  cin >> A >> B;
  string ans = (A <= 8 && B <= 8) ? "Yay!" : ":(";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;
using namespace std;



int dp[20050];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int h,n; cin >> h >> n;
        vector<int> a(n), b(n);
        int amax = 0;
        rep(i,n){
                cin >> a[i] >> b[i];
                chmax(amax,a[i]);
        }

        rep(i,20050) dp[i] = 1001001001;
        dp[0] = 0;

        rep(i,20050){
                rep(j,n){
                        int ni = min(h, i+a[j]);
                        chmin(dp[ni],dp[i] + b[j]);
                }
        }
        cout << dp[h] << endl;

        return 0;
}

Measured memory_bytes: 384
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;
using namespace std;

struct node{
	int u, v, w;
	node(int tu, int tv, int tw){
		u = tu, v = tv, w = tw;
	}
};

vector<node> ans;

int32_t main()
{
	int l; scanf("%d", &l);
	for(int i = 2; i <= 19; i++){
		ans.pb(node(i, i + 1, 0));
		ans.pb(node(i, i + 1, (1 << (20 - i - 1))));
	}
	while(l){
		int p = log2(lowbit(l));
		if(p == 19){
			ans.pb(node(1, 2, 0));
			ans.pb(node(1, 2, 1 << 18));
		}
		else ans.pb(node(1, 20 - p, l ^ lowbit(l)));
		l ^= lowbit(l);
	}
	printf("%d %d\n", 20, ans.size());
	for(auto i : ans){
		printf("%d %d %d\n", i.u, i.v, i.w);
	}
	return 0;
}

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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define lld long long int

int main(){
    int h, w;
    scanf("%d %d", &h, &w);
    int a[h+1][w+1];
    rep(i, 1, h+1){
        rep(j, 1, w+1){
            scanf("%d", &a[i][j]);
        }
    }
    int n=0;
    int y1[h*w], x1[h*w], y2[h*w], x2[h*w];
    rep(i, 1, h){
        rep(j, 1, w+1){
            if(a[i][j]%2==1){
                y1[n]=i;x1[n]=j;y2[n]=i+1;x2[n]=j;n++;
                a[i][j]--;a[i+1][j]++;
            }
        }
    }
    rep(i, 1, w){
        if(a[h][i]%2==1){
            y1[n]=h;x1[n]=i;y2[n]=h;x2[n]=i+1;n++;
            a[h][i]--;a[h][i+1]++;
        }
    }
    printf("%d\n", n);
    rep(i, 0, n){
        printf("%d %d %d %d\n", y1[i], x1[i], y2[i], x2[i]);
    }

    return 0;
}

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

main() {
    int N; cin >> N;
    if(N>=2800) cout << "AGC" << endl;
    else if(N>=1200) cout << "ARC" << endl;
    else cout << "ABC" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

vector<int> x(90001);
vector<int> y(90001);
vector<int> sum(90001);


int main(){
	int h, w, d;
	cin >> h >> w >> d;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			int a;
			cin >> a;
			x[a] = i, y[a] = j;	
		}
	}
	int q;
	cin >> q;
	vector<int> l(q), r(q);
	for (int i = 0; i < q; i++){
		cin >> l[i] >> r[i];
	}
	for (int i = 0; i < d; i++){
		sum[i] = 0;
	}
	for (int i = d; i <= h*w+1; i++){
		sum[i] = sum[i-d] + abs(x[i] - x[i-d]) + abs(y[i] - y[i-d]);
	}

	for (int i = 0; i < q; i++){
		cout << sum[r[i]] - sum[l[i]] << endl;
	}
	return  0;
}

Measured memory_bytes: 5032
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main()
{
 double r;
 double area;
 double length;

 cin >> r;

 area = M_PI * r * r;
 length = M_PI * 2 * r;

 printf("%f%s%f\n", area, " ",length );
 return 0;
}

Measured memory_bytes: 1232
A_D = str(input())
op = ['']*3
l = []
for i in range(4):
  l.append(A_D[i])
for i in range(2**3):
  bit_i = bin(i)[-3:]
  i = bit_i.replace('b','0')
  for j in range(3):
    if i[j] == '0':
      op[j] = '+'
    elif i[j] == '1':
      op[j] = '-'
  if eval(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]) == 7:
    break
print(l[0]+op[0]+l[1]+op[1]+l[2]+op[2]+l[3]+'=7')

Measured memory_bytes: 3064
n, k = map(int, input().split())
s = input()
cnt = 1
li = []
for i in range(n-1):
    if s[i] == s[i+1] and s[i] == "R":
        cnt += 1
    elif s[i] == s[i+1] and s[i] == "L":
        cnt += 1
    else:
        li.append((s[i], cnt))
        cnt = 1
if n > 1:
   li.append((s[i], cnt))
cut = len(li) - 1

print(min(n-1, n - cut - 1 + 2 * k))

Measured memory_bytes: 45424
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = n;
        n = in.nextInt();
        int b = n;

        if(a < b){
            System.out.println("a < b");
        }else if(a == b){
            System.out.println("a == b");
        }else{
            System.out.println("a > b");
        }
        in.close();
    }
}



Measured memory_bytes: 26340
num,yen = map(int,input().split())
flg = 0

for i in range(num+1):
    if flg == 1:
        i -= 1
        break
    #print('debug:i '+str(i))
    for j in range(num-i+1):
        #print('debug:j '+str(j))
        #print('debug:k '+str(num-i-j))
        if i*10000 + j*5000 + (num-i-j)*1000 == yen:
            #print("i:{} j:{} k:{} yen:{}".format(i,j,num-i-j,yen))
            flg = 1
            break

if flg != 1:
    print('-1 -1 -1')
else:
    print("{} {} {}".format(i,j,num-i-j))


Measured memory_bytes: 41068
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>
 
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
 
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
 
int n;
string id;
int m;
vector<int> a;
vector<int> wcard;
 
inline int f(int n) {
    if(n<10) return n;
    int ret = n%10;
    ret += n/10;
    return ret;
}
inline bool ok(string s) {
    int sum = 0;
    int cnt=1;
    for(int i=s.size()-1;i>=0;i--) {
        if(cnt%2==0) {
            sum+=f((s[i]-'0')*2);
        }
        else {
            sum+=s[i]-'0';
        }
        cnt++;
    }
    return sum%10==0;
}
int64_t dfs(int depth,int sum) {
    if(depth == wcard.size()) return sum%10==0;
    int64_t ret = 0;
 
    rep(i,a.size()) {
        int t;
        if((id.size()-wcard[depth])%2==0) {
            t=f(a[i]*2);
        }
        else {
            t=a[i];
        }
        ret += dfs(depth+1,sum+t);
    }
    return ret;
     
}
int fsum(string s) {
    int sum = 0;
    rep(i,s.size()) {
        if(s[i]=='*') continue;
        if((id.size()-i)%2==0) {
            sum+=f((s[i]-'0')*2);
        }
        else {
            sum+=s[i]-'0';
        }
    }
    return sum;
}
int main() {
    cin>>n;
    cin>>id;
    cin>>m;
    a.resize(m);
    rep(i,m) cin>>a[i];
    rep(i,id.size()) if(id[i]=='*') wcard.pb(i);
    int sum = fsum(id);
    int64_t ans = dfs(0,sum);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1368
def main():
    n = int(input())
    count = 0
    count_dict = {}
    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in count_dict:
            count += count_dict[input_data]
            count_dict[input_data] += 1
        else:
            count_dict[input_data] = 1
    print(count)
if __name__ == '__main__':
    main()

Measured memory_bytes: 17852
#include <iostream>
using namespace std;
int main(void)
{
	int X, Y, Z, MAX;
	cin >> X >> Y >> Z;
	MAX = (X > Y) ? X : Y;
	MAX = (MAX > Z) ? MAX : Z;
	if (MAX == X) cout << (Y * Z / 2) << endl;
	if (MAX == Y) cout << (X * Z / 2) << endl;
	if (MAX == Z) cout << (X * Y / 2) << endl;
	return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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

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


    int x, y;
    cin >> x >> y;

    rep(i, x+1)
    {
        if(4*i+2*(x-i)==y)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;



    return 0;


}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n, x;
    cin >> n >> x;
    vector<ll> l(n);
    REP(i, n) cin >> l[i];

    ll d = 0, ans = 1;
    REP(i, n) {
        d += l[i];
        if(d <= x) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
S = str(input())
K = int(input())

if len(S) == 1:
        print(S[0])
        exit(0)

i = 0
while S[i] == '1' and i <= len(S)-2:
        if K <= i + 1:
                print(S[i])
                exit(0)
        i += 1
print(S[i])

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

#define ll long long
const int mod = 1e9 + 7;
const int siz = 1e5 + 7;

int n, K;
int tab [107];
ll dp [107][siz];
ll pref [107][siz];

int main(){
    scanf("%d %d",&n,&K);
    for(int i = 1; i <= n; i++){
        scanf("%d",&tab[i]);
    }

    dp[0][0] = 1LL;
    for(int i = 1; i <= n; i++){
        dp[i][0] = 1LL;
        for(int k = 1; k <= K; k++){
            dp[i][k] = (pref[i - 1][k] - pref[i - 1][max(0, k - tab[i] - 1)] + mod) % mod;
            if(k <= tab[i]) dp[i][k] = (dp[i][k] + 1LL) % mod; //zero cukierkw
        }
        pref[i][0] = 1LL;
        for(int k = 1; k <= K; k++){
            pref[i][k] = (pref[i][k - 1] + dp[i][k]) % mod;
        }
    }
    printf("%lld\n",dp[n][K] % mod);

    return 0;
}


Measured memory_bytes: 161280
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, K, x, a = 0;
    cin >> N >> K;

    for(int i = 0; i < N; i++) {
        cin >> x;
        if(x > K - x) {
            a += (K-x)*2;
        } else {
            a += x*2;
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll W,H,N;
  cin>>W>>H>>N;
 ll up=H;
  ll down=0;
  ll left=0;
  ll right=W;
  for(ll i=0;i<N;i++) {
ll x,y,a;
    cin>>x>>y>>a;
    if(a==1) {
      left=max(left,x);
    }
    else if(a==2) {
right=min(right,x);
    }
    else if(a==3) {
      down=max(down,y);
    }
    else {
up=min(y,up);
    }
  }
  
  if(up>down&&right>left) {
cout<<(up-down)*(right-left)<<endl;
    return 0;
  }
  
  else {
cout<<0<<endl;
  }
}
  
  
  
  
  
  
  
  
  
  
  



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

#define N 101

int main()
{

	int n, ans;
	int arr[N];
	long long table[N][21];

	cin >> n;
	for(int i = 0; i < n - 1; i++) cin >> arr[i];

	for(int i = 0; i < n - 1; i++) {
		for(int j = 0; j < 21; j++) table[i][j] = 0;
	}

	cin >> ans;

	table[0][arr[0]] = 1;

	for(int i = 1; i < n - 1; i++) {
		for(int j = 0; j < 21; j++) {
			if(table[i - 1][j] >= 1) {
				if(j - arr[i] >= 0) {
					table[i][j - arr[i]] += table[i - 1][j];
				}
				if(j + arr[i] <= 20) {
					table[i][j + arr[i]] += table[i - 1][j];
				}
			}
		}
	}

	cout << table[n - 2][ans] << endl;

	return 0;

}

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

int main(){
   int n;cin>>n;
   long int a[n+10];
   for(int i=0;i<n;i++) cin>>a[i];
   long int oddcnt=0;
   long int evencnt=0;
   long int oddsum=0;
   long int evensum=0;
   
   for(int i=0;i<n;i++){
       //even>0に
       oddsum+=a[i];
       evensum+=a[i];
       if(i%2==0 && evensum<=0){
           evencnt+=(-evensum+1);
           evensum=1;
       }else if(i%2==1 && evensum>=0){
           evencnt+=evensum+1;
           evensum=-1;
       }
        //odd>0に
        if(i%2==0 && oddsum>=0){
            oddcnt+=oddsum+1;
            oddsum=-1;
        }else if(i%2==1 && oddsum<=0){
            oddcnt+=(-oddsum+1);
            oddsum=1;
        }
   }
   cout << min(oddcnt,evencnt)<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int max1(int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}

int main(void) {
 
    int a;
    int b;
    scanf("%d %d", &a, &b);
    
    int max;
    int x=a+b;
    int y=a+(a-1);
    int z=b+(b-1);
  
    max=max1(max1(x,y),z);
  
    printf("%d\n",max);
 
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  int a,b;
  a=n/100;
  b=n%100;
  if(a>=20)
    cout<<1<<endl;
  else if(a==0)
    cout<<0<<endl;
  else
    if(0<=b&&b<=5*a)
      cout<<1<<endl;
  else
    cout<<0<<endl;
}

    

Measured memory_bytes: 256
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    string s;
    cin >> s;
    if (s[0] == s[1]) puts("Bad");
    else if (s[1] == s[2]) puts("Bad");
    else if (s[2] == s[3]) puts("Bad");
    else puts("Good");

    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;

const int N=1e5+5;
const int mod=1e9+7;
int f[N],u[N],primedivs[N];

void init()
{
    for(int i=1;i<=N-5;i++) u[i]=1;
    for(int i=2;i<=N-5;i++)
    {
        if(primedivs[i]) continue;
        for(int j=i;j<=N-5;j+=i)
        {
            primedivs[j]++;
            if(j%(i*i)==0) u[j]=0;
        }
    }
    for(int i=1;i<=N-5;i++) if(u[i]&&primedivs[i]%2) u[i]=-1;
}

int Power(int x,int n)
{
    if(n==0) return 1;
    if(n==1) return x;
    if(n%2) return Power(x,n-1)*x%mod;
    int tmp=Power(x,n/2);
    return tmp*tmp%mod;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++) f[i]=Power(k/i,n);
    int res=0;
    for(int i=1;i<=k;i++)
    {
        int cnt=0;
        for(int j=i;j<=k;j+=i) cnt=(cnt+u[j/i]*f[j]+mod)%mod;
        res=(res+cnt*i)%mod;
    }
    cout<<res;
}


Measured memory_bytes: 5996
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

void split(string str, char chr, vector< string > *res){
	stringstream ss(str);
	string itm;
	while(getline(ss, itm, chr)){
		(*res).PB(itm);
	}
}

bool comp(pair< int, int > a, pair< int, int > b){
	if(a.second != b.second) return a.second > b.second;
	return a.first < b.first;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m, r;
	vector< pair< int, int > > p;
	
	while(cin >> n >> m, n){
		
		p.CLR();
		p.RS(m);
		
		REP(i, m){
			p[i] = make_pair< int, int >(i + 1, 0);
		}
		
		REP(i, n){
			REP(j, m){
				cin >> r;
				p[j].second += r;
			}
		}
		
		sort(ALL(p), comp);
		
		REP(i, m){
			cout << (i ? " " : "") << p[i].first;
		}
		cout << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=[]
sma=0
for i in range(n):
    sma+=a[i]
    sa.append(sma)
sb=[]
smb=0
for i in range(m):
    smb+=b[i]
    sb.append(smb)
import bisect
lain=bisect.bisect_right(sa,k)-1
if lain<0:
    sm=0
else:
    sm=sa[lain]
stin=bisect.bisect_right(sb,k-sm)-1

if lain<0:
    print(stin+1)
    exit()
if stin>=m-1:
    print(lain+1+m)
    exit()
am=lain+1+stin+1
mx=am
for i in range(lain,-1,-1):
    sm-=a[i]
    am-=1
    while sm+sb[stin+1]<=k:
        stin+=1
        am+=1
        if stin>=m-1:
            print(max(mx,am))
            exit()
    mx=max(mx,am)
print(mx)
    


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

string s;
string t = "2019/04/30";

int main()
{
    cin >> s;
    if (s <= t)
    {
        cout << "Heisei" << endl;
    }
    else
    {
        cout << "TBD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
N, Q = map(int, input().split())
W = [tuple(map(int, input().split())) for _ in range(N)]
W.sort(key=lambda x:x[2])
D = [int(input()) for _ in range(Q)]
ans = [-1]*Q
skip = [-1]*Q
for s, t, x in W:
    l = bisect_left(D, s-x)
    r = bisect_left(D, t-x)
    while l < r:
        if skip[l] == -1:
            ans[l] = x
            skip[l] = r
            l += 1
        else:
            l = skip[l]
print(*ans, sep='\n')

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

long long n,num[60],l[102],r[102],i,j=0,max=0,maxn,count=0,min=9999999,minn,flag=1;
void wrt(long long a,long long b)
{
	l[j]=a+1;
	r[j]=b+1;
	j++;
}
int main()
{
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&num[i]);
		if(i>0 && num[i-1]>num[i])
		{
			flag=0;
		}
		if(abs(num[i])>abs(max))
		{
			max=num[i];
			maxn=i;
		}
	}
	
	if(flag)
	{
		printf("0");
		return 0;
	}
	
	if(max>0)
	{
		num[n-1]+=max;
		wrt(maxn,n-1);
		count++;
		num[n-1]+=max;
		wrt(maxn,n-1);
		count++;
		for(i=0;i<n-1;i++)
		{
			num[i]+=num[n-1];
			wrt(n-1,i);
			count++;
			num[n-1]+=num[n-1];
			wrt(n-1,n-1);
			count++;
		}
	}
	else
	{
		num[0]+=max;
		wrt(maxn,0);
		count++;
		num[0]+=max;
		wrt(maxn,0);
		count++;
		for(i=n-1;i>0;i--)
		{
			num[i]+=num[0];
			wrt(0,i);
			count++;
			num[0]+=num[0];
			wrt(0,0);
			count++;
		}
	
	}
	printf("%lld\n",count);
	for(i=0;i<count;i++)
	{
		printf("%lld %lld\n",l[i],r[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
int m,n;
int main(void){
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
ans=0
hlist=[[int(x) for x in input().split()]]
for h in hlist:
    count=min(h)
    ans+=count
    tmp=[]
    for i in h:
        i=i-count
        if i == 0:
            if tmp==[]:
                continue
            hlist.append(tmp)
            tmp=[]
            continue
        tmp.append(i)
    if len(tmp)>0:
        hlist.append(tmp)
print(ans)

Measured memory_bytes: 40500
k = int(input())
s = input()
mod = 10**9+7
n = len(s)
fact =[1]*(k+n)
factinv = [1]*(k+n)
inv = [0,1]
 
 
for i in range(2,k+n):
    fact[i] = (fact[i-1] * i) % mod
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv[i] = (factinv[i-1] * inv[i]) % mod

def nCr(n,r):
  r = min(r,n-r)
  return (fact[n] * factinv[r] * factinv[n-r])%mod
ans = 0
for i in range(k+1):
  a = pow(25, i, mod)
  a *= nCr(i+n-1, n-1)
  a *= pow(26,k-i, mod)
  ans += a
  ans %= mod
print (ans)

Measured memory_bytes: 215132
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
//3問目	
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
	int k,p,now=1;
	cin>>k>>p;
	if(k%p==0)cout<<p<<endl;
	else cout<<k%p<<endl;
	}
	return 0;
}

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

using namespace std;

int main(void) {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  
  for(int i=0; i<n; i++) {
    if(s[i] == '+') ans++;
    if(s[i] == '-') ans--;
  }
  
  cout << ans << endl;
}
  

Measured memory_bytes: 256
from itertools import combinations

s = raw_input()
l = len(s)

allstrs = [[s]]
for n in range(1, l):
    pluses = combinations(range(1, l), n)
    for plus in pluses:
        strs = [s[:plus[0]]] + [s[plus[i]:plus[i+1]] for i in range(0,
            len(plus)-1)] + [s[plus[-1]:]]
        allstrs.append(strs)

print(sum([sum([int(x) for x in strs]) for strs in allstrs]))


Measured memory_bytes: 2692
#include <iostream>
using namespace std;
int main()
{
    string number = "";
    while (true)
    {
        cin >> number;
        if (number == "0")
            break;
        int sum = 0;
        for (int i = 0; i < number.size(); i++)
        {
            // 以下の処理はすべて等価
            sum += number[i] - '0';
            // sum += int(number[i]) - 48;
            // sum += int(number[i]) - int('0');
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3144