akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define fast                          \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);
#define FOR(n) for(int i(0);i<n;++i)
#define ASC(i,a,b) for(int i(a); i <=b; ++i)
#define DESC(i,a,b) for(int i(a);i>=b;i--)
#define WL(t) while(t--)
#define forr(i,n) for(int i(0);i<n;++i)
#define SZ(a) int((a).size())
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define BB begin()
#define EE end()
#define all(c) c.BB, c.EE
#define present(container, element) (container.find(element) != container.end())
// ^^for set,map etc
#define cpresent(container, element) (find(all(container), element) != container.end())
// for vector,array etc
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define count(x) __builtin_popcount(x) 
typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef map<char,int> mci;
typedef pair<int, int> pii;
typedef map<int,pii> ipii;
const float INF = numeric_limits<float>::infinity();
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979323846264338;
const LL big=998244353;

#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif

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

Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int s , t ;
string a ;

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

	cin >> a ;

	for (int i = 0 ; i < _sz(a) ; i ++) {
		if (a[i] == 'S') s ++ ;
		else {
			if (s) s -- ;
			else t ++ ;
		}
	}

	cout << s + t << '\n' ;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int N,X,T;
  cin>>N>>X>>T;
  if(N==0){
    cout<<0<<endl;
  }
  else if(N<=X){
    cout<<T<<endl;
  }
  else if(N%X==0){
    cout<<((N/X)*T)<<endl;
  }
  else{
    cout<<((N/X)*T+T)<<endl;
  }
}

Measured memory_bytes: 3592
#!/usr/bin/env python
#coding:utf-8

