akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    
    rep(i, b) {
        rep(j, a) cout << 1;
        rep(j, w - a) cout << 0;
        cout << endl;
    }
    rep(i, h - b) {
        rep(j, a) cout << 0;
        rep(j, w - a) cout << 1;
        cout << endl;
    }
}


Measured memory_bytes: 1280
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

LL M;
string C;
const LL MOD = 1000000007;

int main() {
	cin >> M;
	cin >> C;
	int N = C.size();
	if (N == 1 && M == 0) {
		cout << 0 << endl;
		return 0;
	}
	LL ten = 1;
	LL arr[10] = {};
	for (int i = N - 1; i >= 0; --i) {
		arr[C[i] - '0'] += ten;
		arr[C[i] - '0'] %= MOD;
		ten *= 10;
		ten %= MOD;
	}
	vector<int>per;
	for (int i = 0; i < 10; ++i)per.push_back(i);
	int sent = C[0] - '0';
	do {
		if (per[sent] != 0) {
			LL tmp = 0;
			for (int i = 0; i < 10; ++i) {
				tmp += (arr[i] * per[i]) % MOD;
				tmp %= MOD;
			}
			if (tmp == M) {
				for (char c : C) {
					cout << per[c - '0'];
				}
				cout << endl;
				return 0;
			}
		}
	} while (next_permutation(per.begin(), per.end()));
	cout << -1 << endl;
	return 0;
}


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

int main(void) {
  int n, i;
  scanf(" %d", &n);
  long long int a[n], b[n], x=0, tmp;
  for(i=0; i < n; i++)
    a[i]=0, b[i]=0;

  for(i=0; i < n; i++){
    scanf(" %d", &a[i]);
    b[a[i] - 1]++;
  }
  for(i=0; i < n; i++){
    x+=b[i] * (b[i] - 1);
    //   printf("%d", a[i]);
    //   printf(" %d\n", b[i]);
  }
  x/=2;
  // printf("\n%d\n\n", x);

  for(i=0; i < n; i++){
    //   printf("b:%d\n",b[a[i]-1]);
    tmp=x - (b[a[i] - 1] - 1);
    printf("%lld\n", tmp);
  }
}



Measured memory_bytes: 5632
n = int(input())
a_list = []
b_list = []
ans = 0

for i in range(n):
    a,b = map(int,input().split())
    a_list.append(a)
    b_list.append(b)

for i,j in zip(a_list[::-1],b_list[::-1]):
    if (i+ans)%j != 0:
        inc = j - ((i+ans)%j)
        ans += inc
print(ans)


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

#define rep(a,b) for(ll ii=a;ii<b;ii++)
#define ll long long int
#define test() int tt; cin>>tt; while(tt--) 
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'

int main()
{
  fst_io;
  int n,i,j,k;
  cin>>n;
  vector<int> vi(n+1,0);
  for(i=1;i<=100;i++)
  {
  	for(j=1;j<=100;j++)
  	{
  	  for(k=1;k<=100;k++)
  	  {
        int x = i * i + j * j + k * k + i * j + j * k + k * i;
		if (x <= n) vi[x]++;
  	  }
  	}
  }
  for(i=1;i<=n;i++) cout<<vi[i]<<endl;
  return 0;
}

Measured memory_bytes: 3580
N = int(input())
p = list(map(int, input().split()))
sorted_p = sorted(p)
flg = False
for i in range(N - 1):
    for j in range(i, N):
        temp_p = p.copy()
        temp = temp_p[i]
        temp_p[i] = temp_p[j]
        temp_p[j] = temp
        if temp_p == sorted_p:
            print('YES')
            flg = True
            break
    if flg:
        break
else:
    print('NO')


Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x, &y)
#define sc3(x,y,z) scanf("%d%d%d",&x, &y, &z)
#define pr(a) printf("%d\n",a)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define ll long long
#define F first
#define S second
#define inf INT_MAX
const int N = 1e5 + 5;
int n, m, x, y, k, ans;
int a[15], sum;
int main(){
	cin >> x >> y;
	if (x == 1)x = 14;
	if (y == 1)y = 14;
	if (x > y)puts("Alice");
	else if (x < y)puts("Bob");
	else puts("Draw");

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

int main() {

	long N, H; cin >> N >> H;
	long res = 0;
	vector<long> A, B;

	for (int i = 0; i < N; i++) {
		long a, b; cin >> a >> b;
		A.push_back(a);
		B.push_back(b);
	}

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

	long amax = A[N - 1];

	for (int i = 0; i < N; i++) if (H > 0 && B[i] > amax) { H -= B[i]; res++; } else break;

	if (H > 0) { res += (H - 1) / amax; res++; }

	cout << res << endl;
}

Measured memory_bytes: 2036
S = input()

N = len(S)
ans = [0] * N

for i in range(N):
    if S[i]=="R":
        l_pos = S[i:].find("L") + i
        if (l_pos-i)%2==0:
            ans[l_pos] += 1
        else:
            ans[l_pos-1] += 1
    else:
        r_pos = S[:i].rfind("R")
        if (i-r_pos)%2==0:
            ans[r_pos] += 1
        else:
            ans[r_pos+1] += 1
            
ans = " ".join(map(str, ans))
print(ans)


Measured memory_bytes: 10484
#include<bits/stdc++.h>
#define ull unsigned long long
# define ll long long
# define mod 1000000007LL 
using namespace std;
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll arr[n+1];
    arr[0]=0;
    ll count=0;
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
        if(i%2!=0 && arr[i]%2!=0)
        count++;

    }
    cout<<count;


    
    return 0;
}

