akhauriyash/Code-Regression huggingface dataset:
/*..............................................*\
Author:Kishor Kumar Paroi
Dept:CSE-1703053
RUET,BANGLADESH
\*---------------------------*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//const int N=100*1000;
//const int mod=1e9+7;

//# define int min3(int a,int b,int c){return min(a,min(b,c));}
//#define int max3(int a,int b,int c){return max(a,max(b,c));}
//#define int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
//#define int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b,h;
    cin>>a>>b>>h;
    cout<<.5*(a+b)*h<<endl;
    return 0;
}



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

const int N = 100005, P = 1e9+7;
char s[N]; int sum[N], f[N], pre[3], n, flag;

int main() {
	scanf("%s", &s); n = strlen(s);
	for (int i = 1; i < n; ++i) //判断是否可以操作
		if (s[i] == s[i-1]) { flag = 1; break; }
	if (!flag) { puts("1"); return 0; }
	for (int i = 0; i < n; ++i) sum[i+1] = s[i] - 'a' + 1;
	for (int i = 2; i <= n; ++i) sum[i] = (sum[i] + sum[i-1]) % 3;
	f[n] = 1;
	for (int i = 0; i <= 2; ++i) pre[i] = (i == sum[n] ? n : n + 1);
	for (int i = n - 1; i; --i) {
		f[i] = (sum[i] == sum[n]); //后面的p值是否为0
		for (int j = 1; j <= 2; ++j)
			f[i] = (f[i] + f[pre[(sum[i]+j)%3]]) % P; //后面加一段A或B
		pre[sum[i]] = i; //记录该p值上一次出现的位置
	}
	printf("%d\n", (f[pre[1]] + f[pre[2]]) % P);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <math.h>
//const long long mod = 1000000007;
//const long long mod = 998244353;


int main() {
	int N;
	scanf("%d", &N);
	printf("%d", N*N);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		string s = Console.ReadLine();
		int[] B = new int[N];
		HashSet<int>[] D = new HashSet<int>[N];
		var E = new HashSet<int>();
		for(var i=0;i<N;i++){
			D[i] = new HashSet<int>();
			E.Add(i);
			if(s.Substring(i,1) == "B"){
				B[i] = 1;
			}
		}
		int[,] A = new int[M,2];
		int[,] C = new int[N,2];
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			A[i,0] = int.Parse(str2[0]);
			A[i,1] = int.Parse(str2[1]);
			if(!D[A[i,0]-1].Contains(A[i,1]-1)){
				D[A[i,0]-1].Add(A[i,1]-1);
				if(B[A[i,1]-1] == 1){
					C[A[i,0]-1,1] += 1;
				} else {
					C[A[i,0]-1,0] += 1;
				}
			}
			if(!D[A[i,1]-1].Contains(A[i,0]-1)){
				D[A[i,1]-1].Add(A[i,0]-1);
				if(B[A[i,0]-1] == 1){
					C[A[i,1]-1,1] += 1;
				} else {
					C[A[i,1]-1,0] += 1;
				}
			}
		}
		int ct = N;
		string ans = "No";
		var F = new HashSet<int>();
		foreach(var i in E){
			if(C[i,0]==0 || C[i,1]==0){
				F.Add(i);
			}
		}
		while(ct>0){
			int ct2 = 0;
			var d1 = new HashSet<int>();
			var G = new HashSet<int>();
			foreach(var i in F){
				var d2 = new HashSet<int>();
				foreach(var j in D[i]){
					d2.Add(j);
				}
				foreach(var j in d2){
					D[j].Remove(i);
					C[j,B[i]] -= 1;
					if(C[j,B[i]]==0 && C[j,(B[i]+1)%2]>=1){
						G.Add(j);
						ct2 += 1;
					}
				}
				d1.Add(i);
			}
			foreach(var i in d1){
				F.Remove(i);
				ct -= 1;
				ct2 += 1;
			}
			if(ct2 == 0){
				ans = "Yes";
				break;
			}
			foreach(var i in G){
				F.Add(i);
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 75868
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vpll> vvpll;
typedef unordered_map<ll, ll> um;
typedef unordered_set<ll> us;

#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ts ll t; in(t) while (t--) solve();
#define ks ll t; in(t) FOR(i, 1, t+1) out("Case #" << i << ": " << solve());
#define endl '\n'
#define ln cout << endl;
#define in(x) cin >> x;
#define out(x) cout << x << endl;
#define flush cout << flush;
#define reset(a, b) memset(a, b, sizeof(a));
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FORI(i, a, b, c) for (ll i = a; i < b; i += c)
#define FORD(i, a, b) for (ll i = a; i > b; --i)
#define FOREACH(it, v, r) for (auto it = v.begin() + r; it != v.end(); it++)
#define FORALL(it, v) for (auto it : v)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define vin(v, x) vll v(x); FOR(i, 0, x) in(v[i])
#define all(v) v.begin(), v.end()
#define allr(v, r) v.begin(), v.begin() + r
#define showv(v) FORALL(it, v) cout << it << ' '; ln
#define printv(v) FORALL(it, v) out(it)
#define show2d(v) FORALL(it, v) { FORALL(j, it) cout << j << ' '; ln}
#define showm(v) FORALL(it, v) cout << it.F << ": " << it.S << ' '; ln
#define sortv(v) sort(all(v));
#define revv(v) reverse(all(v));
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))
#define gcd __gcd
#define checkbit(n, i) (n >> i) & 1               // check ith bit
#define bitcount __builtin_popcount               // count set bits
#define firstbitindex __builtin_ctz               // count trailing zeros
#define lastbitindex __builtin_clz                // count leading zeros
#define bitparity __builtin_parity                // check set bits are even or odd
#define findv(v, x) (find(all(v), x) != v.end())  // find in a vector
#define findsm(u, x) (u.find(x) != u.end())       // find in a set / map
#define findstr(s, x) (s.find(x) != string::npos) // find in a string
#define sz(a) a.size()
#define precise(x) cout << fixed << setprecision(x);

const ll MAXN = 1e5, MOD = 998244353, SIZE = 2e7;//, INF = 0x7f7f7f7f7f7f7f7f;
const double EPS = 1e-9, PI = acos(-1);
const int INFi = 0x7f7f7f7f;

//<<------Declare Variables Here----->>//
ll n;
char c[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
string s;

//<<-----Implement Functions Here---->>//
void solve()
{
    in(n)
    while (n)
        --n, s = c[n % 26] + s, n /= 26;
    out(s)
}

//<<----------Start of Main---------->>//
int main()
{
    fastio
    //ts
    solve();
    return 0;
}

Measured memory_bytes: 3672
n = gets.to_i
memo = [0]*n
a = n.times.map{gets.to_i}

memo[0] = 1
count = 0
i = 0
while true
  count += 1
  i = a[i]-1
  if i == 1
    puts count
    exit
  end
  if memo[i] != 0
    puts -1
    exit
  end
  memo[i] += 1
end


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
using namespace std;
int main(){
  fast;
  int n,sum=0;
  ll ans=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  for(int i=0;i<n-1;i++){
    sum-=a[i];
    ans+=(a[i]*1LL*sum);
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
N, M =map(int,input().split())
L = [list(map(int,input().split()))[1:] for i in range(M)]
p = list(map(int,input().split()))
form = "0" + str(N) + "b"
ans = 0
for i in range(2**N):
    pat = format(i,form)
    flg = True
    for j in range(M):
        s = sum(int(pat[k-1]) for k in L[j])
        if s%2 != p[j]:
            flg = False
    if flg == True:
        ans += 1
print(ans)

Measured memory_bytes: 3064
X, N = gets.split(" ").map(&:to_i)
if N == 0
  puts X
else
  array = gets.split(" ").map(&:to_i)

  # p以外の数字の配列
  num = [*-1..101]
  N.times do |i|
      num.delete(array[i-1])
  end

  ary = [9999]
  num.each do |i|
    if (X - i).abs < (X - ary[0]).abs
      ary.insert(0, i)
    else
      ary << i
    end
  end
  p ary[0]
end

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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif
  cout << setprecision(20);

  string S;
  cin >> S;
  vector<char> v;
  for (int i = 0; i < 4; i++) v.push_back(S.at(i));
  sort(v.begin(), v.end());
  if (v[0] == v[1] && v[2] == v[3] && v[1] != v[2]) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int     main(void)
{
    int i, j;
    
    scanf("%d", &i);
    
    int num[i];
    
    j = 0;
    while (j < i)
    {
        scanf("%d", &num[j]);
        j++;
    }
    
    while(j - 1 >= 0)
    {
        printf("%d", num[j -1]);
        j--;
        if (num[j - 1])
            printf(" ");
    }
    printf("\n");
    return (0);
}


Measured memory_bytes: 2044
#include<iostream>
#include<fstream>
#include<math.h>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>

using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n); i++)
#define forsn(i,s,n) for(int i=(s);i<(int)(n); i++)
#define esta(x,v) (find((v).begin(),(v).end(),(x)) !=  (v).end())
#define index(x,v) (find((v).begin(),(v).end(),(x)) - (v).begin())
#define debug(x) cout << #x << " = "  << x << endl
#define pb push_back
#define mp make_pair

typedef long long tint;
typedef unsigned long long utint;
typedef long double ldouble;

typedef vector<int> vint;

int main (){
	tint n;
	cin>>n;
	tint vt, va;
	forn(i, n){
		int t, a;
		cin>>t>>a;
		if(i==0){
			vt=t; va=a;
			continue;
		}else{
			tint dt=vt/t;
			tint da=va/a;
			tint ma=max(dt, da);
			if(ma*a>=va && ma*t>=vt){
				
			}else{
				ma++;
			}
			vt=ma*t;
			va=ma*a;
		}
	}
	cout<<vt+va<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int ans=a*b*c;
	int m=max(a,b);
	m=max(m,c);
	ans/=m;
	printf("%d",ans/2);
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main(void){
    // Your code here!
   long long  a,b;
   cin >> a >> b;
   if(a < 0 && 0 < b){
       cout << "Zero" << endl;
   }
   else if(a == 0 || b == 0){
       cout << "Zero" << endl;
   }
   else if(a > 0){
       cout << "Positive" << endl;
   }
   else{
       if( (b-a)%2 == 0 ){
           cout << "Negative" << endl;
       }
       else{
           cout << "Positive" << endl;
       }
   }
   
}



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

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; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

int s;
vector<ll> dp;

ll f(int a){
    if(dp[a]!=-1)return dp[a];
    if(a<3)return dp[a]=0;
    if(a<6)return dp[a]=1;
    ll res = 0;
    res += f(a-1);
    res %= MOD;
    res += f(a-3);
    res %= MOD;
    return dp[a] = res;
}

int main(){
    cin>>s;
    dp.resize(s+10);
    rep(i,s+10)dp[i] = -1;
    cout<<f(s)<<endl;
}


Measured memory_bytes: 3608
import sys
def cal():
    if D11==D12 and D21==D22 and D31==D32:
        print('Yes')
        sys.exit()

N=int(input())
D11,D12=map(int,input().split())
D21,D22=map(int,input().split())
D31,D32=map(int,input().split())
cal()
for _ in range(0,N-3):
    D11=D21
    D12=D22
    D21=D31
    D22=D32
    D31,D32=map(int,input().split())
    cal()
print('No')

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


int main(){

    long long int n;
    cin>>n;

    long long int arr[n];


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


    sort(arr,arr+n);

    long long ans=0;

    for(int i=0 ; i< n ; i++){

        for(int j=i+1 ; j<n ; j ++){
             if(arr[i]==arr[j] )
               continue;



            for(int k=j+1 ; k<n ; k++){
                if(arr[k]==arr[i])
                continue;

                if(arr[j]==arr[k])
                    continue;


                long long x= arr[k]+arr[j];
                long long y=arr[k]+arr[i];
                long long z=arr[i]+arr[j];

                if(z<=arr[k])
                    continue;

                if(x<=arr[i])
                    continue;

                if(y<=arr[j])
                    continue;

                ans++;



            }
        }
    }

     cout<<ans<<endl;















    return 0;







}


Measured memory_bytes: 3624
import numpy as np
N = int(input())
A = np.array(input().split(),dtype=np.int64)

Acum = A.cumsum()
total = Acum[-1]
diff = np.abs(Acum - (total-Acum))

answer = diff[:-1].min() # 最後の1枚はアライさん

print(answer)

Measured memory_bytes: 32996
using System;
 
class Program
{
    static void Main()
    {
        String [] s=Console.ReadLine().Split(' ');
        int D = int.Parse(s[0]);
        for (int i = 1; i <= D; i++)
        {
            int x = i;
            if (x % 3 == 0)
            {
                Console.Write(" " + i);
            }
            else
            {
                while (x != 0)
                {
                    if (x % 10 == 3)
                    {
                        Console.Write(" " + i);
                        break;
                    }
                    x /= 10;
                }
            }
        }
        Console.WriteLine();
    }
}
 

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int H, W; cin >> H >> W;
	vector<vector<bool>> G(H, vector<bool>(W));
	for (int i = 0; i < H; i++) {
		string s; cin >> s;
		for (int j = 0; j < W; j++) {
			assert(s[j] == '#' || s[j] == '.');
			G[i][j] = (s[j] == '#');
		}
	}

	vector<vector<int>> dist(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i == 0 && j == 0) {
				dist[0][0] = G[0][0];
				continue;
			}
			dist[i][j] = int(1e9);
			if (i) {
				dist[i][j] = min(dist[i][j], dist[i-1][j] + (G[i-1][j] != G[i][j]));
			}
			if (j) {
				dist[i][j] = min(dist[i][j], dist[i][j-1] + (G[i][j-1] != G[i][j]));
			}
		}
	}

	int ans = dist[H-1][W-1] + G[H-1][W-1];
	assert(ans % 2 == 0);
	cout << ans / 2 << '\n';

	return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

enum Color { Black, White };
ll N;
vector<ll> G[MAX_N];    // i から行けるノード
pair<ll, ll> C[MAX_N];  // first: 1 からの距離 second: N からの距離

// 距離の計算
void CalcDist(ll c, ll id, ll prev, ll dist) {
    //printf("id: %lld prev: %lld dist: %lld\n", id, prev, dist);
    if(c == Black) { C[id].first = dist; }
    else { C[id].second = dist; }
    for(auto& node : G[id]) {
        if(node == prev) { continue; }
        CalcDist(c, node, id, dist+1);
    }
}

// 色をカウント
void Cnt(ll& fennec, ll& snuke, ll id, ll prev) {
    if(C[id].first > C[id].second) { snuke++; }
    else { fennec++; }
    for(auto& node : G[id]) {
        if(node == prev) { continue; }
        Cnt(fennec, snuke, node, id);
    }
}

signed main()
{
    cin >> N;
    REP(i, N-1) {
        ll a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    CalcDist(Black, 1, -1, 0);
    CalcDist(White, N, -1, 0);
    ll fennec = 0, snuke = 0;
    Cnt(fennec, snuke, 1, -1);
    if(fennec > snuke) { printf("Fennec\n"); }
    else { printf("Snuke\n"); }

    return 0;
}


Measured memory_bytes: 13696
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];

        long sum = 0;
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }

        System.out.println(sum - N);
        return;
    }

}

Measured memory_bytes: 29828
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<map>
using namespace std;
#define f(n) for(int i=0;i<n;++i)
#define ll long long

int main() {
	int n, k, ans = 0;
	cin >> n >> k;
	vector<int>v;
	f(n) {
		int t;
		cin >> t;
		v.push_back(t);
		ans += t;
	}
	sort(v.begin(), v.end());
	f(n - k) {
		ans -= v[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	char a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	if(a==f&&b==e&&c==d)cout<<"YES";
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	if(n % 2 == 1){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<n/2;i++){
		if(s[i] != s[i+n/2]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
void main()
{
    long n = rdElem;
    long[] a = rdRow;

    if (n == 0)
    {
        writeln(a[0] == 1 ? 1 : -1);
        return;
    }

    if (a[0])
    {
        writeln(-1);
        return;
    }

    long[] v = new long[n+1];
    v[n] = a[n];
    foreach_reverse (i; 0 .. n)
    {
        v[i] = v[i+1] + a[i];
    }

    long u = 1;
    long result = u;
    foreach (i; 1 .. n+1)
    {
        u <<= 1;
        u = min(u, v[i]);
        result += u;
        u -= a[i];
        if (u < 0)
        {
            writeln(-1);
            return;
        }
    }

    result.writeln;
}

enum long mod = 10L^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 6656
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W, mi1,mi2,sum;
LL ans;
LL no;
bool b,bb[1000000000];
string s,t;

int main() {
	cin >> s;
	stack<char> a;
	a.push(s[0]);
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == 'S')a.push(s[i]);
		else {
			if (!a.empty()&&a.top() == 'S')a.pop();
			else a.push(s[i]);
		}
	}

	cout << a.size() << endl;



	return 0;
}



Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	vector<long long> points(n);
	for(long long& x : points) {
		scanf("%lld", &x);
	}
	vector<vector<pair<long long, long long>>> dp(n, vector<pair<long long, long long>>(n));
	for(int i=0; i<n; ++i) {
		dp[i][i].first = points[i];
		dp[i][i].second = 0;
	}
	for(int i=2; i<=n; ++i) {
		for(int j=0; j<n-i+1; ++j) {
			int start = j, end = j+i-1;
			dp[start][end].first = max(points[end] + dp[start][end-1].second, points[start] + dp[start+1][end].second);
			if(points[end] + dp[start][end-1].second >= points[start] + dp[start+1][end].second) {
				dp[start][end].second = dp[start][end-1].first;
			} else {
				dp[start][end].second = dp[start+1][end].first;
			}
		}
	}
	printf("%lld\n", dp[0][n-1].first - dp[0][n-1].second);
	return 0;
}
		


Measured memory_bytes: 143976
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;

#define ll long long

ll gcd(ll A, ll B)
{
    if (A < B)
    {
        swap(A, B);
    }

    while (1)
    {
        ll r = A % B;
        if (r == 0)
        {
            return B;
        }
        A = B;
        B = r;
    }
}

void solve()
{
    ll K;
    cin >> K;
    ll count = 0;
    for (ll a = 1; a <= K; a++)
    {
        for (ll b = 1; b <= K; b++)
        {
            for (ll c = 1; c <= K; c++)
            {
                count += gcd(gcd(a, b), c);
            }
        }
    }

    cout << count << endl;

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>

int main() {
  // 入力
  std::string n;
  std::cin >> n;

  // 良い整数判定
  if (n[0] == n[1] && n[1] == n[2] ||
    n[1] == n[2] && n[2] == n[3]) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;
 
// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }



int main() {
	int N,A,B; cin >> N >> A >> B;
  string s; cin >> s;
  int rank = 0, b= 0;
  vector<string> ans;
  rep(i,N) {
    if (s[i] == 'a'){
      if (rank < (A+B)) {rank++;ans.push_back("Yes");}
      else ans.push_back("No");
    }
    else if (s[i] == 'b'){
      if (rank < (A+B) && b < B) {rank++;b++;ans.push_back("Yes");}
      else ans.push_back("No");
    }
    else {ans.push_back("No");}
  }

  for(auto s:ans) cout << s << endl;

	return 0;
}


Measured memory_bytes: 6260
#include <iostream>
#include <string>
#include <vector>
#include <map>

constexpr int Mod = 1e9+7;

bool judge(std::string last4) {
  if (last4.substr(1, 3) == "AGC") return 0;

  for (int i=1; i<4; i++) {
    std::swap(last4[i-1], last4[i]);
    if (last4.substr(0, 3) == "AGC") return 0;
    if (last4.substr(1, 3) == "AGC") return 0;
    std::swap(last4[i-1], last4[i]);
  }

  return true;
}

struct Solver {
  int const N;
  std::vector<std::map<std::string, int>> cache;

  Solver(int N) : N(N), cache(N) {}

  int solv(int n=0, std::string&& last3="...") {
    if (n==N) return 1;

    if (cache[n].count(last3) > 0) return cache[n][last3];

    int& res = cache[n][last3];

    for (auto c: std::string("ACGT")) {
      std::string const last4 = last3 + c;
      if (judge(last4)) {
        res += solv(n+1, last4.substr(1, 3));
        res %= Mod;
      }
    }

    return res;
  }
};

int main() {
  int N;

  std::cin >> N;

  std::cout << Solver(N).solv() << std::endl;

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

struct UnionFind {
  vi d;
  UnionFind(ll n=0):d(n,-1){}
  ll find(ll x) {
    if(d[x]<0) return x;
    return d[x]=find(d[x]);
  }
  bool unite(ll x,ll y) {
    x=find(x); y=find(y);
    if(x==y) return false;
    if(d[x]>d[y]) swap(x,y);
    d[x]+=d[y];
    d[y]=x;
    return true;
  }
  bool same(ll x,ll y) {return find(x)==find(y);}
  ll size(ll x) {return -d[find(x)];}
};

void solve() {
  ll n,m;
  cin>>n>>m;
  vi x(m),y(m),z(m);
  rep(i,m) cin>>x[i]>>y[i]>>z[i];
  UnionFind uf(n);
  rep(i,m) uf.unite(x[i]-1,y[i]-1);
  set<ll> s;
  rep(i,n) s.insert(uf.find(i));
  out(s.size());
}

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


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, ans = LLINF; cin >> n;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0)chmin(ans, i + (n / i) - 2);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10,mod = 998244353;

int dp[N][3][3];
char str[N];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline void Add(int &x,int y) {
	if((x += y) >= mod) x -= mod;
}

int main() {
	scanf("%s",str + 1);
	int n = strlen(str + 1);
	if(n == 2) return printf("%d\n",2 - (str[1] == str[2])),0;
	if(n == 3) {
		if(str[1] == str[2] && str[2] == str[3]) return puts("1"),0;
		else if(str[1] == str[2] || str[2] == str[3]) return puts("6"),0;
		else if(str[1] == str[3]) return puts("7"),0;
		else return puts("3"),0;
	}

	int ans = 1;
	For(i,1,n - 1) ans = 1ll * ans * 3 % mod;

	For(i,0,2) dp[1][i][i] = 1;
	For(i,2,n) For(j,0,2) For(k,0,2) if(dp[i - 1][j][k])
		For(l,0,2) if(l != j) Add(dp[i][l][(k + l) % 3],dp[i - 1][j][k]);

	int Sum = 0;bool flag1 = true,flag2 = true;
	For(i,1,n) {
		Sum += str[i] - 'a';
		if(i == n) break;
		if(str[i] == str[i + 1]) flag1 = false;
		if(str[i] != str[i + 1]) flag2 = false;
	}
	Sum %= 3,ans += flag1;
	For(i,0,2) ans = (ans - dp[n][i][Sum] + mod) % mod;

	if(flag2) puts("1");
	else printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 7424
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

ll euclid(ll a, ll b)
{
    int nr = 0;
    while (b != 0)
    {
        int c = b;
        b = a % b;
        a = c;
        nr++;
    }
    return nr;

}
int main()
{
    int a, b;
    cin >> a >> b;
    if (((b * 1.0)/ a) - (b / a) < 0.00001)
    {
        cout << a + b;
    }
    else
    {
        cout << b - a;
    }
    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;
typedef pair<int,int> P;
const long long INF = 1LL<<60;
const long long MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max

int main () {

    ll n;cin>>n;
    int k;cin>>k;

    ll cnt=0,mul=1;
    while (mul*k<=n) {
        mul*=k;
        cnt++;
    }

    cout<<cnt+1<<endl;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    while(true) {
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int m = Integer.parseInt(str2[0]);
    int f = Integer.parseInt(str2[1]);
    int r = Integer.parseInt(str2[2]);
    int sum = m + f;

    if(m == -1 && f == -1 && r == -1) {break;}
    else if(m == -1 || f == -1){
      sb.append("F\n");
    }
    else if(sum >= 80){
      sb.append("A\n");
    }
    else if(sum >= 65 && sum < 80){
      sb.append("B\n");
    }
    else if(sum >= 50 && sum < 65){
      sb.append("C\n");
    }
    else if(sum >= 30 && sum < 50){
      if(r >= 50){
        sb.append("C\n");
      }
      else{
        sb.append("D\n");
      }
    }
    else if (sum < 30){
      sb.append("F\n");
    }
    }
    System.out.print(sb);
  }
}

Measured memory_bytes: 24212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++){
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  int ans = d[n/2]-d[n/2-1];
  cout << ans << endl;
}

Measured memory_bytes: 640
import os, sys, re, math

N = int(input())
A = [int(n) for n in input().split()]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

result = A[0]
for a in A[1:]:
    result = gcd(result, a)

print (result)


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

int main(){
	
  int N;
  cin >> N;
  vector<vector<int>> input(N, vector<int>(3));
  vector<vector<int>> dp(N, vector<int>(3));
  for(int i = 0; i < N; i++){
  	for(int j = 0; j < 3; j++){
    	cin >> input[i][j];
    }
  }
  dp[0][0] = input[0][0];
  dp[0][1] = input[0][1];
  dp[0][2] = input[0][2];
  
  for(int i = 1; i < N; i++){
  	dp[i][0] = input[i][0] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = input[i][1] + max(dp[i-1][2], dp[i-1][0]);
    dp[i][2] = input[i][2] + max(dp[i-1][0], dp[i-1][1]);
  }
  
  int res = max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2]));
  cout << res << endl;
  
}


Measured memory_bytes: 11136
#!/usr/bin/python
# -*- coding: utf-8 -*-
S = [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]

K = int(input())

print(S[K-1])


Measured memory_bytes: 38384
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef pair< int , int > pi;
typedef set< int > se;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define Fn 1.618033987
int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll A[4];
    int n=4;
    REP(i,0,n-1)
    {
        cin>>A[i];
    }
    ll ans=LLONG_MIN;
    ll temp;
    REP(i,0,1)
    {
        REP(j,2,3)
        {
            temp=A[i];
            temp=temp*A[j];
            ans=max(ans,temp);
        }
    }
    cout<<ans<<'\n';
    return 0; 
}

Measured memory_bytes: 3648
#include<iostream>
#define MAXN 128
using namespace std;
int xie1[MAXN],xie2[MAXN],lie[MAXN],hang[MAXN];
bool map[MAXN][MAXN];
int n;
int x,y;
void dfs(int i){
	int j,k;
	if (i == 8) {
		for (j = 0;j < 8;++j){
			for (k = 0;k < 8;++k){
				if (map[j][k]) cout<<"Q";
				else cout<<".";
			}
			cout<<"\n";
		}
		return;
	}
	if (hang[i]) dfs(i+1);
	else {
		for (j = 0;j < 8;++j){
			if (!lie[j] && !xie1[i+j] && !xie2[16-j+i]){
				lie[j]=1;
				xie1[i+j]=1;
				xie2[16-j+i]=1;
				map[i][j]=1;
				dfs(i+1);
				lie[j]=0;
				map[i][j]=0;
				xie1[i+j]=0;
				xie2[16-j+i]=0;
			}
		}
	}
}
int main(){
	int i;
	cin>>n;
	for (i = 0;i < n;++i){
		cin>>x>>y;
		lie[y]=1;
		hang[x]=1;
		map[x][y]=1;
		xie1[x+y]=1;
		xie2[16-y+x]=1;
	}
	dfs(0);
	return 0;
}

Measured memory_bytes: 3100
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()


def main():
    n = II()
    r = n // 11 * 2
    t = n % 11
    if t == 0:
        return r
    if t < 7:
        return r+1
    return r+2


print(main())


Measured memory_bytes: 7832
k, t = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
if t == 1:
    print(k-1)
    exit()

x = A[0]
s = sum(A)-A[0]
if s >= x:
    print(0)
else:
    ans = x-s-1
    print(max(ans, 0))


Measured memory_bytes: 38384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	int n;cin>>n;
    vector<string> a(n);
    map<string,vector<int>> b;
    map<pair<string,int>,int> d;
    vector<pair<string,int>> c;
    rep(i,0,n){
        string s;cin>>s;
        int p;cin>>p;
        a[i] = s;
        b[s].push_back(p);
        d[mp(s,p)] = i+1;
    }
    sort(a.begin(),a.end());
    int j = 1;
    rep(i,0,n){
        sort(b[a[i]].rbegin(),b[a[i]].rend());
        for(auto x : b[a[i]]){
            cout<<d[mp(a[i],x)]<<endl;
        }
        b.erase(a[i]);
    }
}

Measured memory_bytes: 3656
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).
*/

