akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
using namespace std;

int main(){
  string s;
  int a,b;
  while(s!="?"){
    cin>>a>>s>>b;
    if(s=="+"){
      cout<<a+b<<endl;
    }else  if(s=="-"){
      cout<<a-b<<endl;
    }else  if(s=="/"){
      cout<<a/b<<endl;
    }else  if(s=="*"){
      cout<<a*b<<endl;
    }
  }
  return 0;
}




Measured memory_bytes: 3132
N,W = map(int,input().split())
value,weight = [],[]
def chmin(a,b):
    if (a > b):
        a = b
        return True
    return False
for i in range(N):
    w,v = map(int,input().split())
    value.append(v)
    weight.append(w)
# dp[i][v]: i番目までの品物から価値vを超えるように選んだ時の重さの最小値
dp = [[float("inf")] * (sum(value)+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    for v in range(sum(value)+1):
        if v - value[i-1] >= 0:
            dp[i][v] = min(dp[i-1][v-value[i-1]] + weight[i-1],dp[i-1][v])
        else:
            dp[i][v] = dp[i-1][v]
ans = 0
for v in range(sum(value),-1,-1):
    if dp[N][v] <= W:
        ans = v
        break
print(ans)

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, M;
	cin >> N >> M;
	vector<int>L(M), R(M);
	int LMax = 0;
	int RMin = 1e9;

	for (int i = 0; i < M; i++){
		cin >> L[i] >> R[i];
		LMax = max(LMax, L[i]);
		RMin = min(RMin, R[i]);
	}
	cout << max(0, RMin - LMax + 1) << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

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

Measured memory_bytes: 3676
//BISMILLAHIR RAHMANIR RAHIM
//SOTO MEAW
//SOTO SONDESH
#include<bits/stdc++.h>

#define ls ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define __ <<" "<<
#define case(z) "Case " << z++ << ": "
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define quit return 0

using namespace std;

void showmyDS(set<int> ds)
{
    set<int> ::iterator it;
    for (it=ds.begin();it!=ds.end();it++)
    {
        cout << *it << endl ;
    }
    cout << endl;
}
int main()
{
    ls
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //int t,l=1;cin>>t;while(t>0){
        int n,m;
        cin >> n >> m ;
        if(n==m)
            cout << "Yes" ;
        else
            cout << "No" ;
    //t--;}

    quit;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
long long dp[1001][1001];
char grid[1001][1001];
const int mod = (int)1e9+7;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	memset(dp, 0, sizeof(dp));
	int h,w; cin >> h >> w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++) cin >> grid[i][j];
	}
	dp[0][0] = 1;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(grid[i][j] == '.'){
				if(i-1 >= 0) dp[i][j] += (dp[i-1][j]%mod)%mod;
				if(j-1 >= 0) dp[i][j] += (dp[i][j-1]%mod)%mod;
			}
		}
	}
	cout << (dp[h-1][w-1])%mod << "\n";
	return 0;
}