while True:
    coin = [500,100,50,10,5,1]
    oturi = 1000 - int(input())
    if oturi == 1000:
        break
    ret = 0
    for c in coin:
        ret += oturi // c
        oturi %= c
    print(ret)

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> dist(m);
  set<int> st;
  multiset<int> all;
  for (int i = 0; i < m; i++) {
    st.insert(i);
    all.insert(0);
  }
  const int inf = (int) 2e9;
  for (int i = 0; i < n; i++) {
    int l, r;
    cin >> l >> r;
    --l;
    int Min = inf;
    auto it = st.lower_bound(l);
    while (it != st.end() && *it <= r) {
      int x = *it;
      Min = min(Min, dist[x] + r - x);
      it = st.erase(it);
      all.erase(all.find(dist[x]));
      dist[x] = inf;
    }
    if (r != m && Min != inf) {
      dist[r] = min(dist[r], Min);
      st.insert(r);
      all.insert(dist[r]);
    }
    if (all.empty()) {
      cout << -1 << '\n';
    } else {
      cout << *all.begin() + i + 1 << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 22712
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N = int(input())

    def dfs(s):
        if int(s) > N:
            return 0
        ret = 1 if all(s.count(c) for c in '357') else 0
        for c in '357':
            ret += dfs(s+c)
        return ret

    print(dfs('0'))


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int d,c[26],s[400][26],t[400],last[400];
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>d;
    rep(i,26)cin>>c[i];
    rep(i,d){
        rep(j,26){
            cin>>s[i][j];
        }
    }
    int score=0;
    fill(last,last+26,-1);
    rep(i,d){
        cin>>t[i];
        t[i]--;
        score+=s[i][t[i]];
        last[t[i]]=i;
        rep(j,26)score-=c[j]*(i-last[j]);
    }
    int m;
    cin>>m;
    while(m--){
        int dd,q;
        cin>>dd>>q;
        dd--,q--;
        int from=t[dd],to=q;
        score-=s[dd][from],score+=s[dd][to];
        int r=d,l=-1;
        rep(i,d){
            if(t[i]==to){
                if(i>dd){
                    r=i;
                    break;
                }
                l=i;
            }
        }
        score+=c[to]*(r-dd)*(dd-l);
        l=-1,r=d;
        rep(i,d){
            if(t[i]==from){
                if(i>dd){
                    r=i;
                    break;
                }
                if(i!=dd)l=i;
            }
        }
        score-=c[from]*(r-dd)*(dd-l);
        t[dd]=q;
        cout<<score<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
  int A[100],N,i,j,minj,count = 0,b,c;
  scanf("%d",&N);
  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }
  for(i = 0; i < N; i++){
    minj = i;
    b = A[minj];
    for(j = i; j < N; j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    if(b!=A[minj])count++;
    b = A[i];
    c = A[minj];
    A[i] = c;
    A[minj] = b;
  }
  for(i = 0; i < N-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[N-1],count);
  return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int a[100005],b[100005],c[100005],dp[100005][5],n;
int f(int idx, int top){
	if(idx>n)return 0;
	if(dp[idx][top]!=-1)return dp[idx][top];
	if(top==1){
		return dp[idx][top] = max(f(idx+1,2)+b[idx],f(idx+1,3)+c[idx]);
	}
	else if(top==2){
		return dp[idx][top] = max(f(idx+1,1)+a[idx],f(idx+1,3)+c[idx]);
	}
	else if(top==3){
		return dp[idx][top] = max(f(idx+1,2)+b[idx],f(idx+1,1)+a[idx]);
	}
	else{
		return dp[idx][top] = max(f(idx+1,2)+b[idx],max(f(idx+1,1)+a[idx],f(idx+1,3)+c[idx]));
	}
}
int main(){
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(int i =1;i<=n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	cout<<f(1,0)<<endl;
}

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

bool dp[ 5010 ];
int A[ 5010 ];

int main()
{
int i;
int j;
int a;
int N, K;
int iCnt;
long long iSum;

	cin >> N;
	cin >> K;

	iCnt = 0;
	iSum = 0;
	for( i = 0; i < N; i++ )
	{
		cin >> a;
		if( a >= K ) continue;

		A[ i ] = a;
		iSum += a;
		iCnt++;
	}

	N = iCnt;
	sort( A, A + N );

	dp[ 0 ] = true;
	iCnt = 0;
	for( i = N - 1; i >= 0; i-- )
	{
		for( j = 0; j < K; j++ )
		{
			if( dp[ j ] && j + iSum >= K ) break;
		}

		if( j == K ) iCnt++;

		iSum -= A[ i ];
		for( j = K - 1; j >= A[ i ]; j-- )
			dp[ j ] |= dp[ j - A[ i ] ];
	}

	cout << iCnt << endl;

	return 0;
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())
mod = 998244353
import sys

if m == 1 and n-1 == k:
    print(1)
    sys.exit()



kai = [1]*(n+1)
inv = [1]*(n+1)
for i in range(n):
    kai[i+1] = (kai[i] * (i+1))%mod
    inv[i+1] = (inv[i] * pow(i+1,mod-2,mod))%mod

count_all = 0
pre_pow = pow(m-1,n-1,mod)
inv_m_mai1 = pow(m-1,mod-2,mod)
for i in range(k+1):
    pattern_color = m*pre_pow%mod
    pattern_place = kai[n-1]*inv[n-1-i]*inv[i]%mod
    count_all = (count_all+pattern_color*pattern_place)%mod
    pre_pow = pre_pow * inv_m_mai1 %mod

print(count_all)

Measured memory_bytes: 73696
#include <iostream>
using namespace std;
using ll = long long;

ll modperm(ll n, ll r, ll d) {
	return
		r == 0 ? 1 :
		n * modperm(n - 1, r - 1, d) % d;
}

ll modpow(ll a, ll p, ll d) {
	return
		p == 0 ? 1 :
		p == 1 ? a % d :
		p % 2 == 0 ? modpow(a, p / 2, d) * modpow(a, p / 2, d) % d :
		modpow(a, p - 1, d) * a % d;
}

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

	ll const DIV = 1000000007;
	int N;
	cin >> N;

	if (N < 2) {
		cout << 0 << "\n";
	} else {
		cout << (modpow(10, N, DIV) - modpow(9, N, DIV) * 2 + modpow(8, N, DIV) + DIV * 2) % DIV << "\n";
	}
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
//#include <boost/range/algorithm/find_if.hpp>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    int sum = 0;
    rep(i, M){
        cin >> A[i];
        sum += A[i];
    }
    if(N >= sum){
        cout << N - sum << endl;
    }else{
        cout << -1 << endl;
    }

     

return 0;}
/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	string s;
	//bit
	cin>>s;
	int n=s.size();
	ll ans=0;
	for(int bit=0;bit<(1<<n-1);++bit){//最後の桁でflagを立てるか立てないかで結果は変わらず、同じ者が出てくるためn-1まで
		ll cul=0;
    	for(int i=0;i<n;++i){
			cul*=10;
			cul+=(int)(s[i]-'0');
    		if(bit&1<<i){
				ans+=cul;
				cul=0;
			}
		}	
		ans+=cul;
	}
	cout<<ans<<endl;
}


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

int main() {
	
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int sum = 0;
		int tmp = i;
		while(tmp){
			sum += tmp % 10;
			tmp /= 10;
		}
		if(sum >= a && sum <= b) ans += i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,len;
	char x[1005];
	scanf("%s",&x);
	len=strlen(x);
	for(i=0;i<len;i++) {
		if(x[i]>='A' && x[i]<='C') {
			x[i]+=('X'-'A');
		}
		else if(x[i]>='D' && x[i]<='Z') {
			x[i]-=('D'-'A');
		}
	}
	printf("%s\n",x);
	return 0;
}

Measured memory_bytes: 520
import sys
from datetime import datetime


y = 2004

#input_file = open(sys.argv[1], 'r')

for line in sys.stdin:
    (m, d) = tuple(map(int, line.split(' ')))
    if m == 0:
        break
    date = datetime(y, m, d)
    print date.strftime("%A")

Measured memory_bytes: 4496
#include <stdio.h>

int main(void){

  int n,m;
  int i,j,k,l;
  int s;
  int taro[100],hanako[100];
  int t=0;

  for(;;){
    scanf("%d %d",&n,&m);
    if(n==0&&m==0)break;
    
    for(i=0;i<n;i++){
      scanf("%d",&s);
      taro[i]=s; 
    }

    for(i=0;i<m;i++){
      scanf("%d",&s);
      hanako[i]=s; 
    }

    int thsum=200;
    int tarocard=101,hanakocard=101;
  
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
        int tarosum=0,hanakosum=0;
        t=taro[i];
        taro[i]=hanako[j];
        hanako[j]=t;
        for(k=0;k<n;k++)
          tarosum+=taro[k];
        for(k=0;k<m;k++)
          hanakosum+=hanako[k];
        if(tarosum==hanakosum&&thsum>=taro[i]+hanako[j]){
          hanakocard=taro[i];
          tarocard=hanako[j];
          thsum=taro[i]+hanako[j];
        }
        t=taro[i];
        taro[i]=hanako[j];
        hanako[j]=t;
      }
    }
    if(tarocard==101||hanakocard==101)printf("-1\n");
    else printf("%d %d\n",tarocard,hanakocard);

    }

  return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n,ans=0;
    lli i,j;
    vector<bool> boo;
    cin>>n;
    rep(i,0,n){
        lli p;
        cin>>p;
        if(i+1==p){
            boo.push_back(true);
        }
        else{
            boo.push_back(false);
        }
    }
    rep(i,0,n){
        if(boo[i]==true){
            ans++;
            i++;
        }
    }
    cout<<ans<<endl;
}


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