f(X,A,B) :- A >= 13, X is B.
f(X,A,B) :- A >= 6, X is B div 2.
f(X,_,_) :- X is 0.

main :-
    get_number(A),
    get_number(B),
    f(X,A,B),
    writeln(X).


Measured memory_bytes: 8088
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int N, K;

	cin >> N >> K;

	long long ans = 0;
	for (int b = K + 1; b <= N; b++) {
		int p = N / b;
		ans += p * max(0, b - K) + max(0, N % b - K + 1);
		if (K == 0) ans--;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringJoiner;

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

        StringJoiner sj = new StringJoiner("\n");
        for (int i = 0; i < 2; i ++) {
            sj.add(scanner.nextLine());
        }

        System.out.println(solve(sj.toString()));
    }

    private static int solve(String stdinString) {
        String[] splits = stdinString.split("\n");
        int N = Integer.parseInt(splits[0]);
        int[] nums = new int[N];

        splits = splits[1].split(" ");
        for (int i = 0; i < N; i ++) {
            nums[i] = Integer.parseInt(splits[i]);
        }

        int max = Integer.MIN_VALUE;
        HashMap<Integer, Integer> xCounts = new HashMap<>();
        for (int i = 0; i < N; i ++) {
            xCounts.put(nums[i] - 1, xCounts.getOrDefault(nums[i] - 1, 0) + 1);
            max = Math.max(max, xCounts.get(nums[i] - 1));

            xCounts.put(nums[i], xCounts.getOrDefault(nums[i], 0) + 1);
            max = Math.max(max, xCounts.get(nums[i]));

            xCounts.put(nums[i] + 1, xCounts.getOrDefault(nums[i] + 1, 0) + 1);
            max = Math.max(max, xCounts.get(nums[i] + 1));
        }

        return max;
    }

    private static String ex1 = "7\n3 1 4 1 5 9 2";
    private static String ex2 = "10\n0 1 2 3 4 5 6 7 8 9";
    private static String ex3 = "1\n99999";

    private static void tests() {
        System.out.println(solve(ex1));
        System.out.println(solve(ex2));
        System.out.println(solve(ex3));
    }
}

