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

int main()
{
	string line;
	while (getline(cin,line) && line != ".")
	{
		stack<char> st;
		bool flag = true;
		for (int i = 0; i < line.size(); i++)
		{
			char c = line.at(i);
			if ((c == ']' || c == ')') && st.size() < 1)
			{
				flag = false;
				break;
			}
			if (c == ']')
			{
				if (st.top() == '[')
				{
					st.pop();
				}
				else
				{
					flag = false;
					break;
				}
			}
			else if (c == ')')
			{
				if (st.top() == '(')
				{
					st.pop();
				}
				else
				{
					flag = false;
					break;
				}
			}
			else if (c == '[')
			{
				st.push(c);
			}
			else if (c == '(')
			{
				st.push(c);
			}
		}

		if (st.size() > 0)flag = false;

		if (flag)
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
	return 0;
}

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

int n;

int a, b, c;

long long mod=1000000007;
long long sil[100007];
long long osil[100007];

long long wyn;

long long dziel(long long a, long long b)
{
	long long wyk=mod-2;
	while(wyk)
	{
		if (wyk&1)
		{
			a*=b;
			a%=mod;
		}
		b*=b;
		b%=mod;
		wyk>>=1;
	}
	return a;
}

long long komb(int a, int b)
{
	if (b<0 || b>a)
		return 0;
	return (sil[a]*((osil[b]*osil[a-b])%mod))%mod;
}

long long komz(int a, int b)
{
	if (!a && !b)
		return 1;
	return komb(a+b-1, b);
}

int main()
{
	scanf("%d", &n);
	scanf("%d%d%d", &a, &b, &c);
	sil[0]=1;
	osil[0]=1;
	for (int i=1; i<=2*n; i++)
	{
		sil[i]=(sil[i-1]*i)%mod;
		osil[i]=dziel(1, sil[i]);
	}
	if (b&1)
	{
		printf("0\n");
		return 0;
	}
	b/=2;
	for (int i=0; i<=c; i++)
	{
		for (int j=0; j+i<=c; j++)
		{
			int r=c-j-i;
			if (r%3)
				continue;
			r/=3;
			long long dod=1;
			
			dod*=komz(b, i);
			dod%=mod;
			
			dod*=komb(a, j);
			dod%=mod;
			
			dod*=komb(a+b+r, r);
			dod%=mod;
			
			wyn+=dod;
			wyn%=mod;
		}
	}
	
	
	wyn*=komb(a+b, a);
	wyn%=mod;
	printf("%lld\n", wyn);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
   int n,m,l,i,k,j;
   long a[124][124],b[124][124],c[124][124];
   scanf("%d %d %d",&n,&m,&l);
   for(i=0;i<n;i++){
       for(k=0;k<m;k++){
           scanf("%ld",&a[i][k]);
       }
   }
   for(k=0;k<m;k++){
       for(j=0;j<l;j++){
           scanf("%ld",&b[k][j]);
       }
   }
   for(i=0;i<n;i++){
       for(j=0;j<l;j++){
           for(k=0;k<m;k++){
               if(k==0){
                   c[i][j]=a[i][0]*b[0][j];
               }else{
                   c[i][j]=c[i][j] + a[i][k]*b[k][j];
               }
           }
       }
   }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            printf("%ld",c[i][j]);
            if(j==l-1)break;
            printf(" ");
        }
        printf("\n");
    }
   

return 0;    
}



Measured memory_bytes: 2108
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():

    n, x, m = LI()
    start = -1
    goal = -1
    a = [0 for _ in range(m+2)]
    acc = [0 for _ in range(m+2)]
    st = {x}
    a[0] = -1
    a[1], acc[1] = x, x
    for i in range(1,m+1):
        a[i+1] = a[i]**2%m
        acc[i+1] = acc[i] + a[i+1]
        if a[i+1] in st:
            start = a.index(a[i+1])
            goal = i
            break
        else:
            st.add(a[i+1])

    ans = 0
    if n<=goal:
        ans = acc[n]
    else:
        ans = acc[goal] + (acc[goal]-acc[start-1])*((n-goal)//(goal-start+1)) + acc[(n-goal)%(goal-start+1)+start-1] - acc[start-1]

    print(ans)
main()


Measured memory_bytes: 94004
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<int> era(1000000,0);
    for(int i=2; i<=1000000; i++){
        if(era[i] == 0){
            for(ll j=i+i; j<=1000000; j += i){
                era[j] = 1;
            }
        }
    }
    int N;
    cin >> N;
    while(N!=0){
        int cnt = 0;
        for(int i=N+1; i<=N*2; i++){
            if(era[i] == 0) cnt++;
        }
        cout << cnt << endl;
        cin >> N;
    }
    return 0;
}


Measured memory_bytes: 6620
#include <iostream>

