akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define inf 4001

int main(void)
{
  int N;
  int Ma, Mb;
  int a[41], b[41], c[41];
  static int dp[41][401][401];
  int i, ca, cb;
  int amax = 0;
  int bmax = 0;
  int ans;
  int tmp1;
  int tmp2;

  scanf("%d %d %d", &N, &Ma, &Mb);
  for(i = 0; i < N; i++) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    amax += a[i];
    bmax += b[i];
  }
  
  for(i = 0; i < N; i++) {
    for(ca = 0; ca <= amax; ca++) {
      for(cb = 0; cb <= bmax; cb++) {
	dp[i][ca][cb] = inf;
      }
    }
  }  
  dp[0][a[0]][b[0]] = c[0];
  dp[0][0][0] = 0;
  
  for(i = 1; i < N; i++) {
    for(ca = 0; ca <= amax; ca++) {
      for(cb = 0; cb <= bmax; cb++) {
	// iを入れる
	if(ca >= a[i] && cb >= b[i]) {
	  tmp1 = dp[i-1][ca-a[i]][cb-b[i]] + c[i];
	} else {
	  tmp1 = inf;
	}
	// iをいれない
	tmp2 = dp[i-1][ca][cb];
	if(tmp1 < tmp2) {
	  dp[i][ca][cb] = tmp1;
	} else {
	  dp[i][ca][cb] = tmp2;
	}
      }
    }
  }
  
  ans = inf;
  for(ca = 0; ca <= amax; ca++) {
    for(cb = 0; cb <= bmax; cb++) {
      if(ca*Mb == cb*Ma && dp[N-1][ca][cb] != 0) {
	if(ans > dp[N-1][ca][cb]) {
	  ans = dp[N-1][ca][cb];
	}
      }
    }
  }
  if(ans == inf) {
    printf("%d\n", -1);
  } else {
    printf("%d\n", ans);
  }
  return 0;
}


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

ll gcd(ll a, ll b) {
  if (a%b==0) return b;
  return gcd(b, a%b);
}

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

int main() {
  ll a,b; cin>>a>>b;
  cout<<lcm(a, b)<<endl;
}

Measured memory_bytes: 256
def binary_search(list, item):
    low = 0
    high = len(list) - 1

    while low <= high:
        mid = (low + high) //2
        guess = list[mid]
        if guess == item:
            return mid
        if guess > item:
            high = mid -1
        else:
            low = mid + 1

    return None

n=int(input())
s=[int(i) for i in input().split()]
q=int(input())
t=[int(i) for i in input().split()]
ans=0
for item in t:
    if(binary_search(s,item) != None):
        ans+=1
print(ans)


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

public class Main {
	
	static int[] nVal, freq;
	static int diff;
	