Measured memory_bytes: 51988
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>
 
#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
 
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e10
 
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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
 
using namespace std;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<P> pv;

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

    sort(all(a));

    ll ma = a[n-1];
    ll mi = a[0];

    rep(i, n){
        if(i != 0 && i != n-1){
            if(a[i] >= 0) {
                P tmp;
                tmp.first = mi;
                tmp.second = a[i];
                pv.push_back(tmp);
                mi -= a[i];
            }else{
                P tmp;
                tmp.first = ma;
                tmp.second = a[i];
                pv.push_back(tmp);
                ma -= a[i];
            }
        }
    }
    P tmp;
    tmp.first = ma;
    tmp.second = mi;
    pv.push_back(tmp);

    cout << ma - mi << endl;
    rep(i, pv.size()){
        cout << pv[i].first << " " << pv[i].second << endl;
    }
}


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

int main()
{ int n,k,v, c=0;
vector <int> A;
cin>> n;
cin >> k;
while (n){
    cin>> v;
        A.push_back(v);
            n--;

} sort(A.begin(), A.end());
for (int i =0; i< k; i++)
    c+= A[i];

cout<<c;

return 0;

}


Measured memory_bytes: 3624
$\=8e18;<>=~$";@x=sort{$a-$b}<>;until(@x<($k=$')){map{@X=@p=sort{$a-$b}@X,/ /*$';$\-=$-=$\+($p[-$k]-pop@p)*($_-"@x")until@p<$k}@x;@X=();shift@x}print

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