using namespace std;

int main() {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  int array[5] = {a,b,c,d,e};
  int min = a;
  int max = a;
  for (int i=1; i<5; i++) {
    if (min > array[i]) {
      min = array[i];
    }
    if (max < array[i]) {
      max = array[i];
    }
  }
  if (max - min <=k) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}

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

using namespace std;

const long long MAX = 1000000000000000000;

void Main() {
    long long N, M, R;
    cin >> N >> M >> R;
    vector<long long> r(R, 0);
    for (long long i = 0; i < R; ++i) {
        cin >> r[i];
        --r[i];
    }
    sort(r.begin(), r.end());

    vector<vector<long long> > towns(N, vector<long long>(N, MAX));
    for (long long i = 0; i < M; ++i) {
        long long a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        towns[a][b] = c;
        towns[b][a] = c;
    }
    for (long long i = 0; i < N; ++i) {
        towns[i][i] = 0;
    }

    for (long long k = 0; k < N; ++k) {
        for (long long i = 0; i < N; ++i) {
            for (long long j = 0; j < N; ++j) {
                towns[i][j] = min(towns[i][j], towns[i][k] + towns[k][j]);
            }
        }
    }

    long long ans = MAX;
    do {
        long long dist = 0;
        for (long long i = 1; i < R; ++i) {
            long long from = r[i - 1];
            long long to = r[i];
            dist += towns[from][to];
        }
        ans = min(dist, ans);
        //for (int i = 0; i < R; ++i) {
        //    cout << r[i] << " ";
        //}
        //cout << dist << endl;
    } while (next_permutation(r.begin(), r.end()));

    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    void solve();
    if(DO_BENCHMARK){
        clock_t clock_start = clock();
        solve();
        clock_t clock_end = clock();
        const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
        cout << "\n" << time << "[ms]\n";
    }
    else solve();
}

/************************************************************************************************************************************************/
void solve(){
    int K;
    string S;
    cin >> K >> S;
    if(S.size() <= K){
        cout << S << endl;
    }
    else{
        for(int i = 0;i < K;i++){
            cout << S[i];
        }
        cout << "..." << endl;
    }
}



Measured memory_bytes: 3672
[N,M] = list(map(int,input().split()))

if N<=1:
    countN = 0

    if M <=1:
        countM = 0
    else:
        countM = (M*(M-1))/2


elif N>=2:
    countN = (N*(N-1))/2

    if M <=1:
        countM = 0
    else:
        countM = (M*(M-1))/2

print(int(countN + countM))

Measured memory_bytes: 38256
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H){
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}	
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> a(m);
  for(int i=0;i<m;i++)
    cin>>a.at(i);
  auto s=lower_bound(a.begin(),a.end(),x);
  cout<<min(distance(a.begin(),s),distance(s,a.end()))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(){
  ll n,y;
  cin >> n >> y;
  rep(i,n)rep(j,n-i){
    if(y==i*10000+j*5000+(n-i-j)*1000){
      cout << i << " " << j << " " << n-i-j << endl;
      return 0;
    }
  }
  cout << "-1 -1 -1" << endl; 
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(void){
int a,b;
cin>>a>>b;
if(a==1){
a=14;
}
if(b==1){
b=14;
}
if(a>b){
cout<<"Alice"<<endl;
}else if(a<b){
cout<<"Bob"<<endl;
}else{
cout<<"Draw"<<endl;
}
}


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

bool custom(pair<int, int> a, pair<int, int> b) {
  return (a.second > b.second);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<long long int> A(n);
  long long int total = 0;
  for(int i=0;i<n;i++) {
    cin >> A[i];
    total += A[i];
  }
  sort(A.begin(), A.end());
  vector<pair<int, int>> BC(m);

  for(int i=0;i<m;i++) cin >> BC[i].first >> BC[i].second;

  sort(BC.begin(), BC.end(), custom);
  int index = 0;
  for(int i=0;i<m;i++) {
    int length = 0;
    for(int j = index; j < n; j++) {
      if(length == BC[i].first) break;
      if(A[j] < BC[i].second) {
        total += BC[i].second - A[j];
        length++;
      }
      else break;
    }
    if(length != BC[i].first) break;
    else index += length;
  }

  cout << total << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
	

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[][] M = new int[6][2];
		M[0][0] = 1;
		M[0][1] = 2;
		M[1][0] = -1;
		M[1][1] = 3;
		M[2][0] = 1;
		M[2][1] = -1;
		M[3][0] = 4;
		M[3][1] = 5;
		M[4][0] = 5;
		M[4][1] = 2;
		M[5][0] = 2;
		M[5][1] = 1;
		
		while(true) {
			String k = stdIn.next();
			if(k.equals("#")) {
				break;
			}
			int[] k1 = new int[k.length()];
			
			for(int i = 0; i < k.length(); i++) {
				k1[i] = k.charAt(i) - '0';
			}
			int now = 0;
			for(int i = 0; i < k1.length; i++) {
				now = M[now][k1[i]];
				if(now == -1) break;
			}
			
			System.out.println((now == 5)?"Yes":"No");
		}
		

	}

}