Measured memory_bytes: 3636
L, R = map(int, raw_input().split())

"""
R ????????1??????
y 0001????0??????
     ^d   ^rd
x 0001???????1??
             ^ld
L ???????????0???
"""

ans = 0

for d in range(70):
  if d<len(bin(L))-3:
    LD = []
  elif d==len(bin(L))-3:
    LD = [i for i in range(-1,d) if i==-1 or (L>>i&1)==0]
  else:
    LD = [d]
  if d<len(bin(R))-3:
    RD = [d]
  elif d==len(bin(R))-3:
    RD = [i for i in range(-1,d) if i==-1 or (R>>i&1)==1]
  else:
    RD = []
  for ld in LD:
    for rd in RD:
      a = 1
      for i in range(d):
        # i<ld:  x==0 or 1
        # i==ld: x==1
        # i>ld:  x==L
        # i<rd:  y==0 or 1
        # i==rd: y==0
        # i>rd:  y==R
        # y>=x
        if i<ld and i<rd:
          a *= 3
        if i<ld and i==rd:
          a *= 1
        if i<ld and i>rd:
          a *= (R>>i&1)+1
        if i==ld and i<rd:
          a *= 1
        if i==ld and i==rd:
          a *= 0
        if i==ld and i>rd:
          a *= (R>>i&1)
        if i>ld and i<rd:
          a *= 2-(L>>i&1)
        if i>ld and i==rd:
          if (L>>i&1)==0:
            a *= 1
          else:
            a *= 0
        if i>ld and i>rd:
          if (L>>i&1)==(R>>i&1):
            a *= 1
          if (L>>i&1)==0 and (R>>i&1)==1:
            a *= 1
          if (L>>i&1)==1 and (R>>i&1)==0:
            a *= 0
      ans += a
print ans%(10**9+7)


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

using namespace std;

typedef long long ll;
typedef long double ld;
const ll inf = 1e9 + 10;
const ll maxn = 1e5 + 163;
const ll alf = 26;
const ll dlm = 1e9+7;
const ll del = 10979 ;
const int eps = 1e-7 ;
const int maxq = 1e2+132 ;

ll w[maxq] , v[maxq] ;
ll dp[maxq][maxn] ;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    int N,W;
    cin>>N>>W;
    for(int i=1;i<=N;i++){
        cin>>w[i]>>v[i];
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=W;j++){
            if((j-w[i])>=0)dp[i][j] = max(dp[i-1][j]  , dp[i-1][j-w[i]] + v[i] ) ;
            else dp[i][j] = dp[i-1][j] ;
        }
    }
    cout<<dp[N][W];
    return 0;
}



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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> vec(H);
  
  for (int i=0; i<H; i++){
    cin >> vec.at(i);
  }
  
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (vec.at(i).at(j) != '#'){
        int c=0;
        
        if (i>0 && j>0){
          if (vec.at(i-1).at(j-1) == '#'){
            c++;
          }
        }
        if (i>0){
          if (vec.at(i-1).at(j) == '#'){
            c++;
          }
        }
        if (i>0 && j<W-1){
          if (vec.at(i-1).at(j+1) == '#'){
            c++;
          }
        }
        if (j>0){
          if (vec.at(i).at(j-1) == '#'){
            c++;
          }
        }
        if (j<W-1){
          if (vec.at(i).at(j+1) == '#'){
            c++;
          }
        }
        if (i<H-1 && j>0){
          if (vec.at(i+1).at(j-1) == '#'){
            c++;
          }
        }
        if (i<H-1){
          if (vec.at(i+1).at(j) == '#'){
            c++;
          }
        }
        if (i<H-1 && j<W-1){
          if (vec.at(i+1).at(j+1) == '#'){
            c++;
          }
        }
        
        if (c == 0){
          vec.at(i).at(j) = '0';
        }
        else if (c == 1){
          vec.at(i).at(j) = '1';
        }
        else if (c == 2){
          vec.at(i).at(j) = '2';
        }
        else if (c == 3){
          vec.at(i).at(j) = '3';
        }
        else if (c == 4){
          vec.at(i).at(j) = '4';
        }
        else if (c == 5){
          vec.at(i).at(j) = '5';
        }
        else if (c == 6){
          vec.at(i).at(j) = '6';
        }
        else if (c == 7){
          vec.at(i).at(j) = '7';
        }
        else if (c == 8){
          vec.at(i).at(j) = '8';
        }
      }
    }
  }
  
  for (int i=0; i<H; i++){
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;

	if(a1 + a2 + a3 > 21) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
string a[maxn]; 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	for(int i=1;i<=5;i++)
		cin>>a[i];
	for(int i=1;i<=5;i++)
	{
		if(a[i]=="0")
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}




Measured memory_bytes: 6764
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string>
#include<vector>

#define ll long long
#define ull unsigned long long

using namespace std;
int main(void) {

	char A = '\0', B = '\0';
	
	scanf("%c %c", &A, &B);

	if (A - B > 0)
		printf(">\n");
	else if (A - B < 0)
		printf("<\n");
	else
		printf("=\n");
	
	return 0;
}

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

int main() {
  	int x;
  	cin >> x;
  
  	if(x == 0) cout << 1 << endl;
  	else cout << 0 << endl;
  	return 0;  
}


Measured memory_bytes: 3568
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int r_len = s.length();

	int count = 0;
	rep(i,r_len-1){
		if(s[i] == 'B' && s[i+1] =='W') count++;
		else if(s[i] == 'W' && s[i+1] =='B') count++;
	}
	cout << count << endl;

	return 0;
}

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

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

    int c[n], s[n], f[n];

    for(int i=0; i<n-1; i++)
        scanf("%d%d%d",&c[i], &s[i], &f[i]);

    for(int i=0; i<n-1; i++){
        int time = s[i] + c[i];

        for(int j=i+1; j<n-1; j++){
            if(s[j] > time)
                time += s[j] - time;

            if(time%f[j] != 0)
                time += (((time/f[j]) + 1) * f[j]) - time;

            time += c[j];
        }

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

    puts("0");

    return 0;
}