Measured memory_bytes: 9088
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'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'};
vector<char>AL(26);
AL = {'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'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	vector<int>B(N);
	int ans = 0;
	rep(i, N) {
		if (i % 2 == 0) {
			ans += A[i];
		}
		else {
			ans -= A[i];
		}
	}
	B[0] = ans/2;
	for (int i = 1; i < N; i++) {
		B[i] = A[i - 1] - B[i - 1];
	}
	rep(i, N) {
		cout << B[i]*2 << ' ';
	}
	cout << endl;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int N, M;
int a[100005];
int dp[100005];
const int MOD = 1000000007;
int main(void){
    cin >> N >> M;
    int t;
    REP(i,M){
        cin >> t;
        a[t] = -1;
    }
    dp[0] = 1;
    for(int i=0;i<N;i++){
        if (a[i+1]>=0) dp[i+1] += dp[i] % MOD;
        if (a[i+2]>=0) dp[i+2] += dp[i] % MOD;
    }
    cout << dp[N] % MOD << endl;


    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int N, K, tmp, answer = INT_MAX;
vector<int> inp;
int main(){
 cin >> N >> K;
 for(int i = 0;i < N; i++){cin >> tmp;inp.push_back(tmp);}
 sort(inp.begin(), inp.end());


 for(int i = 0; i+K-1 < N; i++){
  answer = min(answer, inp[i+K-1] - inp[i]);
 }
 cout << answer << endl;
 return 0; 
};


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

// 最高で10^4 * 2 くらいまでは重くなりうる
ll dp[1100][21000];

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

    ll N;
    cin >> N;
    vll w(N+1), s(N+1), v(N+1);
    vpll vec;
    for(int i = 1; i <= N; i++) {
        cin >> w[i] >> s[i] >> v[i];
        vec.emplace_back(w[i] + s[i], i);
    }
    sort(vec.begin(), vec.end());
    for(int i = 1; i <= N; i++) {
        int idx = vec[i-1].second;
        ll wi = w[idx], vi = v[idx], si = s[idx];
        for(ll j = 0; j <= 21000; j++) {
            chmax(dp[i][j], dp[i-1][j]);
            if(j-wi >= 0 && j-wi <= si) chmax(dp[i][j], dp[i-1][j-wi] + vi);
        }
    }
    ll ans = 0;
    rep(i, 21000) chmax(ans, dp[N][i]);
    cout << ans << endl;
}


Measured memory_bytes: 165120
def cal(y0,m0,d0):
    y = 1
    m = 1
    d = 1
    for days in range(10**6):
        if (y,m,d) == (y0,m0,d0):
            return days
        d += 1
        if y % 3 == 0:
            if d == 21:
                m += 1
                d = 1
            if m == 11:
                y += 1
                m = 1
        else:
            if m % 2 == 1:
                if d == 21:
                    m += 1
                    d = 1
                if m == 11:
                    y += 1
                    m = 1
            elif m % 2 == 0:
                if d == 20:
                    m += 1
                    d = 1
                if m == 11:
                    y += 1
                    m = 1

n = int(input())
ymd = [list(map(int,input().split())) for _ in range(n)]

res = cal(1000,1,1)
for y,m,d in ymd:
    ans = res - cal(y,m,d)
    print(ans)


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const long double pi=acos(-1);
#define x  first
#define y  second
#define read(n,a) for(int i=0;i<n;i++)cin>>a[i];
#define rep(z,n)  for(int i=z;i<n;i++)

ll a[200002]={};
ll b[200003]={};
ll n,m;

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    ///freopen("ss.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
       cin>>n;
       read(n,a);
       ll mod=1e9;
       mod+=7;
       rep(1,n+1)b[i]=b[i-1]+a[i-1];
       ll ans=0;
       rep(0,n)
       {
           ans+=((a[i]%mod) * ((b[n]-b[i+1])%mod))%mod;
           ans%=mod;
       }
       cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 6772
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

typedef long long int ll;

const ll MOD = 1000000007;

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

  int N;
  cin >> N;
  vector<ll> H(N);
  for (auto &x: H) cin >> x;

  H[0]--;
  for (int i = 1; i < N-1; i++) {
    if (H[i-1] < H[i]) H[i]--;
  }
  bool ok = true;
  for (int i = 0; i < N-1; i++) {
    if (H[i] > H[i+1]) ok = false;
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String[] abk = br.readLine().split(" ");
        int a = Integer.parseInt(abk[0]);
        int b = Integer.parseInt(abk[1]);
        int k = Integer.parseInt(abk[2]);
        
        if(k*2 > (b-a)){
            for(int i = a; i <= b; i++)
            System.out.println(i);
        }
        else{
            for(int i = a; i < a+k; i++)
            System.out.println(i);
            for(int i = b-k+1; i <= b; i++)
            System.out.println(i);
        }
    }

}


Measured memory_bytes: 22484
class SegmentTree():
    def __init__(self,arr,func=min,ie=2**63):
        self.n = 2**(len(arr)-1).bit_length()
        self.ie = ie
        self.func = func
        self.tree = [ie for _ in range(2*self.n)]
        for i in range(len(arr)):
            self.tree[self.n+i-1] = arr[i]
        for i in range(self.n-1)[::-1]:
            self.tree[i] = func(self.tree[2*i+1],self.tree[2*i+2])

    def set(self,index,x):
        index += self.n-1
        self.tree[index] = x
        while index:
            index = (index-1)//2
            self.tree[index] = self.func(self.tree[2*index+1],self.tree[2*index+2])

    def query(self,left,right):
        if right <= left:
            return self.ie
        left += self.n-1
        right += self.n-2
        tmp_l = self.ie
        tmp_r = self.ie
        while right-left>1:
            if left & 1 == 0:
                tmp_l = self.func(tmp_l,self.tree[left])
            if right & 1 == 1:
                tmp_r = self.func(self.tree[right],tmp_r)
                right -= 1
            left = left//2
            right = (right-1)//2
        if left == right:
            tmp_l = self.func(tmp_l,self.tree[left])
        else:
            tmp_l = self.func(self.func(tmp_l,self.tree[left]),self.tree[right])
        return self.func(tmp_l,tmp_r)

import sys
input = sys.stdin.readline

N = int(input())
S = input()
Q = int(input())

A = []
for i in range(N):
    A.append(set([ord(S[i])-97]))

def func(x,y):
    return x|y
ie = set()

st = SegmentTree(A,func,ie)

ans = []

for _ in range(Q):
    q,x,y = input().split()
    q = int(q)
    if q == 1:
        st.set(int(x)-1,set([ord(y)-97]))
    else:
        ans.append(len(st.query(int(x)-1,int(y))))

