akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int rev_mod(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

long long int fact[210000];

int main(){
    fact[0] = 1;
    for(int i = 1; i < 210000; i++){
        fact[i] = fact[i - 1] * i;
        fact[i] %= MOD;
    }
    long long int N, M, K;
    cin >> N >> M >> K;
    long long int ans = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= M; j++){
            long long int p = N - i + 1;
            long long int S = p * (p - 1) / 2 % MOD * M % MOD;
            ans += S;
            ans %= MOD;

            p = i;
            S = p * (p - 1) / 2 % MOD * M % MOD;
            ans += S;
            ans %= MOD;

            p = M - j + 1;
            S = p * (p - 1) / 2 % MOD * N % MOD;
            ans += S;
            ans %= MOD;
            
            p = j;
            S = p * (p - 1) / 2 % MOD * N % MOD;
            ans += S;
            ans %= MOD;
        }
    }
    ans *= fact[N * M - 2];
    ans %= MOD;
    ans *= rev_mod(fact[K - 2]);
    ans %= MOD;
    ans *= rev_mod(fact[N * M - K]);
    ans %= MOD;
    ans *= rev_mod(2);
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
string s;int n,t[26],tt[26];
int a[100001],b[100001],p[100001],S[100001];
long long ans=0;
void ask(int x){
	for(int i=x;i<=b[0];i+=i&-i)ans+=p[i];
}
void add(int x){
	for(int i=x;i>=1;i-=i&-i)p[i]++;
}
int main(){
	cin>>s;n=s.size();s=" "+s;
	ref(i,1,n)t[s[i]-'a']++;
	int tottmp=0;
	ref(i,0,25)if(t[i]&1)tottmp++;
	if(tottmp>1){
		cout<<-1<<endl;
		return 0;
	}
	int tot=0;
	ref(i,1,n){
		char c=s[i]-'a';tt[c]++;
		if(t[c]&1){
			if(tt[c]>(t[c]+1)/2)tot++,b[++b[0]]=c;
			if(tt[c]<(t[c]+1)/2)ans+=tot,a[++a[0]]=c;
			if(tt[c]==(t[c]+1)/2)ans+=tot,tot++;
			continue;
		}
		if(tt[c]>t[c]/2)tot++,b[++b[0]]=c;
		else ans+=tot,a[++a[0]]=c;
	}
	ref(i,1,b[0]/2)swap(b[i],b[b[0]+1-i]);
	ref(i,0,25){
		p[0]=0;
		ref(j,1,a[0])if(a[j]==i)p[++p[0]]=j;
		p[0]=0;
		ref(j,1,b[0])if(b[j]==i)S[j]=p[++p[0]];
	}
	memset(p,0,sizeof p);
	ref(i,1,b[0]){
		ask(S[i]);
		add(S[i]);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll h,n; cin>>h>>n;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n) {cin>>a[i]; sum+=a[i];}
    if(sum>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(){
    int i,j,k,n,v;
    int A[10000];

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
        if(i>0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
   
    for(i=1;i<=n-1;i++){
        v = A[i];
        j=i-1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
            A[j+1] = v;

            for(k=0;k<n;k++){
            if(k>0)printf(" ");
            printf("%d", A[k]);
            }
            printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2124
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

func NextStringsLine() []string {
	strs := []string{}
	stringsStr := NextLine()
	tmp := strings.Split(stringsStr, " ")
	for _, s := range tmp {
		strs = append(strs, s)
	}
	return strs
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

/*******************************************************************/

var a, op, b string

func main() {
	tmp := NextStringsLine()
	a = tmp[0]
	op = tmp[1]
	b = tmp[2]
	ai, _ := strconv.Atoi(a)
	bi, _ := strconv.Atoi(b)
	if op == "+" {
		fmt.Println(ai + bi)
	} else {
		fmt.Println(ai - bi)
	}
}


Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    static class Solution {
        int count = 0;
        int k =0;
        long res = 0;
        List<Long> list = new ArrayList();
        public void find(int k) {
            this.k = k;
            for(int len = 1; count<k; len++) {
                generate(len, 0, 0, -1);
            }
            Collections.sort(list);
            System.out.println(list.get(k-1));
        }

        void generate(int len, long val, int curLen, int prev) {
            if(len == curLen) {
                list.add(val);
                count++;
                if(count == k) {
                    res = val;
                }
                return;
            }

            if(count >= k) {
                res = val;
                return;
            }


            for(int i=0; i<=9; i++) {
                int tmp = 0;
                if(curLen == 0 && i== 0) continue;
                if(prev == -1) {
                    tmp = i;
                } else {
                    if(Math.abs(prev-i) <= 1) {
                        tmp = i;
                    } else {
                        continue;
                    }
                }
                generate(len, val*10+tmp, curLen+1, tmp);
            }
        }

    }

    public static void main(String[] args) {
        Solution sol = new Solution();
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        sol.find(k);
    }
}


Measured memory_bytes: 28700
N, P = map(int, input().split())
S = input()
U = [0]*P
ans = 0
if P == 2 or P == 5:
    for i in range(0, N):
        if int(S[i])%P == 0:
            ans += i+1
    print (ans)
else:
    t, s = 0, 1
    for i in range(N-1, -1, -1):
        t = (int(S[i])*s+t)%P
        U[t] += 1
        s = s*10%P
    for u in U:
        ans += u*(u-1)//2
    ans += U[0]
    print (ans)

Measured memory_bytes: 3500
N = int(input())
A = list(map(int, input().split()))
mod = 10**9 + 7
a = max(A)
prime_num = [2]
sgn = [0 for _ in range(max(int(a**0.5)+1, 4))]
sgn[2] = 1
for k in range(3, len(sgn), 2):
  if sgn[k] == 0:
    prime_num.append(k)
    for j in range(k, a+1, 2*k):
      sgn[k] = 1
baisu = []
count = [0 for _ in range(a+1)]
for k in range(N):
  b = 0 + A[k]
  for p in prime_num:
    if p**2 <= b:
      if b%p == 0:
        if count[p] == 0:
          baisu.append(p)
        c = 0
        while b % p == 0:
          b //= p 
          c += 1 
        if c > count[p]:
          count[p] = c
    else:
      break
  if b != 1:
    if count[b] == 0:
      count[b] = 1
      baisu.append(b)

product = 1
for item in baisu:
  product *= pow(item, count[item], mod)
  product %= mod

b = mod-2
blis = []
c = 0
while b >0:
  if b & 1 == 1:
    blis.append(c)
  c += 1
  b >>= 1

def modinv(a):
  if a == 1:
    return 1
  else:
    res = 1
    li = []
    for _ in range(c):
      li.append(a%mod)
      a = a*a%mod
    for item in blis:
      res = res *li[item] %mod
    return res

ans = 0
for k in range(N):
  ans += product*modinv(A[k])
  ans %= mod

print(ans)

Measured memory_bytes: 148844
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))
A.insert(0,0)
ans=0
for i in range(1,N+1):
    #print(i,A[i],A[A[i]])
    if A[A[i]]==i:
        ans+=1
print(ans//2)

Measured memory_bytes: 52912
#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define P pair<int,int>
using namespace std;

P a[200];
signed main() {
	int ans = 1;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		ans = ans * 2 % mod;
	}
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	ans -= n + 1;
	ans %= mod;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			vector<int>V;
			if (a[i].first == a[j].first) {
				for (int k = 0; k < n; k++) {
					if (a[k].first == a[i].first) {
						V.push_back(k);
					}
				}
			}
			else if (a[i].second == a[j].second) {
				for (int k = 0; k < n; k++) {
					if (a[k].second == a[i].second) {
						V.push_back(k);
					}
				}
			}
			else {
				double x = double(a[j].second - a[i].second) / (a[j].first - a[i].first);
				double y = double(a[i].second) - a[i].first*x;
				for (int i = 0; i < n; i++) {
					if (abs(a[i].first*x + y - a[i].second) <= 1e-5) {
						V.push_back(i);
					}
				}
			}
			sort(V.begin(), V.end());
			if (V.size()>=2&&V[0] == i&&V[1]==j) {
				int k = 1;
				for (int j : V) {
					k = k * 2 % mod;
				}
				k -= V.size(); k--;
				ans -= k;
				ans %= mod;
			}
		}
	}
	ans += mod * 5;
	ans %= mod;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    
    int main() {
    
     
     int a,b;
     cin >> a >> b;
     
     int d = a/b;
     int r = a%b;
     double f = (double)a/(double)b;
     
     printf("%d %d %lf\n",d,r,f);
     return 0;
    }


Measured memory_bytes: 3204
#include <iostream>
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

using namespace std;

int main(){
	int n;
	string s;
	string alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string ans;
	while(1){
		cin >> n;
		if(n == 0) break;
		int k[n];
		for(int i = 0; i < n; i++){
			cin >> k[i];
		}
		cin >> s;
		for(int i = 0; i < s.length(); i++){
			int kn = i%ARRAY_LENGTH(k);
			int alpn = alp.find(s[i])-k[kn];
			if(alpn < 0) alpn += 52;
			else if(alpn > 52) alpn -=52;
			cout << alp[alpn];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main() { cin.tie(0); ios::sync_with_stdio(false);
    int N = in;
    vector<int> X(N), Y(N), H(N);
    rep( i, N ) cin >> X[i] >> Y[i] >> H[i];

    rep( x, 101 ) {
    rep( y, 101 ) {
        int h;
        rep( i, N ) {
            if( H[i] != 0 ) {
                h = H[i] + abs(x-X[i]) + abs(y-Y[i]);
                break;
            }
        }

        bool flg = false;
        rep( i, N ) {
            if( H[i] != max( 0, h-abs(x-X[i])-abs(y-Y[i]) ) ) {
                flg = true;
                break;
            }
        }
        if( flg ) continue;
        cout << x << " " << y << " " << h << "\n";
        return 0;
    }
    }
}


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

int main(){
int max,min,i,n,a[10000];
long sum;

sum=0;

scanf("%d",&n);

for(i=0;i<n;i++){
    scanf("%d",&a[i]);
   }

max=min=sum=a[0];

for(i=1;i<n;i++){
    if(a[i]>max){max=a[i];}
    if(a[i]<min){min=a[i];}
    sum+=a[i];
    }

printf("%d %d %ld\n",min,max,sum);

return 0;
}

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

X = 0
D = 0
N = 0

def countwhile(k):
    i=1
    while k(i):
        yield 1
        i += 1

def readlines():
    for _ in range(N):
        a = int(input())
        yield 1+sum(countwhile(lambda i: i*a+1 <= D))

def main():
    global N, X, D
    N = int(input())
    D, X = map(int, input().split())
    return sum(readlines()) + X
	
if __name__ == "__main__":
    print(main())

Measured memory_bytes: 3064
def main(N, M, K, A, B):
    ans = 0
    time = sum(B)
    j = M
    Loop = True
    for i in range(N+1):
        while True:
            if time > K:
                if j == 0:
                    Loop = False
                    break
                j -= 1
                time -= B[j]
            else:
                ans = max(ans, j+i)
                break
        if Loop == False:
            break
        if i == N:
            break
        time += A[i]
    return ans


N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
print(main(N, M, K, A, B))


Measured memory_bytes: 40144
#include<cstdio>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

const int MAX = 100000 + 10;
const long long INF = 1000000000*1000000000LL;
priority_queue<pair<long long,int>, vector<pair<long long,int>>, greater<pair<long long,int>>> q;
vector<pair<int,long long>> v[MAX];

long long dis[MAX];
bool vis[MAX];

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 2 ; i <= n ; i++) v[i].push_back(make_pair(i-1, 0));
    for(int i = 0 ; i < m ; i++) {
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        v[x].push_back(make_pair(y, (long long)z));
        v[y].push_back(make_pair(x, (long long)z));
    }

    dis[1] = 0;
    vis[0] = false;
    for(int i = 2 ; i <= n ; i++) dis[i] = INF, vis[i] = false;

    q.push(make_pair(0, 1));
    while(!q.empty()) {
        while(!q.empty() && vis[q.top().second]) q.pop();
        if(q.empty()) break;

        pair<long long,int> tmp = q.top();
        q.pop();
        int nn = tmp.second;
        long long ss = tmp.first;
        vis[nn] = true;

        for(int i = 0 ; i < v[nn].size() ; i++) {
            int tar = v[nn][i].first;
            long long dd = ss + v[nn][i].second;
            if(dd < dis[tar]) {
                dis[tar] = dd;
                q.push(make_pair(dd, tar));
            }
        }
    }

    printf("%lld\n", dis[n] == INF ? -1 : dis[n]);

    return 0;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<int> l;

void dfs(vector<vector<int>>& edges, vector<bool>& used, int i) {
    for (int j : edges[i]) if (!used[j]) {
        used[j] = true;
        dfs(edges,used,j);
    }
    l.push_back(i);
}

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> edges(n);
    vector<bool> used(n,false);
    for (int i = 0;i < m;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[v].push_back(u);
    }
    for (int i = 0;i < n;++i) if (!used[i]) {
        used[i] = true;
        dfs(edges,used,i);
    }
    vector<int> dp(n,0);
    reverse(l.begin(),l.end());
    for (int i : l) {
        for (int j : edges[i]) dp[j] = max(dp[j],dp[i]+1);
    }
    cout << *max_element(dp.begin(),dp.end()) << endl;
    return 0;
}

Measured memory_bytes: 12664
#include <iostream>

using namespace std;
#define ll long long
int main(){
    int ans=0;
    char a;
    for(int i=0;i<4;i++){
        cin>>a;
        if (a=='-'){
            ans--;
        }else{
            ans++;
        }
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
const int INF = 100000000, mod = 1000000007;
using namespace std;

long long n, a, b, h[100000];

bool check(long long pos) {
    long long count = 0;
    for (int i = 0; i < n; i++) {
        long long tmp = h[i] - b*pos, damage = a - b;
        if (tmp%damage == 0&& tmp>0) count += tmp / damage;
        else if(tmp%damage!=0&&tmp>0) count += tmp / damage + 1;
    }
    return count <= pos;
}

int main() {
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) cin >> h[i];
    long long left = 0, right = 1000000000;
    while (right - left>1) {//h[left]~h[right]
        long long pos = (left + right) / 2;
        if (check(pos)) right = pos;
        else left = pos;
    }
    cout << right << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};

// Self settings
// clang-format off
#define MAX_N 10
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int N;
int L[MAX_N];

int main(void)
{
  cin >> N;
  REP(i, N) cin >> L[i];
  int sum = 0;
  REP(i, N) sum += L[i];
  int m = 0;
  REP(i, N) m = max(m, L[i]);
  cout << ((sum - m) > m ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
    {
        static void Main(string[] args)
        {   
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int i=0; i<n; i++) a[i] = int.Parse(s[i]);
            int[] aPlus = new int[n];
            int minusCount = 0;
            int aPlusMin = 1000000000; 
            long aPlusSum = 0;
            for (int i=0; i<n; i++)
            {
                if (a[i] < 0)
                {
                    minusCount++;
                    aPlus[i] = -a[i];
                }
                else aPlus[i] = a[i];
                aPlusMin = Math.Min(aPlusMin, aPlus[i]);
                aPlusSum += (long)aPlus[i];
            }
            if (minusCount % 2 == 0) Console.WriteLine(aPlusSum);
            else Console.WriteLine(aPlusSum - aPlusMin * 2);
        }
    }
    //mcs Main.cs
    //mono Main.exe

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

int main(){
  int N;
  cin >> N;
  for(int i=1; i<=9; i++){
    for(int j=1; j<=9; j++){
      if(i*j==N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

bool dpx[8001][16001];
bool dpy[8001][16001];

int main() {
  string s;
  cin >> s;
  int x, y;
  cin >> x >> y;
  vector<int> vc;
  int cnt = 0;
  REP(i, s.size()) {
    if (s[i] == 'F') {
      cnt++;
    } else {
      vc.push_back(cnt);
      cnt = 0;
    }
  }
  vc.push_back(cnt);
  vector<int> dx, dy;
  REP(i, vc.size()) {
    if (i % 2 == 0) {
      dx.push_back(vc[i]);
    } else {
      dy.push_back(vc[i]);
    }
  }
  dpx[0][8000] = true;
  dpx[1][8000 + dx[0]] = true;
  REP(i, dx.size()) {
    if (i == 0) continue;
    for (int j = 0; j <= 16000; ++j) {
      if (dpx[i][j]) {
        dpx[i + 1][j + dx[i]] = true;
        dpx[i + 1][j - dx[i]] = true;
      }
    }
  }
  dpy[0][8000] = true;
  REP(i, dy.size()) {
    for (int j = 0; j <= 16000; ++j) {
      if (dpy[i][j]) {
        dpy[i + 1][j + dy[i]] = true;
        dpy[i + 1][j - dy[i]] = true;
      }
    }
  }
  if (dpx[dx.size()][8000 + x] && dpy[dy.size()][8000 + y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 125824
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int sum = 0;
		while(sum < N) {
			sum += 1000;
		}
		System.out.println(sum - N);
	}
}

Measured memory_bytes: 35732
// finish date: 2018/02/18

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>

//掛け算
int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int main() {
    int N;
    string s1, s2;
    cin >> N >> s1 >> s2;
    for (int i = N - 1; i >= 0; i--) {
        if (s1[i] != s2[i]) {
            s1.erase(i, 1);
            s2.erase(i, 1);
            N--;
            i--;
        }
    }
    int mode;
    int ans;
    if(s1[0]==s2[0]){
        ans = 3;
        mode = 0;
    }else{
        ans = 6;
        mode = 1;
    }
    FOR(i,1, N) {
        if (s1[i] == s2[i]) {
            ans = (mode == 0) ? mul(ans, 2) : mul(ans, 1);
            mode = 0;
        }else{
            ans = (mode==0)? mul(ans,2):mul(ans,3);
            mode = 1;
        }
    }
    cout<<ans<<endl;

    return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9;

int main(){
  int N,a[100000];
  cin>>N; 
  for (int i(0);i<N;i++) cin>>a[i];
  for (int i(0);i<N;i++) {
    if (a[i]%2==1) {
      cout << "first" << endl;
      return 0;
    }
  }
  cout << "second" << endl;
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO() \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    int n, k;
    cin >> n >> k;
    vi h(n);
    for (auto &i : h)   cin >> i;
    ll dp[n];
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        dp[i] = MOD;
        for (int j = 1; j <= k && i - j >= 0; ++j) {
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1792
fn main() {
    proconio::input! {
        n: usize,
        xs: [u64;n],
    }
 
    if xs.contains(&0) {
        println!("{}", 0);
        return;
    }
 
    let mut ans = 1u64;
    for i in 0..xs.len() {
        ans = ans.saturating_mul(xs[i]);
        if ans > 10u64.pow(18) {
            println!("{}", -1);
            return;
        }
    }
 
    if ans > 10u64.pow(18) { 
        println!("{}", -1);
    } else {
        println!("{}", ans);
    };
}

Measured memory_bytes: 4516
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
signed main()
{
	int n, a[10] = {1, 1, 0, 2, 0, 0, 1, 0, 1, 0};
	string ans[] = {"hon", "pon", "bon"};
	cin >> n;
	cout << ans[a[n % 10]] << "\n";
}


Measured memory_bytes: 3628
object Main {
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.map(_.split(",").map(_.toInt).splitAt(10))
        for ((l, v) <- in) println(l.scanLeft(0)(_ + _).indexWhere(v(0).toDouble * l.sum / v.sum <= _))
    }
}

Measured memory_bytes: 44132
def num_to_char(s_num):
    ch = []
    for num in s_num:
        ch.append(alphabet[(num%26)-1])
    return ch

s = raw_input()
K = input()

alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','\
q','r','s','t','u','v','w','x','y','z']
ans = []

s_num = []
for char in s:
    s_num.append(alphabet.index(char) + 1)

for i in xrange(len(s_num)):
    if 27 - s_num[i] <= K and (s_num[i] != 1) and (i != len(s_num) - 1):
        K = K - (27 - s_num[i])
        s_num[i] = 27
    elif 27 - s_num[i] <= K and (s_num[i] == 1) and (i != len(s_num) - 1):
        pass
    elif 27 - s_num[i] > K and (s_num[i] != 1) and (i != len(s_num)-1):
        pass
    elif 27 - s_num[i] > K and (s_num[i] == 1) and (i != len(s_num) - 1):
        pass

    elif (i == len(s_num) - 1):
        s_num[i] = s_num[i] + K

print "".join(num_to_char(s_num))

Measured memory_bytes: 4484
N = int(input())
h = [int(i) for i in input().split()]
i = 1
dp = [0 for i in range(N)]
K = 2
 
while not i==N:
    l = min(K,i)
    data = [dp[i-j]+abs(h[i] - h[i-j]) for j in range(1,l+1)]
    dp[i] = min(data)
    i+=1
    
print(dp[N-1])

Measured memory_bytes: 13976
import java.math.*;
import java.util.*;
import java.util.function.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    sc.close();

    BigInteger lcm = Arrays.stream(A)
        .mapToObj(BigInteger::valueOf)
        .reduce(BigInteger.ONE, (a, b) -> a.divide(a.gcd(b)).multiply(b));

//    Map<Integer, Integer> lcm = new HashMap<>();
//    for (int ai : A)
//      for (Map.Entry<Integer, Integer> fAi : f(ai).entrySet())
//        lcm.put(fAi.getKey(), Math.max(lcm.getOrDefault(fAi.getKey(), 0), fAi.getValue()));

    long mod = 1000000007;

//    long modLcm = 1;
//    for (Map.Entry<Integer, Integer> lcm_p : lcm.entrySet())
//      modLcm = (modLcm * modPow(lcm_p.getKey(), lcm_p.getValue(), mod)) % mod;

    long modLcm = lcm.remainder(BigInteger.valueOf(mod)).longValue();

    long ans = 0;
    for (int ai : A)
      ans = (ans + modDiv(modLcm, ai, mod)) % mod;

    System.out.println(ans);
  }

  private static long modDiv(long a, long b, long mod) {
    return (a % mod) * modInv(b, mod) % mod;
  }

  private static long modInv(long x, long mod) {
    return modPow(x, mod - 2, mod);
  }

  private static long modPow(long b, long e, long mod) {
    long ans = 1;
    long x = b % mod;
    for (long y = e; y != 0; y >>= 1) {
      if ((y & 1) == 1) ans = (ans * x) % mod;
      x = (x * x) % mod;
    }
    return ans;
  }
}

Measured memory_bytes: 156488
#include<bits/stdc++.h>
using namespace std;
#define l long long
int main()
{
    l a,b,c,k,ans;
    cin>>a>>b>>c>>k;
    ans=min(a,k);
    k-=(a+b);
    if(k>0)ans-=k;
    
    cout<<ans<<endl;

    return 0;


}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

ll f[1100000],invf[1100000];

ll inv (ll x){
 ll res=1;
  ll k=inf-2;
  ll y=x;
  while(k){
   if(k&1)res=res*y %inf;
    y=y*y%inf;
    k>>=1;
  }
  return res;
}

void init(){
  f[0]=1;
  rep(i,1,1100000)f[i]=f[i-1]*i%inf;
  rep(i,0,1100000)invf[i]=inv(f[i]);
}

ll comb (ll n,ll k){
  if(k<0||k>n)return 0;
  ll a=f[n],b=invf[k],c=invf[n-k];
  return a*b%inf*c%inf;
}








int main(){cout<<fixed<<setprecision(20);
		   ll n,k;
           cin>>n>>k;
           //から部屋で場合わけO(n)
           init();
           ll ans=0;
           if(k>=n-1){
             ans=comb(2*n-1,n);
           }
           else{
             rep(i,0,k+1){//空き部屋がi個
               //nci * n-iHi
               ans+=comb(n,i)*comb(n-1,i);
               ans%=inf;
             }
           }
           cout<<ans%inf<<endl;
}

Measured memory_bytes: 20812
// C - Five Transportations
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll N,A,B,C,D,E; cin>>N>>A>>B>>C>>D>>E;
	ll m = min({A,B,C,D,E});
	cout<< (N+m-1)/m + 4 <<endl;
}

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

int main() {
	int K;
	string S;
	cin >> K >> S;
	if (S.size() <= K) {
		cout << S << endl;
	} else {
		for (int i = 0; i < K; i++) {
			cout << S[i];
		}
		cout << "..." << endl;
	}
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll x;
  cin >>x;
  if(x>=1&&x<=6) cout <<1<<endl;
  else if(x<=11) cout<<2<<endl;
  else{
    ll k=x%11;
    if(k==0) cout <<(x/11)*2<<endl;
    else if(k<=6) cout <<(x/11)*2+1<<endl;
    else cout<<(x/11)*2+2<<endl;
  }
}


Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))

# ===CODE===

eps = 10 ** (-9)


def main():
    h, w = ns()
    mat = [na() for _ in range(h)]

    dp = [[0 for _ in range(w)] for __ in range(h)]

    ans = 0
    for i in range(h):
        for j in range(w):
            if mat[i][j]:
                continue
            if mat[i][j] == 0:
                dp[i][j] = 1
            if i > 0 and j > 0:
                dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
            ans = max(ans, dp[i][j])

    print(ans ** 2)


if __name__ == '__main__':
    main()



Measured memory_bytes: 57620
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    int n;
    cin >> n;
    vector<string> a(n);
    rep(i,n) cin >> a.at(i);
    int ac=0;
    int wa=0;
    int tle=0;
    int re=0;
    rep(i,n){
        if(a.at(i)=="AC") ac++;
        if(a.at(i)=="WA") wa++;
        if(a.at(i)=="TLE") tle++;
        if(a.at(i)=="RE") re++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;

}


Measured memory_bytes: 6424
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>

using namespace std;

string s;

int main(){
	cin >> s;
	if(s.length() & 1) { cout << "No"; return 0; }
	for(int i = 0; i < s.length(); i += 2) if(s[i] == 'h' && s[i + 1] == 'i') continue; else {printf("No"); return 0;}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
//Pantyhose(black) + glasses = infinity

#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

int main() {
	#ifdef GLASSES_GIRL
		freopen(FILE_NAME".in", "r", stdin);
		freopen(FILE_NAME".out", "w", stdout);
	#endif
	ios::sync_with_stdio(0); cin.tie(0);

	int a, b, c;
	cin >> a >> b >> c;

	if (a+b>c && b+c>a && c+a>b && a==b && b==c)
		cout << "Yes";
	else
		cout << "No";
}

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

using namespace std;

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

    int d, x;
    cin >> d >> x;

    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];

    int count = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0;; ++j) {
            int day = j * a[i] + 1;
            if (day > d)
                break;
            ++count;
        }
    }
    cout << count + x << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static Scanner sc;
    public static void main(String[] args) {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] d = new int[N];
        for(int i = 0; i < N; i++) {
            d[i] = sc.nextInt();
        }

        int totalSum = 0;
        for(int i = 0; i < N - 1; i++) {
            for(int j = i + 1; j < N; j++) {
                int hp = d[i] * d[j];
                totalSum += hp;
            }
        }
        
        System.out.println(totalSum);

    }


}


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

const int MAX_N = int(3e5) + 10;

int n;
char s[MAX_N];

const int mod = 998244353;

int main() {
	scanf("%d%s", &n, s + 1);
	int ans = 1;
	for (int i = 1; i <= n; ++i) {
		ans = 1LL * ans * i % mod;
	}

	int r = 0, g = 0, b = 0, rg = 0, rb = 0, gb = 0;
	for (int i = 1; i <= 3 * n; ++i) {
		if (s[i] == 'R') {
			if (gb) {
				ans = 1LL * ans * gb % mod;
				--gb;
			} else if (g) {
				ans = 1LL * ans * g % mod;
				--g, ++rg;
			} else if (b) {
				ans = 1LL * ans * b % mod;
				--b, ++rb;
			} else ++r;
		}
		if (s[i] == 'G') {
			if (rb) {
				ans = 1LL * ans * rb % mod;
				--rb;
			} else if (b) {
				ans = 1LL * ans * b % mod;
				--b, ++gb;
			} else if (r) {
				ans = 1LL * ans * r % mod;
				--r, ++rg;
			} else ++g;
		}
		if (s[i] == 'B') {
			if (rg) {
				ans = 1LL * ans * rg % mod;
				--rg;
			} else if (g) {
				ans = 1LL * ans * g % mod;
				--g, ++gb;
			} else if (r) {
				ans = 1LL * ans * r % mod;
				--r, ++rb;
			} else ++b;
		}
	}

	printf("%d\n", ans);
}

Measured memory_bytes: 4044
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

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

    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    bool flag = true;

    rep(i, n){
        if((a[i]%2) == 0){
            if(!(a[i]%3 == 0 or a[i]%5 == 0))
            {
                flag = false;
                break;
            }
        }
    }

    if(flag) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char b;cin>>b;
    if(b=='A') cout<<"T";
    else if(b=='T') cout<<"A";
    else if(b=='C') cout<<"G";
    else cout<<"C";
    cout<<endl;
}

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

int n;
int x;
std::vector<int> vec;
std::vector<int> vec2;

int main() {
    std::cin >> n;
    vec.assign(n, 0);
    vec2.assign(n, 0);
    for (int i = 0; i < n; i++) {
        std::cin >> x;
        vec[i] = x;
        vec2[i] = x;
    }
    std::sort(vec2.begin(), vec2.end());
    for (int j = 0; j < n; j++) {
        if (vec[j] == vec2[n-1]) {
            std::cout << vec2[n-2];
        }
        else {
            std::cout << vec2[n-1];
        }
        std::cout << std::endl;
    }
}


Measured memory_bytes: 3200
#include <iostream>
#include<string>
#include <bits/stdc++.h>
#include <algorithm>
#include<vector>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define pri 1000000007
#define ss second
using namespace std;
ll f(ll a)
{ 
     if(a%4==0)
         return a;
     if(a%4==1)
          return 1;
     if(a%4==2)
          return a+1;
   if(a%4==3)
            return 0;
 }

int main() {
                 ll n,m;
                cin>>n>>m;
                 ll x=f(n-1);
                 ll y=f(m);
                cout<<(x^y);
}

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

long long pow2(long long x, long long n, int mod=0) {
  if (n == 0) return 1;
  if (mod) {
    if (n & 1) return x * pow2(x, n - 1, mod) % mod;
    long long y = pow2(x, n / 2, mod);
    return y * y % mod;
  } else {
    if (n & 1) return x * pow2(x, n - 1);
    long long y = pow2(x, n / 2);
    return y * y;
  }
}

int MOD = 1e9 + 7;
int U = 1e7;
vector<unsigned long long> fac(U + 1);
vector<unsigned long long> ifac(U + 1);
vector<unsigned long long> n_choose(U + 1);
void make_tables(int n=1e9, int p=MOD) {
  fac[0] = 1;
  for (int i = 0; i < U; i++) fac[i+1] = fac[i] * (i + 1) % p;
  ifac[U] = pow2(fac[U], p - 2, p);
  for (int i = U; i > 0; i--) ifac[i-1] = fac[i] * i % p;
  n_choose[0] = 1;
  for (int i = 0; i < U; i++) n_choose[i+1] = n_choose[i] * (n - i) % p;
  for (int i = 0; i < U + 1; i++) n_choose[i] = n_choose[i] * ifac[i] % p;
}

int mod_choose(int n, int r, int p=MOD) {
  if (r > n || r < 0) return 0;
  return fac[n] * ifac[r] % p * ifac[n-r] % p;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  make_tables();
  int n, m;
  cin >> n >> m;
  int ans;
  int d = abs(n - m);
  if (d >= 2) ans = 0;
  else if (d == 1) ans = fac[n] * fac[m] % MOD;
  else ans = fac[n] * fac[m] * 2 % MOD;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 234624
#include <bits/stdc++.h>
using namespace std;
long long A(long long a){
  return a*a*a*a*a;
}

int main() {
	long long x;
  cin>>x;
  for(long long i=-120;i<=120;i++){
    for(long long j=-120;j<=120;j++){
      if(A(i)-A(j)==x) {cout<<i<<" "<<j<<endl; return 0;}
    }
  }
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h> 
#include<string.h>
#define NIL NULL
 
struct node{
  int key;
  struct node *left;
  struct node *right;
  struct node *p;
};
 
typedef struct node * Node;
 
Node root;

/*宣言*/
void Inorder_tree_walk(Node);
void Preorder_tree_walk(Node);
void insert(int);
void find(Node,int);

/*main関数*/
int main(){
  int i,x,num;
  char s[10];
  int check;

  scanf("%d",&num);
  for (i=0; i<num; i++){
    scanf("%s",s);

    if (strcmp("insert",s)==0){
      scanf("%d",&x);
      insert(x);
    }


    if  (strcmp("print",s)== 0){
      Inorder_tree_walk(root);
      puts("");

      Preorder_tree_walk(root);
      puts("");
    }



    if(strcmp("find",s)==0){
      scanf("%d",&x);
      find(root,x);

      }
  }
  return 0;
}




/*先行順巡回*/
void Preorder_tree_walk(Node tree){
  printf(" %d",tree->key);
  if(tree != NIL){
    if((tree->left) != NIL)Preorder_tree_walk(tree->left);
    if((tree->right) != NIL)Preorder_tree_walk(tree->right);
  }
}
 

/*中間順巡回*/
void Inorder_tree_walk(Node tree){
   
  if(tree != NIL){

    if((tree->left) != NIL){Inorder_tree_walk(tree -> left);}

    printf(" %d",tree->key);
     
    if(tree->right!=NIL){Inorder_tree_walk(tree->right);}
  }
}


/*挿入*/
void insert(int k){
 Node y=NIL;
 Node x=root;
 Node z;

 /*新しいkeyの初期化*/
    z = malloc(sizeof(struct node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;


     while(x!=NIL){
       y=x;       
       if(z->key < x->key) x=x->left;
       else x=x->right;
     }
     z->p=y;

     if(y == NIL) root=z;
     else if((z->key) < (y->key)) y->left=z;
     else y->right=z;
}

 void find(Node tree, int k){

   while (tree != NIL && k != tree->key){

     if(k < tree->key) tree = tree->left;
     else tree=tree->right;
   }
   if( tree==NIL)puts("no");
   if( tree!=NIL)puts("yes");
 }

Measured memory_bytes: 19360
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N; cin >> N;
  long res = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      res += j;
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3592
n=int(input())
a=list(map(int,input().split()))
c=0
k=0
for i in range(0,n):
  if a[i]<0:
    c=c+1
  k=k+abs(a[i])
  a[i]=abs(a[i])
a.sort()
if c%2==1:
  k=k-2*a[0]
  print(k)
else:
  print(k)


Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main() {
    int N; cin >> N;
    vector<int> v(9);
    for(int i=0;i<N;i++){
        int n; cin >> n;
        if(1<=n && n<=399) v[0]=1;
        else if(400<=n && n<=799) v[1]=1;
        else if(800<=n && n<=1199) v[2]=1;
        else if(1200<=n && n<=1599) v[3]=1;
        else if(1600<=n && n<=1999) v[4]=1;
        else if(2000<=n && n<=2399) v[5]=1;
        else if(2400<=n && n<=2799) v[6]=1;
        else if(2800<=n && n<=3199) v[7]=1;
        else v[8]++;
    }
    int m,M;
    M = accumulate(v.begin(), v.end(),0);
    m = M-v[8];
    if(m == 0) m = 1;
    cout << m <<' '<< M << endl;
}


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

int main()
{
    int Q;
    cin >> Q;
    for ( int i = 0; i < Q; i++ ) {
        int c, a, n;
        cin >> c >> a >> n;
        //CAN
        int cnt = min ( { c, a, n } );
        c -= cnt, a -= cnt, n -= cnt;
        //CCA
        int val = min ( c / 2, a );
        cnt += val;
        c -= val * 2, a -= val;
        //CCC
        cnt += c / 3;
        cout << cnt << endl;
    }
    return ( 0 );
}



Measured memory_bytes: 3080
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();

        char[] cha = str.toCharArray();
        String nickname = String.valueOf(cha[0]) + String.valueOf(cha[1]) + String.valueOf(cha[2]);

        System.out.println(nickname);
        sc.close();
    }
}

Measured memory_bytes: 39084
using System;
using System.Linq;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
// 		string str = "101";
		var s = Console.ReadLine().ToCharArray();
		var a = s.ToArray();
		
		Console.WriteLine(a.Count(x => x == '1'));
// 		WriteLine(s.Count(x => x == '1'));
		
		
// 		int result = 0;
// 			if (s1[0] > 0)
// 			{
// 				result += 1;
// 			}
// 			if (s1[1] > 0)
// 			{
// 				result += 1;
// 			}
// 			if (s1[2] > 0)
// 			{
// 				result += 1;
// 			}
// 		Console.WriteLine(result);
	}
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

using namespace std;
typedef pair<int, int> P;

int main() {
	int n, m, p, x[110], ans,all;
	while (1) {
		all = 0;
		cin >> n >> m >> p;
		if (n == 0 && m == 0 && p == 0) {
			break;
		}
		F(i, n) {
			cin >> x[i];
			all += x[i];
		}
		if (x[m - 1] == 0) {
			cout << 0 << endl;
			continue;
		}
		else {
			ans = all*(100-p) / x[m - 1];
			cout << ans << endl;
		}
	}
	return 0;
}

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

int main(){
	//~ double Min=LLONG_MAX;
	//~ vector<int>v;
	//~ for(int i=111111111;i>=1;i--){
		//~ int a=i,c=0;
		//~ while(a)c+=a%10,a/=10;
		//~ double d=i/(double)c;
		//~ if(i<=100000000){
			//~ if(d<=Min)v.push_back(i);
		//~ }
		//~ Min=min(Min,d);
	//~ }
	//~ reverse(v.begin(),v.end());
	//~ for(int i:v){
		//~ cout<<i<<endl;
	//~ }
	vector<ll>v;
	for(int i=1;i<=999;i++)v.push_back(i);
	for(int i=4;i<=16;i++){//桁数
		for(int j=1000;j<=9999;j++){
			ll d=j+1;rep(k,i-4)d*=10;d--;
			v.push_back(d);
		}
	}
	vector<ll>ans;
	double Min=LLONG_MAX;
	for(int i=v.size()-1;i>=0;i--){
		ll a=v[i],c=0;
		while(a)c+=a%10,a/=10;
		double d=v[i]/(double)c;
		if(d<=Min){
			ans.push_back(v[i]);
		}
		Min=min(Min,d);
	}
	reverse(ans.begin(),ans.end());
	int k;scanf("%d",&k);
	rep(i,k){
		cout<<ans[i]<<endl;
	}
}

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

ll gcd(ll m, ll n){
    ll tmp;
    while(m%n != 0){
        tmp = n;
        n = m % n;
        m = tmp;
    }
    return n;
}

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

    ll a, b;
    cin >> a >> b;
    ll lcm = a*b/gcd(a, b);

    cout << lcm << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
if __name__ == '__main__':
    def solve(s, a):
        if len(s) == n:
            print(s)
        else:
            for c in range(ord("a"), a + 1):
                if c == a:
                    solve(s + chr(c), a + 1)
                else:
                    solve(s + chr(c), a)
    n = int(input())
    solve("", ord("a"))



Measured memory_bytes: 4404
use std::io;


fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}
fn read_nums() -> Vec<i64>
{
    let line = read_line();
    let items: Vec<&str> = line.split(' ').collect();

    let mut nums: Vec<i64> = Vec::new();

    for item in items {
        nums.push(to_i(item));
    }
    return nums;
}


fn main() {
    //println!("start");
    let ap = read_nums();
    let a = ap[0];
    let p = ap[1];

    let b = a*3+p;
    let ret = b/2;
    
    print!("{}", ret);
}   

Measured memory_bytes: 4352