int cnt[30];

int main(){
    string s; cin>>s;
    for(int i=0;i<s.size();i++){
        if(cnt[s[i]-'a']){
            cout<<"no"<<endl;
            return 0;
        }else{
            cnt[s[i]-'a']++;
        }
    }
    cout<<"yes"<<endl;
}


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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    int n; cin >> n;
    if (n <= 9) {
        cout << 0 << '\n';
        return 0;
    }
    
    bool erased[101] = {false, };  // 안지워졌으면 소수
    vector<int> prime;
    for (int i = 2; i <= 100; i++) {
        if (!erased[i]) {
            prime.push_back(i);
            for (int j = i * i; j <= 100; j += i) {
                erased[j] = true;
            }
        }
    }
    
    vector<int> fact_cnt(25, 0);  // n!의 소인수분해 결과
    fact_cnt[0] = 8;
    fact_cnt[1] = 4;
    fact_cnt[2] = 2;
    fact_cnt[3] = 1;
    
    for (int i = 11; i <= n; i++) {
        int x = i;
        for (int j = 0; j < 25; j++) {
            while (x % prime[j] == 0) {
                x /= prime[j];
                fact_cnt[j]++;
            }
        }
    }

    // sort(fact_cnt.begin(), fact_cnt.end());
    int cnt = 0;
    
    int num[6] = {0, };
    
    for (int i = 0; i < 25; i++) {
        if (fact_cnt[i] >= 74) num[5]++;
    }
    
    for (int i = 0; i < 25; i++) {
        if (fact_cnt[i] >= 24) num[4]++;
    }
    
    for (int i = 0; i < 25; i++) {
        if (fact_cnt[i] >= 14) num[3]++;
    }
    
    for (int i = 0; i < 25; i++) {
        if (fact_cnt[i] >= 4) num[2]++;
    }
    
    for (int i = 0; i < 25; i++) {
        if (fact_cnt[i] >= 2) num[1]++;
    }
    
    cout << num[5] + num[4] * (num[1] - 1) + num[3] * (num[2] - 1) + num[2] * (num[2] - 1) * (num[1] - 2) / 2 << '\n';

    return 0;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