print('\n'.join(map(str,ans)))

Measured memory_bytes: 488388
#include<bits/stdc++.h>
#define ll          long long
#define dl          double
#define pb          push_back
#define mp          make_pair
#define pll         pair<long long,long long>
#define vll          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (long long)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const ll N=200005;
ll val[N]={0};
vector<ll> g[N];
void dfs(ll cu,ll pa){
	val[cu]+=val[pa];
	for(auto u:g[cu]){
		if(pa==u)continue;
		dfs(u,cu);
	}
}
int main(){
	ll n,q;cin>>n>>q;
	for(ll i=0;i<n-1;i++){
		ll x,y;cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(ll i=0;i<q;i++){
		ll x,v;cin>>x>>v;
		val[x]+=v;
	}
	dfs(1,0);
	for(ll i=1;i<=n;i++)cout<<val[i]<<" ";
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int>A(n);
    for(int i=0; i<n; i++) cin >> A[i];
    cout << accumulate(A.begin(), A.end(), 0)-n << endl;
    return 0;
}

Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


long long dp[50][500][500];
int main(void) {
	long long n, ma, mb; cin >> n >> ma >> mb;
	long long a[60], b[60], c[60];
	long long max_a = 0, max_b = 0,max_c = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
		max_a += a[i];
		max_b += b[i];
		max_c += c[i];
	}

	for (int i = 0; i < 50; i++)
	{
		for (int j = 0; j < 500; j++)
		{
			for (int k = 0; k < 500; k++)
			{
				dp[i][j][k] = INF;
			}
		}
	}

	dp[0][0][0] = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < 500; j++)
		{
			for (int k = 0; k < 500; k++)
			{
				if (dp[i][j][k] == INF)continue;
				else {
					dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
					dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
				}
			}
		}
	}
	ll ans = INF;
	for (int i = 1; i < 500; i++)
	{
		for (int j = 1; j < 500; j++)
		{
			if (i*mb == j * ma and i <= max_a and i <= max_b) {
				ans = min(ans, dp[n][i][j]);
			}
		}
	}
	if (ans > max_c) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 97920
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<list>
#include<iomanip>
#include<cstring>
#include<queue>
#define h 1000000007
#define lli long long int
#define pb push_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
using namespace std;
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lli n, i,  sum=0,prod;
	cin>>n;
	vector<lli>a(n),b(n);
	for(i=0;i<n;i++) 
	{ 
		cin>>a[i];
		sum+=a[i];
		if(i>0)b[i]=sum-a[0];
	} 
	sum=0;
	b[0]=0;
	for(i=0;i<(n-1);i++) 
	{
		prod=(((b[n-1]-b[i])%h)*(a[i]%h))%h; 
		sum=((sum%h)+prod)%h;
	} 
	cout<<sum<<endl;
  return 0;
} 



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

int main() {
    ios::sync_with_stdio(false);
    int a[5],k;
    for (int i = 0; i < 5; i++)
        cin >> a[i];
    cin >> k;
    for (int i = 0; i < 5; i++) {
        for (int j = i+1; j < 5; j++) {
            if (abs(a[i] - a[j]) > k) {
                cout << ":(\n";
                return 0;
            }
        }
    }
    cout << "Yay!\n";
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20180305_AOJ
{
    class ALDS1_3B
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                int[] n_q = line.Split(' ').Select(x => int.Parse(x)).ToArray();
                int n = n_q[0];
                int q = n_q[1];

                Queue<Proc> procs = new Queue<Proc>();
                for (int i = 0; i < n; i++)
                {
                    line = Console.ReadLine();
                    string[] items = line.Split(' ');
                    procs.Enqueue(new Proc(items[0], int.Parse(items[1])));
                }

                int total = 0;
                while (procs.Count > 0)
                {
                    Proc p = procs.Dequeue();
                    p.Time -= q;
                    total += q;
                    if (p.Time > 0)
                    {
                        procs.Enqueue(p);
                    }
                    else
                    {
                        total += p.Time;
                        Console.WriteLine(string.Format("{0} {1}", p.Name, total));
                    }
                }
            }
        }

        class Proc
        {
            public string Name { get; set; }
            public int Time { get; set; }
            public Proc(string name, int time)
            {
                Name = name;
                Time = time;
            }
        }
    }
}



Measured memory_bytes: 18160
#include <iostream>
#include <vector>
#include <algorithm> 
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; ++i)

