akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

struct edge {int to; int weight;};
typedef pair<int, int> P;

int main() {
    int N;
    cin >> N;
    vector<P> x(N), y(N);
    for(int i=0; i<N; ++i) {
        int s, t;
        cin >> s >> t;
        x[i] = P(s, i);
        y[i] = P(t, i);
    }

    sort(begin(x), end(x));
    sort(begin(y), end(y));

    vector<vector<edge>> cost(N, vector<edge>(0));
    for(int i=0; i+1<N; ++i) {
        cost[x[i].second].push_back({x[i+1].second, x[i+1].first - x[i].first});
        cost[x[i+1].second].push_back({x[i].second, x[i+1].first - x[i].first});
        cost[y[i].second].push_back({y[i+1].second, y[i+1].first - y[i].first});
        cost[y[i+1].second].push_back({y[i].second, y[i+1].first - y[i].first});
    }
    
    // Prim's algorithm
    priority_queue<P, vector<P>, greater<P>> mincost;
    vector<bool> used(N, false);
    mincost.push(P(0,0));
    long long res = 0;

    while(!mincost.empty()) {
        P v = mincost.top(); mincost.pop();
        if(used[v.second]) continue;
        used[v.second] = true;
        res += v.first;

        for(edge e : cost[v.second]) {
            mincost.push(P(e.weight, e.to));
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 11636
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 整数の入力 高橋
		int T= sc.nextInt();
		// 整数の入力　青木
		int A = sc.nextInt();
		// 整数の入力　ループ回数
		int K = sc.nextInt();
		
		boolean aoki = false;
		for(int i = 0 ; i < K; i++){
			
			//trueなら青木
			if(aoki){
				
				//偶数
				if(A % 2 == 0){
					T += A / 2;
					A -= A / 2;
				}
				//奇数
				else{
					if(A  == 0){
						continue;
					}
					A -= 1;
					T += A / 2;
					A -= A / 2;
				}
				aoki = false;
			}
			else{
				//偶数
				if(T % 2 == 0){
					A += T / 2;
					T -= T / 2;
				}
				//奇数
				else{
					if(T  == 0){
						continue;
					}
					T -= 1;
					A += T / 2;
					T -= T / 2;
				}
				aoki = true;
			}
		}
		System.out.print(T + " ");
		System.out.print(A);
	}
}


Measured memory_bytes: 22100
from collections import deque
q = deque([])
n = int(input())
G = []
for i in range(n):
  u, k, *vvv = list(map(int, input().split()))
  G.append([v-1 for v in vvv])
visited = [False for _ in range(n)]
q.append(0)
dist = [-1 for _ in range(n)]
dist[0] = 0
while q:
  u = q.popleft()
  visited[u] = True
  for v in G[u]:
    if visited[v] == True:
      continue
    else:
      q.append(v)
      visited[v] = True
      dist[v] = dist[u] + 1
    
for i in range(n):
  print(i+1, dist[i])
  


Measured memory_bytes: 6036
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >>a>>b>>c;
    if(a<b){
        a=a;
        b=b;
    }else{
        int tmp=a;
        a=b;
        b=tmp;
    }
    
    if(b<c){
        b=b;
        c=c;
    }else{
        int wa=b;
        b=c;
        c=wa;
    }
    
    if(a<b){
        a=a;
        b=b;
    }else{
        int wq=a;
        a=b;
        b=wq;
    }
    cout<<a<<" "<<b<<" "<<c<<endl;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

ll lpa[40],lpb[40];
double dpa[40],dpb[40];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,a,b,p,q;
    cin >> n >> m >> a >> b >> p >> q;
    if(a == 1 && b == 1){
        ll cnt = m/(p+q);
        cout << min(m-min(n,cnt)*(p+q),abs(min(n,cnt+1)*(p+q)-m)) << "\n";
    }else{
        ll cnt = min(n,40LL);
        ll mid = cnt/2;
        lpa[0] = lpb[0] = dpa[0] = dpb[0] = 1;
        rep(i,cnt-1){
            lpa[i+1] = lpa[i] * a;
            lpb[i+1] = lpb[i] * b;
            dpa[i+1] = dpa[i] * a;
            dpb[i+1] = dpb[i] * b;
        }
        vl u,v;
        rep(i,(1 << mid)){
            ll val1 = 0;
            double ch1 = 0;
            rep(j,mid){
                if((i >> j) & 1){
                    val1 += p*lpa[j] + q*lpb[j];
                    ch1 += p*dpa[j] + q*dpb[j];
                }
            }
            if(ch1 <= 2*m){
                u.pb(val1);
            }
        }
        rep(i,(1 << (cnt-mid))){
            ll val2 = 0;
            double ch2 = 0;
            rep(j,cnt-mid){
                if((i >> j) & 1){
                    val2 += p*lpa[mid+j] + q*lpb[mid+j];
                    ch2 += p*dpa[mid+j] + q*dpb[mid+j];
                }
            }
            if(ch2 <= 2*m){
                v.pb(val2);
            }
        }
        // svec(u);
        // svec(v);
        sort(all(v));
        ll mn = (1LL << 60);
        rep(i,len(u)){
            int id = upper_bound(all(v),m-u[i]) - v.begin();
            if(id > 0){
                cmn(mn,m-(u[i]+v[id-1]));
            }
            if(id < len(v)){
                cmn(mn,(u[i]+v[id])-m);
            }
        }
        cout << mn << "\n";
    }
    return 0;
}