Measured memory_bytes: 256
import types

_atcoder_code = """
# Python port of AtCoder Library.

__version__ = '0.0.1'
"""

atcoder = types.ModuleType('atcoder')
exec(_atcoder_code, atcoder.__dict__)

_atcoder_dsu_code = """
import typing


class DSU:
    '''
    Implement (union by size) + (path compression)
    Reference:
    Zvi Galil and Giuseppe F. Italiano,
    Data structures and algorithms for disjoint set union problems
    '''

    def __init__(self, n: int = 0):
        self._n = n
        self.parent_or_size = [-1] * n

    def merge(self, a: int, b: int) -> int:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        x = self.leader(a)
        y = self.leader(b)

        if x == y:
            return x

        if -self.parent_or_size[x] < -self.parent_or_size[y]:
            x, y = y, x

        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x

        return x

    def same(self, a: int, b: int) -> bool:
        assert 0 <= a < self._n
        assert 0 <= b < self._n

        return self.leader(a) == self.leader(b)

    def leader(self, a: int) -> int:
        assert 0 <= a < self._n

        if self.parent_or_size[a] < 0:
            return a

        self.parent_or_size[a] = self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]

    def size(self, a: int) -> int:
        assert 0 <= a < self._n

        return -self.parent_or_size[self.leader(a)]

    def groups(self) -> typing.List[typing.List[int]]:
        leader_buf = [self.leader(i) for i in range(self._n)]

        result = [[] for _ in range(self._n)]
        for i in range(self._n):
            result[leader_buf[i]].append(i)

        return list(filter(lambda r: r, result))
"""

atcoder.dsu = types.ModuleType('atcoder.dsu')
exec(_atcoder_dsu_code, atcoder.dsu.__dict__)
DSU = atcoder.dsu.DSU

import sys
# from atcoder.dsu import DSU

sys.setrecursionlimit(10**9)

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

for _ in range(M):
    A, B = map(int, input().split())
    d.merge(A-1, B-1)

print(len(d.groups()) - 1)


Measured memory_bytes: 26068
N, Q = map(int, input().split())
S = list(input())
lr = [list(map(int, input().split())) for i in range(Q)]

mark = [0]*(N+1)

for i in range(2, N+1):
    if S[i-2] == 'A' and S[i-1] == 'C':
        mark[i] = mark[i-1] + 1
    else:
        mark[i] = mark[i-1]

for i in lr:
    print(mark[i[1]]-mark[i[0]])

Measured memory_bytes: 31376
from bisect import bisect_left
from operator import itemgetter

n, q = map(int, input().split())
stx = [tuple(int(x) for x in input().split()) for _ in range(n)]
d = [int(input()) for _ in range(q)]

ans = [-1] * q
skip = [-1] * q

stx.sort(key=itemgetter(2))

for s, t, x in stx:
    L = bisect_left(d, s-x)
    R = bisect_left(d, t-x)
    while L < R:
        if skip[L] == -1:
            ans[L] = x
            skip[L] = R
            L += 1
        else:
            L = skip[L]