int main(){
	int n;
	cin >> n;
	vector<int> vi(n), b;
	rep(i, n){
		cin >> vi[i];
	}

	std::reverse(vi.begin(), vi.end());

	for(int i = 0; i < n; i += 2){
		b.emplace_back(vi[i]);
	}
		
	int len = n - 1;
	if(n % 2 != 0){
		len--;
	}
	
	for(int i = len; i >= 0; i -= 2){
		b.emplace_back(vi[i]);
	}
	
	rep(i, n){
 		cout << b[i] << " ";
	}
	cout << endl;
	
	return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef pair<ll,pair<ll,ll>> pii;
typedef pair<ll,ll> pi;
typedef vector<ll> vl;

#define matrix vector<vector<ll>>
#define llmax LLONG_MAX
#define llmin LLONG_MIN
#define rep(i,n) for(ll (i)=0;(i)<n;++(i))
#define crep(i,m,n) for(ll (i)=m;(i)<n;++(i))
#define zero(a) memset((a),0,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)));
#define sq(a) ((a)*(a))
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define ff first
#define ss second

ll inf=1e18 + 5;

// return nCr value
long long C(int n, int r) {
    if(r>n) return 0;
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }
    return ans;
}

// return whether number is prime or not
vector<ll> sieve(ll n){
    vector<ll> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i] && (long long)i * i <= n) {
            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    return is_prime;
}


void test_case();
int main(){
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    for(ll T=0;T<t;T++){
        test_case();
    }
    //**************************************************************************//
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

void test_case(){
    ll n;scanf("%lld",&n);
    vector<ll>a(n);
    rep(i,n)scanf("%lld",&a[i]);
    vector<vector<ll>>dp(n+5, vector<ll>(n+5, inf));
    for(ll i=n-1;i>=0;--i){
        for(ll j=i;j<n;++j){
            if(i==j)dp[i][j] = 0;
            else{
                ll s = 0;
                crep(k,i,j+1){s+=a[k];}
                for(ll k=i;k<j;++k){
                    dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j] + s);
                }
            }
        }
    }
    cout<<dp[0][n-1];
}


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		long n = Integer.parseInt(br.readLine());

		long result = n*(n - 1)/2;
		
		System.out.println(result);
	}

}


Measured memory_bytes: 20308
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    def f(cnd):
        for i in range(1, N):
            if S[i] == 'o' and cnd[i] == 'S':
                cnd.append(cnd[i-1])
            elif S[i] == 'o' and cnd[i] == 'W':
                cnd.append('S' if cnd[i-1] == 'W' else 'W')
            elif S[i] == 'x' and cnd[i] == 'S':
                cnd.append('S' if cnd[i-1] == 'W' else 'W')
            elif S[i] == 'x' and cnd[i] == 'W':
                cnd.append(cnd[i-1])

        cnd.pop()
        for i in range(N):
            if cnd[i] == 'S' and S[i] == 'o':
                if cnd[(i+1) % N] != cnd[i-1]:
                    return None
            elif cnd[i] == 'S' and S[i] == 'x':
                if cnd[(i+1) % N] == cnd[i-1]:
                    return None
            elif cnd[i] == 'W' and S[i] == 'o':
                if cnd[(i+1) % N] == cnd[i-1]:
                    return None
            elif cnd[i] == 'W' and S[i] == 'x':
                if cnd[(i+1) % N] != cnd[i-1]:
                    return None
        return ''.join(cnd)
    # SS
    ans = f(['S', 'S'])
    if ans:
        return ans

    # SW
    ans = f(['S', 'W'])
    if ans:
        return ans

    # WS
    ans = f(['W', 'S'])
    if ans:
        return ans

    # WW
    ans = f(['W', 'W'])
    if ans:
        return ans

    return -1