	static boolean can(int to) {
		int pot = 1;
		while (pot <= nVal[to]) pot *= 2;
		int target = pot - nVal[to];
		int left = 0, right = to + 1;
		while (left + 1 < right) {
			int med = (left + right) / 2;
			if (nVal[med] > target) right = med;
			else left = med;
		}
		if (nVal[left] == target && (left < to && freq[left] > 0 || left == to && freq[left] > 1)) {
			freq[to]--;
			freq[left]--;
			return true;
		}
		return false;
	}
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int[] values = new int[N];
		for (int i = 0; i < values.length; i++) {
			values[i] = sc.nextInt();
		}
		Arrays.sort(values);
		diff = 1;
		for (int i = 1; i < N; i++) {
			if (values[i] != values[i-1]) diff++;
		}
		nVal = new int[diff];
		freq = new int[diff];
		int idx = 0;
		nVal[0] = values[0];
		freq[0] = 1;
		for (int i = 1; i < N; i++) {
			if (values[i] != values[i-1]) {
				nVal[++idx] = values[i];
			}
			freq[idx]++;
		}
		int ans = 0;
		for (int i = diff - 1; i >= 0; i--) {
			while (freq[i] > 0 && can(i)) {
				ans++;
			}
		}
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 48732
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()

ANS = [2,11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361]
print(*ANS[:N])


Measured memory_bytes: 61312
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;


ll pow5[4001];
ll calc(ll a, ll b) {
  if (a<0) {
    if (b<0){
      return -pow5[-a]+pow5[-b];
    } else{
      return -pow5[-a]-pow5[b];
    }
  } else {
    if (b<0){
      return pow5[a]+pow5[-b];
    } else{
      return pow5[a]-pow5[b];
    }
  }
}

int main() {
  ll X;
  cin >> X;
  for (ll i = 0; i <= 4000; i++) {
    pow5[i] = i*i*i*i*i;
  }
  for (ll i=-4000; i<=4000; i++) {
    for (ll j=-4000; j<=4000; j++) {
      if(calc(i,j) == X) {
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }
}



Measured memory_bytes: 3660
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main(){
    int A, B, C;
    cin >> A >> B >> C;
    for(int i = 0; i < B; i++){
        if(A * i % B == C){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll m){
    ll res = 1, r = x;
    while(n){
        if(n % 2) res = res * r % m;
        r = r * r % m;
        n /= 2;
    }
    return res;
}

ll primroot(ll m, bool inv = false){
    if(!inv){
        if (m == 2) return 1;
        if (m == 167772161) return 3;
        if (m == 469762049) return 3;
        if (m == 754974721) return 11;
        if (m == 998244353) return 3;
    }
    else{
        if (m == 2) return 1;
        if (m == 167772161) return 55924054;
        if (m == 469762049) return 156587350;
        if (m == 754974721) return 617706590;
        if (m == 998244353) return 332748118;
    }
    return -1;
}

vector<ll> NTT(const vector<ll> &f, int n, const ll &m, bool inv){
    if(n == 1){
        return f;
    }
    ll z = modpow(primroot(m, inv), m / n, m);
    ll p = 1;
    for(int i = 0; i < n; i++){
        p = p * z % m;
    }
    vector<ll> f0(n / 2), f1(n / 2);
    for(int i = 0; i < n / 2; i++){
        f0[i] = f[i * 2];
        f1[i] = f[i * 2 + 1];
    }
    vector<ll> Ff0 = NTT(f0, n / 2, m, inv), Ff1 = NTT(f1, n / 2, m, inv);
    vector<ll> Ff(n);
    ll zz = 1;
    for(int i = 0; i < n; i++){
        Ff[i] = (Ff0[i % (n / 2)] + zz * Ff1[i % (n / 2)]) % m;
        zz = zz * z % m;
    }
    return Ff;
}

vector<ll> Convolution(vector<ll> a, vector<ll> b, const ll m){
    int n = 1;
    while(n < (int)a.size() + (int)b.size() - 1) n <<= 1;
    a.resize(n);
    b.resize(n);
    vector<ll> Fa = NTT(a, n, m, false), Fb = NTT(b, n, m, false);
    vector<ll> Fc(n);
    for(int i = 0; i < n; i++) Fc[i] = Fa[i] * Fb[i] % m;
    vector<ll> c = NTT(Fc, n, m, true);
    for(int i = 0; i < n; i++) c[i] = c[i] * modpow(n, m - 2, m) % m;
    return c;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    vector<ll> c = Convolution(a, b, 998244353);
    for(int i = 0; i < n + m - 1; i++) cout << c[i] << " ";
    cout << endl;
}


Measured memory_bytes: 85184
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    s = input()
    for l in range(len(s)):
        for r in range(l,len(s)):
            a = s[:l]+s[r:]
            if a == "keyence":
                print("YES")
                return
    print("NO")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39280
#include <iostream>
#include <cmath>
#include <stack>

using namespace std;
const static int MAX = 1000000;
int cnt;
stack<int> G;

void insertionSort(int A[], int n, int g){
    for (int i = g; i < n; ++i) {
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void shellSort(int A[], int n){
    cnt = 0;
    int h = 1;
    while (h <= n){
        G.push(h);
        h = 3*h + 1;
    }
    int m = (int)G.size();
    cout << m << endl;

    for (int i = 0; i < m; i++) {
        cout << G.top() << " ";
        insertionSort(A, n, G.top());
        G.pop();
    }
    cout << endl;

    cout << cnt << endl;
    for (int i = 0; i < n; i++) cout << A[i] << endl;

}

int main() {
    int A[MAX], n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];

    shellSort(A, n);
    return 0;
}


Measured memory_bytes: 6988
n, k = [ int(v) for v in input().split() ]
s = input()

a_list = []
b_list = []

if s[0] == "0":
    a_list.append(0)
p = 0
for i in s:
    if i == "1" and p < 0:
        b_list.append(-p)
        p = 1
    elif  i == "1" and p >= 0:
        p += 1
    elif  i == "0" and p > 0:
        a_list.append(p)
        p = -1
    elif  i == "0" and p <= 0:
        p -= 1
if p < 0:
    b_list.append(-p)
    a_list.append(0)
else:
    a_list.append(p)


if len(b_list) <= k:
    ans = n
else:
    m = len(b_list) - k
    sequence = sum(a_list[:k+1]) + sum(b_list[:k])
    ans = sequence
    for i in range(m):
        sequence += a_list[i+k+1] - a_list[i]
        sequence += b_list[i+k] - b_list[i]
        ans = max(sequence, ans)
print(ans)

Measured memory_bytes: 45040
#include <bits/stdc++.h>
    #define REP(i, n) for(int i = 0;i < n;i++)
    #define REPR(i, n) for(int i = n;i >= 0;i--)
    #define FOR(i, m, n) for(int i = m;i < n;i++)
    #define FORR(i, m, n) for(int i = m;i >= n;i--)
    #define SORT(v, n) sort(v, v+n);
    #define VSORT(v) sort(v.begin(), v.end());
    #define llong long long
    #define pb(a) push_back(a)
    #define INF 999999999
    using namespace std;
    typedef pair<int, int> P;
    typedef pair<llong, llong> LP;
    typedef pair<int, P> PP;
    typedef pair<llong, LP> LPP;

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

    int main()
    {
       int n;
       cin>>n;
       vector<int> L(n,0);
       REP(i,n) cin>>L[i];
       sort(L.begin(),L.end(),greater<int>());
       int sum=0;
       for(int i=1; i<n; i++)
       {
           sum+=L[i];
       }
       if(L[0]<sum) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
    }

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std; 
int main()
{
	int n,m,i,j,k,l;
	while(~scanf("%d%d",&n,&l))
	{
		m=(n)*l+(n*(n-1))/2;
		int mi=0x3f3f3f3f;
		for(i=0;i<n;i++)
		{
			if(abs(mi)>abs(l+i)) mi=(l+i);
		}
		printf("%d\n",m-mi);
	}
	return 0;
}

Measured memory_bytes: 128
# Problem D - Xor Sum 4

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
ans = 0
MOD = 10**9 + 7

# count
two_factor = 1
for i in range(60):
    tmp_count = 0
    one_count = 0
    zero_count = 0
    for j in range(N):
        if (a_nums[j]>>i)&1==1:
            one_count += 1
        else:
            zero_count += 1
    tmp_count = (one_count * zero_count)%MOD
    ans += (tmp_count * two_factor)%MOD
    two_factor = (two_factor * 2)%MOD

# output
print(ans%MOD)


Measured memory_bytes: 122808
import sys,math,copy

def main():
    # import numpy as np
    input = sys.stdin.readline
    S = ''.join(reversed(input().strip()))

    # dp = np.zeros((13), dtype=int)
    # dp_ = np.zeros((13), dtype=int)
    dp = [0] * 13
    dp_ = [0] * 13
    mod13_list = [i % 13 for i in range(12 ** 2 + 1)]
    list10 = list(range(10))
    list13 = list(range(13))
    divisor = 10 ** 9 + 7
    dp_[0] = 1
    mul = 1
    for i in range(len(S)):
        s = S[i]
        if s == '?':
            for d in list10:
                m = mod13_list[(d * mul)]
                for pm in list13:
                    dp[mod13_list[(pm+m)]] += dp_[pm]

        else:
            si = int(s)
            m = mod13_list[(si * mul)]
            for pm in list13:
                dp[mod13_list[(pm+m)]] = dp_[pm]

        # dp_ = dp % divisor
        # dp = dp * 0 # np.zeros((13), dtype=int)
        for j in list13:
            dp_[j] = dp[j] % divisor
            dp[j] = 0
        mul = mod13_list[(mul * 10)]
    print(dp_[5])

if __name__ == '__main__':
    main()

Measured memory_bytes: 4468
#include<stdio.h>
#include<stdlib.h>
int sort(const int *a, const int *b){
return *a-*b;
}
int main(void){
int n;
  scanf("%d",&n);
  int a[n],b[n];
  for(int i=0;i<n;i++){
	scanf("%d",&a[i]);
    b[i]=a[i];
  }
  qsort(b,n,sizeof(int),sort);
  int c=0;
  for(int i=0;i<n;i++){
	if(a[i]!=b[i])c++;
  }
  if(c==0||c==2)printf("YES");
  else printf("NO");
  return 0;
}

Measured memory_bytes: 128
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
from decimal import Decimal

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N = int(input())
TA = [[] for i in range(N)]
for i in range(N):
    TA[i] = [int(i) for i in input().split()]

min_T,min_A = 1,1
for i in range(N):
    t,a = TA[i]
    # if min_T >= t or min_A>= a:
    multi = max(math.ceil(Decimal(min_T) / Decimal(t)),math.ceil(Decimal(min_A)/Decimal(a)),1)
    min_T,min_A = t*multi, a*multi

print(min_A+min_T)


Measured memory_bytes: 6532
/*input
63
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=805;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
ll D;
ll ex[20]={1};
vector<ll> v;
ll d[maxn];

ll cnt=0;

void dfs(int u){
	if(u==SZ(v)){
		// REP(i,SZ(v)) cout<<v[i]<<" \n"[i==SZ(v)-1];
		// REP(i,SZ(v)) cout<<d[i]<<" \n"[i==SZ(v)-1];
		ll res=1;
		REP(i,SZ(v)){
			if(i) res*=10-abs(d[i]);
			else res*=9-abs(d[i]);
		}
		cnt+=res;
		return;
	}
	for(int i=-9;i<=9;i++){
		d[u]=i;
		D-=i*v[u];
		ll sum=0;
		for(int j=u+1;j<SZ(v);j++) sum+=v[j];
		if(abs(D)<=sum*9) dfs(u+1);
		D+=i*v[u];
	}
}

int main()
{
	for(int i=1;i<20;i++) ex[i]=ex[i-1]*10;

	cin>>D;
	ll ans=0;
	for(int len=2;len<=19;len++){
		cnt=0;
		v.clear();
		for(int i=len-1,j=0;i>j;i--,j++){
			v.pb(ex[i]-ex[j]);
		}
		dfs(0);
		if(len%2) cnt*=10;
		ans+=cnt;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <climits>
#include <string>
#include <set>
#include <numeric>
#include <bitset>
#include <cmath>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <vector>
#include <cassert>
#include <ctime>

using namespace std;
 
#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define FORi(i,a,b) for(int i=int(a);i<=int(b);i++)
#define FOR(i,n) FORi(i,1,n)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
 
using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;
using pii=pair<int, int>;
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto& p: c) os << p << " ";
	return os<<']';
}
 
void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}
 
 
template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}
 
 
constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;
constexpr int maxw=31;
constexpr int maxn=3001;
int a, b, c, d, e, f;
int dp[maxw][maxn];

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

	while(cin>>a>>b>>c>>d>>e>>f) {
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;
		int maxz = -1;
		int maxs = 0;
		FOR(i, f/100) {
			rep(j, min(i*e, f - i*100) + 1) {
				if(a<=i) dp[i][j] |= dp[i-a][j];
				if(b<=i) dp[i][j] |= dp[i-b][j];
				if(c<=j) dp[i][j] |= dp[i][j-c];
				if(d<=j) dp[i][j] |= dp[i][j-d];
				if(dp[i][j] && j*100.0 / (i*100 + j) > maxs*100.0 / maxz) {
					maxz = j+i*100;
					maxs = j;
				}
			}
		}
		if(maxz == -1) cout << a*100 << " " << 0 << endl;
		else cout << maxz << " " << maxs << endl;
	}
	return 0;
}



Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)

int main(int argc, char **argv)
{
  map<string, int> words;
  string s;
  string maxword;

  maxword = "";
  for (;;) {
    cin >> s;
    if (cin.eof())
      break;

    if (s.length() > maxword.length())
      maxword = s;
    words[s]++;
  }

  int most = 0;
  string mostword = "";
  tr (words, i) {
    if (i->second > most) {
      most = i->second;
      mostword = i->first;
    }
  }
  cout << mostword << " " << maxword << endl;
  return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int expression();
int term();
int factor();

string exp;
int p;

int expression(){
    int value = term();
    while( exp[p] == '+' || exp[p] == '-' ){
	if ( exp[p] == '+' ) { p++; value += term(); }
	else { p++; value -= term(); }
    }
    return value;
}

int term(){
    int value = factor();
    while( exp[p] == '*' || exp[p] == '/' ){
	if ( exp[p] == '*' ) { p++; value *= factor(); }
	else { p++; value /= factor(); }
    }
    return value;
}

int factor(){
    int value = 0;
    if ( exp[p] == '(' ){
	p++; value = expression(); p++;
    } else {
	while( isdigit(exp[p]) ) { value = value*10 + exp[p++] - '0';}
    }
    return value;
}

string normalize(string str){
    string v = "";
    for ( int i = 0; i < str.size(); i++ ){
	if ( str[i] == ' ') continue;
	v += str[i];
    }
    return v;
}

vector<string> ans;

void parse( vector<string> expv, vector<char> op ){
    if ( expv.size() == 1 ){
	exp = normalize(expv[0]);
	p = 0;
	int v = expression();
	//	cout << expv[0] << " = " << v << endl;
	if ( v == 10 ) {
	    //cout << expv[0] << endl;
	    ans.push_back(expv[0]);
	}
	return ;
    }

    vector<string> v;
    vector<char> vo;

    for ( int i = 0; i < expv.size()-1; i++ ){
	v = expv;
	vo = op;
	string newe = "(" + v[i] + " " + vo[i] + " " + v[i+1] + ")";
	v.erase(v.begin() + i);
	v[i] = newe;
	vo.erase(vo.begin()+ i);
	parse(v, vo);
    }
}

char getOP(int i){
    if ( i == 0 ) return '+';
    else if ( i == 1 ) return '-';
    else if ( i == 2 ) return '*';
}

int main(){
    string in[4];
    
    while(1){
	ans.clear();
	for ( int i = 0; i < 4; i++ ) cin >> in[i];
	if ( in[0] == "0" && in[1] == "0" && in[2] == "0" && in[3] == "0" ) break;
	sort( in, in + 4);
	
	do{
	    vector<string> expv;
	    for ( int i = 0; i < 4; i++ ) expv.push_back(in[i]);
	    for ( int i = 0; i < 3; i++ ){
		for ( int j = 0; j < 3; j++ ){
		    for ( int k = 0; k < 3; k++ ){
			vector<char> op;
			op.push_back(getOP(i));
			op.push_back(getOP(j));
			op.push_back(getOP(k));
			parse(expv, op);
		    }
		}
	    }
	} while(next_permutation(in, in + 4));


	if ( ans.size() == 0 ) cout << "0" << endl;
	else cout << ans[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 924
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var a = ReadInt();
            var b = ReadInt();
            var h = ReadInt();
            Println((a + b) * h / 2);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


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

#define INF 1e9

using str = string;
using ss = stringstream;

int d[300010];

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

    int n;cin>>n;
    str s;cin>>s;

    for(int i=0;i<n;i++)d[i+1]=d[i]+(s[i]=='W'?1:0);

    int ans=INF;

    for(int i=1;i<=n;i++)ans=min(ans,(d[i-1]-d[0])+(n-i-(d[n]-d[i])));

    cout<<ans<<"\n";

    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    string S;
    cin >> S;
    if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]) {
        printf("Bad\n");
        return 0;
    }
    printf("Good\n");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int,greater<int>>大到小
#include <vector>// ::iterator it;
#include <stack>
#include <cmath> // auto &Name : STLName  Name.
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;
const db eps=1e-10;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=2e5+8;
inline ll read(){ll s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
using namespace std;

int t=0,n,m=0,k=0;
string s;
int ans=0;

int C(int x,int y){
    int cnt=1;
    for(int i=0;i<y;i++) cnt*=x--;
    for(int i=2;i<=y;i++) cnt/=i;
    return cnt;
}

int p(int x){
    int cnt=1;
    while(x--) cnt*=9;
    return cnt;
}

int main(){
    cin>>s;
    n=s.size()-1;
    scanf("%d",&k);
    int i,j;
    for(i=k-1,j=0;i>=0&&j<=n;i--,j++){
        while(s[j]=='0') j++;
        int cnt=s[j]-'0'-1;
        if(cnt>0){
            if(n-j>=i) ans+=cnt*p(i)*C(n-j,i);
        }
        if(n-j>=i+1) ans+=p(i+1)*C(n-j,i+1);
    }
    for(int i=0;i<=n;i++){
        if(s[i]>'0') t++;
    }
    if(t>=k) m=1;
    printf("%d\n",ans+m);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
    int x,y,a,count,count2;
    count = count2 = 0;
    scanf("%d %d\n",&x, &y);
    count = x - y;
    if ( y == 1){
        count = 0;
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

long long dp[110][22]={0};

int main(){
	int n;
	cin>>n;
	int a;
	cin>>a;
	dp[1][a]=1;
	for(int i=2;i<n;i++){
		int x;
		cin>>x;
		for(int j=0;j<21;j++){
			if(j+x<21)dp[i][j+x]+=dp[i-1][j];
			if(j-x>=0)dp[i][j-x]+=dp[i-1][j];
		}
	}
	int c;
	cin>>c;
	cout<<dp[n-1][c]<<endl;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };
int a, b, c, ans = 0;
int now;
int cards[ 10 ];

int main() {
	while ( ~scanf( "%d %d %d", &a, &b, &c ) && a && b && c ) {
		ans = 0;
		for ( int i = 1; i <= 10; i++ ) {
			if ( a == i || b == i || c == i ) {
				continue;
			}
			if ( a + b + i > 20 ) {
				break;
			}
			ans++;
		}
		if ( ans >= 4 ) {
			printf( "YES\n" );
		}
		else {
			printf( "NO\n" );
		}
	}
	return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

bool DEBUG = 0;
const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll n; cin>>n;
	cout<<-(n%1000-1000)%1000<<'\n';
	
	return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#define ll long long
#define add push_back

using namespace std; 

int main() {

    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);

    int T;  T = 1; //cin >> t;
    while(T--){
        ll n,x,t; cin >> n >> x >> t;
        if(n % x == 0){
            cout << (n / x) * t << endl;
        }else{
            cout << ((n / x) + 1) * t << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n, m, sum = 0;
  cin >> n >> m;
  int a[m];
  
  for(int i = 0; i < m; i++){
    cin >> a[i];
    sum += a[i];
  }
  
  int result = n - sum;
  
  if(result >= 0)
  {
     cout << result << "\n";
  }
  else {
      cout << "-1" << "\n";
  }
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
using namespace std;
using ll = long long;
using ld = long double;

//-------------------------------
// UnionFindのclass

class UnionFind {
private:
  ll n;
  vll P;
  void setN(ll N);
  void init();

public:
  UnionFind(ll N);
  ll root(ll x);
  void unite(ll x, ll y);
  bool same(ll x, ll y);
  ll groups();
};

// コンストラクタ
UnionFind::UnionFind(ll N) {
  setN(N);
  init();
}

// nを変更
void UnionFind::setN(ll N) { n = N; }

// Union-Find Treeを初期化する
void UnionFind::init() {
  P.clear();
  rep(i, n) { P.push_back(i); }
}

// 根の値を返す
ll UnionFind::root(ll x) {
  if (P[x] == x) { return x; }
  return (P[x] = root(P[x])); // パス圧縮しつつ返す
}

// 木を結合する（rankはとりあえず無視）
void UnionFind::unite(ll x, ll y) { P[root(x)] = root(y); }

// xとyが同じ集合にあるか判別
bool UnionFind::same(ll x, ll y) {
  if (root(x) == root(y)) {
    return true;
  } else {
    return false;
  }
}

// グループ数を返す
/*
ll UnionFind::groups() {
  unordered_set<ll> s;
  rep(i, n) { s.insert(root(i)); }
  return (ll)s.size();
}
*/

ll UnionFind::groups() {
  ll numOfGroups = 0;
  rep(i, n) {
    if (i == root(i)) { numOfGroups++; }
  }
  return numOfGroups;
}

// ----本問について----
// 問題：Fibonacci Sets
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/1016
// 所要時間：30分
// 学んだこと：
//  Union-Findを使えば簡単．
//  Union-Findクラスにグループ数を返すメソッドgroups()を追加しておいた．
// ------------------

// ----ここから本問のソースコード----
const ll N = 1001;

// グローバル変数（入力）
ll V, d, F[1010];

// 問題文に沿うフィボナッチ数列を作る
void makeFib() {
  F[0] = 1;
  F[1] = 2;
  for (ll i = 2; i < 1010; i++) {
    F[i] = (F[i - 1] + F[i - 2]) % N;
  }
}

void solve() {
  UnionFind u(V);
  rep(i, V) {
    for (ll j = i + 1; j < V; j++) {
      // 距離がd未満だったら同じグループに入れる（問題文とのインデックスのズレを+1で回避）
      if (abs(F[i + 1] - F[j + 1]) < d) { u.unite(i, j); }
    }
  }
  // Union-Find tree内のグループ数を出力
  cout << u.groups() << endl;
}

int main() {
  makeFib();
  while (cin >> V >> d) {
    solve();
  }
  return 0;
}



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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int N, K; cin >>N>>K;
    int ans = K;
    for (int i = 1; i < N; i++)
        ans *= K - 1;
    cout << ans << endl;
}


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

using namespace std;

int N, fac[2018], vol[2018], dp[2018][2018][2][3], old[2018][2][3];
const int mod = 1e9 + 7;
vector < int > v[2018];

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

/*
dp[i][j][parity][0/1/2]

parity of the number of edges chosen to be part of a path
[0/1/2] the number of edges adjacent to i (the root) already chosen
j is the number of different paths (including 1-length ones)?
multiplied by 2^the number of paths of non-zero length that are present already
*/
const int inv2 = (mod + 1) / 2;
void dfs (int nod)
{
    vol[nod] = 1, dp[nod][1][0][0] = 1;
    for (auto it : v[nod])
    {
        dfs (it);
        for (int i=0; i<=vol[nod]; i++)
            for (int j=0; j<2; j++)
                for (int k=0; k<3; k++)
                    old[i][j][k] = dp[nod][i][j][k], dp[nod][i][j][k] = 0;
        for (int i=0; i<=vol[nod]; i++)
            for (int p1=0; p1<2; p1++)
                for (int k1=0; k1<3; k1++)
                    if (old[i][p1][k1])
                        for (int j=0; j<=vol[it]; j++)
                            for (int p2=0; p2<2; p2++)
                                for (int k2=0; k2<3; k2++)
                                    if (dp[it][j][p2][k2])
                                    {
                                        int curr = mul (old[i][p1][k1], dp[it][j][p2][k2]);
                                        for (int e=0; e<2 && e + k2 < 3 && e + k1 < 3; e++)
                                        {
                                            ///e=0/1 whether I chose or not the edge between it and nod
                                            int newSize = i + j - e;
                                            if (k1 > 0 && k2 > 0 && e == 1)
                                                curr = mul (curr, inv2);
                                            if (k1 == 0 && k2 == 0 && e == 1)
                                                curr = add (curr, curr);
                                            adto (dp[nod][newSize][p1 ^ p2 ^ e][e + k1], curr);
                                        }
                                    }
        vol[nod] += vol[it];
    }
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=2; i<=N; i++)
{
    int t;
    scanf ("%d", &t);
    v[t].push_back (i);
}
dfs (1);
fac[0] = 1;
for (int i=1; i<=N; i++)
    fac[i] = mul (fac[i - 1], i);
int ans = 0;
for (int p=0; p<2; p++)
{
    int curr = 0;
    for (int i=1; i<=N; i++)
        for (int j=0; j<3; j++)
            adto (curr, mul (dp[1][i][p][j], fac[i]));
    if (p == 0) adto (ans, curr);
    else ans = subtract (ans, curr);
}
printf ("%d\n", ans);
return 0;
}


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

int main(void){
    char ch;
    while(true){
        scanf("%c", &ch);
        if ( ch == '\n' ){
            printf("%c", ch);
            break;
        }
        else if ((ch >= 65) && (ch <= 90)){
            printf("%c", ch+32);
        }
        else if ((ch >= 97) && (ch <= 122)){
            printf("%c", ch-32);
        }
        else {
            printf("%c", ch);
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s;
  cin>>s;
  int n = s.size();
  int ans = 1;
  {
    int need = n;
    REP(i,n)if(s[i]=='1'){
      CHMIN(need, max(n-1-i, i));
    }
    CHMAX(ans, need);
  }
  REP(i,n)s[i] ^= 1;
  {
    int need = n;
    REP(i,n)if(s[i]=='1'){
      CHMIN(need, max(n-1-i, i));
    }
    CHMAX(ans, need);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string s;
long long int ans=1,n;
map<char,long long int> m;
int main(){
  cin >> n >> s;
  for (size_t i = 0; i < n; i++) {
      m[s[i]]++;
  }
  for(auto x:m){
    ans = (ans*(x.second+1)) % 1000000007;
  }
  cout << ans-1;
}


Measured memory_bytes: 512
//#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=998244353;
const int maxn=3e5+100;
const int N=1e5+100;
const int M=500+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll k,n;
ll p[N];
ll c[N];
ll sum[N];
vector<int>g;

ll check()
{
    ll m=g.size();
    ll res=-INF;
    for(int i=0;i<m;++i) sum[i+1]=sum[i]+c[g[i]];
    for(int i=1;i<=min(m,k);++i) res=max(res,sum[i]);
    if(m>=k||sum[m]<=0) return res;
    for(int i=1;i<=m;++i)
    {
        ll dx=k-i; dx/=m;
        res=max(res,sum[m]*dx+sum[i]);
    }

    return res;
}
int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;cout.tie(0);
    cin>>n>>k;
    rep1(i,n) cin>>p[i];
    rep1(i,n) cin>>c[i];
    ll ans=-INF;
    for(int i=1;i<=n;++i)
    {
        g.clear();
        int px=i;g.PB(px);px=p[px];
        while(px!=i)
        {
            g.PB(px);
            px=p[px];
        }
        ans=max(ans,check());
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    
    using ll = long long;
    
    vector<pair<ll, ll>> a(n);
    
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;   
    }
    
    sort(a.begin(), a.end());
    
    ll ans = 0;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        if (cnt + a[i].second >= m) {
            ans += (m - cnt) * a[i].first;
            break;
        } else {
            cnt += a[i].second;
            ans += a[i].first * a[i].second;
        }
    }
    
    cout << ans << endl;
}


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

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

int cmpAsc(const void* a, const void* b){
    int x = *(int*)a, y = *(int*)b;
    if(x > y){
        return 1;
    }
    if(x < y){
        return -1;
    }
    return 0;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    int v[n];
    rep(i, 0, n){
        scanf("%d", &v[i]);
    }
    int ans = 0;
    rep(i, 0, k+1){
        rep(j, 0, k+1){
            int p[k], pi=0;
            int m[k], mi=0;
            int cnt = 0;
            int buf = 0;
            if(i+j > k){
                continue;
            }
            rep(s, 0, i){
                if(s >= n){
                    break;
                }
                if(v[s] >= 0){
                    p[pi++] = v[s];
                }else{
                    m[mi++] = v[s];
                }
                cnt++;
            }
            rep(s, 0, j){
                if(n-1 - s<0){
                    break;
                }
                if(n-1 - s < i){
                    break;
                }
                if(v[n-1 - s] >= 0){
                    p[pi++] = v[n-1 - s];
                }else{
                    m[mi++] = v[n-1 - s];
                }
                cnt++;
            }
            rep(s, 0, pi){
                buf += p[s];
            }
            rep(s, 0, mi){
                buf += m[s];
            }
            qsort(m, mi, sizeof(int), cmpAsc);
            rep(s, 0, k-cnt){
                if(s >= mi){
                    break;
                }
                buf -= m[s];
            }
            if(buf > ans){
                ans = buf;
            }
        }
    }
    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 128
from collections import deque # BFSはこいつを使え！
def dfs(n):
    adj = 'abcdefghij'
    
    stack = deque(['a'])
    while stack:
        # node = stack.pop(0) # pop(0)がO(n)かかっているのでとても遅い！
        node = stack.popleft()
        if len(node) == n:
            print(node)
        else:
            
            for child in adj[:len(set(node))+1]:
                stack.append(node+child)
    return -1

# 再帰での実装
# def dfs(s,n,adj):
#     if len(s) == n:
#         print(s)
#     else:
#         for child in adj[:len(set(s))+1]:
#             dfs(s+child,n,adj)
#     return -1

def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    # adj = 'abcdefghij'
    # dfs('a',n,adj)
    dfs(n)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11868
#include<bits/stdc++.h>
using namespace std;
long long n,sum;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		if(i%3==0 || i%5==0)
		{
			continue;
		}
		sum+=i;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<limits.h>
int main(){
  int n;
  int i;
  long max = LONG_MIN;
  long min = LONG_MAX;
    long sum = 0;
  int num;

  scanf("%d",&n);

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

    if(num < min){
      min = num;
    }

    if(num >max){
      max =num;
    }

    sum += num;
  }

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

  return 0;
}
  



Measured memory_bytes: 2104
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

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

from collections import OrderedDict

s = ns()
t = ns()
n = len(s)

ds = OrderedDict.fromkeys(s, 0)
dt = OrderedDict.fromkeys(t, 0)

for i in range(n):
    ds[s[i]] += 1

for i in range(n):
    dt[t[i]] += 1

flag = True
for i, j in zip(ds.values(), dt.values()):
    if i != j:
        flag = False

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args)throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] dat=br.readLine().split(" ");
		int a,b,c;
		double S,L,h;
		a=Integer.parseInt(dat[0]);
		b=Integer.parseInt(dat[1]);
		c=Integer.parseInt(dat[2]);
		S=0.5*a*b*Math.sin(Math.toRadians(c));
		h=b*Math.sin(Math.toRadians(c));
		L=a+b+Math.sqrt(a*a+b*b-2*a*b*Math.cos(Math.toRadians(c)));
		System.out.printf("%.8f\n",S);
		System.out.printf("%.8f\n",L);
		System.out.printf("%.8f",h);
	}
}

Measured memory_bytes: 16924
#include <stdio.h>

int main(void)
{
        int x, y;
        int r;

        scanf("%d %d", &x, &y);

        if (x < y) {
                int temp;
                temp = x;
                x = y;
                y = temp;
        }

        while (y) {
                r = x % y;
                x = y;
                y = r;
        }

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

        return 0;
}


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

Measured memory_bytes: 256