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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   double winProb(long x, long y) {
      return 1.0 / (1.0 + pow(10, (y - x) / 400.0));
   }
   void solve() {
      long n; scan(n);
      LI xs(n), ys(n);
      for(long i = 0; i < n; ++i) scan(xs[i], ys[i]);
      long shift = 0;
      for(long i = n - 1; i >= 0; --i) {
         long t = (xs[i] + shift + ys[i] - 1) / ys[i] * ys[i];
         long s = t - xs[i] - shift;
         shift += s;
      }
      printf("%ld\n", shift);
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}



Measured memory_bytes: 1792
import sys

n = int(input())
a = []
b = input().split(" ")
for i in range(n):
	a.append(int(b[i]))

for i in range(1, n):
	a[i] += a[i-1]

mn = abs(a[n-1] - 2*a[0])
for i in range(1, n-1):
	mn = min(mn, abs(a[n-1] - 2*a[i]))

print(mn)


Measured memory_bytes: 28768
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;

int main(){
    string s;
    cin>>s;
    bool a=true;
    for(int i=0;i<s.size();i+=2){
        if(s.at(i)=='L'){
            a=false;
            break;
        }
    }
    for(int i=1;i<s.size();i+=2){
        if(s.at(i)=='R'){
            a=false;
            break;
        }
    }
    if(a){
        cout <<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, k int
	fmt.Scan(&a, &b, &k)

	for i := a; i <= min(b, a+k-1); i++ {
		fmt.Println(i)
	}
	for i := max(b-k+1, a+k); i <= b; i++ {
		fmt.Println(i)
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 512
inf = float('inf')
# ベルマンフォード法
# 計算量O(VE) V:頂点数, E:辺の数
# [引数]   n:頂点数, edges:辺集合, start:始点, end:終点
# [返り値] dist:startからの最短距離, exists_negative_cycle: 負閉路が存在するかどうか
def bellmanford(n : int, edges : list, start : int, goal : int) -> (list, bool):
    dist = [inf] * n
    dist[start] = 0
    exist_negative_cycle = False

    # 負閉路を含まないとき、頂点数nなら更新は高々n-1回で済む
    for _ in range(n-1):
        for v, nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w


    # (1)グラフに負閉路が含まれるときの検出
    # N回目で更新があったとき、グラフは負閉路を含む
    # for v, nv, w in edges:
    #     if dist[nv] > dist[v] + w:
    #         exists_negative_cycle = True

    # (2)startとgoalのパスに負閉路が含まれるときの検出
    is_updated = [False] * n
    for _ in range(n):
        for v, nv, w in edges:
            if dist[nv] > dist[v] + w:
                dist[nv] = dist[v] + w
                is_updated[nv] = True
            if is_updated[v] is True:
                is_updated[nv] = True

    exist_negative_cycle = is_updated[goal]

    return dist, exist_negative_cycle

N, M, P = map(int,input().split())
edges = []
for _ in range(M):
    A, B, C = map(int,input().split())
    A -= 1; B -= 1
    C = C - P
    edges.append((A, B, -C))
 
dist, exist_negative_cycle = bellmanford(N, edges, 0, N-1)
 
if exist_negative_cycle is True:
    ans = -1
else:
    ans = max(-dist[N-1], 0)
 
print(ans)

Measured memory_bytes: 48344
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int firstNum = sc.nextInt();
        int secondNum = sc.nextInt();
        System.out.println(firstNum * secondNum + " " + 2 * (firstNum + secondNum));
    }
}


Measured memory_bytes: 26152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            long[] change_input = input.Select(long.Parse).ToArray();
            long A = change_input[0];
            long B = change_input[1];
            long N =0;
            long K = 0;
            K = A % B;
            N = B - A % B;
            if(K > N)
            {
                Console.WriteLine(Math.Abs(N));
            }
            else
            {
                Console.WriteLine(Math.Abs(K));
            }
            Console.Read();
        }
    }
}

Measured memory_bytes: 28236
package main

import "fmt"