def main():
    N = read_int()
    S = read_str()
    print(slv(N, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 77716
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();

    vvl v(26);
    rep(i, n) {
        v[s[i] - 'a'].pb(i);
    }
    
    ll now = -1;
    ll ans = 0;
    rep(i, m) {
        if(v[t[i] - 'a'].size() == 0) {
            out(-1);
            re0;
        }
        if(upper_bound(all(v[t[i] - 'a']), now) == v[t[i] - 'a'].end()) {
            ans += n;
            now = *v[t[i] - 'a'].begin();
        }  
        else {
            now = *upper_bound(all(v[t[i] - 'a']), now);
        }
    }

    ans += now;
    ans++;

    out(ans);
    re0;
}

Measured memory_bytes: 1724
/*

 Remember, Hope is a good thing... May be the best of things... and No Good thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(0); cout.tie(0);
#define endl "\n"
#define MOD 1000000007
#define MOD1 1e18
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
typedef long double ld;
const ll inf=(1LL<<60)-1;
const ll mxn=1e5;
int dx[]= {-1,1,0,0};
int dy[]= {0,0,-1,1};
long long ans,a[100005];
ll mod(ll x)
{
    ll res=x%MOD;
    while(res<0)
        res+=MOD;
    return res;
}
ll bigmod(ll x,ll n)
{
    ll res=1;
    while(n>0)
    {
        if(n&1)
            res=(res*x)%MOD;
        x=(x*x)%MOD;
        n>>=1;
    }
    return res;
}
/*
sort(v.begin(),v.end(),[&](const pair<ll,ll>&a,const pair<ll,ll>&b)
   {
       if(a.first==b.first)
           return a.second<b.second;
       else
           return a.first>b.first;
   });
   */
void solve()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ll n,k,mx=-MOD1,mn=MOD1;
    cin>>n>>k;
    bool vis[10]= {0};
    bool flag=0;
    for(ll i=0; i<k; i++)
    {
        ll x;
        cin>>x;
        vis[x]=1;
    }
    for(ll i=n;;i++)
    {
        ll j=i;
        while(j>0)
        {
            if(vis[j%10])
                break;
            j/=10;
        }
        if(j==0)
        {
            cout<<i<<endl;
            break;
        }
    }
}
int main()
{
    IOS;
    //ll t;
    //cin>>t;
    //while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3572
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

def main():
    N = II()
    edges = defaultdict(list)
    for _ in range(N):
        x, y = LI()
        edges[x].append(-y)
        edges[-y].append(x)
    visited = defaultdict(int)
    if max(len(li) for li in edges.values()) == 2 and N >= 10 ** 4:
        m, p = 0, 0
        for k in edges.keys():
            if k < 0:
                m += 1
            else:
                p += 1
        return m * p - N
    def solve(v):
        visited[v] = 1
        ret = [v]
        for u in edges[v]:
            if not visited[u]:
                ret += solve(u)
        return ret
    ans = -N
    for node in edges:
        if not visited[node]:
            li = solve(node)
            m, p = 0, 0
            for z in li:
                if z < 0:
                    m += 1
                else:
                    p += 1
            ans += m * p
    return ans

print(main())

Measured memory_bytes: 193868
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
#define MOD 1000000007

ll calc(ll a, ll b, ll p) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = calc(a, b / 2, p);
        return (d * d) % p;
    } else {
        return (a * calc(a, b - 1, p)) % p;
    }
}

ll modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

ll modFact(int n,int from){
    ll ret = 1;
  // cout << "##factrial start## "<< from << endl;
    for(int i = from; i <= n; i++){
        ret = ret * i % MOD;
    }
    //cout << "##factrial end## " << ret << endl;
    return ret;
}

ll combn(int n,int r){
   ll num = modFact(n, n-r+1);
   ll tmp;
  // cout << "numn "<< num << endl;

    tmp = modFact(r, 1);
    tmp = modPow(tmp, MOD - 2, MOD);
    num = num * tmp % MOD;
    return((int)num);
}



int main (){
int n,a,b;
cin >> n >> a >> b ;  
if(n == 2 && a != b){
    cout << 0 << endl;
    return 0;
}
ll cnt = modPow(2,n,MOD) - 1;
// cout << cnt << endl  ;
cnt -= combn(n,a);
cnt -= combn(n,b);
if(cnt < 0)
    cnt += MOD * 2;

cout <<  cnt % MOD << endl;

return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
#define NIL -1

struct Tree
 {
 	int p,l,r;
 };

Tree *T;
int *D;
string *S;

void depth(int t,int dep){
	D[t] = dep;

	if(T[t].r != NIL) 
		depth(T[t].r,dep);

	if(T[t].l != NIL)
		depth(T[t].l,dep+1);
}

void type(int t){
	if(T[t].p == NIL){
		S[t] = "root, ";
	}else if(T[t].l != NIL){
		S[t] = "internal node, ";
	}else{
		S[t] = "leaf, ";
	}

	if(T[t].r != NIL) type(T[t].r);

	if(T[t].l != NIL) type(T[t].l);
}

void family(int t){
	if(T[t].l != NIL){
		t = T[t].l;
		cout << t;
		while(1){
			if(T[t].r != NIL){
				t = T[t].r;
				cout << ", ";
				cout << t;
			}else{
				break;
			}
		}
	}
}

int main(){
	int n;
	cin >> n;
	T = new Tree[n];
	D = new int[n];
	S = new string[n];
	for(int i = 0;i < n;i++){
		T[i].p = T[i].l = T[i].r = NIL;
	}
	int v,d,num,l;
	for(int i = 0;i < n;i++){
		cin >> v >> d;
		for(int j = 0;j < d;j++){
			cin >> num;
			if(j == 0) T[v].l = num;
			else T[l].r = num;
			l = num;
			T[num].p = v;
		}
	}
	int root;
	for(int i = 0;i < n;i++){
		if(T[i].p == NIL) root = i;
	}
	depth(root,0);
	type(root);
	for(int i = 0;i < n;i++){
		cout << "node " << i << ": ";
		cout << "parent = " << T[i].p << ", ";
		cout << "depth = " << D[i] << ", ";
		cout << S[i];
		cout << "[";
		family(i);
		cout << "]" << endl;
	}

	return 0;
}

Measured memory_bytes: 11352
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>

using namespace std;
#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr)
#define fix(n) fixed << setprecision(n)

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    fast_io();
    
    string s;
    cin >> s;
    cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 2984
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a, b, c, d, e, k;
            a = in.nextInt();
            b = in.nextInt();
            c = in.nextInt();
            d = in.nextInt();
            e = in.nextInt();
            k = in.nextInt();

            if (e - a > k) {
                out.println(":(");
            } else {
                out.println("Yay!");
            }
        }

    }
}



Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ll long long int
#define ud unsigned long long int
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()

