akhauriyash/Code-Regression huggingface dataset:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ticket = [list(map(int, input().split())) for _ in range(M)]

a_min = min(a)
b_min = min(b)

ans = a_min + b_min

x = 0
y = 1
c = 2
for t in ticket:
    set_price = a[t[x] - 1] + b[t[y] - 1] - t[c]
    ans = min(ans, set_price)

print(ans)


Measured memory_bytes: 38568
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  int N;
  cin >> N;
  int T, A;
  cin >> T >> A;

  double min = 1000000;
  int minIndex = -1;
  for (int i = 0; i < N; i++) {
    int H;
    cin >> H;

    double temp = T - H * 0.006;
    if (abs(temp - A) < min) {
      min = abs(temp - A);
      minIndex = (i + 1);
    }
  }

  cout << minIndex << endl;

  return 0;
}

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

int main() {
  int a,b,c = 0;
  cin >> a;
  if((a / 100) == 1){
    c++;
  }
  b = a % 100;
  if((b / 10) == 1){
    c++;
  }
  b = b % 10;
  if(b == 1){
    c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define MAX 110

using namespace std;

static const int N = 110;

int main(){
    int n;//頂点数
    cin >> n;

    int Adj[MAX];
    int M[N][N];
    
    int u;
    int k;
    int v;
    
    for(int i=1; i<=n; i++){
        M[i][i] = 0;
    }
    
    
    for(int j=1; j<=n; j++){
        cin >> u >>k;
        for(int a=1; a<=k; a++){
            cin >> v;
            Adj[v] = 1;
            
            if(Adj[v] != 0){
            M[u][v] = 1;
            }
        }
         
        
    }
    
    for(int j=1;j<=n; j++){
        for(int i=1; i<=n; i++){
            if(i != 1){
                cout << " ";
            }
            cout << M[j][i];
        }
        
        cout << endl;
        
    
    }
    
    
    
    return 0;
    
}


Measured memory_bytes: 3128
# p,q,rに時間を整数で入力
p,q,r = map(int,input().split())
# それぞれ要する時間のリストを作成
time = [p,q,r]
# 各時間の合計値から、地点間の最大の時間数を引く
print(sum(time)-max(time))

Measured memory_bytes: 9060
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
vector<ll> v;
vector<string> vs;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
map<ll, ll> mp;

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
val = input().split(' ')
a = int(val[0])
b = int(val[1])
m = int(val[2])

alist = [int(a) for a in input().split(' ')]
blist = [int(b) for b in input().split(' ')]

min_price = sorted(alist)[0] + sorted(blist)[0]

for i in range(m):
    discount = [int(m) for m in input().split(' ')]
    price = alist[discount[0] - 1] + blist[discount[1] - 1] - discount[2]
    if price < min_price:
        min_price = price

print(min_price)


Measured memory_bytes: 18504
#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 20
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ll inf=1e18;
#define mp make_pair
#define ff first
#define ss second

int n,m;
int a[maxn];

inline int read(){
    int x=0,f=1; char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

map<pii,ll> f[maxn][maxn];

ll dp(int l,int r,int x,int y){
	if (l+1==r) return 0;
	if (f[l][r].find(mp(x,y))!=f[l][r].end()) return f[l][r][mp(x,y)];
	ll ret=inf;
	for (int i=l+1;i<r;i++) ret=min(ret,dp(l,i,x,x+y)+dp(i,r,x+y,y)+1ll*(x+y)*a[i]);
	f[l][r][mp(x,y)]=ret; return ret;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	printf("%lld\n",dp(1,n,1,1)+a[1]+a[n]);
    return 0;
}


Measured memory_bytes: 16512
#include <stdio.h>
#include <math.h>

int main(int argc,char* argv[]){
  int n,i;
  double array_x[100];
  double array_y[100];

  for(;;){
    double smallest_x = 9999.0,smallest_y = 9999.0;
    double cur_rad = 0;
    int cur = 0,smallest_cur = 0;
    int count = 0;
    
    scanf("%d",&n);
    if(n == 0){
      break;
    }

    for(i = 0; i < n; i++){
      scanf("%lf,%lf",&array_x[i],&array_y[i]);
      if(smallest_y > array_y[i]){
	smallest_y = array_y[i];
	smallest_x = array_x[i];
	cur = i;
      }else if(smallest_y == array_y[i]){
	if(smallest_x > array_x[i]){
	  smallest_x = array_x[i];
	  cur = i;
	}
      }
    }

    smallest_cur = cur;

    for(;;){
      int next_cur;
      double next_rad = 0;
      double smallest_rad = 2*M_PI;
      
      //printf("cur = %d\n",cur);

      for(i = 0; i < n; i++){
	double tmp,tmp2;
	if(i == cur){continue;}
	tmp = atan2(array_y[i]-array_y[cur],array_x[i]-array_x[cur]);
	if(tmp <= 0){tmp += M_PI*2;}
	//printf("cur = %d, i = %d rad = %lf cur_rad = %lf smallest = %lf\n",cur,i,tmp,cur_rad,smallest_rad);
	tmp2 = tmp - cur_rad;
	if(tmp2 <= 0){
	  tmp2 += 2*M_PI;
	}
	if(smallest_rad > tmp2){
	  smallest_rad = tmp2;
	  next_rad = tmp;
	  next_cur = i;
	}
      }

      count++;

      if(next_cur == smallest_cur){
	break;
      }else{
	cur = next_cur;
	cur_rad = next_rad;
      }
    }

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

    
  }
  
  return 0;
  
}

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

typedef long long ll;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

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

    ll N; cin >>N;
    vector<ll> x(N), y(N);
    
    rep(i, N) {
        cin >> x[i] >> y[i];
    }
    
    double sum = 0;
    for (int i = 0; i < N-1; i++) {
        for (int j = i+1; j < N; j++) {
            sum += sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
        }
    }

    double ans = 2 * sum / N;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string a,b;
cin>>a>>b;
a+=b[b.size()-1];
if(a==b)
{
    cout<<"Yes"<<endl;
}
else
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>

int i,num;
int main()
{
  int a[251];
  scanf("%d",&num);
  for(i=1;i<=num;i++)
    scanf("%d",&a[i]);
for(i=1;i<=num;i++){
    printf("node %d: key = %d, ",i,a[i]);
    if(i!=1)
      printf("parent key = %d, ",a[i/2]);
    if(2*i<=num)
      printf("left key = %d, ",a[2*i]);
if(2*i+1<=num)
      printf("right key = %d, ",a[2*i+1]);
 printf("\n");


}
  return 0;
}

Measured memory_bytes: 600
a,b=map(int, input().split())
s = list(input())
if s[b-1]=="A":
        s[b-1]="a"
elif s[b-1]=="B":
        s[b-1]="b"
else:
        s[b-1]="c"
l =""
for i in s:
        l += i
print(l)


Measured memory_bytes: 3060
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;
  vll a(n-1);
  vll ans(n, 0);
  rep(i, n-1){
    cin >> a[i];
    a[i]--;
    ans[a[i]]++;
  }
  for(auto&& e: ans){
    print(e);
  }
}


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

int main(){
int X;
  cin >> X;
int d[1001] = {0};
d[1] = 1;  
int ans = 0;
  
  for(int i = 2;i < 35;i++){
  int a = i;
    for(int j = 2;j < 10;j++){
    if(int(pow(a,j)) < 1001){
    d[int(pow(a,j))]++;
    }
    else break;  
    }  
  }
  
  for(int i = 1;i <= X;i++){
  if(d[i] > 0){
  ans = i;
  }
  }

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int n, k, height[101000], way[101000];
inline int cal(int i, int j){
	return height[i] - height[j] < 0 ? height[j] - height[i] : height[i] - height[j];
}
int get(int p){
	int res = 0x3f3f3f3f;
	for( int i = p-1; p-i <= k && i >= 1; --i )
		res = min(res, way[i] + cal(i, p));
	return res;
}
int main(){
	scanf("%d%d", &n, &k);
	for( int i = 1; i <= n; ++i )
		scanf("%d", &height[i]);
	way[1] = 0;
	way[2] = cal(1, 2);
	for( int i = 3; i <= n; ++i )
		way[i] = get(i);
	printf("%d\n", way[n]);
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (x*((f(x,y/2)*f(x,y/2))%mod))%mod;
}
int64_t comb(int64_t n,int64_t k){
int64_t a=1;
  for(int64_t i=1;i<=k;i++){
  a=(a*(n+1-i))%mod;
    a=(a*f(i,mod-2))%mod;
  }return a;
}
int main(){
  int64_t r1,c1,r2,c2;
  cin>>r1>>c1>>r2>>c2;
  int64_t ans=(comb(r2+c2+2,r2+1)+comb(r1+c1,r1)-comb(r2+c1+1,c1)-comb(r1+c2+1,r1)+2*mod)%mod;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3604
#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>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

//const long long MOD = 1000000007;
const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	double n, k; cin >> n >> k;
	double ans = 0;
	double a = 1.0 / n;
	rep(i, n) {
		int tmp = i+1;
		int cnt = 0;
		while (tmp < k) {
			tmp *= 2; cnt++;
		}
		ans += a * pow(0.5, cnt);
	}
	cout << fixed<<setprecision(15)<<ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define sync ios_base::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e5 * 2 + 1;
const int inf = 1e9 + 7;
const int MOD = 1e9 + 7;
const int P = 1e5 + 3;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int bpow(int x, int n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        int k = bpow(x, n / 2);
        return k * k % MOD;
    }
    return bpow(x, n - 1) * x % MOD;
}
int C(int n, int k) {
    int f = 1;
    for (int i = n; i > n - k; i--) {
        f *= i;
        f %= MOD;
    }
    int fk = 1;
    for (int i = 1; i <= k; i++) {
        fk *= i;
        fk %= MOD;
    }
    f = (f * bpow(fk, MOD - 2)) % MOD;
    return f;
}
int f[N], b[N];
signed main() {
    sync;
#ifdef varex
    freopen("test.in", "r", stdin);
    // freopen("test.out", "w", stdout);
#endif
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c) return cout << "No", 0;
    if (a == b || b == c || a == c) return cout << "Yes\n", 0;
    cout << "No\n";
    return 0;
}

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

typedef long long ll;
using namespace std;
int main()
{
  ll n,k,a[100010],b[100010],cnt[100010]={0};
  cin>>n>>k;
  rep(i,n)cin>>a[i]>>b[i];

  rep(i,n){
    cnt[a[i]]+=b[i];
  }


  ll tmp=0;
  rep(i,100010){
    tmp+=cnt[i];
    if(tmp>=k){
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 5940
#include <stdio.h>
int main(void){
    int a, b;
    scanf("%d%d", &a, &b);
    if(a / 100 == 7 || (a / 10)%10 == 7 || (a%100)%10 == 7){
        printf("Yes");
    }else{
        printf("No");
    }
    
}


Measured memory_bytes: 1736
#include<iostream>
#include <cstdio>
#include <map>
using namespace std;
map<char,int> arrs;
char arr[5];
int main(){
	scanf("%s",&arr);
	for(int i=0;i<4;i++){
		arrs[arr[i]]++;
	}	
	if(arrs.size()==2&&arrs[arr[0]]==2){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
} 

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

int total(int n) {
  if(n == 0) {
    return 0;
  }
  int first = n % 10;
  return first + total((n - first) / 10);
}
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int answer = 0;

  for(int i=1;i<=n;i++) {
    int digit = total(i);
    if(digit >= a && digit <= b) {
      answer += i;
    }
  }

  cout << answer << endl;
}

Measured memory_bytes: 256
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    k = kwargs["k"]
    # A[i] は i + 1 個の数を選ぶときにその和としてあり得るものの個数
    A = [0 for i in range(n + 1)]
    A[0] = n + 1
    res = 0

    for i in range(1, n + 1):
        A[i] = A[i - 1] + n - 2 * i

    for i in range(n + 1):
        if i + 1 >= k:
            res += A[i] % MOD

    res %= MOD
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    #kwargs["n"] = cin[0]
    #kwargs["n"], kwargs["k"] = cin
    #kwargs["n"] = [int(i) for i in cin][0]
    kwargs["n"], kwargs["k"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 38800
#include "bits/stdc++.h"
using namespace std;

const int N = 2e5 + 20;

int n, q, t, x;
set <pair <int, int>> row, col;

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

    row.insert({n, n});
    col.insert({n, n});

    long long ans = 1ll * (n - 2) * (n - 2);
    while(q--)
    {
        scanf("%d%d", &t, &x);

        if(t == 1)
        {
            auto it = col.lower_bound({x, 0});
            ans -= (*it).second - 2;
            row.insert({(*it).second - 1, x});
        }
        else
        {
            auto it = row.lower_bound({x, 0});
            ans -= (*it).second - 2;
            col.insert({(*it).second - 1, x});
        }
    }

    printf("%lld\n", ans);
}

Measured memory_bytes: 13216
// 154 B

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    for(int i=0; i<b; i++){
        cout << a;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

class UnionFind {
    // 経路圧縮によるrank更新はなし
    public:
        vector<int> rank, par, size; // rank[x]: xの高さ, par[x]: xの親のノード, size[x]: x

    // 初期化
    UnionFind() {}
    UnionFind(int size){
        rank.resize(size, 0);
        par.resize(size, 0);
        rep(i, size) makeSet(i);
    }

    void makeSet(int x){
        par[x] = x;
        rank[x] = 1;
    }

    // 根を再帰的に求める(経路圧縮)
    int findRoot(int x){
        if(x != par[x]){
            par[x] = findRoot(par[x]);
        }
        return par[x];
    }

    // 根が同じかどうか
    bool same(int x, int y){
        return findRoot(x) == findRoot(y);
    }

    //  xとyの木を併合
    bool unite(int x, int y){
        x = findRoot(x);
        y = findRoot(y);
        if(x==y) return false;
        if(rank[x]<rank[y]) swap(x, y);

        // 単純に繋げない場合, makeSetのrank[x] = 0にするのを忘れずに
        // if(rank[x]==rank[y]) rank[x]++;


        // 単純に一列につなげる場合
        rank[x] += rank[y];


        par[y] = x;
        return true;
    }

    int getRank(int x){
        return rank[findRoot(x)];
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;

    UnionFind ds = UnionFind(n);
    int x, y, z;
    rep(i, m){
        cin >> x >> y >> z;
        x--; y--;
        ds.unite(x, y);
    }
    vector<int> rootl(n);
    rep(i, n){
        rootl[i] = ds.findRoot(i);
    }
    sort(rootl.begin(), rootl.end());
    rootl.erase(unique(rootl.begin(), rootl.end()), rootl.end());
    cout << rootl.size() << endl;

    return 0;
}

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


int main(){
	int a,b;
	char ch,ch2;
	string s,s2;
	cin >> a >> b;
	
	ch=a+'0',ch2=b+'0';
	for(int i=0;i<a;i++){
		s+=ch2;
	}
	for(int i=0;i<b;i++){
		s2+=ch;
	}
	cout << min(s,s2) << endl;
	return 0;
}

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

int main() {
	int n, a, b;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		cin >> a >> b;
		cout << a + b << endl;
	}
}

Measured memory_bytes: 256
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))

x.sort(reverse=True)
y.sort()

Z=y[0]

if x[0]>=Z:
    print("War")
elif X>=Z:
    print("War")
elif Z>Y:
    print("War")
else:
    print("No War")

Measured memory_bytes: 3064
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    string s, t;
    cin >> n >> s >> t;
    for( int i = 0; i < n; ++i ) {
        cout << s[i] << t[i];

    }
    cout << endl;
    return 0;
}



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


int main(){ 
    int n, q; cin >> n >> q;
    dsu d(n);
    rep(i, q){
        int t, u, v; cin >> t >> u >> v;
        if(t==0)d.merge(u, v);
        else{
            if(d.same(u, v))cout << "1" << ln;
            else cout << "0" << ln;
        }
    }
}

Measured memory_bytes: 4000
import java.util.Scanner;
public class Main{
    static tree[] wd;
	public static void main(String[] args) {
	    int x,i,j,n,root = 0,hz;
	// TODO Auto-generated method stub
     Scanner sca = new Scanner(System.in);
     n=sca.nextInt();
     wd=new tree[n];
     int[]checkmap=new int[n+1];
    for(j=0;j<n;j++){
    	x=sca.nextInt();
	if(j==0)root=x;
	wd[x]=new tree(x);
	for(i=0;i<2;i++){
	    hz=sca.nextInt();
	    if(i==0){
            wd[x].setleft(hz);
	    }else{
	    wd[x].setright(hz);
	    }
	    if(hz==-1)hz=n;
	checkmap[hz]=1;
	}
    }
    for(j=0;j<n;j++){
	if(checkmap[j]!=1)root=j;
    }
    chain(root,-1);
     for(i=0;i<n;i++){
    	 System.out.print("node "+wd[i].getnode()+": parent = "+ wd[i].getpar()+", sibling = "+sersib(i)+", degree = "+wd[i].getdeg()+", depth = "+serdepth(i,0)+", height = "+serheight(i,0)+", ");
	 if(wd[i].getpar()==-1){
    	System.out.println("root");
	 }else if(wd[i].getdeg()==0){
    	 System.out.println("leaf");
    	}else{
	   System.out.println("internal node");
    	}
     }
   
     
	}
    public static void chain(int chi,int p){
	int i;
	wd[chi].setpar(p);
	if(wd[chi].getdeg()==0)return;
	if(wd[chi].getleft()!=-1) chain(wd[chi].getleft(),chi);
	if(wd[chi].getright()!=-1)chain(wd[chi].getright(),chi);
	}
    public static int serdepth(int x,int cnt){
	    if(wd[x].getpar()==-1)return cnt;
		cnt++;
		return serdepth(wd[x].getpar(),cnt);
	}
    public static int sersib(int n){
	if(wd[n].getpar()==-1)return -1;
        if(wd[wd[n].getpar()].getright()==n){
	    return wd[wd[n].getpar()].getleft();
	}else{
		return wd[wd[n].getpar()].getright();
	}
    }
	    public static int serheight(int n,int cnt){
	int x=-1,y=-1;
	if(wd[n].getleft()==-1&&wd[n].getright()==-1) return cnt;
	if(wd[n].getleft()!=-1){
	    x=serheight(wd[n].getleft(),cnt+1);
	}
        if(wd[n].getright()!=-1){
	    y=serheight(wd[n].getright(),cnt+1);
	}
	if(x<y)return y;
        return x;
	}
    
}
class tree{
    int node,par,n,i,degree=0,sibling,depth,height;
    int left,right;
    tree(int node){
	this.node=node;
    }
    public int getnode(){
	return node;
    }
    public void setleft(int c){
	left=c;
	if(left!=-1) degree++;
    }
    public int getleft(){
	return left;
    }
    public void setright(int c){
	right=c;
	if(right!=-1) degree++;
    }
    public int getright(){
	return right;
    }
    public void setpar(int p){
	par=p;
    }
    public int getpar(){
	return par;
    }
    public int getdeg(){
	return degree;
    }
    
}



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

int bill,num[4],rtrn[4],coin[4]={10,50,100,500};

int main()
{
	bool first=true;
	while(cin>>bill&&bill!=0)
	{
		if(!first) cout<<endl;
		else first=false;
		int sum=0;
		for(int i=0;i<4;i++)
		{
			cin>>num[i];
			sum=sum+num[i]*coin[i];
			rtrn[i]=0;
		}

		sum-=bill;

		for(int i=3;i>-1;i--)
		{
			while(sum>=coin[i]){sum-=coin[i]; rtrn[i]++;}
		}

		for(int i=0;i<4;i++)
		{
			int x=num[i]-rtrn[i];
			if(x>0) cout<<coin[i]<<" "<<x<<endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define io ios_base::sync_with_stdio(0);cin.tie(0);
#define mod 1000000009
#define pi 2*acos(0)
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
using namespace std;


int main()
{

	io;
	
	int n; cin >> n;
	string a, b; cin >> a >> b;
	for (int i = 0; i < n; i++)
	{
		cout << a[i] << b[i];
	}
}



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

int main() {
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a >= k) cout<<k<<"\n";
    else if(a+b >= k) cout<<a<<"\n";
    else cout<<a-(k-a-b)<<"\n";
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= 5) {
    cout << 0 << endl;
  } else if (a <= 12) {
    cout << b / 2 << endl;
  } else {
    cout << b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int o,n,k,i,j;
  int key;
  int A[110];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);

  /*for(o=1;o<=n;o++)
    {
      if(o == n){printf("%d\n",A[o]);}
      else printf("%d ",A[o]);
    }
  */
  for(j=1;j<=n;j++)
    {   
	      key = A[j];		
	      i = j-1;
	      while(i>0 && A[i]>key)
		{
		  A[i+1]=A[i];  
		  i = i-1;
		}
	      A[i+1] = key;
	      for(k=1;k<=n;k++){
		if(k == n)printf("%d\n",A[k]);
		else printf("%d ",A[k]);
	      }
    }
  
  return 0;
}


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

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

  int a, b;
  cin >> a >> b;

  if (a + b >= 10) cout << "error\n";
  else cout << a + b << '\n';

  return (0);
}


Measured memory_bytes: 3580
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <vector>

class DrawLots
{
private:
	int w;					// 縦線の数
	int n;					// 横線の数
	int a, b;				// 入れ替える数値(実際は-1することによってインデックスになる)
	std::vector<int> W;		// int型の動的配列Wを作成
public:
	DrawLots();
	~DrawLots();
	void Print();
	void ExchengeElement();
};

int main()
{
	DrawLots DL = DrawLots();
	DL.ExchengeElement();
	DL.Print();
}

DrawLots::DrawLots()
{
	std::cin >> w;
	std::cin >> n;
	
	W = std::vector<int>(w);

	W.assign(w, 1);

	for (int i = 0; i < w; i++)
	{
		W[i] = i + 1;
	}
}

DrawLots::~DrawLots()
{
}

void DrawLots::ExchengeElement()
{
	int tmp;
	for (int i = 0; i < n; i++)
	{
		
		scanf("%d,%d", &a, &b);

		tmp = W[a-1];
		W[a-1] = W[b-1];
		W[b-1] = tmp;

	}
}

void DrawLots::Print()
{
	for (unsigned int i = 0; i < W.size(); i++)
	{
		std::cout << W[i] << std::endl;
	}
}


Measured memory_bytes: 3200
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
	int n;
	vector<int> v;
	scanf("%d", &n);
	v.resize(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &v[i]);
	}
	sort(v.begin(), v.end(), greater<int>());
	int cnt = 0;
	int a[8] = {};
	for (int i = 0; i < n; i++) {
		if (1 <= v[i] && v[i] <= 399) {
			a[0] = 1;
		}
		if (400 <= v[i] && v[i] <= 799) {
			a[1] = 1;
		}
		if (800 <= v[i] && v[i] <= 1199) {
			a[2] = 1;
		}
		if (1200 <= v[i] && v[i] <= 1599) {
			a[3] = 1;
		}
		if (1600 <= v[i] && v[i] <= 1999) {
			a[4] = 1;
		}
		if (2000 <= v[i] && v[i] <= 2399) {
			a[5] = 1;
		}
		if (2400 <= v[i] && v[i] <= 2799) {
			a[6] = 1;
		}
		if (2800 <= v[i] && v[i] <= 3199) {
			a[7] = 1;
		}
		if (3200 <= v[i]) {
			cnt += 1;
		}
	}
	int ans = 0;
	for (int i = 0; i < 8; i++) {
		if (a[i] == 1) {
			ans += 1;
		}
	}
	if (ans == 0) {
		printf("%d %d\n", 1, cnt);
	} else {
		printf("%d %d\n", ans, ans + cnt);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;
	cin >> n;
    int temp=n,sum=0;
    while(temp) sum+=(temp%10),temp/=10;
    if(n%sum==0) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        s: String,
        t: String,
    }

    let a = s.into_bytes();
    let b = t.into_bytes();
    let mut ans = 0;
    for i in 0..a.len() {
        if a[i] != b[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2792
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n;
  while(cin >> n && n){
    vector<vector<int>> items(n+1);
    vector<vector<int>> rev_items(n+1);
    int x, y;
    for(int i = 0; i <= n; i++){
      int m; cin >> m;
      vector<pair<int, int>> nodes(m);
      for(int j = 0; j < m; j++){
        cin >> x >> y;
        nodes[j] = {x, y};
        if(j == 0) continue;
        else if(j == 1){
          items[i].push_back(max(abs(nodes[0].first - x), abs(nodes[0].second - y)));
        }
        else{
          if(nodes[j-1].first == x){
            if((x - nodes[j-2].first) * (y - nodes[j-1].second) > 0) items[i].push_back(abs(y - nodes[j-1].second));
            else items[i].push_back(-1 * abs(y - nodes[j-1].second));
          }
          else{
            if((y - nodes[j-2].second) * (x - nodes[j-1].first) < 0) items[i].push_back(abs(x - nodes[j-1].first));
            else items[i].push_back(-1 * abs(x - nodes[j-1].first));
          }
        }
      }
      for(int j = m-1; j >= 0; j--){
        x = nodes[j].first, y = nodes[j].second;
        if(j == m-1) continue;
        else if(j == m-2){
          rev_items[i].push_back(max(abs(nodes[m-1].first - x), abs(nodes[m-1].second - y)));
        }
        else{
          if(nodes[j+1].first == x){
            if((x - nodes[j+2].first) * (y - nodes[j+1].second) > 0) rev_items[i].push_back(abs(y - nodes[j+1].second));
            else rev_items[i].push_back(-1 * abs(y - nodes[j+1].second));
          }
          else{
            if((y - nodes[j+2].second) * (x - nodes[j+1].first) < 0) rev_items[i].push_back(abs(x - nodes[j+1].first));
            else rev_items[i].push_back(-1 * abs(x - nodes[j+1].first));
          }
        }
      }
      if(i > 0 && items[i].size() == items[0].size()){
        bool f = true;
        for(int j = 0; j < items[0].size(); j++){
          if(items[0][j] != items[i][j]){
            f = false;
            break;
          }
        }
        if(f){
          cout << i << endl;
          continue;
        }
        f = true;
        for(int j = 0; j < items[0].size(); j++){
          if(items[0][j] != rev_items[i][j]){
            f = false;
            break;
          }
        }
        if(f){
          cout << i << endl;
        }
      }
    }
    cout << "+++++" << endl;
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> d(n);
    for (size_t i = 0; i < n; i++) cin >> d[i];

    long long ans = 0;
    for (size_t i = 0; i < n; i++) {
        for (size_t j = i+1; j < n; j++) {
            ans += d[i] * d[j];
        }
    }

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


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  V<P> p(n);
  rep(i, n) cin >> p[i].first >> p[i].second;

  sort(p.begin(), p.end());
  ll num = 0;
  rep(i, n) {
    num += p[i].second;
    if (num >= k) {
      cout << p[i].first << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 4832
#include<bits/stdc++.h>
using namespace std;
constexpr int N = 100000 + 2;
long long n;
// long long collect(int n, int m){
//     long long ans = 1;
//     for (int i = 1; i <= m;i++){
//         ans *= (n - i + 1);
//         ans /= i;
//     }
//     return ans;
// }
// long long store[43];
// int ans[201];
// int main(){
//     cin >> n;
//     for (int i = 2; i <= 42;i += 2){
//         for (int j = 2; j <= i;j += 2)
//             store[i] += collect(i, j);
//         //cout << store[i] << endl;
//     }
//     int x = 1;
//     int y = 42;
//     int z = 1;
//     while (y >= 2){
//         if (store[y] <= n){
//             for (int i = 1; i <= y;i++)
//                 ans[z++] = x;
//             x++;
//             n -= store[y];
//         }
//         else
//             y -= 2;
//     }
//     cout << z - 1 << endl;
//     for (int i = 1; i < z;i++)
//         printf("%d%c", ans[i], i == z - 1 ? '\n' : ' ');
//     return 0;
// }

// int main(){
//     cout << collect(4, 4) << endl;
//     return 0;
// }
int a[N], b[N];
int main(){
    cin >> n;
    n++;
    constexpr int sup = 90;
    int m = sup;
    int i = 0, j = 0;
    while (n > 1)
    {
        if (n & 1){
            a[++i] = m--;
            n--;
        }
        else{
            b[++j] = m--;
            n >>= 1;
        }
    }
    cout << ((i + j) << 1) << endl;
    for (int k = 1; k <= i; k++)
        cout << a[k] << ' ';
    for (int k = j; k;k--)
        cout << b[k] << ' ';
    for (int k = sup - i - j + 1; k <= sup; k++)
        cout << k << ' ';
    return 0;
}

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

int main() {  
  int a, b, c; cin >> a >> b >> c;
  long long k; cin >> k;
  
  long long ans;
  
  if (k % 2) ans = b - a;
  else ans = a - b;
  
  if (abs(ans) < 1e18) cout << ans << endl;
  else cout << "Unfair" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iSScan(n)
	x := sum(a)
	s := 0
	ans := mod * mod
	for _, v := range a {
		s += v
		ans = smaller(ans, abs(s*2-x))
	}
	fmt.Println(ans)
}


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


int N,C,K;
const int MAX_N = 100010;

int a[MAX_N];

int main(){
	scanf("%d%d%d",&N,&C,&K);

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

	sort(a,a+N);

	int cnt=0;
	for(int i=0,j=0,t=0;i<N;i++,j--){
		if(j==0){
			cnt++;
			t=a[i]+K;
			j=C;
		}else{
			if(a[i]>t){
				cnt++;
				t=a[i]+K;
				j=C;
			}
		}
	}

	printf("%d\n",cnt);
	return 0;
}


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

using namespace std;

#define endl '\n'

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);
  
  int a,b,c,k;

  cin >> a >> b >> c >> k;

  int ans;
 
  ans = min(a,k);
  k -= min(a,k);

  if(k){
    k -= min(b,k);
  }

  if(k){
    ans -= min(k,c);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q;
  string s;
  cin>>n>>q>>s;
  vector<int> t(n,0);
  for(int i=1;i<n;++i){
    if(s[i]=='C'&&s[i-1]=='A'){
      t[i]=t[i-1]+1;
    }
    else t[i]=t[i-1];
  }
  for(int i=0;i<q;++i){
    int l,r;
    cin>>l>>r;
    cout<<t[r-1]-t[l-1]<<"\n";
  }
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

using namespace std;

int main(void){
	int a, b, k;
	int i;
	scanf("%d%d%d", &a, &b, &k);
	if (b - a+1 > 2 * k){
		for (i = 0; i < k; i++)printf("%d\n", a + i);
		for (i = k; i>0; i--) printf("%d\n", b - i+1);
	}
	else{
		for (i = a; i <= b; i++){
			printf("%d\n", i);
		}
	}
	return 0;
}

Measured memory_bytes: 128
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
int n, m;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m;
    cout << (n+m-1)/m << "\n";
}



Measured memory_bytes: 256
#include <stdio.h>
#define true 1
#define false 0
int solve(int, int);
int n,A[20];
int main()
{
  int q,m[200],i,c[20],flag;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  scanf("%d",&q);
  for(i=0;i<q;i++)
    {
      scanf("%d",&m[i]);
      flag=solve(0,m[i]);
      if(flag==1)
	{
	  printf("yes");
	  printf("\n");
	}
      if(flag==0)
	{
	  printf("no");
	  printf("\n");
	}
    }
  return 0;
}
int solve(int i, int m)
{
  int res;
  if(m==0) return true;
  if(i>=n) return false;
  res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}



Measured memory_bytes: 2108
N = int(input())

mylist = []
for n in range(N):
    x, l = map(int, input().split())
    mylist += [[x+l, x-l]]
#print(mylist)
mylist.sort()
#print(mylist)

mymin = -9999999999
myans = 0
for n in range(N):
    #print(mymin, mylist[n][1], mylist[n][0])
    if mymin <= mylist[n][1]:
        myans += 1
        mymin = mylist[n][0]
        
print(myans)

Measured memory_bytes: 20084
#include <stdio.h>
int insertionSort(int A[], int n, int g);
int shellSort(int A[], int n);
int main(){
  int total;
  scanf("%d", &total);
  int A[total];
  int i, j;
  int cnt;
  for(i=0; i<total; ++i){
	scanf("%d", &A[i]);
  }
    cnt=shellSort(A, total);
	
  //出力
	printf("%d\n", cnt);
  for(i=0; i<total; ++i){
	printf("%d\n", A[i]);
  }

}
int insertionSort(int A[], int n, int g){
  int i, j;
  int v;
  int count=0;
  for(i=g; i<n; ++i){
	v=A[i];
	j=i-g;
	while((j>=0)&&(A[j]>v)){
	  A[j+g]=A[j];
	  j=j-g;
	  ++count;
	}
	A[j+g]=v;
  }
  return count;
}
int shellSort(int A[], int n){
  int index=1;
  int i=1, j;
  int cnt=0;
  while(i<=n){
	i=i*3+1;
	++index;
  }
  --index;
  int G[index];
  i=1;
  for(j=0; j<index; ++j){
	G[j]=i;
	i=i*3+1;
  }
  printf("%d\n", index);
  for(j=(index-1); j>=0; --j){
	printf("%d", G[j]);
  	cnt=cnt+insertionSort(A, n, G[j]);
	if(j>0)
	  printf(" ");
	else
	  printf("\n");
  }
  return cnt;
}



Measured memory_bytes: 5680
#include <iostream>
//#include <bits/stdc++.h>
#include <numeric> //For gcd()
#define ll long long int
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fo(i, n) for (int i = 0; i < n; ++i)
#define foe(i, n) for (int i = 1; i <= n; ++i)
#define Fo(i, k, n) for (int i = k; i < n; ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++(i))
#define vi vector<int>
#define vll vector<ll>
#define vvl vector<vector<ll>>
#define vpll vector<pair<ll, ll>>
#define MOD 998244353
#define MAX 1024
using namespace std;
using pi = pair<ll, ll>;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    ll k,a,b;
    cin>>k>>a>>b;
    bool flag=0;
    for(ll i=1;i<=1010 ;i++){
        if(k*i <= b && k*i>=a){
            flag=1;
            break;
            
        }
    }
    if(!flag) cout<<"NG"<<endl;
    else cout<<"OK"<<endl;
	return 0;
}

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

typedef long long ll;

int n, a, b, c, d;

int main(){
	scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	if (a > b){
		std::swap(a, b);
	}
	for (int i = 0; i <= n - 1; ++ i){
		ll left = 1ll * c * i - 1ll * d * (n - 1 - i);
		ll right = 1ll * d * i - 1ll * c * (n - 1 - i);
		if (b - a >= left && b - a <= right){
			return printf("YES\n"), 0;
		}
	}
	return printf("NO\n"), 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for (int i=0;i<n;i++)

ll mod = 1e9+7;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > task(m);
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if (a>m) continue;
        task[m-a].push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    for (int i=m-1;i>=0;i--){
        for (auto j:task[i]){
            q.push(j);
        }
        if (!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5632
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

static A: [u32; 32] = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];

fn main() {
    input!{
        k: usize,
    };
    
    println!("{}", A[k - 1]);
}


Measured memory_bytes: 4352