Measured memory_bytes: 23172
#include <cstdio>
#include <cstring>

const int N = 60, M = 1e3 + 10;

char s[N][M], x[M];
int t[M];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s%d", s[i], &t[i]);
  }
  scanf("%s", x);
  int ret = 0;
  for (int i = n - 1; i >= 0; --i) {
    if (strcmp(x, s[i]) == 0) break;
    ret += t[i];
  }
  printf("%d\n", ret);
  return 0;
}


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

template <class T> void readVal(vector<T>& vec, int idx) {
    T input;
    std::cin >> input;
    vec[idx] = input;
}

int main()
{
    int size;
    cin >> size;
    vector<int> x(size); 
    vector<int> y(size);
    for (int i = 0; i < size; i++) {
        readVal(x, i);
        readVal(y, i);
    }
    int ans(1), dir(0), vecx(0), vecy(0), new_vecx(0), new_vecy(0);
    for (int i = 0; i <= size; i++) {
        new_vecx = x[(i + 1) % size] - x[i % size];
        new_vecy = y[(i + 1) % size] - y[i % size];
        int cross_prod = (vecx * new_vecy - vecy * new_vecx);
        if (cross_prod != 0) {
            if (cross_prod * dir >= 0) {
                dir = cross_prod > 0 ? 1 : -1;
            }
            else {
                ans = 0;
                break;
            }
        }
        vecx = new_vecx;
        vecy = new_vecy;
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const int inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

int32_t main(void)
{
	IOS;
	int n, k; cin>>n>>k;
	vi a(n);
	for(int i = 0; i < n; i++)
		cin>>a[i];
	int dp[k+1]={};
	dp[0]=2;
	if(*min_element(all(a)) == 1)
		dp[1]=1;
	else dp[1]=2;
	for(int i = 2; i <= k; i++) {
		int f=0;
		for(int j = 0; j < n; j++) {
			if(i-a[j] >= 0 && dp[i-a[j]]==2) {
				f=1;
				dp[i]=1;
				break;
			}
		}
		if(!f)
			dp[i]=2;
	}
	if(dp[k]==1) cout<<"First"<<endl;
	else  cout<<"Second"<<endl;
	time();	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    cout << x + y / 2 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

typedef pair<int, int> point;

int H, W;
vector<int> coins;
vector<point> cells;

vector<pair<point, point>> ans;

int main(void) {
    cin >> H >> W;


    for (int h = 0; h < H; h++) {
        vector<int> tmp_coins(W);
        vector<point> tmp_cells(W);
        for (int w = 0; w < W; w++) {
            cin >> tmp_coins[w];
            tmp_cells[w] = {h, w};
        }
        if (h % 2 != 0) {
            reverse(tmp_coins.begin(), tmp_coins.end());
            reverse(tmp_cells.begin(), tmp_cells.end());
        }
        for (int w = 0; w < W; w++) {
            coins.push_back(tmp_coins[w]);
            cells.push_back(tmp_cells[w]);
        }
    }

    // for (int i = 0; i < H * W; i++) {
    //     printf("(%d, %d): %d\n", cells[i].first, cells[i].second, coins[i]);
    // }

    for (int i = 0; i < H * W - 1; i++) {
        if (coins[i] % 2 != 0) {
            ans.push_back({cells[i], cells[i + 1]});
            coins[i]--;
            coins[i + 1]++;
        }
    }

    printf("%d\n", (int) ans.size());
    for (auto &path : ans) {
        auto from = path.first;
        auto to = path.second;
        printf("%d %d %d %d\n", from.first + 1, from.second + 1, to.first + 1, to.second + 1);
    }

    return 0;
}


Measured memory_bytes: 7144
import java.util.Scanner;
public class Main {
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a<b){
            System.out.println("a < b");
        } else if(a>b){
            System.out.println("a > b");
        }
        else{
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26120
#include <iostream>

using namespace std;

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

	int h, m, s;
	
	h = S / 3600;
	m = (S - h * 3600) / 60;
	s = S - h * 3600 - m * 60;
	cout << h << ":" << m << ":" << s << endl;
}


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

int main(){
    string s;
    cin >> s;
    ll n = s.size();
    vector<vector<ll>> dp(n+10, vector<ll>(2));
    dp[0][0] = 0;
    dp[0][1] = 1;
    rep(i, 0, n) {
        ll cur = s[i] - '0';
        dp[i+1][0] = min(dp[i][0] + cur, dp[i][1] + (10 - cur));
        dp[i+1][1] = min(dp[i][0] + cur + 1, dp[i][1] + (9 - cur));
    }
    cout << dp[n][0] << endl;
    return 0;
}

Measured memory_bytes: 58888
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int minlength = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        string t = Console.ReadLine();
        for (int i = 0; i <= minlength; i++)
        {
            for (int j = i; j < minlength; j++)
            {
                if (s[j] != t[j - i]) goto end;
            }
            Console.WriteLine(minlength + i);
            return;
            end:;
        }
    }
}

Measured memory_bytes: 11092
while True:
    H, W = map(int, input().split())
    if H==0 and W==0:
        break
    
    for i in range(H):
        for j in range(W):
            if (j+i)%2 == 0:
                print('#',end='')
            else:
                print('.',end='')
        print('')
    
    print('')


Measured memory_bytes: 7012
def main():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(2)]

    dp = [[0] * N for _ in range(2)]
    dp[0][0] = A[0][0]

    for r in range(2):
        for c in range(N):
            if r != 0:
                dp[r][c] = max(dp[r - 1][c] + A[r][c], dp[r][c])
            if c != 0:
                dp[r][c] = max(dp[r][c - 1] + A[r][c], dp[r][c])
    print(dp[1][N - 1])


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;