for x in ans:
    print(x)


Measured memory_bytes: 54032
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
 
 
 int main(){
  ll  n ; cin>> n ;
  ll nd = n ;
  ll ko=0 ;
  while(nd%2==0){
    nd/=2 ;
    ko++ ;
  }
  ll base = pow(2,ko) ;
  ll aase = n-base ;
  if(nd==1||n<=2) cout<< "No"<<endl ;
  else{
    cout<<"Yes"<<endl ;
    ll k= (n-1)/2 ;
    rep(i,k){
      ll p= 2*(i+1) ;
      cout<<p<<" "<<p+1<<endl ;
      cout<<p+1<<" "<<1<<endl ;
      cout<<1<<" "<<p+n<<endl ;
      cout<<p+n<<" "<<p+1+n<<endl ;
    }
     cout<<n+1<<" "<<2<<endl ;
   if(n%2==0){
     cout<<base+1<<" "<<n<<endl ;
     cout<<aase+n<<" "<<2*n<<endl;
   }

  }
   return 0 ;
 }



Measured memory_bytes: 3968
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int n, c, ans = 1000000000;
	cin >> n >> c;
	vector<vector<int>> d(c + 1, vector<int>(c + 1)), a(n, vector<int>(n));
	for(int i = 1; i <= c; i++){
		for(int j = 1; j <= c; j++){
			cin >> d[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
		}
	}
	vector<vector<int>> cnt(3, vector<int>(c + 1));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cnt[(i + j) % 3][a[i][j]]++;
		}
	}
	for(int i = 1; i <= c; i++){
		for(int j = 1; j <= c; j++){
			if(i == j) continue;
			for(int k = 1; k <= c; k++){
				if(i == k || j == k) continue;
				int t = 0;
				for(int l = 1; l <= c; l++){
					t += cnt[0][l] * d[l][i];
					t += cnt[1][l] * d[l][j];
					t += cnt[2][l] * d[l][k];
				}
				ans = min(ans, t);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
   
int a[1000000], n;
    
int BinarySearch(int key)
{
   int left = 0;
   int right = n;
   int mid;
   
   while ( left < right ) {
      mid = ( left + right) / 2;
      if  ( key == a[mid] ) return 1;
      if ( key > a[mid] ) left = mid + 1;
      else if ( key < a[mid] ) right = mid;
   }
   return 0;
}
    
   
int main()
{
   int i, k, q, sum = 0;
   
   scanf("%d", &n);
   for ( i = 0; i < n; i++ ) {
      scanf("%d", &a[i]);
   }
   
   scanf("%d", &q);
   for ( i = 0; i < q; i++ ) {
      scanf("%d", &k);
      if ( BinarySearch( k ) ) ++sum;
   }
   
   printf("%d\n", sum);
        
   return 0;
}

Measured memory_bytes: 2096
fn read_multi<T: std::str::FromStr>() -> Vec<T> {
    let mut s = std::string::String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_2d<T: std::str::FromStr>(n: i64) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace()
            .map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}


fn main() {
    //println!("Hello, world!");
    let vn: Vec<i64> = read_multi();
    //println!("{:?}", vn);

    let vvn: Vec<Vec<i64>> = read_2d(vn[0]); //i32
    //println!("{:?}", vvn);

    // let mut ans: i64 = 0;

    // 　x + y + z の場合を0
    let mut sum0: Vec<i64> = std::vec::Vec::<i64>::new();
    let mut sum1: Vec<i64> = std::vec::Vec::<i64>::new();
    let mut sum2: Vec<i64> = std::vec::Vec::<i64>::new();
    let mut sum3: Vec<i64> = std::vec::Vec::<i64>::new();
    let mut sum4: Vec<i64> = std::vec::Vec::<i64>::new();
    let mut sum5: Vec<i64> = std::vec::Vec::<i64>::new();
    let mut sum6: Vec<i64> = std::vec::Vec::<i64>::new();
    let mut sum7: Vec<i64> = std::vec::Vec::<i64>::new();

    for i in 0..vn[0] as usize {
        sum0.push(vvn[i][0] + vvn[i][1] + vvn[i][2]);
        sum1.push(vvn[i][0] + vvn[i][1] - vvn[i][2]);
        sum2.push(vvn[i][0] - vvn[i][1] + vvn[i][2]);
        sum3.push(vvn[i][0] - vvn[i][1] - vvn[i][2]);
        sum4.push(- vvn[i][0] + vvn[i][1] + vvn[i][2]);
        sum5.push(- vvn[i][0] + vvn[i][1] - vvn[i][2]);
        sum6.push(- vvn[i][0] - vvn[i][1] + vvn[i][2]);
        sum7.push(- vvn[i][0] - vvn[i][1] - vvn[i][2]);
    }
    sum0.sort_unstable();
    sum0.reverse();
    sum1.sort_unstable();
    sum1.reverse();
    sum2.sort_unstable();
    sum2.reverse();
    sum3.sort_unstable();
    sum3.reverse();
    sum4.sort_unstable();
    sum4.reverse();
    sum5.sort_unstable();
    sum5.reverse();
    sum6.sort_unstable();
    sum6.reverse();
    sum7.sort_unstable();
    sum7.reverse();

    //println!("{:?}", sum0);
    //println!("{:?}", sum7);
    
    //let mut a: i64 = 0;
    let mut va: Vec<i64> = [0,0,0,0,0,0,0,0].to_vec();
  
    for i in 0..vn[1] as usize {
        va[0] = va[0] + sum0[i];
        va[1] = va[1] + sum1[i];
        va[2] = va[2] + sum2[i];
        va[3] = va[3] + sum3[i];
        va[4] = va[4] + sum4[i];
        va[5] = va[5] + sum5[i];
        va[6] = va[6] + sum6[i];
        va[7] = va[7] + sum7[i];
    }
    
    va.sort();
    va.reverse();
    //println!("{:?}", va);
    println!("{}", va[0]);


}


Measured memory_bytes: 2328
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define int long long
#define endl "\n"
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b,c) for(int a=b; a<c; a++)
#define frr(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define pii pair<int,int>
#define R(a) ll a; cin >> a;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
#define RA(a, n) ll a[(n) + 1] = {}; fr(i, 1, (n)+1) {cin >> a[i];}
#define RM(a, n, m) int a[n + 1][m + 1] = {}; fr(i, 1, n+1) {fr(j, 1, m+1) cin >> a[i][j];}
#define reset(X) memset(X, 0, sizeof(X))
using vi=vector<int>;
const int inf = 1e18;
const int mod=1e9+7;
unsigned int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int modInverse(int n, int p)
{
    return power(n, p-2, p);
}
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    if(b.fi==a.fi)return (b.se>=a.se);
    return (b.fi>a.fi);
}
signed main()
{
    fastio;
    RA(a,3);
    sort(a+1,a+4);
    if(a[2]==a[1]&&a[2]!=a[3]||(a[2]==a[3]&&a[2]!=a[1]))
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}

int n, c[500], s[500], f[500], ta = 0;

signed main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}
	for (int i = 0; i < n - 1; i++) {
		for (int j = i; j < n - 1; j++) {
			if (s[j] >= ta)ta = s[j] + c[j];
			else {
				if ((ta - s[j]) % f[j] == 0) {
					ta += c[j];
				}
				else {
					ta = c[j] + s[j] + f[j] * (((ta - s[j]) / f[j]) + 1);
				}
			}
		}
		cout << ta << endl;
		ta = 0;
	}
	cout << 0 << endl;
	getchar(); getchar();
	return 0;
}

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

