akhauriyash/Code-Regression huggingface dataset:
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")
MAX_DIGIT = 50

############
############
############

Q = i_inpl()
l, r = [], []

max_r = -INF
for _ in range(Q):
    li, ri = l_inpl()
    l.append(li)
    r.append(ri)
    max_r = max(max_r, ri)

MAX_X = 100030
prime_table = [True] * MAX_X
prime_table[0] = prime_table[1] = False

for (i, is_prime) in enumerate(prime_table):
    if is_prime:
        for n in range(i*i, MAX_X, i):
            prime_table[n] = False

# 1は2017に似てない数字
cumsums = [0]
for odd in range(3, max_r+3, 2):
    tmp = 0
    if prime_table[odd] and prime_table[(odd+1)//2]:
        tmp += 1
    cumsums.append(cumsums[-1] + tmp)

for li, ri in zip(l, r):
    if li > 1:
        li = li//2 - 1
    else:
        li = 0
    ri = ri//2
    print(cumsums[ri]-cumsums[li])


Measured memory_bytes: 68952
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
from collections import deque

n = getN()
tree = [[] for i in range(n)]
visited = [0 for i in range(n)]
color = [0 for i in range(n)]

for i in range(n-1):
    a, b, c = getList()
    tree[a-1].append((b-1, c))
    tree[b-1].append((a-1, c))

for i, vert in enumerate(tree):
    if len(vert) == 1:
        root = i
        break

deq = deque()
deq.append(root)

while(len(deq) != 0):
    cur = deq.pop()
    for (target, dist) in tree[cur]:
        if visited[target] == 0:
            color[target] = (color[cur] + dist) % 2
            visited[target] = 1

            deq.append(target)



for c in color:
    print(c)

Measured memory_bytes: 68528
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define an size()
#define S second
#define F first

using namespace std;
const ll maxn=1002;
ll mod=1e9+7;
ll b,kk,c,d;
ll entekh[1011][1011];
ll fuc[maxn+100][maxn+100];
ll fcc[maxn+100][maxn+100];
ll ans=0;

ll dp[maxn][maxn];
bool viz[maxn][maxn];
vector<pair<ll,ll> > vaz;
ll f(ll n,ll a )
{
    if (viz[n][a])
    {
        return dp[n][a];
    }
    if (n==0)
    {
        return 1;
    }
    if (a>b)
    {
        return 0;
    }

    ll v=0;
    ll j=1;
    for(ll i=c; i<=d  && i*a<=n; i++)
    {
        j=(((entekh[a*i][n]*((fuc[a*i][1]*fcc[a][i])%mod))%mod)*fcc[i][1])%mod;
        j*=f(n-a*i,a+1);
        j%=mod;
        v+=j;
        v%=mod;
    }
    v+=f(n,a+1);
    v%=mod;
    dp[n][a]=v;
   // cout<<n<<' '<<a<<':'<<v<<endl;
    viz[n][a]=1;
    return v;
}
ll tav(ll a,ll b)
{
    ll v;
    if (b==1)
    {
        return a;
    }
    if (b&1)
    {
        v=tav(a,b/2);
        return(((v*v)%mod)*a)%mod;
    }
    else
    {
        v=tav(a,b/2);
        return(v*v)%mod;
    }
}

int main()
{
    ll n,a;
    cin>>n>>a>>b>>c>>d;
    kk=n;
    if (c==0)
    {
        c=1;
    }
    for (ll i=0; i<maxn; i++)
    {
        entekh[0][i]=1;
    }
    for (ll i=0; i<maxn; i++)
    {
        entekh[i][i]=1;
    }
    for (ll j=1; j<maxn; j++)
    {
        for (ll i=1; i<=j; i++)
        {

            entekh[i][j]=(entekh[i-1][j-1]+entekh[i][j-1])%mod;
        }
    }

    fuc[0][1]=1;
    for (ll i=1; i<maxn; i++)
    {
        fuc[i][1]=(fuc[i-1][1]*i)%mod;
        fcc[i][1]=tav(fuc[i][1],mod-2);
    }

    for (ll i=1; i<maxn; i++)
    {
        for (ll j=2; j<maxn; j++)
        {
            fuc[i][j]=(fuc[i][j-1]*fuc[i][1])%mod;
            fcc[i][j]=tav(fuc[i][j],mod-2);
        }
    }
    cout<<f(n,a);

}


Measured memory_bytes: 35712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();
		char a[][] = new char[n][];
		for (int i = 0; i < n; i++)
			a[i] = nextString().toCharArray();

		boolean rows[] = new boolean[n];
		for (int i = 0; i < n; i++) {
			int j = 0;
			for (; j < m && a[i][j] == '.'; j++)
				;
			if (j == m)
				rows[i] = true;
		}

		boolean cols[] = new boolean[m];
		for (int i = 0; i < m; i++) {
			int j = 0;
			for (; j < n && a[j][i] == '.'; j++)
				;
			if (j == n)
				cols[i] = true;
		}

//		Helper.tr(rows, cols);
		for (int i = 0; i < n; i++) {

			for (int j = 0; j < m; j++) {

				if (rows[i] || cols[j])
					continue;
				out.print(a[i][j]);
			}
			if (!rows[i])
				out.println();
		}
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 22740
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#pragma warning (disable: 4996)
using namespace std;

using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    if (n < 0)return 0;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

ll merge_cnt(vector<ll>& a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin() + n / 2);
    vector<ll> c(a.begin() + n / 2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    while (ai < n) {
        if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
            a[ai++] = b[bi++];
        }
        else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> z(n);
    for (int i = 0; i < n; i++) {
        cin >> z[i];
    }
    ll ok = 0;
    ll ng = 1000000001;
    while (abs(ng - ok) > 1) {
        ll mid = (ok + ng) / 2;
        vector<ll>d(n,-1);
        for (int i = 0; i < n; i++) {
            if (z[i] >= mid)d[i] = 1;
        }
        vector<ll> rui(n + 1);
        for (int i = 0; i < n; i++) {
            rui[i + 1] = rui[i] + d[i];
        }
        if (n * (n + 1) / 2 / 2 >= merge_cnt(rui))ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 7152
//完全二叉树complete binary tree
#include <iostream>
#define MAX 100000
using namespace std;

int parent(int i){
	return i/2;
} 

int left(int i){
	return 2*i;
}

int right(int i){
	return 2*i+1;
}

int main(){
	
	int H, i, A[MAX+1];
	
	cin>>H;
	for(int i=1;i<=H;i++)
		cin>>A[i]; 
	
	for(int i=1;i<=H;i++){
		cout<<"node "<<i<<": key = "<<A[i] <<", ";
		if(parent(i)>=1)
			cout<<"parent key = "<<A[parent(i)] <<", ";
		if(left(i)<=H)
			cout<<"left key = "<<A[left(i)]<<", ";
		if(right(i)<=H)
			cout<<"right key = "<<A[right(i)]<<", ";
		cout<<endl;	
	}
	
	return 0;
}


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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;


ll sum(ll n) {
  ll m=0;
  FOR(i,0,12){
    m+=n%10;
    n/=10;
  }
  return m;
}


ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}


ll lcm(ll a,ll b){
  ll n;
  n=a*b/gcd(a,b);
  return n;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/


signed main() {
  ll n;
  ci(n);
  vll A(n);
  FOR(i,0,n){
    ci(A[i])
  }
  
  SORT(A);
  
  ll ans=0;
  FOR(i,0,n){
    FOR(j,0,n){
      if(i==j){
        continue;
      }
      else{
        ll a=M(A[i]-A[j],A[j]-A[i]);
        ans=M(ans,a);
      }
    }
  }
  co(ans)
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

const int mod = 1000000007; // 998244353;
struct mint {
  long long x;
  mint(long long x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    return mint(*this) += a;
  }
  mint operator-(const mint& a) const {
    return mint(*this) -= a;
  }
  mint operator*(const mint& a) const {
    return mint(*this) *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2); }
  mint& operator/=(const mint& a) { return *this *= a.inv(); }
  mint operator/(const mint& a) const {
    return mint(*this) /= a;
  }
};
istream& operator>>(istream& is, const mint& a) {
  return is >> a.x;
}
ostream& operator<<(ostream& os, const mint& a) {
  return os << a.x;
}

int main(){
  string s;
  cin>>s;
  int n=s.size();
  vector<int>pw(n+1);
  pw[0]=1;
  rep(i,n){
    pw[i+1]=pw[i]*10;
    pw[i+1]%=13;
  }
  vector<vector<mint>>dp(n+1,vector<mint>(13));

  dp[0][0]=1;
  rep(i,n){
    rep(j,13){
      if(s[i]=='?'){
        rep(k,10){
          dp[i+1][(j+k*pw[n-i-1])%13]+=dp[i][j];
        }
      }
      else{
        int x=s[i]-'0';
        dp[i+1][(j+x*pw[n-i-1])%13]+=dp[i][j];
      }
    }
  }

  cout<<dp[n][5]<<endl;
  return(0);
}


Measured memory_bytes: 14080
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int M, K;
  cin >> M >> K;
  if (K >= 1 << M) {
    cout << -1 << ' ';
    return 0;
  }
  if (M == 1) {
    if (K == 0) {
      cout << "0 1 1 0" << '\n';
    } else {
      cout << -1 << '\n';
    }
  } else {
    for (int i = 0; i < 1 << M; i++) if (i != K) {
      cout << i << ' ';
    }
    cout << K << ' ';
    for (int i = (1 << M) - 1; i >= 0; i--) if (i != K) {
      cout << i << ' ';
    }
    cout << K << ' ';
    cout << '\n';
  }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int left = a + b;
  int right = c + d;
  if(left > right)
    cout << "Left" << endl;
  else if(left == right)
    cout << "Balanced" << endl;
  else
    cout << "Right" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void){
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    if(n*a>=b)
    printf("%d",b);
    else{printf("%d",n*a);}
    return 0;
}

Measured memory_bytes: 128
from functools import lru_cache
from bisect import bisect
from sys import stdin
input = stdin.readline
A, B, Q = map(int, input().split())
S = [int(input()) for _ in range(A)]
T = [int(input()) for _ in range(B)]

@lru_cache(maxsize=None)
def func(f, x):
    L = S if f else T
    i = bisect(L, x)
    if i == 0:
        return abs(x - L[0])
    elif i == len(L):
        return abs(x - L[-1])
    else:
        return min(abs(x - L[i]), abs(x - L[i - 1]))

for x in [int(input()) for _ in range(Q)]:
    ans = float("inf")
    i = bisect(S, x)
    if i != 0:
        ans = min(ans, func(0, S[i - 1]) + x - S[i - 1])
    if i != A:
        ans = min(ans, func(0, S[i]) + S[i] - x)
    i = bisect(T, x)
    if i != 0:
        ans = min(ans, func(1, T[i - 1]) + x - T[i - 1])
    if i != B:
        ans = min(ans, func(1, T[i]) + T[i] - x)
    print(ans)

Measured memory_bytes: 117212
#include <bits/stdc++.h>
#define ll long long
using namespace std;
/* vector <vector <ll>> v(2e6);
 vector <bool> vis(2e6,false);
 vector <bool> vis2(2e6,false);
 vector <bool> res(2e6,false);
 long long s=0;
  bool flag=true;
void dfs(int x,int n)
{
      vis[x]=true;
      if(x==n-1)
        s++;
    for(int i=0;i<v[x].size()&&flag;i++)
        {
            if(!vis[v[x][i]])
           {
               dfs(v[x][i],n);
           }
           else if(v[x][i]==n-1)
            s++;
        }
}
*/
 
int main()
{
 ll t,n,m,k,x,l,r,i,sum=0,y,sx,sy,ex,ey,ans=0;
string s;
cin>>s;
k=0;
 while (k<s.size())
   sum+=s[k++]-'0';
if(sum%9==0)
    cout<<"Yes\n";
else
    cout<<"No\n";
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
           int n,m;
           cin>>n;
           string a;
           cin>>a;
           bool p=false,q=false,c=true, p0=false;int t=0;
           for(int i=0;i<n;i++){
                   if(a[i]=='2'){p0=true;}
                   if(a[i]=='2'&&t==0)p=!p;
                   if(a[i]=='3'&&t==0)q=!q;
                   m=n-(i+1);
                   if(m==0)break;
                   while(!(m&1)){t++;m>>=1;}
                   m=i+1;
                   while(!(m&1)){t--;m>>=1;}
                
                 
           }
           if(p)cout<<1<<endl;
           else{
                 if(p0)cout<<0<<endl;
                 else{
                         if(q)cout<<2<<endl;
                         else cout<<0<<endl;
                 }
           }
         
         
}

        


Measured memory_bytes: 1412
#include <iostream>
#include <string>
#define MAX_N 100
using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  int x[MAX_N];
  int ans = 0;
  for(int i = 0; i < N; i++){
    cin >> x[i];
    ans += 2 * min(x[i], abs(K - x[i]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		try {
			String[] inputList = br.readLine().split(" ");
			int H = Integer.parseInt(inputList[0]);
			int W = Integer.parseInt(inputList[1]);
			int[][] a = new int[H][W];
			int[] b = new int[H];
			int i, x;
			for (i = 0; i < H; i++) {
				inputList = br.readLine().split(" ");
				for (x = 0; x < inputList.length; x++) {
					a[i][x] = Integer.parseInt(inputList[x]);
				}
			}
			for (i = 0; i < W; i++) {
				int input = Integer.parseInt(br.readLine());
				for (x = 0; x < H; x++) {
					b[x] = b[x] + a[x][i] * input;
				}
			}

			for (i = 0; i < H; i++) {
				System.out.println(b[i]);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 22668
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;


const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;

    //白をx個黒をN-x個並べるを(0-からNまで試す)
    //
    vector <int> shiro(N+1, 0);
    shiro[0] = 0;
    //shiro[N] = 
    for(int i = 0; i < N; ++i)
    {
      shiro[i+1] = shiro[i];
      if(s[i] == '.')++shiro[i+1];
    }

    int res = MOD;
    for(int i = 0; i <= N; ++i)
    {
      int cnt = 0;
      //白にすべき範囲の黒 + 黒にすべき範囲の白
      cnt = (i - shiro[i]) + (shiro[N] - shiro[i]);
      res = min(res, cnt);
    }
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 1412
#include<iostream>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<algorithm>
#include <vector>
#include<cstdio>
#include <numeric>
#include <queue>
#include <list>
#include <math.h>
#include <stdio.h>
#include <math.h>
#include <errno.h>
#include <fenv.h>
#include <iomanip>
using namespace std;

int main(){
    int A;
    int B;
    int H;
    int M;
    cin>>A>>B>>H>>M;
    double l=H*30.0+0.5*M;
    double h=6.0*M;
    double ss=abs(l-h);
    static const double pi = 3.141592653589793;
    double unit=pi/180.0;
    double a=pow(A,2)+pow(B,2)-2*A*B*cos(unit*ss);
    double ans=sqrt(a);
    cout<<fixed<<setprecision(15)<<ans<<endl;

}

Measured memory_bytes: 4196
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a,b,c,d,i,j,k;
        while (sc.hasNextInt()){
        	 int n=sc.nextInt();
        	 b=0;
        	for(i=0;i<10;i++){
        		for(j=0;j<10;j++){
        			for(k=0;k<10;k++){	
        				for(a=0;a<10;a++){
        					if(i+j+k+a==n)
        						b++;
        					else if(i+j+k+a>n)break;
        					
        					
        				}
        			}
        		}
        	}System.out.println(b);
        }
    }
}

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

const int ms = 8009;

vector<int> d[2];
char memo[2][ms][2 * ms];

char dp(int at, int i, int pos) {
  if (i == d[at].size())
    return pos == ms;
  char &ans = memo[at][i][pos];
  if (ans != -1) return ans;
  return ans = dp(at, i + 1, pos + d[at][i]) || dp(at, i + 1, pos - d[at][i]);
}

int main() {
  memset(memo, -1, sizeof memo);

  string s;
  int x, y;
  cin >> s >> x >> y;
  int i = 0;
  while (i < s.size() && s[i] == 'F') i++, --x;

  int at = 0;
  while (i < s.size()) {
    while (i < s.size() && s[i] == 'T') {
      at = 1 - at;
      i++;
    }

    int cnt = 0;
    while (i < s.size() && s[i] == 'F') {
      cnt++;
      i++;
    }
    if (cnt) d[at].push_back(cnt);
  }
  if (dp(0, 0, ms + x) && dp(1, 0, ms + y)) {
    puts("Yes");
  } else {
    puts("No");
  }
}

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

int n, m;
int b[15], p[16], g[15];

int calc()
{
	int a[15];
	int res = 0;
	for (int i = 0; i < n; i++) a[i] = b[i];
	for (int i = 0; i < n; i++){
		int q = find(a + i, a + n, g[i]) - a;
		if (q == n) return 1 << 28;
		for (int j = q; j > i; j--){
			swap(a[j], a[j - 1]);
			res++;
		}
	}
	return res;
}

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%d", b + i);
	for (int i = 0; i < m; i++){
		scanf("%d", p + i + 1);
		p[i + 1] += p[i];
	}
	
	for (int i = 0; i < m; i++){
		for (int j = p[i]; j < p[i + 1]; j++){
			g[j] = i & 1;
		}
	}
	
	int res = calc();
	for (int i = 0; i < n; i++) g[i] ^= 1;
	res = min(res, calc());
	
	printf("%d\n", res);
}

Measured memory_bytes: 1192
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	T := nextFloat64()
	A := nextFloat64()
	H := nextInts(N)
	rtn := -1000000.0
	idx := 0
	for i := 0; i < N; i++ {
		h := T - float64(H[i])*0.006
		if AbsFloat64(rtn-A) > AbsFloat64(h-A) {
			rtn = h
			idx = i
		}
	}
	fmt.Println(idx + 1)
}
func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func AbsFloat64(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


Measured memory_bytes: 640
x = input()
y = x.split(" ")
triangle = [int(i) for i in y]
max_index = -1
max = 0
for line in range(len(triangle)):
    if(triangle[line] > max):
        max = triangle[line]
        max_index = line
del triangle[max_index]

print(int(triangle[0] * triangle[1] / 2))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
signed main(){
	int a,b;
	cin>>a>>b;
	if(a>b)cout<<2*a-1<<endl;
	else if(a<b)cout<<2*b-1<<endl;
	else cout<<a+b<<endl; 
	return 0;
}


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

typedef struct node{
  int key;
  struct node *next , *prev;
}Node;

Node *nil;

Node* search(int key){
  Node *cur=nil->next;
  while(cur!=nil&&cur->key!=key){
    cur=cur->next;
  }
  return cur;
}

void init(){
  nil=(Node *)malloc(sizeof(Node));
  nil->next=nil;
  nil->prev=nil;
}

void print() {
  Node *cur=nil->next;
  int count=0;
  while(1){
    if(cur==nil) break;
    if(count++>0) printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t){
  if(t==nil ) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}
void deleteKey(int key){
  deleteNode(search(key));
}

void insert(int key) {
  Node *x =(Node *)malloc(sizeof(Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key,n,i,size=0;
  char com[20];
  int np=0,nd=0;
  scanf("%d",&n);
  init();
  for(i = 0;i<n;i++) {
  scanf("%s%d",com,&key);
  if(com[0] == 'i') {
    insert(key);
    np++;
    size++;
  }
  else if(com[0]=='d') {
    if(strlen(com)>6) {
      if(com[6]=='F') deleteFirst();
      else if(com[6]=='L') deleteLast();
    }
    else {
      deleteKey(key); nd++;
    }
    size--;
  }
}
print();
return 0;
}



Measured memory_bytes: 32960
#include <iostream>
#include <string>
#include <stack>
#include <map>

using namespace std;

int main() {
    map<char,char> close_of;
    close_of['('] = ')';
    close_of['['] = ']';

    while(true) {
        string line;
        getline(cin, line);
        if(line == ".") break;

        bool ok = true;
        stack<char> stk;
        for(int i = 0; i < line.size(); ++i) {
            char c = line[i];
            if(c == '(' || c == '[') {
                stk.push(c);
            }
            else if(c == ')' || c == ']') {
                if(stk.size() == 0 || c != close_of[stk.top()]) {
                    ok = false;
                    break;
                }
                stk.pop();
            }
        }
        if(stk.size() != 0) ok = false;

        cout << (ok?"yes":"no") << endl;
    }

    return 0;
}

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

//http://abc067.contest.atcoder.jp/tasks/abc067_a

using namespace std;


typedef long long LL;
typedef pair<LL,LL> pp;


int main()
{
	int A, B;
	cin >> A >> B;
	if (A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) {
		cout << "Possible";
	}
	else {
		cout << "Impossible";
	}
	cout << endl;
	exit(0);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  cout<<(n+1)/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<pair<pii,pair<int,pii> >, null_type, less<pair<pii,pair<int,pii> > >, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
	fast;
	int a,v;cin>>a>>v;
	int b,w;cin>>b>>w;
	int t;cin>>t;

	if(v<=w)
	{
		cout<<"NO";
		return 0;
	}

	if(a>b)
		swap(a,b);

	if(a+v*t>=b+w*t)
		cout<<"YES";
	else
		cout<<"NO";
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

//境界値に注意！！！

int main() {
    string s,dict="abcdefghijklmnopqrstuvwxyz";
    cin >> s;
    for (int i=0;i<s.size();++i){
        for (int j=0;j<dict.size();++j){
            if (s[i]==dict[j]){
                dict.erase(dict.begin()+j);
            }
        }
    }
    if (dict[0]){
        cout << dict[0] << endl;
        return 0;
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

constexpr int N = 8;

std::pair<int, vvec<bool>> solve(vvec<bool> map, int y, int x, int queenCount, vec<bool> h, vec<bool> w, vec<bool> tr, vec<bool> br)
{
    ++queenCount;

    map[y][x] = true;
    h[y] = true;
    w[x] = true;
    tr[y + x] = true;
    br[7 - y + x] = true;

    if (queenCount == N)
    {
        return make_pair(queenCount, map);
    }

    for (int i = 0; i < N; ++i)
        for (int j = 0; j < N; ++j)
        {
            if (!h[i] && !w[j] && !tr[i + j] && !br[7 - i + j])
            {

                auto m = solve(map, i, j, queenCount, h, w, tr, br);

                if (m.first == N)
                {
                    queenCount = N;
                    map = m.second;
                    goto LOOP_END;
                }
            }
        }

    LOOP_END:

    return make_pair(queenCount, map);
}

int main()
{
    using namespace std;
    // cerr.rdbuf(nullptr);

    int k;
    cin >> k;

    vec<bool> h(8);
    vec<bool> w(8);
    vec<bool> tr(15);
    vec<bool> br(15);

    vvec<bool> map(N, vec<bool>(N));

    int r, c;
    for (int i = 0; i < k - 1; ++i)
    {
        cin >> r >> c;
        map[r][c] = true;
        h[r] = true;
        w[c] = true;
        tr[r + c] = true;
        br[7 - r + c] = true;
    }

    cin >> r >> c;
    auto ans = solve(map, r, c, k - 1, h, w, tr, br).second;

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

    return 0;
}


Measured memory_bytes: 3116
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

class Program
{
    static void Main()
    {
        var sc = new Scanner();

        var ring = sc.String();
        int n = sc.Int();

        sc.StringArray(n)
            .Select(x => x + x)
            .Count(x => x.Contains(ring))
            .Print();

        //sc.StringArray(n)
        //    .Select(x => x + x)
        //    .Where(x => x.Contains(ring))
        //    .Count()
        //    .Print();

        Console.ReadKey();
    }
}

static class Extensions
{
    public static IEnumerable<T> Output<T>(this IEnumerable<T> source)
    {
        foreach (var item in source)
        {
            Console.WriteLine(item);
        }
        return source;
    }

    public static T Print<T>(this T obj)
    {
        Console.WriteLine(obj);
        return obj;
    }
}

public class Scanner
{
    public Scanner()
    {
        byte[] inputBuffer = new byte[1024];
        System.IO.Stream inputStream = Console.OpenStandardInput(inputBuffer.Length);
        Console.SetIn(new System.IO.StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length));
    }
    string[] buffer = new string[0];
    int index = 0;
    public char[] SplitChars { get; set; }
    public string String()
    {
        if (index < buffer.Length) return buffer[index++];
        string line = "";
        while (line == "") line = Console.ReadLine();
        if (line == null) return null;
        buffer = line.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries);
        index = 0;
        return buffer[index++];
    }
    public string[] StringArray(int count) { return NextArray(count, x => x); }
    public void Skip(int count) { for (int i = 0; i < count; i++) String(); }
    public T Next<T>(Func<string, T> parser) { return parser(String()); }
    public T[] NextArray<T>(int count, Func<string, T> parser)
    {
        var arr = new T[count];
        for (int i = 0; i < count; i++) arr[i] = Next(parser);
        return arr;
    }
    public int Int() { return Next(int.Parse); }
    public int[] IntArray(int count) { return NextArray(count, int.Parse); }
    public double Double() { return Next(double.Parse); }
    public double[] DoubleArray(int count) { return NextArray(count, double.Parse); }
}

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


int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<bool> oshita(N,false);
  vector<ll> osu(1,0);
  oshita.at(0) = true;
  for ( ll i = 0; i < N; i++ ) {
    cin >> A.at(i);
    A.at(i)--;
  }
  for(ll i = 0; i < N; i++ ) {
    osu.push_back(A.at(osu.at(i)));
    if(osu.at(i+1) == 1){
      cout << i+1 <<  endl;
      break;
    }
    if(oshita.at(osu.at(i+1)) == true){
      cout << -1 << endl;
      break;
    }   
    oshita.at(osu.at(i + 1)) = true;
  }
  //cout << osu.size() << endl;
  /*for( ll i = 0; i < N; i++) {
    cout << osu.at(i) << endl;
    cout << oshita.at(i) << endl;
  }*/
}
    
  

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  if(a==1){
    cout<<"Hello World"<<endl;
    return 0;
  }
  ll b,c;
  cin>>b>>c;
  cout<<b+c<<endl;
  return 0;
}
  
  
    
    
  


Measured memory_bytes: 3604
def solve():
    n, k = map(int, input().split())
    s = input()
    if len(s) != n:
        raise Exception('Error')
    s_l = list(s)
    s_l[k-1] = s[k-1].lower()
    s_n = "".join(s_l)
    print(s_n)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include<cstdio>

int main(){
  int n, m, i, j, key, c;
  scanf("%d %d", &n, &m);
  int a[n][m], b[m][1];
  for(i = 0; i < n; i++){
    for(j = 0; j < m; j++){
      scanf("%d", &a[i][j]);
    }
  }
  for(i = 0; i < m; i++){
    for(j = 0; j < 1; j++){
      scanf("%d", &b[i][j]);
    }
  }
  for(i = 0; i < n; i++){
    for(j = 0; j < 1; j++){
      c = 0;
      for(key = 0; key < m; key++){
        c = c + a[i][key] * b[key][j];
      }
      printf("%d",c);
    }
    printf("\n");/*それぞれ１行に出力*/
  }
  return 0;
}



Measured memory_bytes: 2740
#include <stdio.h>

int main(int argc, char* argv[]){
	int x[10000];
	int i, j = 0;
	int a;
	
	do{
		scanf("%d", &a);
		x[i] = a;
		i++;
	}while(a != 0);

	for(j = 0; j < i - 1; j++){
		printf("Case %d: %d\n", j + 1, x[j]);
	}

	return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
using ll = long long;
using namespace std;
int main(){
    string s;
    cin >> s;
    int k;
    cin>> k;
    vector<string> vec;
    if(s.size()==1){
        cout<<s[0]<<endl;
        return 0;
    }
    for(int i=0;i<=(int)s.size();i++){
        for(int j=1;j<6;j++){
            vec.push_back(s.substr(i,j));
        }
    }
   // cout<<vec[1]<<endl;
   // cout<<vec[]<<endl;
   // cout<<vec.size()<<endl;
   
    sort(vec.begin(),vec.end());
    vec.erase(unique(vec.begin(),vec.end()));
    
    cout<<vec[k]<<endl;
}


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

int main() {
  int N;
  cin >> N;
  int64_t ans=0;
  int64_t m=0;
  for(int i=0;i<N;i++){
    int64_t a;
    cin >> a;
    m=max(a,m);
    ans+=m-a;
  }
  cout << ans;
}

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

typedef long long ll;
const int N = 2000006;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	vector<pair<int,int> > v;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		v.push_back({y,x});
	}
	
	sort(v.begin(),v.end());
	
	int cnt = 0;
	for(int i=0;i<n;i++){
		cnt += v[i].second;
		if(cnt > v[i].first){
			cout<<"No";
			return 0;
		}
	}
	
	cout<<"Yes";
	
	return 0;
}


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


int main(void){
    string S;
    cin >> S;
    int ans1 = 0;
    int ans2 = 0;
    for (int i = 0; i < S.length(); i++)
    {
        if(i%2 == 0){
            if(S[i] == '0') ans1++;
            else ans2++;
        }
        else{
            if(S[i] == '1') ans1++;
            else ans2++;
        }
    }
    cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

typedef long long lli;

const int MAX = 10002;
int n,m,k;

void solve(){
  lli dp[2][MAX];
  fill(dp[0],dp[2],0);
  for(int i=1;i<=m;i++) dp[0][i] = 1;

  for(int i=1;i<n;i++){
    for(int j=1;j<MAX;j++){
      if(dp[0][j-1] > 0 && dp[0][j] == 0) break;
        for(int k=1;k<=m;k++){
          dp[1][j+k] += dp[0][j];
        }
    }
    for(int j=0;j<MAX;j++){
      dp[0][j] = dp[1][j];
      dp[1][j] = 0;
    }
  }

  lli ans = 0;
  for(int i=0;i<MAX;i++) ans += (lli)max(1,i-k) * dp[0][i];
  printf("%.8f\n",(double)ans / pow((double)m, (double)n));
}

int main(){
  while(cin >> n >> m >> k && (n|m|k)){
    solve();
  }
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define pb push_back
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
#define INF 300000000000001
#define ll_max 9000000000000000000
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<pair<ll,ll> > vll;
typedef vector<int> vi;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll N = 1001;
const ll M = log2(N);

struct point {
    ll x, y, i;
    bool operator == (const point b)
    {
        if(this -> x == b.x && this -> y == b.y) return 1;
        return 0;
    }
    bool operator != (const point b) {return !(*this == b);}
    friend bool operator < (const point a, const point b)
    {
        if(a.x != b.x)
            return a.x < b.x;
        return a.y < b.y;
    }
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cerr << word << " = " << a << endl;
    debug(s, args...);
}
bool overflow;
ll fast_exp(ll x, ll n)
{
    if(n == 0) return 1;
    ll ans;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         if(ans > ans * ans % mod)
                overflow = 1;
         ans = ans * ans % mod;
    }
    else
    {
        ans = fast_exp(x, n - 1);
        if(ans > ans * x % mod)
            overflow = 1;
        ans = ans * x % mod;
    }
    return ans;
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n = 0, m = 0, x = 0, y = 0, ans = 1, k;
        cin >> n;
        ans = n * (n - 1) +  n * (n - 1) * (n - 2) / 6 + n;
        for(int i = 1; i < n; i++)
        {
            cin >> x >> y;
            if(x > y) swap(x, y);
            ans -= x * (n - y + 1);
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3644
a,b,c=map(int,input().split())
if a==1:
    if b==0 and c==0:
        print("Close")
    elif b==1 and c==0:
        print("Open")
else:
    if b==1 and c==0:
        print("Close")
    elif b==0 and c==1:
        print("Open")
    else:
        print("Close")
        


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

int main(){
    int n;
    cin >> n;
    if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9){
        cout << "hon" << endl;
    }
    else if(n%10==0||n%10==1||n%10==6||n%10==8){
        cout << "pon" << endl;
    }
    else{
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  string X;
  cin >> N >> X;
  
  int count=0;
  rep(i,N) {
    if(X[i]=='1') count++;
  }
  
  if(count==0) rep(i,N) cout << 1 << endl;
  
  else if(count==1) {
    if(X[N-1]=='0') {
      rep(i,N-1) {
        if(X[i]=='0') cout << 1 << endl;
        else cout << 0 << endl;
      }
      cout << 2 << endl;
    }
    else {
      rep(i,N-1) cout << 2 << endl;
      cout << 0 << endl;
    }
  }
  
  else {
    vi twop(N),twon(N);
    twop[0]=1,twon[0]=1;
    int sump=0,sumn=0;
    if(X[N-1]=='1') {
      sump++;sumn++;
    }
    rep(i,N-1) {
      twop[i+1]=twop[i]*2;
      twon[i+1]=twon[i]*2;
      twop[i+1]%=(count+1);
      twon[i+1]%=(count-1);
      if(X[N-i-2]=='1') {
        (sump+=twop[i+1])%=(count+1);
        (sumn+=twon[i+1])%=(count-1);
      }
    }
    
    rep(i,N) {
      int x,f=1;
      if(X[i]=='1') {
        x=sumn-twon[N-i-1]+count-1;
        x%=(count-1);
      }
      else x=(sump+twop[N-i-1])%(count+1);
      while(x>0) {
        int c=0;
        rep(j,19) if(x&(1<<j)) c++;
        x%=c;
        f++;
      }
      cout << f << endl;
    }
  }
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

vector<int> p[210000];
ll dp[210000];

void add(ll &a, ll b) {
    a += b;
    if (a >= mod) a -= mod;
}

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

    int N; cin >> N;
    vector<int> c(N);
    rep(i, N) cin >> c[i];

    rep(i, N) p[c[i]].pb(i);

    dp[0] = 1;
    REPS(i, 1, N) {
        add(dp[i], dp[i-1]);
        int color = c[i-1];
        int it = lower_bound(all(p[color]), i-1) - p[color].begin();
        if (it > 0) {
            int j = p[color][it-1]; // c[j] = c[i]となるj
            if ((i - 1) - j > 1) {
                add(dp[i], dp[j+1]);
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 13824
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int h,w;
int n;
int tbl[501][501];
int main(){
  cin >> h >> w;
  cin >> n;
  vector<int> col;
  for(int i=0;i<n;++i){
    int a;
    cin >> a;
    for(int j=0;j<a;++j)
      col.push_back(i+1);
  }
  int p=0;
  for(int i=0;i<h;++i){
    if(i%2==0)
      for(int j=0;j<w;++j)
	tbl[i][j]=col[p++];
    else
      for(int j=w-1;j>=0;--j)
	tbl[i][j]=col[p++];
  }

  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j)
      cout << tbl[i][j] << " ";
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
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 N;
vector<ll> V(100,0);
ll j = 1,k = 0,p = 1;
vector<ll> M;

void sok(){
  M.pb(1);
    REP(o,59){
        p *= 2;
        M.pb(p);
    }
}

void solve(int A,int i){
    REP(u,58){
        if(A >= M[u] && A <= M[u+1]){
            V[u]++;
            if(A-M[u] == 0) break;
            solve(A-M[u],i);
        }
    }
}

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
  sok();
    cin >> N;
    int A[N];
    REP(i,N){
        cin >> A[i];
        solve(A[i],i);
    }
    REP(i,V.size()){
        if(V[i] == 0) continue;
        if(V[i] % 2 == 1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 640
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.file;
import std.math;

int main() {
	float x, y;  // x to east, y to north
	float dir; // direction by radian, 0.0 = east, pi/2 = north
	
	x = 0.0, y = 0.0;
	dir = PI/2;
	
	string l;
	while((l = readln().split[0], l.length)){
		if(!l.split.length || l.split(",")[0] == "0" && l.split(",")[1] == "0") break;
		
		float a, b;
		a = to!float(l.split(",")[0]), b = to!float(l.split(",")[1]);
		
		x += a * cos(dir);
		y += a * sin(dir);
		
		dir += -b / 180 * PI;
		}
	printf("%d\n", to!int(x));
	printf("%d\n", to!int(y));
	return 0;
	}

Measured memory_bytes: 1104