typedef long long int lli;

int main(void){
  lli N,K;
  cin >> N >> K;
  int count = 1;
  lli num = K;
  lli x = N;
  while(true){
    if((int)(x/num) == 0){
      break;
    }else{
      num = num * K;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
typedef long long int ll;

void input(){
   int n; cin >>n;
   vector<double>a(n);
    priority_queue<double, vector<double>, greater<double> >pq;
   f(i, n)cin>>a[i], pq.push(a[i]);
  while(pq.size() > 1){
    double x = pq.top();pq.pop();
    double y = pq.top(); pq.pop();
    pq.push((x + y) / 2.0);
  }
  cout <<fixed<<showpoint<<setprecision(6) << pq.top() << endl;
}
int main()
{
 input();
 return 0;
}


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

using namespace std;

const int N = 2e5;

int n,m;
int arr[N+5], tree[4*N + 5], tree2[4*N + 5];

void build(int idx, int l, int r){
	if(l == r){
		tree[idx] = arr[l];
		return;
	}
	int mid = (l + r) / 2;
	build(idx*2,l,mid);
	build(idx*2+1,mid+1,r);
	tree[idx] = max(tree[idx*2], tree[idx*2+1]);
}

int query(int idx, int l, int r, int a, int b){
	if(l >= a && r <= b) return tree[idx];
	if(l > b || r < a) return 0;
	int mid = (l + r) / 2;
	return max(query(idx*2, l, mid, a, b), query(idx*2+1, mid+1, r, a, b));
}

void build2(int idx, int l, int r){
	if(l == r){
		tree2[idx] = arr[l];
		return;
	}
	int mid = (l + r) / 2;
	build2(idx*2,l,mid);
	build2(idx*2+1,mid+1,r);
	tree2[idx] = min(tree2[idx*2], tree2[idx*2+1]);
}

int query2(int idx, int l, int r, int a, int b){
	if(l >= a && r <= b) return tree2[idx];
	if(l > b || r < a) return N + 5;
	int mid = (l + r) / 2;
	return min(query2(idx*2, l, mid, a, b), query2(idx*2+1, mid+1, r, a, b));
}

void update(int idx, int& ct1, int& ct2, int v){
	if(arr[idx] > arr[idx+1]) ct1 += v;
	else ct2 += v;
}

int main(){
	cin >> n >> m;
	for(int i=1; i<=n; i++){
		cin >> arr[i];
	}
	build(1,1,n);
	build2(1,1,n);
	int ans = 1;
	bool flag = false;
	int ct1 = 0, ct2 = 0;
	for(int i=1; i<m; i++){
		update(i, ct1, ct2, 1);
	}
	if(ct1 == 0) flag = true;
	for(int i=m+1; i<=n; i++){
		update(i-1, ct1, ct2, 1);
		update(i-m, ct1, ct2, -1);
		int q1 = query(1,1,n,i-m+1,i-1);
		int q2 = query2(1,1,n,i-m+1,i-1);
		if(q1 > arr[i]) ans++;
		else if(q2 < arr[i-m]){
			if(ct1 == 0 && flag) continue;
			if(ct1 == 0) flag = true;
			ans++;
		}
//		printf("%d : %d, %d %d\n",i,ans,ct1,ct2);
	}
//	printf("ans %d, cnt %d\n",ans,cnt);
//	ans -= (cnt - 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7168
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

static const int MAX_V = 110;
static const int INF = (1<<30);

typedef pair<int, int> P;

struct edge{ int to, cap, cost, rev;};

int V;
vector<edge> G[MAX_V];
int h[MAX_V], dist[MAX_V], prevv[MAX_V], preve[MAX_V];

void add_edge(int from, int to, int cap, int cost){
	G[from].push_back((edge){to, cap, cost, (int)G[to].size()});
	G[to].push_back((edge){from, 0, -cost, (int)G[from].size()-1});
}

int min_cost_flow(int s, int t, int f){
	int res = 0;
	fill(h, h + V, 0);
	while (f > 0){
		priority_queue<P, vector<P>, greater<P> > que;
		fill(dist, dist + V, INF);
		dist[s] = 0;
		que.push(P(0, s));
		while (!que.empty()){
			P p = que.top(); que.pop();
			int v = p.second;
			if (dist[v] < p.first) continue;
			for (int i = 0; i < G[v].size(); ++i)
			{
				edge &e = G[v][i];
				if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(P(dist[e.to], e.to));
				}
			}
		}
		if (dist[t] == INF) return -1;
		for (int v = 0; v < V; ++v) h[v] += dist[v];

		int d = f;
	    for (int v = t; v != s; v = prevv[v]) d = min(d, G[prevv[v]][preve[v]].cap);
	    f -= d;
	    res += d * h[t];
	    for (int v = t; v != s; v = prevv[v])
	    {
	    	edge &e = G[prevv[v]][preve[v]];
	    	e.cap -= d;
	    	G[v][e.rev].cap += d;
	    }
	}
	return res;
}

int main(int argc, char const *argv[])
{
	int E, F;
	cin >> V >> E >> F;
	for (int i = 0; i < E; ++i)
	{
		int s, t, c, d;
		cin >> s >> t >> c >> d;
		add_edge(s, t, c, d);
	}
	cout << min_cost_flow(0, V-1, F) << endl;
	return 0;
}


Measured memory_bytes: 3200
n = int(input())
a,b = map(int, input().split())
lis = list(map(int, input().split()))

lis = sorted(lis, reverse=True)

cnt = 0
for i in range(n):
    tmp = []
    for j in lis:
        if j >= b+1:
            tmp.append(j)
            break
    for k in lis:
        if a+1 <= k <= b:
            tmp.append(k)
            break
    
    for l in lis:
        if l <= a:
            tmp.append(l)
            break
    
    if len(tmp) == 3:
        cnt += 1
    
    for x in tmp:
        lis.remove(x)

print(cnt)


Measured memory_bytes: 9124
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int a, b, m; cin >> a >> b >> m;
    vector<int> A(a), B(b);
    int min_A = INF, min_B = INF;
    rep(i, a){
        cin >> A[i];
        chmin(min_A, A[i]);
    }
    rep(i, b){
        cin >> B[i];
        chmin(min_B, B[i]);
    }
    int res = min_A + min_B;
    rep(i, m){
        int x, y, c; cin >> x >> y >> c; x--, y--;
        chmin(res, A[x] + B[y] - c);
    }
    cout << res << ln;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 200005;
const int INF = (LL)1e9 + 5;
const LL MOD = 998244353;

#define pos first
#define pw second

int N;
LL a[MAXN], cnt1[MAXN], cnt2[MAXN];

void solve(LL *cnt) {
	vector<PII> stk;
	stk.push_back({N, INF});
	
	cnt[N - 1] = 0;
	for (int i = N - 2; i >= 0; i--) {
		LL add = 0;
		
		if (a[i] > a[i + 1]) {
			LL tmp = a[i + 1];
			while (a[i] > tmp) {
				tmp *= 4;
				add += (stk.back().pos - (i + 1)) * 2;
				stk.back().pw--;
				if (stk.back().pw <= 0) stk.pop_back();
			}
		}
		else {
			LL pw = 0, tmp = a[i];
			while (tmp <= a[i + 1]) {
				tmp *= 4;
				pw += 1;
			}
			if (pw > 1) stk.push_back({i + 1, (int)pw - 1});
		}
		
		cnt[i] = cnt[i + 1] + add;
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	
	solve(cnt1);
	reverse(a, a + N);
	for (int i = 0; i < N; i++) a[i] *= 2;
	solve(cnt2);
	reverse(cnt2, cnt2 + N);
	for (int i = 0; i < N; i++) cnt2[i] += (i + 1);
	
	LL ans = min(cnt1[0], cnt2[N - 1]);
	for (int i = 0; i < N - 1; i++) {
		ans = min(ans, cnt2[i] + cnt1[i + 1]);
	}
	
	cout << ans << "\n";
}


Measured memory_bytes: 4992
N, X, Y = map(int,input().split())

A = [0]*(N-1)

t = 0
for i in range(N):
    for j in range(N-1-i):
        t = min(j+1,abs(X-i-1)+abs(Y-j-i-2)+1)
        A[t-1] += 1

for e in A:
    print(e)

Measured memory_bytes: 46172
s = input()
res = ""

for i in range(len(s)):
    if 65 <= ord(s[i]) and ord(s[i]) <= 90:
        res += chr(ord(s[i]) + 32)
    elif 97 <= ord(s[i]) and ord(s[i]) <= 122:
        res += chr(ord(s[i]) - 32)
    else:
        res += s[i]

print(res)



Measured memory_bytes: 5560
import numpy
from scipy.misc import comb
import math
import collections

n = int(input())
a = list(map(int,input().split()))

cumulative_sum = numpy.cumsum(a)
cumulative_sum = numpy.append(cumulative_sum, 0)
count = collections.Counter(cumulative_sum)

ret = 0
for v in count.values():
    if v < 2:
        continue
    ret += math.factorial(v) // (math.factorial(v - 2) * math.factorial(2)) 
print(ret)




Measured memory_bytes: 46684
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;

const int Inf = 100000;
const int mod = 1000000007;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

unsigned long long h, w;

void Solve()
{
	cin >> h >> w;
	if(h == 1 or w == 1)
	{
		cout << 1;
		return;
	}
	if(h % 2 == 0)
	{
		cout << h / 2 * w;
	}
	else
	{
		cout << (h - 1) / 2 * w + (w + 1) / 2;
 	}
}

int main()
{
	Solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	string s,t;
    cin>>s>>t;
    int sum=0;
  	for(int i=0;i<3;i++){
      if(s[i]==t[i]){
        sum++;
      }
    }
  
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
#define chmax(a,b) a=max(a,b);
#define chmin(a,b) a=min(a,b);
ll po(ll x,ll y){
  ll res=1;
  for(;y;y>>=1){
    if(y&1)mul(res,x);
    mul(x,x);
  }
  return res;
}
#define N 200010
typedef pair<ll,ll> P;
ll l[N],r[N],f[N],n;
vector<P> v;
vector<ll> yset;
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    ll x,y; cin>>x>>y;
    v.push_back(make_pair(x,y));
    yset.push_back(y);
  }
  sort(yset.begin(),yset.end());
  sort(v.begin(),v.end());
  ll ma=-1;
  for(int i=0;i<n;i++){
    chmax(ma,v[i].second);
    r[i]=lower_bound(yset.begin(),yset.end(),ma)-yset.begin();
  }
  ll mi=1e10;
  for(int i=n-1;i>=0;i--){
    chmin(mi,v[i].second);
    l[i]=lower_bound(yset.begin(),yset.end(),mi)-yset.begin();
  }
  //for(int i=0;i<n;i++)cout<<i<<":"<<l[i]<<" "<<r[i]<<endl;
  for(int i=0;i<n;i++)f[i]=0; f[0]=1;
  ll bef=0,sum=1,p=0;
  for(int i=0;i<n;i++){
    for(;p<n&&r[p]==i;p++){
      for(;bef<l[p];bef++)mad(sum,-f[bef]);
      mad(f[r[p]+1],sum);
      mad(sum,sum);
    }
  }
  if(f[n]<0)f[n]+=mod;
  cout<<f[n]<<endl;
  return 0;
}


Measured memory_bytes: 12780
#include<bits/stdc++.h>
typedef long long LL;
typedef double dl;
#define opt operator
#define pb push_back
const LL maxn=1e6+9,mod=998244353;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
LL n,K,s,t;
LL f[maxn],C[61][61],g[61],vis[61],a[maxn],mark[maxn],pos[maxn],lg[maxn];
int main(){
    n=Read(); K=Read(); s=Read(); t=Read();
    for(LL i=1;i<=n;++i){
    	a[i]=Read();
	}
	LL tot(0);
    for(LL i=0;i<18;++i){
    	if((s&(1<<i))==(t&(1<<i))){
    		for(LL j=1;j<=n;++j) if((a[j]&(1<<i))!=(s&(1<<i))){
    			vis[j]=1;
			}
		}else{
			mark[i]=1; pos[i]=tot++;
		}
	}
	//for(LL j=1;j<=n;++j) printf("%d ",vis[j]); puts("");
	for(LL j=1;j<=n;++j){
		LL ret(0);
		for(LL i=0;i<18;++i) if(mark[i]){
			ret+=((a[j]&(1<<i))?(1<<pos[i]):0);
		}
		a[j]=ret;
	}
	//for(LL j=1;j<=n;++j) printf("%d ",a[j]); puts("");
	LL up((1<<tot)-1);
	C[0][0]=1;
	for(LL i=1;i<=n;++i){
		C[i][0]=1;
		for(LL j=1;j<=i;++j){
			C[i][j]=C[i-1][j-1]+C[i-1][j];
		}
	}
	for(LL i=1;i<=n;++i){
		for(LL j=1;j<=K;++j) g[i]+=C[i][j];
	}
	for(LL i=1;i<=up;++i){
		lg[i]=lg[i-(i&-i)]+1;
	}
	LL ans(0);
	for(LL i=0;i<=up;++i){
		for(LL j=1;j<=n;++j){
			if(vis[j]) continue;
			f[a[j]&i]++;
		}
		LL ret(0);
		for(LL j=1;j<=n;++j){
			LL tmp(a[j]&i);
			ret+=g[f[tmp]];
			f[tmp]=0;
		}
		if(lg[i]&1) ans-=ret;
		else ans+=ret;
	}
	printf("%lld\n",ans);
	return 0;
}


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

typedef long long ll;

ll N,X;
ll ans = 0;

int main()
{
    scanf("%lld%lld",&N,&X);
    ans += N;
    ll a = X,b = N - X;
    while(1)
    {
        if(a > b)swap(a,b);
        if(a == 0)
        {
            ans -= b;
            break;
        }
        ans += b / a * a * 2;
        b %= a;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
// ARC094
// C - Same Integers

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

int a[3];

int main() {
    cin >> a[0] >> a[1] >> a[2];

    int max_a = *max_element(a, a + 3);
    int s = a[0] + a[1] + a[2];
    int ans = (3 * (max_a + (3 * max_a - s) % 2) - s) / 2;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s[105],t[105];
vector<int> ans;
int n,m;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>s[i];
	cin>>m;
	for(int i=0;i<m;i++)
		cin>>t[i];
	for(int i=0;i<n;i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++)
		{
			if(s[i]==s[j])
				cnt++;
		}
		for(int j=0;j<m;j++)
		{
			if(s[i]==t[j])
				cnt--;
		}
		ans.push_back(cnt);
	}
	for(int i=0;i<m;i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++)
		{
			if(t[i]==s[j])
				cnt++;
		}
		for(int j=0;j<m;j++)
		{
			if(t[i]==t[j])
				cnt--;
		}
		ans.push_back(cnt);
	}
	sort(ans.begin(),ans.end(),greater<int>());
	cout<<max(0,ans[0]);
	return 0;
}

Measured memory_bytes: 256
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

int main(void) {
  ll N, X;
  cin >> N >> X;
  vector<ll> x(N);
  rep(i, N) {
    cin >> x[i];
  }

  if (N == 1) {
    cout << abs(X - x[0]) << endl;
    return 0;
  }


  ll D = gcd(abs(X - x[0]), abs(X - x[1]));
  for (int i = 2; i < N; ++i) {
    D = gcd(D, (ll)abs(X - x[i]));
  }

  cout << D << endl;

  return 0;
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long H;
    cin>>H;
    long long suma = 0;
    long long ile = 1;
    while(H)
    {
        suma+=ile;
        ile*=2;
        H/=2;
    }
    cout<<suma;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  char str[4];

  scanf("%s",str);

  for(int i=0;i<3;i++)
    if(str[i]=='1')
      str[i]='9';
    else
      str[i]='1';

  printf("%s\n",str);
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll h, w, d, a;std::cin >> h >> w >> d;
  vvl k = vv(h*w+1, 2, 0, ll);
  vll ne(h*w+1, 0);

  re(i, h) {
    re(j, w) {
      std::cin >> a;
      k[a] = vll{i, j};
    }
  }
  rep(i, 1, h*w+1){
    if(i-d<=0) continue;
    ne[i] = abs(k[i][0]-k[i-d][0]) + abs(k[i][1]-k[i-d][1]);
  }
  rep(i, 1, h*w+1) ne[i] += (i<=d?0:ne[i-d]);
  ll q;std::cin >> q;
  re(i, q){
    ll l, r;std::cin >> l >> r;
    std::cout << ne[r] - ne[l] << '\n';
  }
  return 0;
}


Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll M;
    cin >> M;
    ll sum = 0, digit = 0;
    rep(i,0,M){
        ll a,b;
        cin >> a >> b;
        sum += a * b;
        digit += b;
    }
    ll ans = sum / 9 + digit - 1;
    if(sum % 9 == 0)ans--;
    cout << ans << endl;
}

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

#define BUF_SIZE 20

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(char *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define HEIGHT_MAX 10
#define WIDTH 5
#define SET_MAX 10000
#define HEIGHS 3
#define BOARD_MAX (HEIGHT_MAX*(WIDTH+1))

void display(char *array, int width) {
    int j;
    for(j = 0; j < width; j++) {
        printf("%d ", array[j]);
    }
    putchar('\n');
    return;
}

int judge(char *arr, int size) {
    char cur = arr[0];
    int cnt = 1;
    int i, j;
    int score = 0;
    for(i = 1; i < size; i++) {
        char next = arr[i];
        if(cur == next) {
            cnt++; continue;
        }
        if(cnt >= HEIGHS) {
            score += cnt*cur;
            // disappeared until previous ball
            for(j = i-cnt; j <= i-1; j++) {
                // when disappearred, labeled as 0
                arr[j] = 0;
            }
        }
        cur = next; cnt = 1;
    }
#ifdef DEBUG
    printf("score: %d\n", score);
#endif
    return score;
}

int main(void) {
    int i;
    int scores[SET_MAX];
    int idx = 0;
    while(1) {
        int height = get_int();
        if(!height) break;
        // array[*][WIDTH]: guard(0)
        char array[HEIGHT_MAX][WIDTH+1] = {0};

        // 0: highest
        for(i = height-1; i >= 0; i--) {
            fget_array(array[i], WIDTH);
        }
        int score = 0;
        while(1) {
            int w, h;
            char newbuf[HEIGHT_MAX][WIDTH+1] = {0};
#ifdef DEBUG
            // display currrent board
            for(i = height-1; i >= 0; i--) {
                display(array[i], WIDTH+1);
            }
#endif
            // judge
            int new_score = 0;
            for(h = 0; h < height; h++) {
                new_score += judge(array[h], WIDTH+1);
            }
            if(!new_score) break;
            score += new_score;
            // drop
            for(w = 0; w < WIDTH; w++) {
                int idx = 0;
                for(h = 0; h < height; h++) {
                    char cur = array[h][w];
                    if(!cur) continue;
                    newbuf[idx++][w] = cur;
                }
            }
            // replace array with new
            memcpy(array[0], newbuf[0], BOARD_MAX);
        }
        scores[idx++] = score;
    }
    for(i = 0; i < idx; i++) {
        printf("%d\n", scores[i]);
    }
    return 0;
}


Measured memory_bytes: 2052
<?php

while (true) {
    $map = array();
    for ($i = 0; $i < 8; $i++) {
        $line = trim(fgets(STDIN));
        if ($line === '') {
            break 2;
        }
        $map[$i] = str_split($line);
    }

    foreach ($map as $y => $arr) {
        foreach ($arr as $x => $n) {
            if ($n !== '1') {
                continue;
            }
            echo search($map, $x, $y), PHP_EOL;
            break 2;
        }
    }
    //空行を取り除く
    fgets(STDIN);
}

//最初に見つけた点から調べる
function search($map, $x, $y)
{
    $right = isset($map[$y][$x + 1]) && $map[$y][$x + 1] === '1';
    $bottomRight = isset($map[$y + 1][$x + 1]) && $map[$y + 1][$x + 1] === '1';
    $bottom = isset($map[$y + 1][$x]) && $map[$y + 1][$x] === '1';
    $bottomLeft = isset($map[$y + 1][$x - 1]) && $map[$y + 1][$x - 1] === '1';

    //右、右下、下に点が存在するのはA
    if ($right && $bottomRight && $bottom) {
        return 'A';

    //右、右下に点が存在するのはE
    } elseif ($right && $bottomRight) {
        return 'E';

    //右、下に点が存在するのはG
    } elseif ($right && $bottom) {
        return 'G';

    //右下、下に点が存在するのはF
    } elseif ($bottomRight && $bottom) {
        return 'F';

    //右に点が存在するのはC
    } elseif ($right) {
        return 'C';

    //左下に点が存在するのはD
    } elseif ($bottomLeft) {
        return 'D';

    //残りはB
    } else {
        return 'B';
    }
}

Measured memory_bytes: 6672
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;
ll dp[1000100][2];


int main(){
    int n;
    cin>>n;
    vector<vector<P> > v(n);
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        while(a){
            a--;
            int x,y;
            cin>>x>>y;
            x--;
            v[i].push_back(P(x,y));
        }
    }
    int ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        vector<int> justice;
        vector<int> unjus;
        for(int i=0;i<n;i++){
            if(1 & bit>>i){
                justice.push_back(i);
            }else{
                unjus.push_back(i);
            }
        }

        vector<bool> f(n,false);
        bool flag=true;

        for(int i:justice){
            f[i]=true;
        }
        for(int i:unjus){
            f[i]=false;
        }
        for(int i:justice){
            for(int j=0;j<v[i].size();j++){
                int x=v[i][j].first;
                int y=v[i][j].second;
                y=(bool)y;
                if(f[x]!=y){
                    flag=false;
                    break;
                }
            }
            if(!flag) break;
        }
        if(flag) ans=max(ans,(int)justice.size());
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3632
mat = []
for i in range(10):
    mat.append([0]*10)

while True:
    try:
        lst = list(map(int, input().split(',')))
        x, y, s = lst[0], lst[1], lst[2]
        
        if s == 1:
            tmplst = [[x, y], [x, y-1], [x-1, y], [x+1, y], [x, y+1]]

        elif s == 2:
            tmplst = [[x, y], [x, y-1], [x-1, y], [x+1, y], [x, y+1], [x-1, y-1], [x+1, y-1], [x-1, y+1], [x+1, y+1]]

        else:
            tmplst = [[x, y], [x, y-1], [x-1, y], [x+1, y], [x, y+1], [x-1, y-1], [x+1, y-1], [x-1, y+1], [x+1, y+1], [x, y-2], [x-2, y], [x+2, y], [x, y+2]]

        for i in tmplst:
            if i[0] < 0 or i[0] > 9 or i[1] < 0 or i[1] > 9:
                pass
            else:
                mat[i[1]][i[0]] +=1
        
    except EOFError:
        break

summat = 0
maxmat = 0
for j in mat:
    summat += j.count(0)
    if maxmat < max(j):
        maxmat = max(j)

print(summat)
print(maxmat)



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

const int INF = 1e9 + 10;

bool operator<(const pair<int, int> &p1, const pair<int, int> &p2) {
  return p1.first < p2.first;
};
int main() {
  long long n;
  cin >> n;
  vector<long long> A(n);
  for (long long i = 0; i < n; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  priority_queue<pair<long long, long long>> pQ;
  pQ.push({A[1], A[0]});
  pQ.push({A[1], A[0]});
  long long ans = A[0];
  for (long long i = 2; i < n; i++) {
    pair<long long, long long> biggest = pQ.top();
    pQ.pop();
    ans += biggest.first;
    pQ.push({A[i], biggest.first});
    pQ.push({A[i], biggest.second});
  }
  cout << ans << endl;
}


Measured memory_bytes: 9036
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int n, a[100010], c, ans=999999999;
    pair<int, int> cnt[100010], cnto[100010];
    memset(cnt, 0, sizeof(cnt));
    memset(cnto, 0, sizeof(cnto));
    cin>>n;
    for (int i=0; i<n; i++) cin>>a[i];
    for (int i=0; i<100005; i++) { cnt[i].second=i; cnto[i].second=i; }
    for (int i=0; i<n; i++)
    {
        if (i%2==0) cnt[a[i]].first++;
        else cnto[a[i]].first++;
    }
    sort(cnt, cnt+100005); reverse(cnt, cnt+100005);
    sort(cnto, cnto+100005); reverse(cnto, cnto+100005);
    for (int i=0; i<100005; i++)
    {
        bool ok=false;
        for (int j=0; j<100005 && !ok; j++)
        {
            if (cnt[i].second!=cnto[j].second)
            {
                ans=min(ans, n-cnt[i].first-cnto[j].first);
                ok=true;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main(void) {
  int N, M; cin >> N >> M;

  for (int i = 0; i < M; i++) {
    int a; cin >> a;
    N -= a;
  }

  cout << (N < 0 ? -1 : N) << endl;

  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

inline void work() {
    int K;
    string S;
    cin >> K;
    cin >> S;
    if (S.size() <= K)
        cout << S;
    else
        cout << S.substr(0, K) + "...";
}

int main() {
    // freopen(".txt", "r", stdin);
    quickread();
    work();
   
    return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define all(x) (x).begin(),(x).end()

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

    vector<int> v(n, 0);
    rep(i, n) {
        cin >> v.at(i);
    }
    int ans = 0;
    rep(i, n) {
        if (v.at(i) >= k) {
            ans++;
        }
    }
    
    cout << ans << endl;
}


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

int main(void) {
    int N;cin>>N;
    vector<double> vc;
    for (int i = 0; i < N; i++) {
        double v;cin>>v;
        vc.push_back(v);
    }
    sort(vc.begin(), vc.end());
    double cur = vc.at(0);
    for (int i = 1; i < N; i++) {
        cur = (vc.at(i) + cur) / 2.0;
    }
    printf("%.6f\n", cur);
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    map<int, bool> fr, fg, fb;
    vector<int> r, g, b;
    rep (i, n) {
        if (s[i] == 'R') {fr[i] = true; r.push_back(i);}
        if (s[i] == 'G') {fg[i] = true; g.push_back(i);}
        if (s[i] == 'B') {fb[i] = true; b.push_back(i);}
    }
    int bs = b.size();
    ll ans = 0;
    for (int i : r) {
        for (int j : g) {
            int x = (i + j) / 2, y, z;
            if (j > i) {
                y = j + (j - i);
                z = i - (j - i);
            } else {
                y = i + (i - j);
                z = j - (i - j);
            }
            ans += bs;
            eprintf("%d %d : %d %d %d\n", i, j, x, y, z);
            if ((j - i) % 2 == 0 && fb[x]) ans--;
            if (y < n && fb[y]) ans--;
            if (z >= 0 && fb[z]) ans--;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3992
#include <stdio.h>
#include <string.h>
int main(void)
{
char s[1000];
int n;
int ACcount = 0;
int WAcount = 0;
int TLEcount = 0;
int REcount = 0;

scanf("%d",&n);
for (int i = 1; i <=n; i++){
scanf("%s",s);

 if(strcmp(s,"AC")==0){
    ACcount++;
}else if(strcmp(s,"WA")==0){
    WAcount++;
}else if(strcmp(s,"TLE")==0){
    TLEcount++;
}else if(strcmp(s,"RE")==0){
    REcount++;
  }
 }

printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",ACcount,WAcount,TLEcount,REcount);
  return 0;
 }


Measured memory_bytes: 1736
#include <stdio.h>
#include <stdlib.h>

#define M 100000

int aa[M], bb[M];

int compare(const void *a, const void *b) {
	int i = *(int *) a;
	int j = *(int *) b;

	return aa[i] - aa[j];
}

int main() {
	static int ii[M];
	int n, m, i, b, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d%d", &aa[i], &bb[i]);
		ii[i] = i;
	}
	qsort(ii, m, sizeof *ii, compare);
	ans = 1;
	b = n + 1;
	for (i = 0; i < m; i++) {
		if (aa[ii[i]] >= b) {
			ans++;
			b = n + 1;
		}
		if (b > bb[ii[i]])
			b = bb[ii[i]];
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h> 
using namespace std;
 
const long long MOD = (long long)1e9 + 7;
int n, m,a[1100],b[1100];

 
int main()
{
	bool check();
    
	while(cin>>n>>m)
    {
         for (int i=1;i<=n;++i) 
		    scanf("%d", a + i);
         for (int i=1;i<=m;++i)
		    scanf("%d", b + i);
         
		 sort(a+1,a+1+n);
         sort(b+1,b+1+m);
         
		 if(!check()) 
		 cout<<0; 
         
		 else
         {
             a[n+1]=n+1;
             b[m+1]=m+1;
             
			 int l[2]={0,0};
             long long res=1; 
             
			 for(int i=1;i<=n*m;++i)
             {
                while(l[0]<=n&&a[l[0]]<i)
				   l[0]++; 
                while(l[1]<=m&&b[l[1]]<i)
				   ++l[1];
                long long d=0;
                    if(a[l[0]]==i&&b[l[1]]==i)
                        d=1;
                
				else if(a[l[0]]==i&&b[l[1]]!=i)
                        d=m-l[1]+1;
                else if(b[l[1]]==i&&a[l[0]]!=i)
                        d=n-l[0]+1;
                else
                    d=(m-l[1]+1)*(n-l[0]+1)-(n*m-i);
                res=(res*d)%MOD; 
             } 
             cout<<res;
         }
     }
     return 0;
 }  
bool check()
{
    for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
	        if(a[i]==a[j]) 
				return false;
    
	for(int i=1;i<=m;++i) 
		for(int j=i+1;j<=m;++j)
	        if(b[i]==b[j]) 
				return false; 
    
	return true; 
}

Measured memory_bytes: 256
#include<stdio.h>
double max(double a,double b){return a>b?a:b;}
int main(){
	int n,m;
	int i,j,k;
	double dp[2][100];
	double ch[100][100];
	while(1){
	scanf("%d %d",&n,&m);
	if(n==0)return 0;
	for(i=0;i<n;i++)for(j=0;j<n;j++)scanf("%lf",&ch[i][j]);
	for(i=0;i<n;i++)dp[0][i]=1.0f;
	for(i=1;i<m;i++){
		for(j=0;j<n;j++){
			dp[i%2][j]=0.0f;
			for(k=0;k<n;k++)dp[i%2][j]=max(dp[i%2][j],dp[(i+1)%2][k]*ch[k][j]);
		}
	}
	double ans=0.0f;
	for(i=0;i<n;i++)ans=max(ans,dp[(m+1)%2][i]);
	printf("%.2lf\n",ans);
	}
}

Measured memory_bytes: 744
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
const long long int mod = 100000;//10^5
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

ll n,k;
ll a[100001]={0};
ll ct[60]={0};

int main(){
	cin>>n>>k;
	rep(i,n)cin>>a[i];
	rep(i,60){
		rep(j,n){
			if(a[j]&(1LL<<i)){
				ct[i]++;
			}
		}
	}
	ll ans = 0;
	bool tight = true,begin = false;
	for(int i = 60;i>=0;i--){
		if(!tight){
			if(ct[i]>n-ct[i]){
				ans &= ~(1LL<<i);
			}else{
				ans |= (1LL<<i);
			}
		}else{
			if(k&(1LL<<i)){
				begin = true;
				if(ct[i]>n-ct[i]){
					ans &= ~(1LL<<i);
					tight = false;
				}else{
					ans |= (1LL<<i);
				}
			}else{
				if(begin)ans &= ~(1LL<<i);
			}
		}
	}
	//cout<<ans<<endl;
	ll sum = 0;
	rep(i,n){
		sum += a[i] ^ ans;
	}
	cout<<sum<<endl;
}

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

int main() {
  int N, D, ans;
  cin >> N >> D;
  if (N % ( 2 * D + 1) == 0){
    ans = N / ( 2 * D + 1);
  }
  else{
  	ans = N / (2 * D + 1) + 1;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int flag, num, cnt = 0;
		
		for(int i = 0; i < n; i++) {
			flag = 0;
			
			num = sc.nextInt();
			
			if(num % 2 == 0 && num != 2) {
				flag = 1;
			}
			
			for(int j = 3; j <= Math.sqrt(num) && flag == 0; j+=2) {
				if(num % j == 0) {
					flag = 1;
					break;
				}
			}
			
			if(flag == 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 41760