int infact[300][300] = {};

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

#define MAX_V 300
vector<edge> G[MAX_V];
bool used[MAX_V];

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

// v...target vertex, t...end vertex, f...maximum flow 
int dfs(int v, int t, int f){
    if(v == t)  return f;

    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                infact[v][e.to] = 1;
                infact[e.to][v] = -1;
                return d;
            }
        }
    }

    return 0;
}

const int INF = 1<<29;

// maxflow from s to t
int max_flow(int s, int t){
    int flow = 0;
    while(1){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0)  return flow;
        flow += f;
    }
}

int main(){
    int n, m;
    cin >> n >> m;
    int v[n][n];
    for(int i = 0; i < n*n; i++)    v[i/n][i%n] = 0;
    vector<int> a(m), b(m);
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        add_edge(a[i], b[i], 1);
        add_edge(b[i], a[i], 1);
        v[a[i]][b[i]] = 1;
        v[b[i]][a[i]] = -1;
    }
    int s, t;
    cin >> s >> t;
    cout << max_flow(--s, --t) << endl;
    vector<int> ans;
    for(int i = 0; i < m; i++){
        if(v[a[i]][b[i]]*infact[a[i]][b[i]] == -1)  ans.push_back(i+1);
    }
    cout << ans.size() << endl;
    for(int val : ans)  cout << val << endl;
    return 0;
}


Measured memory_bytes: 3972
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;
const int MAX_N = 1e5 +6;
const LL INF = 1e17 + 6;

LL pre[MAX_N];
LL a[MAX_N];

int main () {
	int n;
	while (scanf("%d",&n) != EOF) {
		for (int i=1;n>=i;i++) {
			scanf("%lld",&a[i]);
		}
		sort(a+1,a+n+1);
		vector<LL> v;
		v.push_back(-INF);
		for(int i=1;n>=i;i++) {
			v.push_back(a[i]);
		}
		v.push_back(INF);
		for(int i=1;n>=i;i++) {
			pre[i] = pre[i-1] + a[i];
		}
		int ans=0;
		for (int i=1;n>=i;i++) {
			LL now=pre[i]*2;
			int id = i;
			while (true) {
				//bool update = false;
				int _ = upper_bound(v.begin(),v.end(),now) - v.begin();
//				cout<<"_ = "<<_<<"i = "<<i<<endl;
				_--;
				now = pre[_]*2;
				if (_ == id) break;
				else id=_;
			}
			if (id==n) ans++;
		}
		printf("%d\n",ans);
	}
}