Measured memory_bytes: 17276
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;
bool solve()
{
	int k,a,b;
	cin>>k>>a>>b;
	for (int i=a;i<=b;i++)
		if (i%k==0)
			return true;
	return false;
}
int main() 
{
	ios::sync_with_stdio(false);
	if (solve())
		cout<<"OK";
	else
		cout<<"NG";
	return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
using ll = long long int;
//typedef pair<int,int> P;

int main(void){
	ll A,B,C,K;
	cin >> A >> B>> C >> K;
	ll ans=0;
	if(A<K){
		ans+=A;
	}else{
		cout << K;
		return 0;
	}
	K-=A;
	if(B<K){
	}else{
		cout << ans;
		return 0;
	}
	K-=B;
	cout << ans-K;
	return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
	Scanner sc=new Scanner(System.in);
	int H=sc.nextInt();
	int W=sc.nextInt();
	int h=sc.nextInt();
	int w=sc.nextInt();

	System.out.println((W*H)-(((W*h)+(H*w))-(w*h)));
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

bool prime[10500];
// bool used[(1<<15) + 50][(1<<15) + 50];

void mp(void)
{
	fill(prime, prime + 10500, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i < 10500; i++){
		if (prime[i]){
			for (int j = i * 2; j < 10500; j += i){
				prime[j] = false;
			}
		}
	}

	return;
}

int main(void)
{
	int n;

	mp();
	while (scanf("%d", &n) != EOF){
		int ret = 0;

		for (int i = 1; i <= n; i++){
			if (prime[i] && prime[n - i + 1]){
				// cout << i << " " << n - i + 1 << endl;
				ret++;
			}
		}
		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int N, L, Q;
int X[100000];
int U[19][100000];

int main() {
  cin >> N;
  for (int i=0; i<N; i++) cin >> X[i];
  cin >> L >> Q;
  for (int i=N-1; i>=0; i--) {
    U[0][i] = min((int)(upper_bound(X, X+N, X[i]+L) - X - 1), N-1);
    for (int k=0; k<18; k++) {
      U[k+1][i] = U[k][U[k][i]];
    }
  }
  for (int i=0; i<Q; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    if (a > b) swap(a, b);
    int c = 1;
    for (int k=18; k>=0; k--) {
      if (U[k][a] < b) {
        a = U[k][a];
        c += (1<<k);
      }
    }
    cout << c << "\n";
  }
  return 0;
}


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

int main() {
  int a,b;
  for (int i = 0;; i++) {
    cin>>a>>b;
    if (a==0 && b==0) return 0;
    else cout<<min(a,b)<<" "<<max(a,b)<<endl;
  }
}



Measured memory_bytes: 3096
from collections import defaultdict, deque


def longest_path(n, edges):
    adj_list = defaultdict(list)
    for x, y in edges:  # x -> y
        adj_list[y].append(x)

    state = [0] * n
    distances = [0] * n
    stack = deque(range(n))

    while stack:
        x = stack.pop()
        if state[x] == 0:
            state[x] = 1
            stack.append(x)
            stack.extend(adj_list[x])
        elif state[x] == 1:
            state[x] = 2
            if adj_list[x]:
                distances[x] = max(distances[y] for y in adj_list[x]) + 1

    return max(distances)


def main():
    n, m = [int(x) for x in input().split()]
    edges = [None] * m
    for i in range(m):
        edges[i] = [int(x) - 1 for x in input().split()]

    return longest_path(n, edges)


print(main())


Measured memory_bytes: 81880
#include <iostream>

using namespace std;


int main(int argc, char *argv[])
{
	int K, N, A[200005], d[200005];

	cin >> K >> N;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		if (i > 0) {
			d[i] = A[i] - A[i - 1];
		}
	}
	d[0] = A[0] + (K - A[N - 1]);

	int mn = K;

	for (int i = 0; i < N; i++) {
		mn = min(mn, K - d[i]);
	}

	cout << mn << endl;

	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 11451419194545;

int main(){

    string s; 
    cin >> s;

    map<string ,ll> mp;
    mp["SUN"] = 0;
    mp["MON"] = 1;
    mp["TUE"] = 2;
    mp["WED"] = 3;
    mp["THU"] = 4;
    mp["FRI"] = 5;
    mp["SAT"] = 6;

    ll ans = 7 - mp[s];

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> C(H);
  rep(i, H) cin >> C[i];
  // bit全探索
  int ans = 0;  
  for (int i = 0; i < (1<<H); i++) {
    for (int j = 0; j < (1<<W); j++) {
      // iが縦のbit
      int temp = 0;      
      for (int k = 0; k < H; k++) {
        if (i>>k&1) continue;
        for (int l = 0; l < W; l++) {
          if (j>>l&1) continue;
          if (C[k][l] == '#') temp++;
        }
      }
      if (temp == K) ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std ;
#define rep(i,n) for(int i =0;i<n;i++)
int main(){
	int n,a[50],count=0;
	while(cin>>n)
	{rep(i,n)
	 {cin>>a[i];
	 }
	 for(int j=1;j<(n-1);j++)
	 {
	 if((a[j]>a[j-1])&&(a[j]<a[j+1]))
	 {count++;
	 }
	 else if((a[j]>a[j+1])&&(a[j]<a[j-1]))
	 {count++;
	 }
	 }
	 cout<<count<<endl;
	}
	return 0;	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> pll;
typedef long double ldouble;
typedef pair<double, double> pdd;

void solve() {
	ll a, b; cin >> a >> b;
	int ans = 0;
	while(a <= b) ++ans, a <<= 1;
	printf("%d\n", ans);
}

int main(){
	int Tc = 1; // scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}




Measured memory_bytes: 256
import java.util.*;


public class Main{

	public static void main(String args[]){

		Scanner s = new Scanner(System.in);

		int num1 = s.nextInt();
		int num2 = s.nextInt();
		int num3 = s.nextInt();

		int min = Math.min(num1,Math.min(num2,num3));

		if(min == num1){
			if(num2 < num3){
				System.out.println(num1 + " " + num2 + " " + num3);
			}else{
				System.out.println(num1 + " " + num3 + " " + num2);
			}
		}else if(min == num2){
			if(num1 < num3){
				System.out.println(num2 + " " + num1 + " " + num3);
			}else{
				System.out.println(num2 + " " + num3 + " " + num1);
			}
		}else if(min == num3){
			if(num1 < num2){
				System.out.println(num3 + " " + num1 + " " + num2);
			}else{

				System.out.println(num3 + " " + num2 + " " + num1);
			}
		}

	}

}


Measured memory_bytes: 26124
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if ((A + B) >= C) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 504
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    long[] sum = new long[n];
    sum[0] = a[0];
    for(int i = 1; i < n; i++) {
      sum[i] = sum[i - 1] + a[i]; 
    }
    long ans = Long.MAX_VALUE;
    for(int i = 0; i < n - 1; i++) {
      long x = sum[i];
      long y = sum[n - 1] - sum[i];
      ans = Math.min(ans, Math.abs(x - y));
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 87932
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define inf 100000000007
#define maks 200007
#define pb(k) push_back(k)
#define ppb(k) pop_back(k)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vii vector<int>
#define mp make_pair
using namespace std;
ll q,s,h,d,n,ans;
main()
{
	cin>>q>>s>>h>>d>>n;
	s=min(s,2*q);
	h=min(h,2*s);
	d=min(d,2*h);
	while (n>1){
		n-=2;
		ans+=d; 
	}
	if (n>0) ans+=h;
	cout<<ans;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())

# for i in range(A, B+1):
#     if (A <= i and i <= A+K-1) or (B-K+1<= i and i <= B):
#         print(i)

S=set()

for i in range(A, min(B+1, A+K)):
    S.add(i)
for i in range(max(A, B-K+1), B+1):
    S.add(i)
for k in sorted(S):
    print(k)

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

import static java.lang.Integer.parseInt;

/**
 * Frog Going Straight
 */
public class Main {

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

		line = br.readLine();

		int D, L;
		D = parseInt(line.substring(0, line.indexOf(' ')));
		L = parseInt(line.substring(line.indexOf(' ') + 1));

		int[] dp = new int[D + 1];

		for (int i = 0; i <= D; i++) {
			if (i < L) dp[i] = i;
			else dp[i] = Integer.MAX_VALUE;
		}

		for (int i = L; i <= D; i++) {
			dp[i] = Math.min(dp[i], dp[i - L] + 1);
		}

		System.out.println(dp[D]);
	}
}

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

int main() {
    vector<int> sum(20);
    rep(i, 20) cin >> sum[i];
    vector<int> w(10);
    rep(i, 10) w[i] = sum[i];
    vector<int> k(10);
    rep(i, 10) k[i] = sum[i + 10];
    sort(w.begin(), w.end());
    sort(k.begin(), k.end());
    int a = w[9] + w[8] + w[7], b = k[9] + k[8] + k[7];
    cout << a << " " << b << endl;
}



Measured memory_bytes: 3160
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
#define biggest(A,B) A=max(A,B)
#define smallest(A,B) A=min(A,B)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	fastio;
	LL n;
	cin>>n;
	LL res;
	res=(n*n+n)/2;
	res*=n;
//	cout<<res<<endl;
		rb(i,1,n){
			
		LL j=(n*n+n)/2;
		j-=i*(n-i+1);
		res-=j;
		}
	rb(i,2,n){
		int u,v;
		cin>>u>>v;
		if(u>v)
		swap(u,v);
		res-=u*(n-v+1);
	}
	assert(res>=0);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  
  if (A > K){
    cout << K << endl;
  }
  else if (K <= A + B){
    cout << A << endl;
  }
  else {
    cout << A -(K-A-B) << endl;
  }
}

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

int N;
set<int> st;

void input()
{
    cin >> N;

    for (int i = 0; i < N; i++) {
        int ai;
        cin >> ai;
        st.insert(ai);
    }
}

int main()
{
    input();

    if (st.size() == N)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 9600
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

namespace { // Basics

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

template<typename T>
__attribute__((unused))
const auto minimum = static_cast<T const &(*)(T const &, T const &)>(std::min);

template<typename T>
__attribute__((unused))
const auto maximum = static_cast<T const &(*)(T const &, T const &)>(std::max);

template<typename T>
__attribute__((unused))
T constexpr infty = std::numeric_limits<T>::max / 3;
template<>
__attribute__((unused))
auto constexpr infty<int> = 1'100'100'100;
template<>
__attribute__((unused))
auto constexpr infty<long long int> = 100'500'400'300'200'100LL;

using lli = long long int;
using ld = long double;

} // namespace

using namespace std;

int main() {
  // cout << fixed << setprecision(10);

  string A, B; cin >> A >> B;
  cout << (A == B ? "=" : A > B ? ">" : "<") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;

ll x;

ll Count(ll n) {

    if (n == -1) {
        return 0;
    } else {
        return n / x + 1;
    }
}

int main() {

    ll a, b;
    cin >> a >> b >> x;

    ll ans = 0;

    ans += Count(b);
    ans -= Count(a-1);

    cout << ans << endl;

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    double count = 0;
    for(int i=1;i<n+1;i++){
        if(i % 2 != 0){
            count += 1;
        }
    }
    cout << count / n;
   

    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> xs(n);
    for (int& x : xs) {
        cin >> x;
    }
    long long total_sum = 0;
    for (int x : xs) {
        total_sum += x;
    }
    vector<int> divisors;
    for (int i = 1; i*i <= total_sum; ++i) {
        if (total_sum % i == 0) {
            divisors.push_back(i);
            if (total_sum != i*i) {
                divisors.push_back(total_sum / i);
            }
        }
    }
    int best = 1;
    for (int divisor : divisors) {
        int subtractions = total_sum / divisor;
        multiset<int> ys(xs.begin(), xs.end());
        while (subtractions > 0) {
            int hi = *ys.rbegin();
            ys.erase(ys.find(hi));
            if (hi - subtractions * divisor > 0) {
                ys.insert(hi - subtractions * divisor);
                subtractions = 0;
            } else if (hi > divisor) {
                subtractions -= hi/divisor;
                ys.insert(hi % divisor);
            } else {
                --subtractions;
                ys.insert(hi - divisor);
            }
        }
        int cost = 0;
        for (int y : ys) {
            if (y > 0) {
                cost += y;
            }
        }
        if (cost <= k) {
            best = max(divisor, best);
        }
    }
    cout << best << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
int INF = 0x3f3f3f3f;

int main() {
    int n;
    cin >> n;
    vector<int> A(n + 1);
    for(int i = 1; i <= n; ++i) {
        cin >> A[i];
    }
    map<int, int> log;
    for(int i = 1; i <= n; ++i) {
        log[i + A[i]]++;
    }
    ll res = 0;
    for(int i = 1; i <= n; ++i) {
        res += log[i - A[i]];
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 21156
#include <cmath>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);

	int n;
	cin >> n;

	ll ans = 1;
	for(int i=1; i<=n; ++i)
		ans = (ans*i)%1000000007;
	
	cout << ans << "\n";

	return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P,P> PP;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int h,w;
string s[555];

int dd[]={-1,0,1,0,-1};

int change(int nh,int nw){
	int cnt=0;
	vector<char> cs;
	vector<P> ps;
	rep(d,4){
		int dh=dd[d],dw=dd[d+1];
		int i=nh,j=nw;
		while(i>=0&&i<h&&j>=0&&j<w&&s[i][j]=='.'){
			i+=dh; j+=dw;
		}
		if(i>=0&&i<h&&j>=0&&j<w){
			cs.pb(s[i][j]);
			ps.pb(P(i,j));
		}
	}
	rep(k,cs.size())rep(l,k){
		if(cs[k]!='.'&&cs[k]==cs[l]){
			s[ps[k].fi][ps[k].se]='.';
			s[ps[l].fi][ps[l].se]='.';
			cnt+=2;
		}
	}
	return cnt;
}

int main(){
	cin.sync_with_stdio(false);
	cin>>h>>w;
	rep(i,h)cin>>s[i];
	int res=0;
	while(1){
		int cnt=0;
		rep(i,h)rep(j,w){
			if(s[i][j]!='.')continue;
			cnt+=change(i,j);
		}
		if(cnt==0)break;
		res+=cnt;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3360
n = int(input())
check = 0
keep = []

def q(n, check):
    if n in keep:
        return check
    else:
        keep.append(n)
    if n % 2 == 0:
        n = n // 2
    else:
        n = 3 * n + 1
    return q(n, check+1)
print(q(n,check)+1)


Measured memory_bytes: 9196
import java.util.*;

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    var inputStr = scanner.next()
    val array = inputStr.toCharArray()
    var result = 0
    for (char in array) {
        if (char == '+') {
            result++
        } else {
            result--
        }
    }
    System.out.print(result)
}

Measured memory_bytes: 31128
#include <iostream>
#include <vector>
using namespace std;
bool isLeap(int year)
{
	if (year % 400 == 0) return true;
	if (year % 100 == 0) return false;
	return year % 4 == 0;
}
int main()
{
	int a, b, k = 0;
	while (cin >> a >> b) {
		if (a == 0 && b == 0) break;
		if (k++) cout << endl;
		vector<int> res;
		for (int i=a; i<=b; ++i) if (isLeap(i)) res.push_back(i);
		if (res.empty()) {
			cout << "NA" << endl;
		}
		else {
			for (int i=0; i<res.size(); ++i) cout << res[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;

int MOD=1000000007;


int main () {
    int N,M;
    cin >> N >> M;
    vector<int> S(N,-1);
    for (int i=0; i<M; i++) {
        int s, c;
        cin >> s >> c;
        s--;
        if (S[s]==-1) S[s] = c;
        else if (S[s] != c) {
            cout << -1 << endl;
            return 0;
        }
    }
    if (N!=1 && S[0]==0) {
        cout << -1 << endl;
        return 0;
    }
    if (N==1 && S[0]==-1)  {
        cout << 0 << endl;
        return 0;
    }
    if (S[0]==-1)   S[0] = 1;
    for (int i=1; i<N; i++) {
        if (S[i]==-1) S[i]=0;
    }
    for (int i=0; i<N; i++)  cout << S[i];
    cout << endl;
}

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


int main(int argc, char const *argv[])
{
	int n,i,j,k;
	cin>>n;
	long long int a[n+1];
	long long int pref[n+1];
	pref[0]=0;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		pref[i]=pref[i-1]+a[i];
	}
	long long int dp[n+1][n+1];
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(j>=i)
			{
				dp[i][j]=0;
			}
		}
	}
	for(i=1;i<=n;i++)
	{
		int r=1;
		int c=i+1;
		while(c<=n)
		{
			long long int op=1000000000000000000;
			for(k=r;k<c;k++)
			{
				op=min(op,dp[r][k]+dp[k+1][c]+pref[c]-pref[r-1]);
			}
			dp[r][c]=op;
			r++;
			c++;
		}
	}
	cout<<dp[1][n];
	return 0;
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

void add(int &a, int b){
  a = ((a+b) % MOD + MOD) % MOD;
}

inline int mul(int a, int b) {
    add(a,0); add(b,0);
    #if !defined(_WIN32) || defined(_WIN64)
      return (int) ((long long) a * b % MOD);
    #endif
      unsigned long long x = (long long) a * b;
      unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
      asm(
        "divl %4; \n\t"
        : "=a" (d), "=d" (m)
        : "d" (xh), "a" (xl), "r" (MOD)
      );
      return m;
}

inline int modpow(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
      }
      a = mul(a, a);
      b >>= 1;
  }
  return res;
}

inline int inv(int a) {
    a %= MOD;
    if (a < 0) a += MOD;
    int b = MOD, u = 0, v = 1;
    while (a) {
      int t = b / a;
      b -= t * a; swap(a, b);
      u -= t * v; swap(u, v);
    }
    assert(b == 1);
    if (u < 0) u += MOD;
    return u;
}


 
signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  
  int n,k;
  cin >> n >> k;

  int ans = 0;
  int a = k * (k - 1) / 2,
  b = (n + 1) * n / 2 - (n + 1 - k) * (n + 1 - k - 1) / 2;
 
  add(ans ,b - a + 1);
  REP(i, n - k + 1){
    add(a , k + i);
    add(b , n - k - i);
    add(ans, b - a + 1);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define INF 1023456789

int n, m, a, b;
vector<int> AL[100005];
int p[100005];
queue<int> q;

int main(){
  //freopen("input.txt","r",stdin);
	scanf("%d%d",&n,&m);
  for(int i=0;i<m;++i){
    scanf("%d%d",&a,&b);
    --a; --b;
    AL[a].push_back(b);
    AL[b].push_back(a);
  }
  for(int i=0;i<n;++i) p[i] = INF;
  p[0] = -1;
  q.push(0);
  while(!q.empty()){
    int u = q.front();
    q.pop();
    for(int v: AL[u]){
      if(p[v] == INF){
        p[v] = u;
        q.push(v);
      }
    }
  }
  for(int i=1;i<n;++i){
    if(p[i] == INF){printf("No"); return 0;}
  }
  printf("Yes\n");
  for(int i=1;i<n;++i) printf("%d\n",p[i]+1);
}

Measured memory_bytes: 10672
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>

#define llong long long
#define rep(i,l,n) for(llong (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a) ((a)>0?(a):(-(a)))

using namespace std;

int main(){
	int x;
	cin >> x;
	x ^= 1;
	cout << x;
}

Measured memory_bytes: 3592
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    map<int, int> m;
    rep(i, n){
        int d;
        cin >> d;
        m[d]++;
    }
    int nn;
    cin >> nn;
    map<int, int> mm;
    rep(i, nn){
        int d;
        cin >> d;
        mm[d]++;
    }

    for(P p : mm){
        if(p.second > m[p.first]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N,D,ans=0;
  cin>>N>>D;
  for(ll i=0;i<N;i++){
    ll a,b;
    cin>>a>>b;
    if (a*a+b*b<=D*D){
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

const int MOD = 1e9 + 7;

struct Matrix {
	ll v[50][50];
	Matrix() {
		for (int i = 0; i < 50; i++)
			for (int j = 0; j < 50; j++)
				v[i][j] = 0;
	}
};

ll N, K;
Matrix A, I;

Matrix operator*(const Matrix& a, const Matrix& b) {
	Matrix ret;
	for (int i = 0; i < 50; i++)
		for (int j = 0; j < 50; j++)
			for (int k = 0; k < 50; k++) {
				ret.v[i][j] += a.v[i][k] * b.v[k][j] % MOD;
				ret.v[i][j] %= MOD;
			}
	return ret;
}

Matrix pow(Matrix a, ll b) {
	if (b == 0) return I;
	if (b & 1) return a * pow(a, b - 1);
	Matrix ret = pow(a, b / 2);
	return ret * ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			cin >> A.v[i][j];
	for (int i = 0; i < N; i++) I.v[i][i] = 1;

	Matrix Ak = pow(A, K);
	ll ans = 0;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++) {
			ans += Ak.v[i][j];
			ans %= MOD;
		}
	cout << ans << '\n';
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  int L;
  L = M * 2;
  vector<int> city(L);
  for (int i=0; i<L; i++){
    cin >> city.at(i);
  }
  
  for(int i=0; i<N; i++){
    int a=0;
    for(int j=0; j<L; j++){
      if (city.at(j)==i+1){
        a++;
      }
    }
    cout << a << endl;
  }
}
  

Measured memory_bytes: 256
#include<stdio.h>

long long f(long long h){
	if(h == 1){
    	return 1;
    }
    if(h < 1) {
    	return 0;
    }
    return 1 + 2*f(h/2) ;
}

int main() {
   long long h;
   scanf("%lld", &h);
   printf("%lld\n", f(h));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
int main() {
  int n;
  cin >> n;
  vector <int> a(n);
  for(int i=0;i<n;++i) cin >> a[i];
  sort(a.begin(),a.end());
  bool ok=true;
  for(int i=0;i<n;++i) {
    if(a[i]==a[i+1]) ok=false;   
  }
  if(ok) cout << "YES" << endl;
  else cout << "NO" << endl;
}




Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c, k; cin >> a >> b >> c >> k;
	if (k % 2 == 0) {
		cout << a - b << endl;
	}
	else {
		cout << b - a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    ll t, a;
    cin >> t >> a;
    REP(i, n - 1){
        ll t2, a2;
        cin >> t2 >> a2;
        const ll k = max((t + t2 - 1) / t2, (a + a2 - 1) / a2);
        t = k * t2;
        a = k * a2;
    }
    cout << t + a << endl;
    return 0;
}


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

const int inf = 1e9+1;

int calc(int a, int b, int c) {
    int tmp = a+b-2*c;
    if (tmp==0) return inf;
    int res = 0;
    while (tmp%2==0) {
        ++res;
        tmp /= 2;
    }
    return res;
}

int main() {
    int a, b, c; cin >> a >> b >> c;
    int tmp = min(calc(a, b, c), min(calc(a, c, b), calc(b, c, a)));
    if (a%2!=0 || b%2!=0 || c%2!=0) cout << 0;
    else if (tmp==inf) cout << -1;
    else cout << tmp;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
        int ans = 0;

        while(x >= 5){
            if(x >= 500){
                x -= 500;
                ans += 1000;
            }else{
                x -= 5;
                ans += 5;
            }
        }

        System.out.println(ans);
    }
}


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

using ll = long long;

pair<int, int> f(string &s) {
  int d = 0;
  ll keep = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '.') {
      d = s.size() - i - 1;
    }
    else {
      keep = keep * 10 + (s[i] - '0');
    }
  }
  
  int two = 0, five = 0;
  while (keep % 2 == 0) {
    two++;
    keep /= 2;
  }
  while (keep % 5 == 0) {
    five++;
    keep /= 5;
  }
  
  two -= d;
  five -= d;
  if (two > 10) two = 10;
  if (five > 10) five = 10;
  
  return make_pair(two, five);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<vector<ll>> x(21, vector<ll>(21));
  
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    pair<int, int> p = f(s);
    //p.first += 10;
    //p.second += 10;
    for (int j = -p.first + 10; j < 21; j++) {
      for (int k = -p.second + 10; k < 21; k++) {
        ans += x[j][k];
      }
    }
    x[p.first + 10][p.second + 10]++;
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *a,int n){
	for(int i=0;i<n;i++)printf("%d%c",a[i],(i!=n-1?' ':'\n'));
}
void array_show(LL *a,int n){
	for(int i=0;i<n;i++)printf("%lld%c",a[i],(i!=n-1?' ':'\n'));
}

vector<int> v1;
LL num[200005];

int main(){
	int n;
	int i,j,k;
	LL a,b,c;
	cin>>n;
	for(i=0,a=-1;i<n;i++){
		cin>>b;
		if(a!=b)v1.push_back(b);
		a=b;
	}
	for(i=0,a=1;i<v1.size();i++,b=a){
		if(num[v1[i]]==0){
			num[v1[i]]=a;
			continue;
		}
		a+=num[v1[i]];
		num[v1[i]]+=b;
		if(a>=MAX)a%=MAX;
		if(num[v1[i]]>=MAX)num[v1[i]]%=MAX;
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 2676
#include <iostream>
int cnt[100001];
int main()
{
    int n, q;
    scanf("%d", &n, &q);
    long long s = 0;
    for(int i = 0; i < n; i++)
    {
        int a;
        scanf("%d", &a);
        s += a;
        cnt[a]++;
    }
    for (scanf("%d", &q); q--;)
    {
        int b, c;
        scanf("%d %d", &b, &c);
        s += 1ll * cnt[b] * (c - b);
        cnt[c] += cnt[b];
        cnt[b] = 0;
        printf("%lld\n", s);
    }
    return 0;
}

Measured memory_bytes: 4212
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  ll n;
  string s;
  cin >> n >> s;
  
  int ans = 1;
  repo(i,n){
    if(s[i]!=s[i-1])ans++;
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;

int main(){
    //縦横2倍する
    int N; cin>>N;
    vector<int> t(N),v(N);
    vector<int> point(N+1,0);
    for (int i = 0; i < N; ++i) {
        cin>>t[i]; t[i]*=2;
        point[i+1]=point[i]+t[i];
    }
    for (int i = 0; i < N; ++i) {
        cin>>v[i]; v[i]*=2;
    }
    vector<vector<int>> limit(N+2,vector<int> (point[N]+1,0));

    //初速0制限
    for(int i=0;i<=point[N];++i){
        limit[0][i]=i;
    }
    //最終0制限
    for(int i=0;i<=point[N];++i){
        limit[N+1][point[N]-i]=i;
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <=point[N]; ++j) {
            if(j<point[i]) limit[i+1][j]=v[i]+point[i]-j;
            else if(j>point[i+1]) limit[i+1][j]=v[i]+j-point[i+1];
            else limit[i+1][j]=v[i];
        }
    }

    vector<int> speed(point[N]+1,(int)1e9);
    for (int i = 0; i <=point[N]; ++i) {
        for (int j = 0; j <=N+1; ++j) {
            speed[i]=min(speed[i],limit[j][i]);
        }

    }

    double ans=0.0;
    for(int i=0;i<point[N];++i){
        ans+=(speed[i]+speed[i+1])/2.0;
        //printf("%d : %d\n",i,speed[i]);
    }
    ans/=4;

    printf("%.5f \n",ans);

    return 0;
}



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

int main(){
  string t, s;
  int c = 0;
  cin >> t >> s;
  for(int i = 0; i < 3; i++)
    if(s[i] == t[i])
      c++;
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256