int main()
{
  int N, K; scanf("%d %d", &N, &K);
  vector<ll> A(N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld", &A[i]);
  }
  sort(A.begin(), A.end(), greater<ll>());
  ll sum = 0;
  int ans = N;
  for (int i = 0; i < N; ++i) {
    if (sum + A[i] < K) {
      sum += A[i];
    }
    else {
      ans = min(ans, N - (i + 1));
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#n,k
n,k = (int(x) for x in input().split())

#wk=[[0] * n for i in range(k)]
#a=[]
wk=[]
cnt=0

while cnt<k:
    d=input()
    a = (int(x) for x in input().split())
    for i in a:
        wk.append(i)
    cnt+=1
#    print(cnt,wk)
wk=set(wk)
ans = n - len(wk)
print(ans)


Measured memory_bytes: 9148
import sys
from collections import deque

N, M = map(int, input().split())

Edge = [[] for _ in range(3*N)]

for _ in range(M):
    u, v = map(int, sys.stdin.readline().split())
    u -= 1
    v -= 1
    Edge[u].append(N + v)
    Edge[N + u].append(2*N + v)
    Edge[2*N + u].append(v)

S, T = map(int, input().split())
S -= 1
T -= 1

Q = deque([S])
visited = set([S])
dist = [-3]*(3*N)
dist[S] = 0


while Q:
    vn = Q.pop()
    for vf in Edge[vn]:
        if vf in visited:
            continue
        visited.add(vf)
        dist[vf] = dist[vn] + 1
        Q.appendleft(vf)

print(dist[T]//3)    


Measured memory_bytes: 93220
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<double,int> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
const int SIZE=5+1e6;
const LL INF=1LL<<60;

LL N,K;
LL A[SIZE];
LL x[SIZE];
LL counts[SIZE];
PQ qu;
bool solve(){
	cin >> N;
	FOR(i,1,N+1){
		cin >> A[i];
		x[A[i]-1]=i;
		REP(j,i-1){
			qu.push(pr(A[i],i));
		}
	}
	REP(i,N*N){
		if(x[i]!=0){
			if(counts[x[i]]!=x[i]-1) return false;
			counts[x[i]]++;
			REP(j,N-counts[x[i]]){
				qu.push(pr(INF,x[i]));
			}
		}
		else if(qu.empty()) return false;
		else{
			LL val=qu.top().second;
			x[i]=val;
			counts[val]++;
			qu.pop();
		}

	}
	return true;
}
int main(){
	if(solve()){
		cout << "Yes" << endl;
		REP(i,N*N){
			if(i) cout << " ";
			cout << x[i];
		}
		cout << endl;
	}
	else{
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 6252
# ABC142E - Get Everything
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    p = 1 << N
    dp = [float("inf")] * p
    dp[0] = 0
    for _ in range(M):
        a, _ = map(int, input().split())
        x = sum(1 << (i - 1) for i in map(int, input().split()))
        for y in range(p):
            if dp[x | y] > dp[y] + a:
                dp[x | y] = dp[y] + a
    ans = dp[-1] if dp[-1] != float("inf") else -1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
using namespace std;
//けんちょんさんの記事を参考に

const long long INF = 1LL << 60;

int main(){
    //入力
    int n; cin >> n;
    //初期化
    vector<long long> dp(n+1,INF);

    int c6 = 0 ,c9 = 0;
    for ( int i = 1 ; i < 10; i++ ){
        if ( pow(6,i) <= 100000 ) c6++;
        if ( pow(9,i) <= 100000 ) c9++;
    }

    //初期条件
    dp[0] = 0;
    for ( int i = 1 ; i <= n; i++ ){
        dp[i] = min(dp[i],dp[i-1]+1);
        for ( int j = 1 ; j <= c6; j++){
            if ( i >= (int)pow(6,j)) dp[i] = min(dp[i],dp[i-pow(6,j)]+1);
        } 
        for ( int j = 1 ; j <= c9 ; j++){
            if ( i >= (int)pow(9,j) ) dp[i] = min(dp[i],dp[i-pow(9,j)]+1);
        }
    }
    cout << dp[n] << endl;
}

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

int main() {

  long long int t, n, m, in_v;

  cin >> t;

  double ans = 0.00;
  double in_r;

  for ( long long int i = 0; i < t+1; i++ ) {

    cin >> n >> m;

    double cnt = 0.00;
    double a = 0.00;

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

      cin >> in_v >> in_r;
      cnt += in_v * in_r;
      a += in_r;

    }
    cnt /= a;
    if ( i < t ) {
      ans = max( ans, cnt );
    }else {
      if ( ans - cnt > 0.0000001 ) {
	cout << "YES" << endl;
      }else {
	cout << "NO" << endl;
      }
    }

  }

  return 0;

}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define ll long long
#define NM (int)2e5
#define oo (ll)1e18
using namespace std;

int lg[NM],grad[NM];
vector <int> v[NM];

int main()
{   int n,m;
    cin>>n>>m;
    for(int x,y; m--; v[y].push_back(x))
    {   cin>>x>>y;
        grad[x]++;
    }
    queue <int> q;
    for(int i=1; i<=n; i++)
        if(!grad[i])
        {   q.push(i);
            lg[i]=1;
        }
    int sol=1;
    for(int frunza; !q.empty(); q.pop())
    {   frunza=q.front();
        for(int x : v[frunza])
            if(grad[x])
            {   lg[x]=lg[frunza]+1;
                grad[x]--;
                if(!grad[x])
                {   q.push(x);
                    sol=max(sol,lg[x]);
                }
            }
    }
    cout<<sol-1;
    return 0;
}

Measured memory_bytes: 12168
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
typedef pair<int, bool> sP;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void solve() {
	string s; ll k; cin >> s >> k;
	int n = s.size();
	if (n == 1) {
		cout << k / 2 << endl; return;
	}
	vector<bool> ch(n, false);
	ll tmp = 0;
	rep(i, s.size()) {
		if (i > 0 && s[i] == s[i - 1] && !ch[i - 1]) {
			ch[i] = true; tmp++;
		}
	}
	if (ch[n - 1]||s[0]!=s[n-1]) {
		cout << tmp * k << endl;
	}
	else {
		vector<bool> ch2(n, false);
		ll tmp2 = 1;
		ch2[0] = true;
		rep(i, s.size()) {
			if (i > 0 && s[i] == s[i - 1] && !ch2[i - 1]) {
				ch2[i] = true; tmp2++;
			}
		}
		if (ch2[n - 1]) {
			ll d = k / 2;
			ll ans = d * (tmp + tmp2);
			if (k % 2)ans += tmp;
			cout << ans << endl;
		}
		else {
			ll ans = tmp + tmp2 * (k - 1);
			cout << ans << endl;
		}
	}
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(7);
	//init();
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[2000][2000], a[200000], b[200000];
string str[3], ss;
bool f[200000];
char c[800][800];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<Edge>vec[20000];
vector<edge>ed;
vector<LL>v[23];
map<string, LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	auto cc = [](Tll x, Tll y) {return x.fir != y.fir ? x.fir < y.fir : x.sec < y.sec; };
	priority_queue<Tll,vector<Tll>,decltype(cc)>pq1(cc),pq2(cc);
	rep(i, n) {
		cin >> a[i] >> b[i];
		pq1.push(Tll{ a[i] + b[i],a[i],i });
		pq2.push(Tll{ a[i] + b[i],b[i],i });
	}
	rep(i, n) {
		if(i%2==0)
		while (1) {
			Tll cur = pq1.top();
			pq1.pop();
			if (f[cur.third] == 0) {
				f[cur.third] = 1;
				if (i % 2)
					t += b[cur.third];
				else
					s += a[cur.third];
				break;
			}
		}
		else 
			while (1) {
				Tll cur = pq2.top();
				pq2.pop();
				if (f[cur.third] == 0) {
					f[cur.third] = 1;
					if (i % 2)
						t += b[cur.third];
					else
						s += a[cur.third];
					break;
				}
			}
	}
	cout << s-t << endl;
	return 0;
}


Measured memory_bytes: 9644
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
  string s ,t ;
  cin>>s>>t ;
  ll a= s.size() ;
  ll ans=0 ;
  rep(i,a){
     if(s[i]!=t[i]) ans++ ;
  }
  cout<<ans<<endl ;
     return 0;
  }
  

Measured memory_bytes: 3920
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 2010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, x, y, d[MAXN][MAXN], res[MAXN];
vector<int> a[MAXN];

void bfs(int u) {
    FOR(i,1,n) d[u][i] = 1000000000;
    d[u][u] = 0;
    queue<int> q;
    q.push(u);
    while (SZ(q)) {
        int r = q.front(); q.pop();
        FOR(i,0,SZ(a[r])-1) {
            int v = a[r][i];
            if (d[u][v] > d[u][r] + 1) {
                d[u][v] = d[u][r] + 1;
                q.push(v);
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> x >> y;
    FOR(i,1,n-1) {
        a[i].push_back(i+1);
        a[i+1].push_back(i);
    }
    a[x].push_back(y);
    a[y].push_back(x);
    FOR(i,1,n) bfs(i);
    FOR(i,1,n)
        FOR(j,1,n) res[d[i][j]]++;
    FOR(i,1,n) res[i] /= 2;
    FOR(i,1,n-1) cout << res[i] << "\n";
    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

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

const int INF = 1e9;
const int MOD = 1e9 + 7;
const double eps = 1e-9;

int n, a, b;
ll l, r, m;

int calc(vector<int> h) {
    l = 0, r = INF;

    while (r - l > 1) {
        m = (l + r) / 2;
        ll sum = 0;

        rep(i, n) {
            if (h[i] > m * b) {
                ll tmp = h[i] - m * b;
                sum += (tmp + (a - 1)) / a;
            }
        }

        if (sum <= m) r = m;
        else l = m;
    }

    return r;
}

/* 二分探索解 */
int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    cin >> n >> a >> b;
    a -= b;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int ans = calc(h);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int num,i,j,save;
    int first[100];
    int second[100];
    int third[100];
    
    scanf("%d",&num);
    
    for(i=0;i<100;i++){
        first[i]=0;second[i]=0;third[i]=0;
    }
    
    for(i=1;i<=num;i++){
        scanf("%d",&save);
        if(first[save-1]==0){
            first[save-1]=i;
        }
        else{
            first[save-1]=-1;
        }
        scanf("%d",&save);
        if(second[save-1]==0){
            second[save-1]=i;
        }
        else{
            second[save-1]=-1;
        }
        scanf("%d",&save);
        if(third[save-1]==0){
            third[save-1]=i;
        }
        else{
            third[save-1]=-1;
        }
    }
    for(i=1;i<=num;i++){
        save=0;
        for(j=0;j<100;j++){
            if(first[j]==i){
                save+=j+1;
            }
        }
        for(j=0;j<100;j++){
            if(second[j]==i){
                save+=j+1;
            }
        }
        for(j=0;j<100;j++){
            if(third[j]==i){
                save+=j+1;
            }
        }
        printf("%d\n",save);
    }
}



Measured memory_bytes: 2044
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define int long long
string s;
int l,r,ans=0;
signed main(){
	cin>>s;
	r=s.size()-1;
	while(l<=r){
		if(s[l]!=s[r])ans++;
		l++,r--;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    try(Scanner sc = new Scanner(System.in)){
      int n = Integer.parseInt(sc.next());
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      if(a * n > b){
        System.out.println(b);
      }else{
        System.out.println(a * n);
      }
    }
  }
}
      

Measured memory_bytes: 21844
#include<iostream>
#include <math.h>
#include <algorithm>
#include<queue>
#include<map>
//#include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)

main(){
    int n, pi, count=0;
    vector<int> p;
    cin >> n;
    FOR(i,0,n){
        cin >> pi;
        p.push_back(pi);
    }

    FOR(j,1,n-1){
        if((p[j-1]<p[j]&&p[j]<=p[j+1])||(p[j-1]>=p[j]&&p[j]>p[j+1])){
            count += 1;
        }
    }  

    cout << count << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define MOD 10000

string s;
short dp[2][3][10][500][501]; //[free][増減][prev][余り][index]
int m;

int solve( bool fr, int updw, int pre, int mod, int index){
  if( index == s.size() ) return !mod;
  if( dp[fr][updw][pre][mod][index] != -1 ) return dp[fr][updw][pre][mod][index];
  int ret = 0, end = fr ? 9 : s[index];
  for(int i = 0, u ; i <= end ; i++ ){
    switch(updw){
    case 0: //さいしょ
      if( pre && pre == i ) continue;
      else if( pre == 0 ) u = 0;
      else if( pre > i ) u = 1;
      else u = 2;
      break;
    case 1: //次あっぷ
      if( pre >= i ) continue;
      else u = 2;
      break;
    case 2: //次だうん
      if( pre <= i ) continue;
      else u = 1;
      break;
    }
    ret += solve( fr|(i!=s[index]), u, i, (mod*10+i)%m, index+1);
  }
  return dp[fr][updw][pre][mod][index] = ret % MOD;
}

void java(){
  for(int i = s.size() - 1 ; i >= 0 ; i-- ){
    if(s[i] == 0) s[i] = 9;
    else{
      s[i]--;
      break;
    }
  }
}

int main(){
  string s1;
  cin >> s >> s1 >> m;
  for(int i = 0 ; i < s.size() ; i++ ) s[i] -= '0';
  java();
  fill_n( ****dp, 2 * 3 * 10 * 500 * 501, -1);
  int an = solve( 0, 0, 0, 0, 0);
  s = s1;
  for(int i = 0 ; i < s.size() ; i++ ) s[i] -= '0';
  fill_n( ****dp, 2 * 3 * 10 * 500 * 501, -1);
  int bn = solve( 0, 0, 0, 0, 0);
  cout << ( bn - an + MOD ) % MOD << endl;
}

Measured memory_bytes: 30640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
 
int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    ld a;
    rep(i,N){
        cin >> a;
        A[i] = ll(a*1000000000 + 0.5);
    }
    vector<vector<ll>> S(40, vector<ll>(40)), B(40, vector<ll>(40));
    vector<Pll> P(N);
    rep(i,N){
        ll cnt_2 = 0;
        ll tmp = A[i];
        while(tmp%2==0){
            cnt_2++;
            tmp /= 2;
        }
        //cnt_2 = min(cnt_2, 18LL);
        ll cnt_5 = 0;
        tmp = A[i];
        while(tmp%5==0){
            cnt_5++;
            tmp /= 5;
        }
        //cnt_5 = min(cnt_5, 18LL);
        B[cnt_2][cnt_5]++; 
        P[i] = make_pair(cnt_2, cnt_5);
    }
    rep(i,39){
        rep(j,39){
            S[i+1][j+1] = S[i+1][j] + B[i][j]; 
        }
    }
    rep(j,40){
        rep(i,39){
            S[i+1][j] += S[i][j];
        }
    }
    ll ans = 0;
    rep(i,N){
        ll t = P[i].fi;
        ll f = P[i].se;
        ll nt = max(18-t, 0LL);
        ll nf = max(18-f, 0LL);
        ans += S[39][39] + S[nt][nf] - S[nt][39] - S[39][nf];
        if(t >= 18-t && f >= 18-f){
            ans--;
            //ans++;
        }
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 8040
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, a, b; cin >> n >> a >> b;
  vll x(n); REP(i, n) cin >> x[i];
  sort(x.begin (), x.end());
  ll tmpi = x[0];
  ll ans = 0;
  rep(i, 1, n) {
    if ((x[i]-tmpi)*a < b) ans += (x[i]-tmpi)*a;
    else ans += b;
    tmpi = x[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#define N 10000000
 
void insert(int);
void inorder(int);
void preorder(int);
int find(int, int);
 
typedef struct{
  int k, r, l;
}Node;
 
Node T[N+1];
int M;
 
void insert(int x){
  int n = 0;
  while(1){
    if(x < T[n].k){
      if(T[n].l == -1){
        T[n].l = M;
        T[M++].k = x;
        break;
      }
      else n = T[n].l;
    }
    else{
      if(T[n].r == -1){
        T[n].r = M;
        T[M++].k = x;
        break;
      }
      else n = T[n].r;
    }
  }
}
 
void inorder(int n){
  if(T[n].l != -1){
    inorder(T[n].l);
  }
  printf(" %d", T[n].k);
  if(T[n].r != -1){
    inorder(T[n].r);
  }
}
 
void preorder(int n){
  printf(" %d",T[n].k);
  if(T[n].l != -1){
    preorder(T[n].l);
  }
  if(T[n].r != -1){
    preorder(T[n].r);
  }
}
 
int find(int n, int x){
  if(T[n].k == x) return 1;
  if(x < T[n].k && T[n].l != -1){
      if(find(T[n].l, x)) return 1;
    }
    if(T[n].k < x && T[n].r != -1){
      if(find(T[n].r, x)) return 1;
    }
    return 0;
}
 
int main(){
  int n, i, x, in, first=1;
  char str[100];
 
  scanf("%d",&n);
 
  for(i=0; i<=n; i++){
    T[i].k = T[i].l = T[i].r = -1;
  }
  M = 0;
  while(n--){
    scanf("%s",str);
    if(!strcmp(str, "insert")){
      scanf("%d", &x);
      if(first){
        T[M++].k = x;
        first = 0;
      }
      else insert(x);
    }
    else if(!strcmp(str, "find")){
      scanf("%d", &in);
      if(find(0., in) == 1) printf("yes\n");
      else printf("no\n");
    }
    else{
      inorder(0);
      printf("\n");
      preorder(0);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-6
//#define p 2173412051LL
#define sz 2

using namespace std;

int n;
ll a[ 200010 ];

ll checkLess( ll );
ll checkMore( ll );

int main() {
	ll m;
	ll l = -1e18, r = 1e18, mid;
	ll t1, t2, t3, fk;
	scanf( "%d", &n );
	scanf( "%lld", &m );
	for( int i = 0; i < n; ++i )
		scanf( "%lld", &a[ i ] );
	sort( a, a + n );
	fk = 1LL * n * ( n - 1 ) / 2;
	while( l <= r ) {
		mid = ( l + r ) >> 1;
		t1 = checkLess( mid );
		t2 = checkMore( mid );
		t3 = fk - t2;
		if( t1 < m && t3 >= m  ) {
			printf( "%lld", mid );
			return 0;
		}
		if( t1 >= m )
			r = mid - 1;
		else
			l = mid + 1;
	}
	return 0;
}

ll checkLess( ll x ) {
	ll res = 0;
	int lst;
	for( int i = 0; i < n - 1; ++i ) {
		if( a[ i ] == 0 ) {
			if( x > 0 )
				res += n - 1 - i;
		} else if( a[ i ] > 0 ) {
			if( x >= 0 ) {
				if( x % a[ i ] )
					lst = lower_bound( a + i + 1, a + n, x / a[ i ] + 1 ) - a;
				else
					lst = lower_bound( a + i + 1, a + n, x / a[ i ] ) - a;
			} else {
				lst = lower_bound( a + i + 1, a + n, x / a[ i ] ) - a;
			}
			res += lst - 1 - i;
		} else {
			if( x <= 0 ) {
				lst = upper_bound( a + i + 1, a + n, x / a[ i ] ) - a;
			} else {
				if( x % a[ i ] )
					lst = upper_bound( a + i + 1, a + n, x / a[ i ] - 1 ) - a;
				else
					lst = upper_bound( a + i + 1, a + n, x / a[ i ] ) - a;
			}
			res += n - lst;
		}
	}
	return res;
}

ll checkMore( ll x ) {
	ll res = 0;
	int lst;
	for( int i = 0; i < n - 1; ++i ) {
		if( a[ i ] == 0 ) {
			if( x < 0 )
				res += n - 1 - i;
		} else if( a[ i ] > 0 ) {
			if( x >= 0 ) {
				lst = upper_bound( a + i + 1, a + n, x / a[ i ] ) - a;
			} else {
				if( x % a[ i ] )
					lst = upper_bound( a + i + 1, a + n, x / a[ i ] - 1 ) - a;
				else
					lst = upper_bound( a + i + 1, a + n, x / a[ i ] ) - a;
			}
			res += n - lst;
		} else {
			if( x <= 0 ) {
				if( x % a[ i ] )
					lst = lower_bound( a + i + 1, a + n, x / a[ i ] + 1 ) - a;
				else
					lst = lower_bound( a + i + 1, a + n, x / a[ i ] ) - a;
			} else {
				lst = lower_bound( a + i + 1, a + n, x / a[ i ] ) - a;
			}
			res += lst - 1 - i;
		}
	}
	return res;
}

Measured memory_bytes: 1792
#include <iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int main() {
	int N;
	int a[250];
	cin >> N;

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

	int c = 0;

	while (true) {
		bool kisuu = false;

		for (int i = 0; i < N; ++i) {
			if (a[i] % 2 != 0)kisuu = true;
		}

		if (kisuu == true)break;

		for (int i = 0; i < N; ++i) {
			a[i]=a[i] / 2;
		}
		c = c+1 ;
	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int i, n;
  int max = -1; 
  int min = 10000000000;
  int array[200];
  
  scanf("%d\n", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &array[i]);
  
  for (i = 0; i < n; i++) {
    if (array[i] > max)
      max = array[i];
    if (array[i] < min)
      min = array[i];
  }
  
  printf("%d", max - min);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if (a == 5 && b == 5 && c == 7) {
    cout << "YES" <<endl;
  }
  else if (a == 5 && b == 7 && c == 5) {
    cout << "YES" <<endl;
  }
  else if (a == 7 && b == 5 && c == 5) {
    cout << "YES" <<endl;
  }
  else  {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3544
# AGC022 A - Diverse Word
s=input()
n=len(s)
mozi=[0]*26
ans=''
if s=='zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif n<26:
    for ss in s:
        mozi[ord(ss)-97]+=1
    for i in range(len(mozi)):
        if mozi[i]==0:
            break
    ans=s
    ans+=chr(97+i)
    print(ans)
elif n==26:
    for i in range(1,27):
        if s[-i]>s[-i-1]:
            break
    ss=sorted(s[-i:])
    for sss in ss:
        if sss>s[-i-1]:
            break
    print(s[:-i-1]+sss)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
int main(){
    ll n;cin>>n;
    ll ma=0;
    vi v(n);
    rep(i,n){
        cin>>v[i];chmax(ma,v[i]);
    }
    ll ans=0;
    vi t;
    REP(i,1,ma+1)if(ma%i==0)t.pb(i);
    rep(i,n)ans+=*lower_bound(all(t),v[i])-v[i];
    out(ans);
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
using namespace std;
int main(){
  string a;
  cin>>a;
  int l[26];
  for(int i=0;i<26;i++){
    l[i]=0;
  }
  for(int i=0;i<a.size();i++){
    l[a[i]-'a']++;
  }
  int ans=0;
  for(int i=0;i<26;i++){
    if(l[i]%2==1)ans++;
  }
  if(ans==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        sc.close();
        if(r < 1200){
            System.out.println("ABC");
        }else if(r < 2800){
            System.out.println("ARC");
        }else{
            System.out.println("AGC");
        }
    }
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

int main() {
    ll n, k, x, y;
    cin >> n >> k >> x >> y;


    ll x_d = min(n, k);
    ll y_d = max(n - k, 0ll);

    ll ans = x_d * x + y_d * y;

    cout << ans << endl;

}

Measured memory_bytes: 256
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b

main = do
 [a,b] <- readLnInt
 putStr $ (a > b)?("safe","unsafe")


Measured memory_bytes: 3768
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define ll long long
const ll N = 1e5+10 ;
int w[N],v[N];
int dp[N];
int main(){
   int n,k;
   cin >> n >> k;
   int m = -1;
   memset(dp,0x3f,sizeof dp);
   dp[0] = 0;
   for(int i = 1;i <= k;++i) {cin>>w[i]>>v[i];}
   for(int i = 1;i <= k;++i){
      for(int j = w[i];j <= 1e4;++j){
          dp[j] = min(dp[j],dp[j-w[i]] + v[i]);
      }
   }
   m = 0x3f3f3f3f;
   for(int i = n;i <= 1e4;++ i){
      m = min(m,dp[i]);
   }
   cout<<m<<endl;
}


Measured memory_bytes: 640
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
if all([not i for i in a]):
  print("Yes")
else:
  if n % 3:
    print("No")
  else:
    for i in a[1:]:
      d[i] += 1
    now1,now2 = a[0],0
    ans = [now1]
    for i in a[1:]:
      xor = now1^i
      d[i] -= 1
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = i, xor
        ans.append(now1)
        ans.append(now2)
        break
      d[i] += 1
      d[xor] += 1        
    else:
      print("No")
      exit()
    for i in range(n-3):
      xor = now1^now2
      d[xor] -= 1
      if d[xor] >= 0:
        now1, now2 = now2, xor
        ans.append(now2)
        continue
      else:
        print("No")
        exit()
    else:
      if now1^now2 == a[0]:
        print("Yes")
      else:
        print("No")
      exit()

Measured memory_bytes: 17316
import sys
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappop, heappush

N, Q = map(int, input().split())
INF = float('inf')

events = []
for i in range(N):
    S, T, X = map(int, input().split())
    events.append((S - X, 0, X))
    events.append((T - X, 1, X))

for _ in range(Q):
    events.append((int(input()), 2, 0))

events.sort()

cnt = defaultdict(int)
cnt[INF] += 1
que = [INF]

for t, flag, x in events:
    if flag == 0:
        if cnt[x] == 0:
            heappush(que, x)
        cnt[x] += 1
    elif flag == 1:
        cnt[x] -= 1
    else:
        while cnt[que[0]] == 0:
            heappop(que)
        print(que[0] if que[0] != INF else -1)



Measured memory_bytes: 98124
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	scanf("%d", &n);

	int c[9];
	memset(c, 0, sizeof c);
	for (int i = 0; i < n; i++)
	{
		int a;
		scanf("%d", &a);
		c[min(a / 400, 8)]++;
	}
	int mn = 0;
	for (int i = 0; i < 8; i++)
		mn += (c[i] > 0);
	if (mn)
		printf("%d %d\n", mn, mn + c[8]);
	else
		printf("1 %d\n", c[8]);

	return 0;
}

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

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  long double conc = 0;
  int water = 0, sugar = 0;

  for (int i = 0; i <= f; i += 100 * a) {
    for (int j = 0; i + j <= f; j += 100 * b) {
      int A = i + j;
      int Adiv = (i + j) / 100;
      for (int k = 0; k <= Adiv * e; k += c) {
        for (int l = 0; k + l <= Adiv * e; l += d) {
          int B = k + l;
          if (A + B == 0) continue;
          if (A + B > f) continue;
          if (conc <= double(100 * B) / double(A + B)) {
            conc = double(100 * B) / double(A + B);
            water = A;
            sugar = B;
          }
        }
      }
    }
  }

  cout << water + sugar << ' ' << sugar << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18

int main() {
    long long n; cin >> n;
    long long ans = INF;
    for (long long i = 1LL; i * i <= n; i++) {
        if (n % i != 0) continue;
        long long j = n / i;
        ans = min(ans, i + j - 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

int n;
int ac = 0;
int wa = 0;
int tle = 0;
int re = 0;

cin>>n;

string arr [n];

for (int i =0; i<n; i++) {
cin >> arr[i];
}

for (int i = 0; i<n; i++){
    if(arr[i] == "AC"){
        ac++;
    } else if(arr[i] == "WA"){
        wa++;
    } else if(arr[i] == "TLE"){
        tle++;
    } else if(arr[i] == "RE"){
        re++;
    }
}

cout<<"AC x "<<ac <<endl;

cout<<"WA x "<<wa <<endl;

cout<<"TLE x "<<tle <<endl;

cout<<"RE x "<<re <<endl;

    return 0;
}

Measured memory_bytes: 6716