ld dp[3000][3000];

	int main(){
		ios_base::sync_with_stdio(0);
		cin.tie(0);
		cout.tie(0);
		ll n;
		cin>>n;
		ve<ld>ar(n+1);
		lr(n){
			cin>>ar[i+1];
		}
		dp[1][0]=1-ar[1];
		dp[1][1]=ar[1];
		// cout << fixed << setprecision(12) << dp[1][0] << " " << dp[1][1] << "\n";
		for(ll i=2;i<=n;i++){
			for(ll j=0;j<=i;j++){
				if(j!=i)
					dp[i][j]+=dp[i-1][j]*(1-ar[i]);
				if(j!=0)
					dp[i][j]+=dp[i-1][j-1]*(ar[i]);
				// cout << fixed << setprecision(12) << dp[i][j] << " ";
			}
			cout << "\n";
		}
		ld ans=0;
		for(ll i=n;i>n/2;i--)
			ans+=dp[n][i];
		cout << fixed << setprecision(12) << ans << "\n";
		return 0;
	}

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

using namespace std;

int main() {
	string s; cin >> s;
	long long b = 0, ans = 0;
	for (char c : s) {
		if (c == 'B') ++b;
		else ans += b;
	}
	cout << ans << endl;

	return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)

static const ll INF = 1e18;

template<typename T>
static inline void chmin(T& ref, const T  value) {
    if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T& ref, const T value) {
    if (ref < value) ref = value;
}

ll mpow(ll x, ll n, ll m) {
	ll ans = 1; x %= m;
	while (n != 0) {
		if (n & 1) ans = ans * x % m;
		x = x * x % m;
		n = n >> 1;
	}
	return ans;
}

vector<ll> naive(int n, string s) {
	vector<ll> nums(n);
	rep(i, n) nums[i] = s[i] - '0';
	vector<ll> vals(n);
	for (int i = 0; i < n; i++) {
		ll value = 0;
		ll v = 1;
		nums[i] = (nums[i] + 1) % 2;
		ll pcount = 0;
		for (int j = 0; j < n; j++) {
			if (nums[j]) pcount++;
		}
		for (int j = n - 1; j >= 0; j--) {
			value += nums[j] * v;
			v *= 2;
		}
		nums[i] = (nums[i] + 1) % 2;
		vals[i] = value % pcount;
	}
	return vals;
}

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<ll> dp(n + 1, -1);
	dp[0] = 0;
	for (int i = 1; i <= n; i++) {
		ll next = i % __builtin_popcountll(i);
		dp[i] = dp[next] + 1;
	}
	//string s に対して、bit反転したものを % popcount したときの余りは?
	//popcount = s の数 ± 1
	ll pcount = 0;
	rep(i, n) {
		if (s[i] == '1') {
			pcount++;
		}
	}
	vector<ll> m;
	for (auto p : { pcount + 1, abs(pcount - 1)}) {
		ll current = 0;
		if (p > 0) {
			rep(i, n) {
				current *= 2;
				current += (s[i] == '1' ? 1 : 0);
				current %= p;
			}
		}
		m.push_back(current);
	}
	rep(i, n) {
		if (s[i] == '1') {
			//minus
			const ll mod = pcount - 1;
			if (mod == 0) {
				cout << 0 << endl;
			}
			else {
				ll m2 = mpow(2, n - 1 - i, mod);
				ll ans = (m[1] - m2 + mod) % (mod);
				//cout << i << "," << ans << endl;
				cout << dp[ans] + 1 << endl;
			}
		}
		else {
			//plus
			const ll mod = pcount + 1;
			ll m2 = mpow(2, n - 1 - i, mod);
			ll ans = (m[0] + m2) % (mod);
			//cout << i << "," << ans << endl;
			cout << dp[ans] + 1 << endl;
		}
	}
	//cout << "debug" << endl;
	//auto a = naive(n, s);
	//for (auto p : a) {
	//	cout << p <<"," << dp[p] + 1 << endl;
	//}
	return 0;
}


Measured memory_bytes: 5224
package main