func main() {
    var a, b int64
    var k int
    fmt.Scan(&a, &b, &k)

    for i := 0; i < k; i++ {
        if i % 2 == 0 {
            a /= 2
            b += a
        } else {
            b /= 2
            a += b
        }
    }
    fmt.Println(a, b)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main()
{
	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	ll cnt=0;
	sort(a,a+n);
	for(ll i=0;i<n-2;i++)
	{
		for(ll j=i+1;j<n-1;j++)
		{
			for(ll k=j+1;k<n;k++)
			{
				if(a[k]<a[i]+a[j])
				{
					cnt++;
				}
			}
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
     
    int H, W,i,j;
    while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0)
    break;
     
     
    for(i=1;i<=H;i++){
        for(j=1;j<=W;j++){
            printf("#");
            
            }printf("\n");
            }printf("\n");
        }
    return 0;
}


Measured memory_bytes: 2048
// include
// ----------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>

// repetition
// ----------------------------------------------------------------------------
#define FOR(i, a, b) for (i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// memory clear
// ----------------------------------------------------------------------------
#define CLRNUM(a) memset((a), 0, sizeof(a))
#define CLRBOOL(a, flag) memset((a), flag, sizeof(a))
#define CLRCHAR(a) memset((a), '\0', sizeof(a))

// debug
// ----------------------------------------------------------------------------
#define DEBUGINT(x) printf("%d\n", x);
#define DEBUGFLOAT(x) printf("%f\n", x);
#define DEBUGCHAR(x) printf("%c\n", x);
#define DEBUGSTR(x) printf("%s\n", x);
#define DEBUGFORINT(i, a, b, x) FOR(i, a, b){ printf("%d ", x[i]); }
#define DEBUGFORFLOAT(i, a, b,x ) FOR(i, a, b){ printf("%f ", x[i]); }
#define DEBUGFORCHAR(i, a, b, x) FOR(i, a, b){ printf("%c ", x[i]); }
#define DEBUGREPINT(i, n, x) REP(i, n){ printf("%d ", x[i]); }
#define DEBUGREPFLOAT(i, n, x) REP(i, n){ printf("%f ", x[i]); }
#define DEBUGREPCHAR(i, n, x) REP(i, n){ printf("%c ", x[i]); }

// other
// ----------------------------------------------------------------------------
#define PUTNL printf("\n")

// constant
// ----------------------------------------------------------------------------
#define INF 1000000000

int main(void)
{
    double rate, y;
    int i;

    while (scanf("%lf", &rate) != EOF){
        rate /= 9.8;
        y = 4.9 * (rate * rate);
        
        if (y - (int)y != 0){
            y++;
        }

        for (i = 0; (5 * i - 5) < (int)y; ++i);

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

    return 0;    
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  ll N,n,sum=0;
  cin>>N;
  n=N;
  while(n!=0){
    sum+=n%10;
    n/=10;
  }
  if(N%sum==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import numpy as np
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

dic = {"r":P, "s":R, "p":S}#key:筐体が出した手、val:それに勝ったら貰える点
points = 0

for st in range(K):
    series = T[st::K]
    prev = "x"
    for now in series:
        if now != prev:
            points += dic[now]
            prev = now
        else:
            prev = "x"
            
print(points)

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

const int maxn = 1e5+5;
int p[maxn];

vector<int>* par[maxn];
int N, M;

void init() {
    for (int i = 1; i <= N; i++) {
        par[i] = new vector<int>;
        par[i]->push_back(i);
    }
}

void Union(int a, int b) {
    auto pa = par[a], pb = par[b];
    if (pa == pb) return;
    if (pa->size() < pb->size()) {
        swap(pa,pb);
    }
    for (int i: *pb) {
        pa->push_back(i);
        par[i] = pa;
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        cin >> p[i];
    }
    init();
    while (M--) {
        int x, y; cin >> x >> y;
        Union(x,y);
    }
    set<vector<int>*> sets;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (sets.count(par[i])) continue;
        sets.insert(par[i]);
        set<int> indices;
        for (int j: *par[i]) {
            indices.insert(j);    
        }
        for (int j: *par[i]) {
            if (indices.count(p[j])) ans++;
        }
    }
    cout << ans << '\n';
}



Measured memory_bytes: 15476
#include<stdio.h>

int main(void)
{
    int input[6];
    for(int i=0;i<5;i++)
    {
        scanf("%d",&input[i]);
    }
    for(int j=0;j<5;j++)
    {
        if(input[j]==0)
        {
            printf("%d",j+1);
        }
    }
    return 0;
}

Measured memory_bytes: 1640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll popcount(ll x){
    ll res=0;
    while(x>0){
        res+=x%2;
        x/=2;
    }
    return res;
}
ll f(ll x){
    return x%popcount(x);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    int z=-1;
    cin>>n;
    string s;
    cin>>s;
    vec X(n);
    rep(i,n) X[i]=(s[i]=='1');
    ll a=0;
    rep(i,n) if(X[i]) a++;
    if(a==1){
        rep(i,n) if(X[i]) z=i;
    }
    vec A(n,1),B(n,1);
    rep(i,n-1){
        A[i+1]=(A[i]*2)%(a+1);
        if(a!=1)B[i+1]=B[i]*2%(a-1);
    }
    ll C=0,D=0;
    rep(i,n) if(X[n-i-1]){
        (C+=A[i])%=(a+1);
        if(a!=1) (D+=B[i])%=(a-1);
    }
    rep(i,n){
        if(i==z){
            cout<<0<<"\n";
            continue;
        }
        if(X[i]){
            int x=(D-B[n-i-1]+a-1)%(a-1),ans=1;
            while(x>0) x=f(x),ans++;
            cout<<ans<<"\n";
        }
        else{
            int x=(C+A[n-i-1])%(a+1),ans=1;
            while(x>0) x=f(x),ans++;
            cout<<ans<<"\n";
        }
    }
}

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

def main():
    a = list(map(int,input().split()))
    if a[0]*a[3]*a[4] == 0:
        ans = 2*(a[0]//2+a[3]//2+a[4]//2)
    else:
        ans = max(2*(a[0]//2+a[3]//2+a[4]//2),\
            3+2*((a[0]-1)//2+(a[3]-1)//2+(a[4]-1)//2))
    print(a[1]+ans)

if __name__ == "__main__":
    main()

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    int a[n]; for (int i = 0; i<n; i++) cin >> a[i];
    cout << (((n-k)+(k-2))/(k-1))+1 << "\n";
}

Measured memory_bytes: 3948
use proconio::input;

const MOD: usize = 1_000_000_007;

fn pow(mut x: usize, mut e: usize) -> usize {
    let mut res = 1;
    while e > 0 {
        if e & 1 == 1 {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        e >>= 1;
    }
    res
}

fn main() {
    input! {
        (n, k): (usize, usize)
    }

    let mut memo: Vec<usize> = vec![0; k + 1];
    for x in (1..=k).rev() {
        let mut c = pow(k / x, n);

        for i in 2..=k / x {
            if let Some(&v) = memo.get(i * x) {
                c = (c + MOD - v) % MOD;
            }
        }

        memo[x] = c;
    }

    let mut ans = 0;
    for x in 1..=k {
        ans = (ans + memo[x] * x % MOD) % MOD;
    }

    println!("{}", ans);
}


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

using ll = long long;

int main() {
    ll N;
    cin >> N;
    ll digit = 1;
    for (ll i = 2; i <= sqrt(N); i++) {
        if (N%i == 0) {
            digit = i;
        }
    }
    cout << to_string(N/digit).length() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int x;
string S,T;
int main() {
	cin>>S>>T;
	for(int i=0;i<S.length();i++) {
		if(S[i]!=T[i]) {
			x++;
		}
	}
	cout<<x<<endl;
}


Measured memory_bytes: 3860
// Let Go Your Earthly Tether , Enter The Void , Empty And Become Wind

#include<bits/stdc++.h>

#define all(x) x.begin() , x.end()

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

#define debug(x) cerr << #x << " = " << x << endl

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

ll h , ans = 0 ;
ll pw[80] ;

int main() {
        ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
        cin >> h ;
        ll lg = log2(h) ;
        pw[0] = 1 ;
        for (int i = 1 ; i < 60 ; i ++)
                pw[i] = pw[i - 1] * 2 ;
        for (ll i = 0 ; i <= lg ; i ++)
                ans += pw[i] ;
        cout << ans ;
        return (0) ;
}


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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int max = pow(10, 5), N;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        cin >> list[i], list[i]--;

    vector<int> gu_list(max, 0), ki_list(max, 0);
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 1)
            ki_list[list[i]]++;
        else
            gu_list[list[i]]++;
    }
    vector<pair<int, int>> gu, ki;
    for (int i = 0; i < max; i++)
    {
        ki.push_back(make_pair(ki_list[i], i));
        gu.push_back(make_pair(gu_list[i], i));
    }

    sort(ki.begin(), ki.end()),sort(gu.begin(), gu.end());
    reverse(ki.begin(), ki.end()), reverse(gu.begin(), gu.end());
    if (ki[0].second != gu[0].second)
        cout << N - (ki[0].first + gu[0].first) << endl;
    else
        cout << min(N - ki[0].first - gu[1].first, N - ki[1].first - gu[0].first);

}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define INF (1e9)
#define s second
#define f first
#define N 50
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> P1;
typedef pair<int,P1> P2;
int x,y,stx,sty,skx,sky;
int d[N][N][N][N];
int dat[N][N];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};

int bfs(){
  queue<P2> q;
  d[sty][stx][sky][skx]=0;
  q.push(P2(0,P1(P(sty,stx),P(sky,skx))));
  while(!q.empty()){
    P2 t=q.front(); q.pop();
    int cost=t.f;
    int ty=t.s.f.f,tx=t.s.f.s;
    int ky=t.s.s.f,kx=t.s.s.s;
    if(d[ty][tx][ky][kx]<cost)continue;
    if(ty==ky&&tx==kx)return cost;
    for(int i=0;i<4;i++){
      int nty=ty+dy[i],ntx=tx+dx[i];
      int nky=ky-dy[i],nkx=kx-dx[i];
      if(nty<0||ntx<0||y<=nty||x<=ntx)
	nty=ty,ntx=tx;
      else if(dat[nty][ntx])
	nty=ty,ntx=tx;
      if(nky<0||nkx<0||y<=nky||x<=nkx)
	nky=ky,nkx=kx;
      else if(dat[nky][nkx])
	nky=ky,nkx=kx;
      if(d[nty][ntx][nky][nkx]>cost+1){
	d[nty][ntx][nky][nkx]=cost+1;
	q.push(P2(cost+1,P1(P(nty,ntx),P(nky,nkx))));
      }
    }
  }
  return -1;
}

int main(){
  while(1){
    cin>>x>>y;
    if(!x&&!y)break;
    cin>>stx>>sty>>skx>>sky;
    stx--,sty--,skx--,sky--;
    for(int i=0;i<y;i++)
      for(int j=0;j<x;j++)
	cin>>dat[i][j];
    for(int i=0;i<y;i++)
      for(int j=0;j<x;j++)
	for(int k=0;k<y;k++)
	  for(int l=0;l<x;l++)
	    d[i][j][k][l]=INF;
    int ans=bfs();
    if(ans==-1)cout<<"NA"<<endl;
    else cout<<ans<<endl;

  }
  return 0;
}

Measured memory_bytes: 25948
// AOJ ITP1_10_B Triangle
// 2018.4.28 bal4u

#include <stdio.h>
#include <math.h>

#define PI 3.141592653589793

int main()
{
	double a, b, c, s, C;
	double S, L, h; 
	
	scanf("%lf%lf%lf", &a, &b, &C);
	c = sqrt(a*a + b*b - 2*a*b*cos(C*PI/180));
	L = a+b+c;
	s = L/2;
	S = sqrt(s*(s-a)*(s-b)*(s-c));
	h = 2*S/a;
	printf("%.8lf\n%.8lf\n%.8lf\n", S, L, h);
	return 0;
}


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

ll mod = 1e9+7;

int main(){
    int N;
    cin >> N;
    vector<int> fact(N+1, 0);
    for (int i = 2; i <= N; i++) {
        int x = i;
        int t = 2;
        while (x >= 2) {
            while (x % t == 0) {
                x /= t;
                fact[t]++;
            }
            t++;
        }
    }
    ll ans = 1;
    for (int i = 2; i <= N; i++) ans = ans * (fact[i]+1) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
using namespace std;

/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define fi first
#define se second


int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans=0;

    for(int i=0;i<n;i++){
        auto x = lower_bound(a.begin(),a.end(),b[i]);
        auto y = lower_bound(c.begin(),c.end(),b[i]+1);
        ans+=(x-a.begin())*(c.end()-y);
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n;
    cin>>n;
    long long int a[n+1],b[n];
    long long int ans=0;
    for(long int i=0;i<n+1;i++)
    {
        cin>>a[i];
        ans+=a[i];
    }
    for(long int i=0;i<n;i++)
    cin>>b[i];
    //long long int temp=0;
    for(long int i=0,j=0;i<n;i++)
    {
        long long int temp=min(a[i],b[i]);
        a[i]-=temp;
        b[i]-=temp;
    temp=min(a[i+1],b[i]);
        a[i+1]-=temp;
        b[i]-=temp;
    }
    for(long int i=0;i<n+1;i++)
    ans-=a[i];
    cout<<ans;
}

Measured memory_bytes: 1792
def main():
  from numpy import int32,sum
  _,a,b,*h=map(int,open(0).read().split())
  h=int32(h)
  i,j=0,2**30
  while~i+j:
    k=(j+i)//2
    t=(b*k-h)//(a-b)
    if-k>sum(t[t<0]):i=k
    else:j=k
  print(j)
main()

Measured memory_bytes: 23124
a = list(map(int, input().split()))
c7 = 0
c5 = 0
for x in a:
  if x == 7:
    c7 += 1
  if x == 5:
    c5 += 1
if c7 == 1 and c5 == 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 2940
import heapq
N = int(input())
A = [int(i) for i in input().split()]
posi=[]
posidata=[]
nega=[]
negadata=[]
for i in range(N):
    heapq.heappush(posi,A[i])
    heapq.heappush(nega,-A[3*N-1-i])
posisum = sum(posi)
negasum = sum(nega)
posidata.append(posisum)
negadata.append(negasum)
for i in range(N):
    heapq.heappush(posi,A[N+i])
    a = heapq.heappop(posi)
    posisum += A[N+i]-a
    posidata.append(posisum)
    heapq.heappush(nega,-A[2*N-1-i])
    b = heapq.heappop(nega)
    negasum += -A[2*N-1-i]-b
    negadata.append(negasum)
print(max(posidata[i]+negadata[-1-i] for i in range(N+1)))
    

Measured memory_bytes: 38292
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

    int H, W;
    cin >> H >> W;

    int h, w;
    cin >> h >> w;

    cout << (H - h) * (W - w) << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))


int main(){
    ll N,K;
    cin >> N >> K;
    vector<pair<ll,ll>>A(N);
    vector<ll>rui(N+1);

    rui.at(0) = 0;
    for(ll i = 0;i < N;i++){
        cin >> A[i].first >> A[i].second;
    }

    sort(A.begin(),A.end());

    for(ll i = 0;i < N;i++){
        rui.at(i+1) = A[i].second + rui.at(i);
    }

    const ll j = lower_bound(ALL(rui),K) - 1 - rui.begin();

    cout << A[j].first << endl;

    return 0;

}

Measured memory_bytes: 5528
#include<iostream>
#include<string>
#include<algorithm>
#define MAX_N 101
using namespace std;

string s[MAX_N];

int main() {
    int N, L;
    cin >> N >> L;
    for (int i = 0; i < N; i++) cin >> s[i];
    sort(s, s + N);
    for (int i = 0; i < N; i++) cout << s[i];
    cout << endl;
    return 0;
}

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

int n, m, a;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < m; ++i) {
		cin >> a;
		n -= a;
	}
	cout << max(n, -1) << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>

int main(){
	char acl[1000] = "";
	int K;
	//%i = unsigned ints / %d = signed ints
	scanf("%i", &K);
	for(int i = 0; i < K; i++){
		strcat(acl, "ACL");
	}

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

Measured memory_bytes: 1644
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

bool solve(string S) {
    if (S[0] != 'A')RT 0;
    int nc = 0;
    FOR(i, 2, sz(S) - 1) {
        if (S[i] == 'C')nc++;
    }
    if (nc != 1)RT 0;
    each(c, S) {
        if (c != 'A'&&c != 'C'&&isupper(c)) {
            RT 0;
        }
    }
    RT 1;
}

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

    string S;
    while (cin >> S) {
        cout << (solve(S) ? "AC" : "WA") << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int N =2*1e5 +5;

int n;
char s[N];
vector < char > v;

int main(){
    scanf("%s",s);
    n = strlen(s);
    for(int i=0;i<n;i++){
        v.push_back(s[i]);
        size_t sz = v.size();
        if(sz>=2){
            if(v[sz-2]=='S' && v[sz-1]=='T'){
                v.pop_back();
                v.pop_back();
            }
        }
    }
    printf("%u\n",v.size());
    return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
  int N; cin >> N;
  vector<int> T(N);

  int sum = 0;
  rep(i,N){
    cin >> T[i];
    sum+= T[i];
  }
  int M ; cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  rep(i,M){
   cin >> P[i] >> X[i];
   }
  rep(i,M){
    cout << sum + X[i] - T[P[i]-1] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int a, b, c; cin >> a >> b >> c;
  cout << max({a, b, c}) * 9 + (a+b+c) << endl;
  return 0;
}

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

bool bsearch(int* S, int v, int n)
{
    int l = 0, r = n, mid = n;
    while(r > l + 1)
    {
        mid = (l + r) / 2;
        if(S[mid] > v)
        {
            r = mid;
        }
        else if(S[mid] < v)
        {
            l = mid;
        }
        else{
            return 1;
        }
    }
    return 0;
}

int main()
{
    int S[100000], T[50000];
    int n, m;
    cin >> n;
    for(int i=0;i<n;++i) cin >> S[i];
    cin >> m;
    for(int i=0;i<m;++i) cin >> T[i];
    int ans = 0;
    for(int i=0;i<m;++i)
    {
        ans += bsearch(S, T[i], n);
    }
    cout << ans << endl;
}



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

int main(){
	int n;
	while(cin>>n){
		bool f=false;
		for(int i=0; i<10; i++){
			if((n & 1<<i)!=0){
				if(f) cout << " ";
				cout << (1<<i);
				f = true;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2960
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define ld                 long double
#define ff                 first
#define ss                 second
#define P                 pair<int,int>
#define pb                 push_back
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
const int N = 100005;//change it when needed
int n, k;
int a[N];
int dp[N];
int go(int i) {
    if (i < k) {
        return abs(a[i] - a[0]);
    }
    int &ans = dp[i];
    if (ans != -1)return ans;
    ans = inf;
    for (int j = 1; j <= k; j++) {
        if (i - j >= 0) {
            ans = min(ans, abs(a[i] - a[i - j]) + go(i - j));
        }
    }
    return ans;
}
void solve() {
    int  m, ans = 0, cnt = 0, sum = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        dp[i] = -1;
    }
    cout << go(n - 1) << endl;
}

int32_t main()
{
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    // int t; cin >> t; while (t--)
    solve();
    return 0;
}

Measured memory_bytes: 6528
#ifdef BUILT_LOCAL

#include "niklib.h"

#endif

#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>

using namespace std;

pair<long long, long long> dfs(string s) {
    if (s.length() == 0) return make_pair(1, 0);
    long long n = 0, m = 0, c = 0;
    for (long long i = 0; i < s.length(); i++) {
        n = n * 10 + (s[i] - '0');
        auto t = dfs(s.substr(i + 1));
        m += n * t.first + t.second;
        c += t.first;
    }
    return make_pair(c, m);
}

int main() {
    string s;
    cin >> s;
    auto r = dfs(s);
    cout << r.second << endl;
}


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

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

ans = (100 ** 2) * 100 + 1

_min = min(x)
_max = max(x)

for i in range(_min, _max + 1):
    tmp = 0
    for j in x:
        tmp += (j - i) ** 2
    ans = min(ans, tmp)

print(ans)


Measured memory_bytes: 38512
s = list(input())
inf = 10 ** 5 + 1
table = [[inf, 0] for _ in range(26)]
a = ord("a")
if len(s) == 2:
  if s[0] == s[1]:
    print(1, 2)
  else:
    print(-1, -1)
else:
  for i in range(len(s) - 2):
    if s[i] == s[i + 1] or s[i] == s[i + 2]:
      table[ord(s[i]) - a][0] = i + 1
      table[ord(s[i]) - a][1] = i + 3
  for i in range(26):
    if table[i][1] != 0:
      print(table[i][0], table[i][1])
      exit(0)
  print(-1, -1)

Measured memory_bytes: 3956
def main():
    N, K = (int(i) for i in input().split())
    X = [int(i) for i in input().split()]
    ans = 10**12
    for i in range(N-K+1):
        u = X[i]
        v = X[i+K-1]
        if u*v >= 0:
            ans = min(ans, max(abs(u), abs(v)))
        else:
            ans = min(ans, min(abs(u), v)*2+max(abs(u), v))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62576
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())

    cnt = [[0] * 10 for _ in range(10)]
    for i in range(1, n + 1):
        i = str(i)
        head = int(i[0])
        foot = int(i[-1])
        cnt[head][foot] += 1

    res = 0
    for i in range(1, n + 1):
        i = str(i)
        head = int(i[0])
        foot = int(i[-1])
        res += cnt[foot][head]
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9196
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#include <assert.h>
#include <numeric>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)(1e5+5)
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){fast;
	ll n;cin>>n;string s;
	while(n){
		s.pb(n%26+96+26*(n%26==0));
		if(n%26==0) n=n/26-1;
		else n/=26;
	}reverse(all(s));
	cout<<s<<endl;
}


Measured memory_bytes: 3588
<?php
list($n, $m) = explode(" ", trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
	$a[$i] = explode(" ", trim(fgets(STDIN)));
}
for ($j = 0; $j < $m; $j++) {
	$b[] = fgets(STDIN);
}
for ($k = 0; $k < $n; $k++) {
	$c = 0;
	for ($l = 0; $l < $m; $l++) {
		$c += $a[$k][$l] * $b[$l];
	}
	echo $c."\n";
}

Measured memory_bytes: 17216
#include <stdio.h>
#include <stdlib.h>
#define LL long long

int cmp(const void *a, const void *b) {
    LL x = *(LL*)a, y = *(LL*)b;
    return (x > y) ? -1 : ((x == y) ? 0 : 1) ;
}

void solve(LL *a, LL *b, LL *c, int x, int y, int z, int k) {
    int i, j, m, n;
    LL *d = (LL*)malloc((x*y+2) * sizeof(LL));
    m = 0;
    for(i = 0; i < x; ++i) {
        for(j = 0; j < y; ++j) {
            d[m] = a[i] + b[j]; ++m;
        }
    }
    qsort(d, m, sizeof(LL), cmp);
    /*
    printf("\n");
    for(i = 0; i < m; ++i) { printf("%lld\n", d[i]); }
    printf("\n");
    */
    LL *e = (LL*)malloc((k*z + 2)*sizeof(LL));
    m = (m < k) ? m : k;
    n = 0;
    for(i = 0; i < z; ++i) {
        for(j = 0; j < m; ++j) {
            e[n] = c[i] + d[j]; ++n;
        }
    }
    qsort(e, n, sizeof(LL), cmp);
    for(i = 0; i < k; ++i) {
        printf("%lld\n", e[i]);
    }
    free(d); free(e);
}

int main(void)
{
    int x, y, z, k, i;
    scanf("%d %d %d %d", &x, &y, &z, &k);
    LL *a = (LL*)malloc((x+2)*sizeof(LL));
    LL *b = (LL*)malloc((y+2)*sizeof(LL));
    LL *c = (LL*)malloc((z+2)*sizeof(LL));
    for(i = 0; i < x; ++i) { scanf("%lld", &a[i]); }
    for(i = 0; i < y; ++i) { scanf("%lld", &b[i]); }
    for(i = 0; i < z; ++i) { scanf("%lld", &c[i]); }
    solve(a, b, c, x, y, z, k);
    free(a); free(b); free(c);
    return 0;
}

Measured memory_bytes: 54920
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 16;
int n;
LL dp[1<<N];
bool vis[1<<N];
LL tot[1<<N];
LL arr[N + 5][N + 5];
int maxn;

LL calc(int bm) {
	if(bm == 0) return 0;
	if(vis[bm] == 1) return dp[bm];
	dp[bm] = -1e15;
	vis[bm] = 1;
	for(int i = bm; i > 0; i = (bm & (i - 1))) {
		dp[bm] = max(dp[bm], calc(bm ^ i) + tot[i]);
	}
	return dp[bm];
}

void hora(int tc) {
	cin>>n;
	for(int i = 0;i < n;i++) for(int j = 0;j < n;j++) cin>>arr[i][j];
	maxn = (1<<n) - 1;
	for(int i = 1;i <= maxn;i++) {
		LL to = 0;
		LL b = 1;
		for(int j = 0;j < n;j++, b *= 2) {
			if((i & b) == 0) continue;
			LL c = 1;
			for(int k = 0;k < n;k++, c *= 2) {
				if((i & c) == 0) continue;
				to += arr[j][k];
			}
		}
		tot[i] = to / 2;
	}
	memset(vis, 0, sizeof vis);
	cout<<calc(maxn)<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    string s, sr;
    cin >> s;
    sr = s;
    reverse(all(sr));

    if(s != sr){
        cout << "No" << endl;
        return 0;
    }
    s = sr.substr(((sr.size()+3)/2)-1);
    sr = s;
    reverse(all(sr));

    if(s != sr){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>

#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>


using namespace std;

typedef pair<int,int> pii;

const int maxn = 1000005;
//    ifstream in("A-small-attempt0.in");
//    ofstream out("A-small-attempt0.out");
//    ifstream in("A-large.in");
//    ofstream out("A-large.out");
auto &in = cin;
auto &out = cout;
int main() {
//    solve("abcabab");
    int a,b;
    in >> a >> b;
    if((a&1) && (b&1))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
//struct cmp {bool operator()(const pair<int, char> &a, const pair<int, char> &b) {if (a.first == b.first) {return a.second > b.second;} else {return a.first > b.first;}}};
#include<bits/stdc++.h>
#define endl "\n"
#define _  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define min_heap priority_queue <int, vector<int>, greater<int> >
#define max_heap priority_queue <int>
#define ll long long
//#define int long long
#define MOD 1000000007#define deb3(x,y,z) cout << #x << "=" << x << "\t"<<#y<<"="<<y<< "\t"<<#z<<"="<<z<<endl;
#define DEBUG cout<<"Hello1\n";
#define deb(x) cout << #x << " " << x << endl;
#define deb2(x,y) cout << #x << "=" << x << "\t\t"<<#y<<"="<<y<<endl;
#define deb3(x,y,z) cout << #x << "=" << x << "\t"<<#y<<"="<<y<< "\t"<<#z<<"="<<z<<endl;
#define all(v) (v).begin(),(v).end()
using namespace std;

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}

	ll mid = (sum) / n;
	ll mid2 = mid + 1;


	ll ans1 = 0, ans2 = 0;
	for (auto x : a) {
		ans1 += (x - mid) * (x - mid);
		ans2 += (x - mid2) * (x - mid2);
	}

	cout << min(ans2, ans1);
}

int32_t main() {
_
	solve();
}



Measured memory_bytes: 256
N, P = map(int, input().split())


def prime_factorize(n):
    res, a = [], 2
    while a*a <= n:
        if n % a == 0:
            ex = 0
            while n % a == 0:
                ex += 1
                n //= a
            res.append((a, ex))
        a += 1
    if n != 1:
        res.append((n, 1))
    return res

primes = prime_factorize(P)
ret = 1
for i, e in primes:
    ret *= i ** (e//N)

print(ret)



Measured memory_bytes: 38512
n = int(input())
x,y = map(int,input().split())
a = list(map(int,input().split()))

aa = float('inf')
ans = 0

for i in a:
    avg = x - i * 0.006
    dif = abs(y-avg)
    aa = min(aa,dif)
    if dif <= aa:
        ans = a.index(i)
        
print(ans+1)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int main() {
    string a, b;
    cin >> a >> b;
    int x = stoi(a+b);
    for(int i=1; i<=1000; i++) {
        if(x==i*i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> c(h+2, vector<char>(w+2));
    for(int j = 0; j < w+2; j++){
        c[0][j] = c[h+1][j] = '#';
    }
    for(int i = 1; i < h+1; i++){
        string s;
        cin >> s;
        c[i][0] = c[i][w+1] = '#';
        for(int j = 1; j < w+1; j++)
            c[i][j] = s.at(j-1);
    }
    for(int i = 0; i < h+2; i++){
        for(int j = 0; j < w+2; j++)
            cout << c[i][j];
        cout << "\n";
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string h;
  cin>>h;
  for(int i=0;i<4;i++){
    cout<<h[i];
  }
  cout<<" ";
  for(int i=4;i<12;i++){
    cout<<h[i];
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll dp[100005]={};
int main(){
    std::ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	vector<ll> v;
	for(int i=0;i<n;i++){
		ll num;cin>>num;
		v.push_back(num);
	}
	for(int i=1;i<=k;i++){
		for(int j=0;j<v.size();j++){
			if(i-v[j]>=0){if(dp[i-v[j]]==0 ) dp[i]=1;}
		}
	}	
	//cout<<dp[k]<<endl;
	if(dp[k]==1) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	int N;
	cin >> N;
	int *d = new int[N];

	for(int i = 0; i < N; i++){
		cin >> d[i];
	}
	sort(d, d + N);

	int count = 1;
	for(int i = 0; i < N - 1; i++){
		if(d[i] == d[i + 1])
			continue;
		else
			count += 1;
	}
	cout << count << endl;


	delete[] d;
	return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

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

    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    sort(all(a));

    int cnt = 0;
    // vector<bool> flag(n, 1);
    // rep(i, n) {
    //     if (flag[i] == 0) continue;
    //     if (a[i] == a[i+1]) {
    //         cnt--;
    //         for (int j=i+1; a[i]==a[j] && j<n; j++) flag[j] = 0;
    //     }
     
    //     cnt++;
    //     for (int j=n-1; j>i && 2*a[i] <= a[j]; j--) {
    //         if ((a[j] % a[i]) == 0) flag[j] = 0;
    //     }
    // }

    vector<int> flag(1e6+5, 0);
    rep(i, n) {
        flag[a[i]]++;
        if (flag[a[i]] > 1) continue;
        for (int j=2*a[i]; j<=a[n-1]; j+=a[i]) flag[j]++;
    }

    rep(i, n) if (flag[a[i]] == 1) cnt++;

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 8804
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n, m;
bool used[1001];
int cmp[1001];
vector<P> g[1001], gr[1001];
vector<int> vs;
vector<P> dag[1001];

void add_edge(int x, int y, int i){
	g[x].push_back(P(y, i));
	gr[y].push_back(P(x, i));
}

void dfs(int x){
	used[x]=1;
	for(auto q:g[x]){
		int y=q.first;
		if(!used[y]) dfs(y);
	}
	vs.push_back(x);
}
 
void rdfs(int v, int k){
	used[v]=1;
	cmp[v]=k;
	for(auto q:gr[v]){
		int y=q.first;
		if(!used[y]){
			rdfs(y, k);
		}else if(cmp[y]!=k){
			dag[cmp[y]].push_back(P(k, q.second));
		}
	}
}
 
int scc(){
	fill(used, used+n, 0);
	vs.clear();
	for(int i=0; i<n; i++){
		if(!used[i]) dfs(i);
	}
	fill(used, used+n, 0);
	int k=0;
	for(int i=vs.size()-1; i>=0; i--){
		if(!used[vs[i]]) rdfs(vs[i], k++);
	}
	return k;
}

int cmp2[1001];

void dfs2(int x, int a){
	used[x]=1;
	for(auto q:g[x]){
		int y=q.first;
		if(y==a) continue;
		if(!used[y]) dfs2(y, a);
	}
	vs.push_back(x);
}
 
void rdfs2(int v, int k, int a){
	used[v]=1;
	cmp2[v]=k;
	for(auto q:gr[v]){
		int y=q.first;
		if(y==a) continue;
		if(!used[y]){
			rdfs2(y, k, a);
		}else if(cmp2[y]!=k){
			dag[cmp2[y]].push_back(P(k, q.second));
		}
	}
}
 
int scc2(int a){
	fill(used, used+n, 0);
	fill(cmp2, cmp2+n, 0);
	for(int i=0; i<n; i++) dag[i].clear();
	vs.clear();
	for(int i=0; i<n; i++){
		if(i==a) continue;
		if(!used[i]) dfs2(i, a);
	}
	fill(used, used+n, 0);
	int k=0;
	for(int i=vs.size()-1; i>=0; i--){
		if(!used[vs[i]]) rdfs2(vs[i], k++, a);
	}
	return k;
}

int main()
{
	cin>>n>>m;
	for(int i=0; i<m; i++){
		int a, b; cin>>a>>b; a--; b--;
		add_edge(a, b, i);
	}
	int k=scc();
	int ans[200000]={};
	for(int i=0; i<k; i++){
		int ct[1001]={};
		for(auto q:dag[i]){
			ct[q.first]++;
		}
		for(int j=0; j<k; j++){
			for(auto q:dag[j]){
				ct[q.first]+=ct[j];
				if(ct[q.first]>2) ct[q.first]=2;
			}
		}
		for(auto q:dag[i]){
			if(ct[q.first]>1){
				ans[q.second]=-1;
			}else{
				ans[q.second]=1;
			}
		}
	}
	for(int i=0; i<n; i++){
		int k2=scc2(i);
		int ct[1001]={};
		for(auto q:g[i]){
			if(ans[q.second]==0) ct[cmp2[q.first]]++;
		}
		for(int j=0; j<k2; j++){
			for(auto q:dag[j]){
				ct[q.first]+=ct[j];
				if(ct[q.first]>2) ct[q.first]=2;
			}
		}
		for(auto q:g[i]){
			if(ans[q.second]!=0) continue;
			if(ct[cmp2[q.first]]>1) ans[q.second]=1;
			else ans[q.second]=-1;
		}
	}
	for(int i=0; i<m; i++){
		if(ans[i]==1) cout<<"same"<<endl;
		else cout<<"diff"<<endl;
	}
	return 0;
}

Measured memory_bytes: 10788
#include<iostream>
#include<vector>
#include<cmath>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main() {
	
	uint N;
	cin >> N;
	
	vector<vector<int>> P(N, vector<int>(N, -1));
	
	for(uint i=0; i<N; i++) {
		uint A;
		cin >> A;		
		for(uint j=0; j<A; j++) {
			int x, y;
			cin >> x >> y;
			P[i][x-1] = y;
		}
	}
	
	uint ans = 0;
	
	for(uint i=0; i<pow(2, N); i++) {
		boost::dynamic_bitset<> tf;
		tf.append(i);
		
		bool judge = true;
		for(uint l=0; l<N && judge; l++) {
			if(tf[l]) {
				for(uint m=0; m<N && judge; m++) {
					if(P[l][m] == -1 || l == m) {
						continue;						
					} else if(P[l][m] != tf[m]) {
						judge = false;
					}
				}
			}
		}
		uint tans = tf.count();
		ans = (judge) ? max(ans, tans) : ans;
	}
		
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n, i, j, q, tmp, count = 0;

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

  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%d", &tmp);
    for (j = 0; j < n ; j++) {
      if (tmp == a[j]) {
        count++;
        break;
      }
    }
  }

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



Measured memory_bytes: 2760
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        long[] val = new long[100001];
        long ans = 0;
        for (int i = 0; i < n; i++) {
            int a = in.ni();
            val[a]++;
            ans += a;
        }
        int q = in.ni();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int b = in.ni(), c = in.ni();
            if(val[b]>0){
                ans -= val[b]*b;
                ans += val[b]*c;
                val[c] += val[b];
                val[b] = 0;
            }
            sb.append(ans).append("\n");
        }
        out.println(sb.toString());
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 56188