Measured memory_bytes: 2676
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
const int N=1e5+5;
int a[N],b[N],d[N],p[N],ans[N],vis[N],st[N],tt=0,n,m;ll k;
void dfs(int u){if(!vis[u])vis[u]=1,st[++tt]=u,dfs(p[u]);}
main()
{
    scanf("%lld",&n);for(int i=1;i<=n;i++)scanf("%lld",&a[i]),d[i]=a[i]-a[i-1];
    scanf("%lld%lld",&m,&k);
    for(int i=1;i<=n;i++)p[i]=i;
    for(int i=1;i<=m;i++)scanf("%lld",&b[i]),swap(p[b[i]],p[b[i]+1]);
    for(int i=1;i<=n;i++)
    {
        if(vis[i])continue;
        tt=0;dfs(i);
        for(int j=1;j<=tt;j++)ans[st[j]]=d[st[(j+k-1)%tt+1]];
    }
    for(int i=1;i<=n;i++)printf("%lld.0\n",ans[i]+=ans[i-1]);
}


Measured memory_bytes: 9068
#include <iostream>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
    int n,c,k;
    cin>>n>>c>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int op=a[0]+k;
    int pas=1;
    int num=1;
    for(int i=1;i<n;i++)
    {
        if(a[i]>op||pas==c)
        {
            op=a[i]+k;
            pas=1;
            num++;
        }
        else
            pas++;
    }
    cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)


void solve(long long N, std::vector<long long> L){
    ll ans = 0;
    sort(L.begin(), L.end());
    rep(i, N){
        for(ll j=i+1; j< N; j++){
            //* L[i], L[j]
            ll a = L[i], b = L[j];
            ll lb = abs(a-b), ub = a+b;
            auto upper = lower_bound(L.begin(), L.end(), ub );
            auto lower = lower_bound(L.begin(), L.end(), lb+1);
            ll tmp = upper - lower;
            ans += tmp;
            if(lb < a && a < ub)
                ans -= 1;
            if(lb < b && b < ub)
                ans -= 1;
        }
    }
    cout << ans/3 << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122
#define int long long

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
/*
#pragma comment(linker, "/STACK: 20000000005")
*/


using namespace std;


const int N = 200005, MOD = 1e9 + 7;



main()
{
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    if ((int)s.size() == 6 && s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int n, w[105];
    cin >> n;
    REP(i, n) cin >> w[i];

    int ans = INT_MAX;

    REP(i, n-1){
        int f = 0, e = 0;
        for(int j = 0; j <= i; j++) f += w[j];
        for(int k = i + 1; k < n; k++) e += w[k];
        int tmp = abs(f - e);
        ans = min(tmp, ans);
    }

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


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>;

bool ans = false;
int k;

void dfs(int a, int b, int c, int x) {
  if(x <= k) {
    if(b > a && c > b) {
      ans = true;
      return;
    }
    dfs(a * 2, b, c, x+1);
    dfs(a, b * 2, c, x+1);
    dfs(a, b, c * 2, x+1);
  }
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cin >> k;

  dfs(a, b, c, 0);

  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3632
using System;
using System.Linq;
namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var abc=Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToList();
            abc.Sort();
            Console.WriteLine(abc[2]==abc[0]+abc[1]?"Yes":"No");
        }
    }
}



Measured memory_bytes: 11348
#include <stdio.h>

//             0  1  2   3   4    5    6     7     8     9     10     11
int coins[] = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};   // 使える引き出し方
int count[] = {5, 5, 8,  5,  8,   5,   8,    5,    8,    5,     2,     1};   // 上記引き出し方を最大何回使う可能性があるか

int bank(int in, int c){
	if (c == 0) return (in > count[c]) ? 10000 : in;                         // 1円で払う時専用。6枚以上払うのはおかしい。上の階層で払わなすぎたのでNGを突き返す。
	int ret = 10000;                                                         // 最小値を競わせるため、NG値を入れておく。
	for (int i = 0; i <= count[c]; i++){
		if (in - coins[c] * i < 0) break;                                    // 引き出してマイナスになるとおかしい。これ以上は今の引き出し方を増やす必要はない。
		int tmp = bank(in - coins[c] * i, c - 1);                            // 引き出した残りを次の深さの人に渡す。
		if (tmp + i < ret) ret = tmp + i;                                    // 戻り値の中で一番小さいものを選ぶ。（今階層の引き出し方を何回使ったかを足す）
	}
	return ret;
}

int main(int in){
	scanf("%d", &in);
	printf("%d", bank(in, 11));
	//getchar();getchar();
	return 0;
}