import (
	"fmt"
	"math"
)

var s string
var ans int

func main() {
	fmt.Scan(&s)
	A, Z := make([]int, len(s)), make([]int, len(s))

	var j, k int
	for i := 0; i < len(s); i++ {
		if string(s[i]) == "A" {
			A[j] = i
			j++
		}
		if string(s[i]) == "Z" {
			Z[k] = i
			k++
		}
	}

	fmt.Println(Z[k-1] - A[0] + 1)
}

/*  ----------------------------------------  */
func lcm(x, y uint64) uint64 {
	return (x / gcd(x, y)) * y
}

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;
const int MOD = 1e9 + 7;

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

    int ans = 0, pnt = 0;
    map<int, string> mp;
    map<int, int> mpnt;
    rep(i, 0, m){
        int a; cin >> a;
        string s; cin >> s;
        if(!mp.count(a)){
            mp[a] = "WA";
            mpnt[a] = 0;
        }
        if(mp[a] != "AC"){
            if(s == "AC"){
                mp[a] = s;
                ans++;
                pnt += mpnt[a];
            }
            else mpnt[a]++;
        }
    }

    cout << ans << " " << pnt << endl;

    return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;

int main(){
    int n,t,a,h,ans;
    cin>>n>>t>>a;
    double dif,g=1000000;
    for(int i=1;i<=n;i++){
        cin>>h;
        dif=fabs(t-0.006*h-a);
        if(g>dif){
            g=dif;
            ans=i;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
    
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < n; i++){
		    int a = sc.nextInt();
		    map.put(a, map.getOrDefault(a, 0) + 1);
		}
		
		// 計算
		int result = 0;
		for(Integer i : map.values()){
		    if(i%2 == 1) result++;
		}
		
		// 出力
		System.out.println(result);
		
	}
}


Measured memory_bytes: 63184
#include<iostream>
#include<string>
#define MAX 10
using namespace std;

int main(){
  string s;
  int ans[MAX], sum[MAX];
  while(cin >> s){
    for(int i=0; i<s.size(); i++){
     ans[i] = s[i] - '0'; 
    }
    int count=10;
    while(1){
      for(int i=0; i<count-1; i++){
	sum[i] = (ans[i] + ans[i+1]) % 10;
      }
      for(int i=0; i<MAX; i++){
	ans[i] = sum[i];
      }
      count--;
      if(count == 1) break;
    }
    cout << sum[0] << endl;
  }
}

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

using namespace std;

int main(){
    int P, Q, R;
    cin >> P >> Q >> R;
    
    vector<int> list = {P, Q, R};
    sort(list.begin(), list.end());

    cout << list[0] + list[1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   
   int N,half;
   int dif[100001],num[100001]={0};
   int i,j,k,tmp,result;
   scanf("%d",&N);
   
   for(i=1;N>=i;i++){
       scanf("%d",&dif[i]);
       num[dif[i]]++;
   }
   
   j=1;
   k=1;
   
   while(N>=k){
       while(num[j]>0){
           dif[k] = j;
           num[j]--;
           k++;
       }
       j++;
   }
  
   
   half = N/2;
   result = dif[half+1]-dif[half];
   
   printf("%d\n",result);
   
   
   return 0;
}




Measured memory_bytes: 896
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
# stdin = open("sample.txt")

MOD = 1000000007
INF = float('inf')
alpha = ["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"]
def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def main():
    n = int(stdin.readline().rstrip())
    a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
    dic = {}
    ans = 0
    for i in range(len(a)):
        if a[i] in dic:
            dic[a[i]] += 1
        else:
            dic[a[i]] = 1
    for k, v in dic.items():
        if v != 0:
            ans += k*v
    q = int(stdin.readline().rstrip())
    for i in range(q):
        b, c = [int(x) for x in stdin.readline().rstrip().split()]
        if b in dic:
            ans += (c-b)*dic[b]
            print(ans)
            if c in dic:
                dic[c] += dic[b]
            else:
                dic[c] = dic[b]
            dic[b] = 0
        else:
            print(ans)

main()

Measured memory_bytes: 21768
N, T = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
buy_price = float('inf')
count = {}
for i in range(N):
    buy_price = min(buy_price, A[i])
    profit = A[i] - buy_price
    count[profit] = count.get(profit, 0) + 1
print(count[sorted(count.keys())[-1]])


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

typedef long long ll;

int mod = 1e9 + 7;
ll p = 5e5 + 100;

int main() {	
	vector<ll> com(p + 1);
	vector<ll> inv(p + 1);
	vector<ll> mul(p + 1);
	com[0] = 1;
	for (ll i = 1; i <= p; ++i) {
		com[i] = (com[i - 1] * i) % mod;
	} 
    inv[0] = 1;
    inv[1] = 1;
	for (ll i = 2; i <= p; ++i) {
		inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod; 
	}
	mul[0] = 1;
	for (int i = 1; i <= p; ++i) {
		mul[i] = (mul[i - 1] * inv[i]) % mod;
	}
	
	ll a,b, n;
	cin >> a >> b >> n;
	n = min(b - 1,n);
	cout << ((n * a) / b) - a * (n / b);
}










Measured memory_bytes: 14712
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <map>

using namespace std;

int main(){

	int N;
	cin>>N;
	switch(N%10)
	{
		case 2 : cout<<"hon"; break;
		case 4 : cout<<"hon"; break;
		case 5 : cout<<"hon"; break;
		case 7 : cout<<"hon"; break;
		case 9 : cout<<"hon"; break;
		case 0 : cout<<"pon"; break;
		case 1 : cout<<"pon"; break;
		case 6 : cout<<"pon"; break;
		case 8 : cout<<"pon"; break;
		case 3 : cout<<"bon"; break;
	}

}


Measured memory_bytes: 3608
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let r = read_vec::<f64>()[0];
    let c = 2.0 * r * std::f64::consts::PI;
    println!("{}", c);
}