a = nl()
l = [0]*n
for x in a:
    l[x-1] += 1
print(*l, sep='\n')


Measured memory_bytes: 31100
#include<bits/stdc++.h>
const int N=200005;
using namespace std;
struct dat{
	int a,b,x;
	friend bool operator <(dat u,dat v){
		return 1ll*u.a*v.b<1ll*v.a*u.b;
	}
}a[N],tp;
priority_queue<dat>q;
int n,p[N],f[N],x,y;
long long ans;
bool vis[N];
int get(int x){
	return f[x]^x?f[x]=get(f[x]):x;
}
int main(){
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	scanf("%d",p+i);
	for(int i=1;i<=n;i++){
		scanf("%d",&x),f[i]=i;
		q.push(a[i]={!x,x,i});
	}vis[1]=1;
	for(;q.size();){
		x=(tp=q.top()).x,q.pop();
		if(vis[x]||tp.a^a[x].a||tp.b^a[x].b)
		continue;
		vis[x]=1;
		y=get(p[x]);
		ans+=1ll*a[y].b*tp.a;
		f[x]=y,a[y].a+=tp.a,a[y].b+=tp.b;
		q.push(a[y]);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 8436
<>;for(glob<>){
	$x+=$_;$X+=$-=1+(--$|?-$x:$x);$-&&($x=2*$|-1);
	$y+=$_;$Y+=$-=1+(--$|?-$y:$y);$-&&($y=2*$|-1);
	--$|
}
print$X<$Y?$X+0:$Y+0

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

std::vector<int> v(61),w(61);
const int INF=1e9+7;
int dp[600000][50];
int dfs(int S,int X){
  if(S<600000&&S>=0&&X<=50&&X>=0){
    int &res=dp[S][X];
    if(res!=-1)return res;
    if(S<0){res=0;return res;}
    if(S>(v[X]-1)*2){res=w[X];return res;}
    if(S==0&&X==0){res=1;return res;}
    res=(dfs(S,X-1)+dfs(S-v[X-1],X-1)+dfs(S-v[X],X-1))%INF;return res;
  }
  else{
    int res;
    if(S<0){res=0;return res;}
    if(S>(v[X]-1)*2){res=w[X];return res;}
    if(S==0&&X==0){res=1;return res;}
    res=(dfs(S,X-1)+dfs(S-v[X-1],X-1)+dfs(S-v[X],X-1))%INF;return res;
  }
}

signed main(){
  v[0]=1;for(int i=1;i<61;i++)v[i]=v[i-1]*2;
  w[0]=1;for(int i=1;i<61;i++)w[i]=w[i-1]*3%INF;
  memset(dp,-1,sizeof(dp));
  int N;
  cin>>N;
  cout<<dfs(N,60)<<endl;
}


Measured memory_bytes: 234624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author acesine
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            Set<Character> set = new HashSet<>();
            for (char c : s.toCharArray()) {
                set.add(c);
            }
            if (s.length() != set.size()) {
                out.println("no");
            } else {
                out.println("yes");
            }
        }

    }
}



Measured memory_bytes: 21844