Measured memory_bytes: 128
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a,b;scanf("%d%d",&a,&b);printf("%d\n",6-a-b);
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
// #include <string>
// #include <vector>
// #include <algorithm> // to use min_element

using namespace std;


int main(){
	int i=0, n;
	cin >>n;
	while ((int)pow(2.0,  i)<=n){
		i++;
	}
	cout << (int) pow(2.0, i-1);
return 0;
}

Measured memory_bytes: 256
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
int main()
{   char s[100001];
    scanf("%s",s);
    int q;
    scanf("%d",&q);
    int flag=0,fn=0,rn=0;
    int  fadd[200001]={-1},radd[200001]={-1};
    for(int i=0;i<q;i++){
        int tmp;
        scanf("%d",&tmp);
        if(tmp==1){
            if(flag==1)flag=0;else flag=1;
        }else{
            int f;
            char a[2];
            scanf("%d",&f);
            scanf("%s",a);
            if(f==1&&flag==0){
                fadd[fn]=a[0]-'a';
                fn++;
            }else if(f==1&&flag==1){
                radd[rn]=a[0]-'a';
                rn++;
            }else if(f==2&&flag==0){
                radd[rn]=a[0]-'a';
                rn++;
            }else{
                fadd[fn]=a[0]-'a';
                fn++;
            }
        }
    }
  if(flag==0){
        for(int i=fn-1;i>=0;i--){
            printf("%c",fadd[i]+'a');
        }
        printf("%s",s);
        for(int i=0;i<rn;i++){
            printf("%c",radd[i]+'a');
        }
    }else{
        for(int i=rn-1;i>=0;i--){
        printf("%c",radd[i]+'a');
        }
        int l=strlen(s);
        for(int i=l-1;i>=0;i--){
            printf("%c",s[i]);
        }
        for(int i=0;i<fn;i++){
            printf("%c",fadd[i]+'a');
        }
    }
    

    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#define ll long long
#define rep(i,l,r,d) for(ll i=(l);i<(r);i+=(d))
#define max(p,q) ((p)>(q)?(p):(q))
int main(void){
    ll A, B, C, K, ANS, M;
    scanf("%lld %lld %lld\n%lld", &A, &B, &C, &K);
    M = max(A, max(B, C));
    ANS = A+B+C-M;
    rep(i, 0, K, 1) M *= 2;
    printf("%lld\n", ANS+M);
    return 0;
}


Measured memory_bytes: 128
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int out=1,n,o2=1,a;
	cin>>n;
	rep(i,n){
		cin>>a;
		if(a%2==0) out*=2;else out*=1;
		o2*=3;
	}
	cout<<o2-out<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
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;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int levenshtein(string &S, string &T){
    int n = S.size();
    int m = T.size();

    vector<vector<int>> dp(n+1, vector<int>(m+1));

    REP(i, n+1) dp[i][0] = i;
    REP(i, m+1) dp[0][i] = i;

    Rep(i, 1, n+1){
        Rep(j, 1, m+1){
            dp[i][j] = min({dp[i][j-1] + 1, dp[i-1][j] + 1, dp[i-1][j-1] + !(S[i-1] == T[j-1])});
        }
    }
    return dp[n][m];
}

int main(void)
{
    string S,T;
    cin >> S >> T;
    pr(levenshtein(S,T));
}


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

int main() {
	int n, a;
	cin >> n >> a;
	
	// 余り
	int c = n % 500;
	
	if (a >= c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  ll N;
  cin>>N;
  
  vector<ll>d(N);
  ll sum=0;
  ll ans=0;
  rep(i,N){
    cin>>d[i];
    sum+=d[i];
  }
  rep(i,N){
    ans+=(sum-d[i])*d[i];
  }

  cout<<ans/2<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
typedef long long ll;

bool jdg(vector<int>& w, int max_w, int track)
{
	bool ret = true;
	int sum = 0;

	for (vector<int>::iterator it = w.begin(); it != w.end(); it++) {
		sum += *it;

		if (sum <= max_w) {
			/* Do nothing */
		}
		else {
			track--;
			if (track <= 0) {
				ret = false;
				break;
			}
			else {
				sum = *it;
			}
		}
	}

	return ret;
}

int main()
{
	int n, k;
	int lower = 0, upper = 1;
	int center;
	int ans;

	cin >> n >> k;
	vector<int> w(n);
	rep(i, n) {
		cin >> w[i];
		lower = max(lower, w[i]);
	}
	
	upper = lower * n / k + 1;
	ans = upper;

	while (lower <= upper) {
		center = (lower + upper) / 2;
		if (jdg(w, center, k)) {
			ans = min(ans, center);
			upper = center - 1;
		}
		else {
			lower = center + 1;
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1000000007 ))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define bigint __int128
#define sqrt sqrtl
#define cbrt cbrtl
#define endl '\n'
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef pair<float,float> ff;
typedef vector<ff> vff;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi;






typedef pair<ii,int> iii;
#define  f first.first
#define  s first.second
#define  t second

#define inf 1e15



int32_t main()
{
	IOS
	int n,m,l;cin>>n>>m>>l;
	vector<ii>g[n+1];
	
	for(int i=1;i<=m;i++)
	{
		int a,b,w;cin>>a>>b>>w;
		if(w>l)continue;
		g[a].push_back({b,w});
		g[b].push_back({a,w});
	}
	
	int dp[n+1][n+1];
	for(int i=1;i<=n;i++)
	{
		vector<ii>dis(n+1,{inf,inf});
		vector<bool>vis(n+1);
		priority_queue<iii,vector<iii>,greater<iii>>pq;
		
		dis[i]={0,0};
		pq.push({dis[i],i});
		while(pq.size())
		{
			int u=pq.top().t;pq.pop();
		    if(vis[u])continue;
			vis[u]=true;
			for(auto it:g[u])
			{
				int v=it.first;
				int w=it.second;
				
				int min_t=dis[u].first;
			    int trav=dis[u].second+w;
			    
				if( trav > l )
				{
					min_t++;
					trav=w;
				}
				if(  dis[v] > make_pair(min_t,trav) )
				{
					dis[v]={min_t,trav};
					pq.push({dis[v],v});
				}
			}
		}
		for(int j=1;j<=n;j++)
		dp[i][j]=dis[j].first+(dis[j].second!=0);
	}
	int q;cin>>q;
	for(int i=1;i<=q;i++)
	{
		int u,v;cin>>u>>v;
		cout<<(dp[u][v] < inf ? dp[u][v]-1 : -1)<<endl;
	}
	
}
	
		
	
	
	
	
	
	
	

 


Measured memory_bytes: 8004
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
#define exp double(1e-6)
#define PI acos(-1)
const int MAXN=int(2e5+5);
int n;
LL k,K;
int a[MAXN],f[MAXN];
int a2[MAXN],f2[MAXN];
bool cmp(int a,int b) {
    return a>b;
}
void Debug() {
    for(int i=1;i<=n;i++)
        printf("%d ",a[i]);
    puts("");
    for(int i=1;i<=n;i++)
        printf("%d ",f[i]);
    puts("");
}
bool Check(LL x) {
    for(int i=1;i<=n;i++) {
        if((LL)a[i]*f[i]<=x)
            continue;
        else
            k-=((LL)a[i]*f[i]-x+f[i]-1)/f[i];
    }
    return k>=0;
}
LL BS() {
    LL l=0,r=(LL)a[n]*f[1];
    while(l+1<r) {
        k=K;
        LL mid=(l+r)/2;
        if(Check(mid))
            r=mid;
        else
            l=mid;
    }
    k=K;
    return Check(l)?l:r;
}
int main()
{
    scanf("%d%lld",&n,&k);
    K=k;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&f[i]);
    sort(a+1,a+n+1);
    sort(f+1,f+n+1,cmp);
    //Debug();
    printf("%lld",BS());
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>//用tree

using namespace __gnu_pbds;

using namespace std;
typedef long long ll;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;

const int mn = 1e6 + 5;
const int mod = 998244353;

int n;
int a[mn];
int b[mn];

bool judge() {
    if (n % 3) return 0;
    int u = n / 3;
    int cnt = 0;
    for (int i = 1; i <= u; i++) {
        b[++cnt] = a[i];
        b[++cnt] = a[i + u];
        b[++cnt] = a[i + u + u];
    }
    b[0] = b[n];
    b[n + 1] = b[1];
    for (int i = 1; i <= n; i++) if ((b[i - 1] ^ b[i + 1]) != b[i]) return 0;
    return 1;
}

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif
    scanf("%d", &n);
    bool flag0 = 1;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (a[i]) flag0 = 0;
    }
    sort(a + 1, a + n + 1);
    if (judge() || flag0) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n;
    cin >> n;
    vector<ll> s(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }

    ll ans = 0;
    for(int c = 0; c < n; c++){
        ll score = 0;
        set<ll> st;
        for(int k = 0; k < n; k++){
            ll a = n-1 -k*c;
            ll b = a-c;
            if(a<=0 || b<=0){break;}
            if(st.count(k*c)==1){break;}
            score += s[k*c];
            st.insert(k*c);
            if(st.count(n-1-k*c)==1){break;}
            score += s[n-1-k*c];
            st.insert(n-1-k*c);
            ans = max(ans, score);
        }
    }

    cout << ans << endl;

    return 0;
}


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

#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 LL long long
#define INF INT_MAX

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n;
  int a, b;
  int p;

  int d[4] = {0};

  cin >> n;
  cin >> a >> b;

  REP (i, n) {
    cin >> p;
    if (p <= a) d[0]++;
    else if (p <= b) d[1]++;
    else d[2]++;
  }

  cout << min({d[0], d[1], d[2]}) << endl;

}


Measured memory_bytes: 256