Measured memory_bytes: 2136
INF = float("inf")

H, N, *AB = map(int, open(0).read().split())

dp = [INF] * (H + 10 ** 4 + 10)
dp[0] = 0

for a, b in zip(*[iter(AB)] * 2):
    for i in range(a, len(dp)):
        if dp[i - a] != INF:
            dp[i] = min(dp[i], dp[i - a] + b)

print(min(dp[H:]))

Measured memory_bytes: 64988
/*
    _____
  .'|||||'.
 /  >   <  \
|     ^     |
|  \     /  |
 \  '---'  /
  '._____.'
    |||||
*/

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
using namespace std;
#define CL(x,v); memset(x,v,sizeof(x));
#define INF 0x3f3f3f3f
#define LL long long
#define REP(i,r,n) for(int i=r;i<=n;i++)
#define RREP(i,n,r) for(int i=n;i>=r;i--)
int H,W,h,w;
int a[100][100];
int main()
{
scanf("%d%d",&H,&W);
scanf("%d%d",&h,&w);
for (int i=1;i<=h;i++)
    for (int j=1;j<=W;j++)
    a[i][j]=1;
for (int i=1;i<=H;i++)
   for (int j=1;j<=w;j++)
   a[i][j]=1;
    int ans=0;
for (int i=1;i<=H;i++)
    for (int j=1;j<=W;j++)
     if (a[i][j]==0) ans++;
printf("%d\n",ans);
    return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  if(K==1) cout<<0<<endl;
  else cout<<N-K<<endl;
}



Measured memory_bytes: 3560
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int n, m;
	E[] es;

	void run(){
		for(;;){
			n=sc.nextInt();
			m=sc.nextInt();
			if(n==0){
				break;
			}
			es=new E[m];
			for(int i=0; i<m; i++){
				int u=sc.nextInt()-1;
				int v=sc.nextInt()-1;
				int w=sc.nextInt();
				es[i]=new E(u, v, w);
			}
			solve();
		}
	}

	int[] p, rank;

	void solve(){
		Arrays.sort(es, new Comparator<E>(){
			@Override
			public int compare(E e1, E e2){
				return e1.w-e2.w;
			}
		});

		p=new int[n];
		rank=new int[n];
		int ans=-1;

		for(int j=0; j<m; j++){
			// union-find tree
			for(int i=0; i<n; i++){
				p[i]=i;
				rank[i]=0;
			}
			int min=es[j].w;
			int max=min;
			for(int i=j; i<m; i++){
				// ツ枝ツづーツ津嘉つキツづゥツつイツづづ盈axツ更ツ新
				if(find(es[i].u)!=find(es[i].v)){
					union(es[i].u, es[i].v);
					max=Math.max(max, es[i].w);
				}
			}
			// ツ全ツ暗ヲツ姪伉つゥツづつ、ツつゥ
			boolean f=true;
			for(int i=0; i<n; i++){
				f&=find(i)==find(0);
			}
			if(f){
				if(ans==-1||max-min<ans){
					ans=Math.min(INF, max-min);
				}
			}
		}
		println(""+ans);
	}

	int find(int x){
		if(p[x]==x){
			return x;
		}else{
			return p[x]=find(p[x]);
		}
	}

	void union(int x, int y){
		x=find(x);
		y=find(y);
		if(x==y){
			return;
		}

		if(rank[x]<rank[y]){
			p[x]=y;
		}else{
			p[y]=x;
			if(rank[x]==rank[y]){
				rank[x]++;
			}
		}
	}

	class E{
		int u, v, w;

		E(int u, int v, int w){
			this.u=u;
			this.v=v;
			this.w=w;
		}
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000