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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(int n){
    vector<vector<string>> graph_(n);
    map<string,int> encode;
    vector<int> strength(n),sum(n);
    rep(i,0,n){
        string a;
        int b,c;
        cin >> a >> b >> c;
        encode[a]=i;
        strength[i]=b;
        sum[i]=b;
        if(i>0) sum[i]+=sum[i-1];
        rep(j,0,c){
            string d;
            cin >> d;
            graph_[i].push_back(d);
        }
    }
    vector<vector<int>> graph(n);
    rep(i,0,n){
        rep(j,0,graph_[i].size()){
            graph[i].push_back(encode[graph_[i][j]]);
        }
    }

    int maxi=0;
    function<int(int64_t,int,int)> rec=[&](int64_t s,int i,int k){
        if(i==n) return maxi=max(maxi,k);
        if(k+sum[n-1]-sum[i-1]<=maxi) return maxi;
        int res=rec(s,i+1,k);
        bool f=true;
        for(int j:graph[i]) if((s>>j)&1){
            f=false;
            break;
        }
        if(f) res=max(res,rec(s|(int64_t(1)<<i),i+1,k+strength[i]));
        return maxi=max(maxi,res);;
    };

    cout << rec(1,1,strength[0]) << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    for(;;){
        int n;
        cin >> n;
        if(!n) break;
        solve(n);
    }
    return 0;
}

Measured memory_bytes: 3316
package main

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

var sc = bufio.NewScanner(os.Stdin)

const inf = 1 << 60
const mod int = 1e9 + 7

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := ri(), ri()

	dp := make([]int, n+1)

	a := make([]int, m)
	for i := 0; i < m; i++ {
		a[i] = ri()
		dp[a[i]] += -1
	}

	dp[0] = 1
	if dp[1] != -1 {
		dp[1] = 1
	}

	for i := 2; i < len(dp); i++ {
		if dp[i] == -1 {
			continue
		}
		var x, y int
		if dp[i-2] != -1 {
			x = dp[i-2]
		} else {
			x = 0
		}
		if dp[i-1] != -1 {
			y = dp[i-1]
		} else {
			y = 0
		}
		dp[i] = (x + y) % mod
	}

	fmt.Println(dp[n])
}


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


n=int(input())
l=list(map(int,input().split()))
m=[l[0]]
for i in range(1,n):
    m.append(m[-1]+l[i])
check=0
if m[-1]%2==1:
    check=1
if m[-1]%2==0:
    sa=m[n-1]
    base=m[-1]/2
    for k in range(n):
        if abs(base-m[k])<sa:
            sa=abs(base-m[k])
    print(int(sa*2+check))
else:
    m1=m
    for _ in range(n):
        m1[_]+=1
    sa=m1[n-1]
    base=m1[-1]/2
    for k in range(n):
        if abs(base-m1[k])<sa:
            sa=abs(base-m1[k])
    ans1=sa*2+1
    for v in range(n-1):
        m[v]-=1
    m[-1]+=1
    sa=m[n-1]
    base=(m[n-1]/2)//1
    for k in range(n):
        if abs(base-m[k])<sa:
            sa=abs(base-m[k])
    ans2=sa*2+1
    print(int(min(ans1,ans2)))

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



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

using namespace std;

int main(int argc, const char *argv[]) {
  int a, b;
  cin >> a >> b;

  int ans = a + b;
  if (ans < 10) {
    cout << ans << '\n';
  } else {
    cout << "error" << '\n';
  }

  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
  	cin>>n;
  	vector<int>x1(n);
  	for(int i=0;i<n;i++){
    	cin>>x1[i];
    }
  	
   int sum=0,count; 
  	vector<int>vec(0);
  	map<int,int>m;
  	for(int i=1;i<=100;i++){
    		sum=0;
        	for(int k=0;k<n;k++){
            	sum=sum+(x1[k]-i)*(x1[k]-i);
              	
            }
      		m[i]=sum;
      		vec.push_back(sum);
    }
  	
  	sort(vec.begin(),vec.end());
  	for(int i=1;i<=100;i++){
    	if(m[i]==vec[0]){
        	count=i;
        }
    
    }
  	
  	//最少になるような位置はcountに記録されているので合計をsum2として
  	int sum2=0;
  	for(int i=0;i<n;i++){
    	sum2=sum2+((x1[i]-count)*(x1[i]-count));
    
    }
  	cout<<sum2<<endl;
  	
}

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 n;
    string s;
    cin>>n>>s;
    set<int> res;
    set<int>tmp;
    for(int i=0;i<s.size();i++){
        if(tmp.count(s[i]-'0')) continue;
        tmp.insert(s[i]-'0');
        for(int j=i+1;j<s.size();j++){
            for(int k=j+1;k<s.size();k++){
                res.insert(100*(s[i]-'0')+10*(s[j]-'0')+(s[k]-'0'));
                if(s[j]==s[k]) break;
            }
        }
    }
    cout << res.size() << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
signed main(){
  string s;cin>>s;
  int res=0;
  string ac="CODEFESTIVAL2016";
  rep(i,16){
    if(s[i]!=ac[i])res++;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
const ll N=26;
ll solve(ll D,vii &A,vi &C,vi &S){
    vi last(N,-1);
    ll a=0;
    rep(i,0,D){
        ll memo; memo=S[i];
        ll X=i-last[memo]-1;
        a-=X*(X+1)/2*C[memo];
        last[memo]=i;
        a+=A[i][memo];
    }
    rep(i,0,N){
        ll X=D-last[i]-1;
        a-=X*(X+1)/2*C[i];
    }
    return a;
}
int main(){
    ll D; cin>>D;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi S(D);
    rep(i,0,D){
        cin>>S[i];
        S[i]--;
    }
    ll M; cin>>M;
    ll ans=solve(D,A,C,S);
    rep(i,0,M){
        ll d,q; cin>>d>>q;
        d--;
        q--;
        S[d]=q;
        ans=solve(D,A,C,S);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3704
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans, cnt = 0;
int N, offset = 0, period;
ll K;
vi A, dist, Res;
vector<bool> visited;

void solve(){
    visited.resize(N, false);
    Res.resize(N);

    int cur = 0;

    while(!visited[cur]){
        Res[cnt] = cur;
        visited[cur] = true;
        
        cur = dist[cur];
        cnt++;
    }

    // cout << cnt << endl;
    // cout << cur << endl;

    if(cur != 0){
        int tmp = 0;
        while(tmp != cur){
            tmp = dist[tmp];
            offset++;
        }
    }

    // cout << offset << endl;

    period = cnt - offset;

    if(K < offset){
        cout << Res[K] + 1 << endl;
    } else {
        K -= offset;

        ans = K % period;

        cout << Res[offset+ans]+1 << endl;
    }


}

int main(){
    cin >> N >> K;
    vi A;
    A.resize(N);
    dist.resize(N);

    rep(i, N) {
        cin >> A[i];
        A[i]--;
        dist[i] = A[i];
    }

    solve();
}


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
char a[1000001],b[1000001],c[1000001];
int l;
bool judge(){
	for (int i=0;i<l;i++)
	    if (a[i]!=b[i]) return false;
	return true;
}
int main(){
	cin>>a;
	l=strlen(a);
	for (int i=0;i<l;i++)
	    b[l-1-i]=a[i];
	for (int i=0;i<l;i++)
	    if (b[i]=='b') b[i]='d';
	        else if (b[i]=='d') b[i]='b';
	        else if (b[i]=='p') b[i]='q';
	        else if (b[i]=='q') b[i]='p';
	if (judge()) printf("Yes");
	    else printf("No");
	return 0; 
}

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

int main() {
  int K, S;
  cin >> K >> S;

  int res = 0;
  for (int x = 0; x <= K; ++x) {
    for (int y = 0; y <= K; ++y) {
      int z = S - x - y;
      if (0 <= z && z <= K) {
        ++res;
      }
    }
  }

  cout << res << endl;
}



Measured memory_bytes: 256
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
#define int ll 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
pii a[N];
int d[N * 4], t[N * 4];
void build (int v, int l, int r) {
	if (l == r) {
		d[v] = a[l].S;
		return;
	}
	int mid = l + r >> 1;
	build (v * 2, l, mid);
	build (v * 2 + 1, mid + 1, r);
}
void push (int v, int l, int r) {
	d[v] -= t[v];
	if (l != r) {
	 	t[v * 2] += t[v];
	 	t[v * 2 + 1] += t[v];
	}
	t[v] = 0;
}
int get (int v, int l, int r, int pos) {
	push (v, l, r);
	if (l == r) return d[v];
	else {
		int mid = l + r >> 1;
		if (pos <= mid) get (v * 2, l, mid, pos);
		else get (v * 2 + 1, mid + 1, r, pos);	
	}
}
void update (int v, int l, int r, int nl, int nr, int x) {
	push (v, l, r);
	if (nl > r || l > nr) return;
	if (nl <= l && r <= nr) {
		t[v] += x;
		push (v, l, r);
		return;
	}	
	int mid = l + r >> 1;
	update (v * 2, l, mid, nl, nr, x);
	update (v * 2 + 1, mid + 1, r, nl, nr, x);
}
void solve () {
	int n, d, x;
	cin >> n >> d >> x;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i].F >> a[i].S;			
	}		
	sort (a + 1, a + n + 1);
	build (1, 1, n);     
	int sum = 0;
	for (int i = 1; i <= n; i ++) {
		int o = get (1, 1, n, i);
		if (o > 0) {
			int R = a[i].F + 2 * d;
			int l = i, r = n;
			int pos = i;
			while (l <= r) {
				int mid = l + r >> 1;
				if (a[mid].F <= R) {
					l = mid + 1;
					pos = mid;
				}
				else {
					r = mid - 1;
				}
			}
			
			sum += (o + x - 1) / x;

			update (1, 1, n, i, pos, (o + x - 1) / x * x);	
		}
	}
	cout << sum;
}
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//  cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 15872
# from fractions import gcd
from math import gcd
k = int(input())

ans = 0

for i in range(1, k + 1):
    for j in range(i + 1, k + 1):
        ans += gcd(i, j)
        for t in range(j + 1, k + 1):
            ans += gcd(gcd(i, j), t)

ans *= 6
ans += sum([i for i in range(1, k + 1)])
print(ans)


Measured memory_bytes: 9172
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
int main(){
    int n;
    cin >> n;
    long long a[120][4][4][4];
    rep(i,120){
        rep(j,4){
            rep(k,4){
                rep(l,4){
                    a[i][j][k][l] = 0;
                }
            }
        }
    }
    rep(i,4){
        rep(j,4){
            rep(k,4){
                a[3][i][j][k] = 1;
            }
        }
    }
    a[3][0][2][1] = 0;
    a[3][0][1][2] = 0;
    a[3][2][0][1] = 0;
    for(int i=4;i<=n;i++){
        rep(j,4){
            rep(k,4){
                rep(l,4){
                    rep(m,4){
                        if(m == 0 && k == 2 && l == 1){
                        }
                        else if(j == 0 && k == 2 && l == 1){
                        }
                        else if(j == 2 && k == 0 && l == 1){ 
                        }
                        else if(j == 0 && k == 1 && l == 2){ 
                        }
                        else if(m == 0 && j == 2 && l == 1){
                        }
                        else{
                            a[i][j][k][l] = a[i][j][k][l] + a[i-1][m][j][k];
                            a[i][j][k][l] = a[i][j][k][l] % MOD;
                        }
                    }
                }
            }
        }
    }
    long long ans = 0;
    rep(i,4){
        rep(j,4){
            rep(k,4){
                ans = ans + a[n][i][j][k];
                ans = ans % MOD;
            }
        }
    }
    cout << ans << endl;
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define RREP(i,a) for(int i = a;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int N, M;
VPII shops;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    rep (i, N) {
        int a, b;
        cin >> a >> b;
        shops.pb(PII(a, b));
    }
    sort(all(shops));
    LL ans = 0LL;
    rep (i, shops.size()) {
        LL buy = min(M, shops[i].second);
        ans += buy * shops[i].first;
        M -= buy;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(void) {
  int n,m;
  int res;
 
  while(1) {
    cin >> n >> m;
    if(n == 0 && m == 0) break;
     
    res = 0;
 
    int p[n];
    for(int i = 0; i < n; i++)
      cin >> p[i];
     
    stable_sort(p, p + n);
 
    for(int i = n-1; i >= 0; ) {
      for(int j = 0; j < m-1; j++) {
    if(i < 0) break;
    res += p[i];
    i--;
      }
      i--;
    }
     
    cout << res << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1228
N,M = list(map(int,input().split()))
ac = [0]*N
wa = [0]*N
for i in range(M):
    p,s = list(map(str,input().split()))
    p = int(p)
    if s == 'AC':
        ac[p - 1] = 1
    elif s == 'WA':
        if ac[p - 1] == 0:
            wa[p - 1] += 1
for i in range(N):
    if ac[i] == 0:
        wa[i] = 0
print(sum(ac),sum(wa))

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <typename T>
vector<T> Dijkstra(int s, vector<vector<pair<int, T>>> & G, vector<int> & prev, const T INF = 1e9){
    using P = pair<T, int>;
    int V = G.size();
    vector<T> dist(V, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);
    prev.assign(V, -1);
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            int to = G[v][i].first;
            T cost = G[v][i].second;
            if(dist[to] > dist[v] + cost){
                dist[to] = dist[v] + cost;
                prev[to] = v;
                que.emplace(dist[to], to);
            }
        }
    }
    return dist;
}

signed main(){
    int n,m;
    cin >> n >> m;
    int a[m],b[m];
    REP(i,m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    for(int i = 0; i < n; i++){
        vector<vector<pair<int, int>>> G(n + 1);
        for(int j = 0; j < m; j++){
            if(b[j] == i){
                G[a[j]].emplace_back(n, 1);
            }else{
                G[a[j]].emplace_back(b[j], 1);
            }
        }
        vector<int> prev;
        vector<int> dist = Dijkstra(i, G, prev);
        if(dist[n] != INF){
            vector<int> cand;
            bool used[n] = {};
            int now = n;
            while(prev[now] != -1){
                now = prev[now];
                used[now] = true;
                cand.emplace_back(now);
            }
            bool indeg[n] = {};
            for(int j = 0; j < m; j++){
                if(used[a[j]] && used[b[j]]){
                    if(indeg[b[j]]) goto no;
                    indeg[b[j]] = true;
                }
            }
            cout << cand.size() << endl;
            for(auto v : cand){
                cout << v + 1 << endl;
            }
            return 0;
        }
        no:;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
int32_t main()
{
fastio;
int n;in n;
int arr[n];
rep(i,n) in arr[i];
int ans=0;
for(int i=0;i<n-1;i++){
    for(int j=i;j<n;j++){
        if(i==j) continue;
        else ans+=arr[i]*arr[j];
    }
}
out ans;
    return 0;
}


Measured memory_bytes: 256
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanLines)
  var result []int
  for {
    num := getStdin()
	if num == "0" {
		break
	}

	sum := 0
    for _, v := range num {

	    v, _ := strconv.Atoi(string(v))
		sum = sum + v
    }
	result = append(result, sum)
  }
  length := len(result)
  for i := 0; i < length; i++ {
	  fmt.Println(result[i])
  }

}

func getStdin() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

func nextInt() (int) {
	sc.Scan()
	v, e := strconv.Atoi(sc.Text())
    if e != nil { panic(e) }
    return v
}

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}



Measured memory_bytes: 1092
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N;
    string good = "ABC";
    string bad = "ABD";

    cin >> N;

    if (N < 1000) cout << good << endl;
    else cout << bad << endl;

    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
A=list(map(int,input().split()))
ones=[0]*40
for a in A:
    for i in range(40):
        if a&(1<<i):
            ones[i]+=1
x=0
for i in range(39,-1,-1):
    if x+(1<<i)>k:
        continue
    elif ones[i]<n-ones[i]:
        x+=(1<<i)
ans=0
for a in A:
    ans+=x^a
print(ans)

Measured memory_bytes: 14620
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int CMAX = 100 / 4;
            int DMAX = 100 / 7;


            for (int i = 0; i <= CMAX; i++)
            {
                for (int j = 0;j <= DMAX; j++)
                {
                    if(i*4 + j*7 == N)
                    {
                        Console.WriteLine("Yes");
                        return;
                    }


                }
            }

            Console.WriteLine("No");
            return;
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long n,c=0,k,i,a,ans=0;
	unordered_map<long long,long long>m;
	cin>>n>>k;
	m[0]=1;
	vector<int>x(n+1);
	for(i=1;i<=n;i++)
	{
		if(i>=k)m[x[i-k]]--;
		cin>>a;
		c=(c+a)%k;
		x[i]=(c-i%k+k)%k;
		ans+=m[x[i]];
		m[x[i]]++;
	}
	cout<<ans<<'\n';
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll X;
  scanf("%lld", &X);

  if (X >= 30) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3660
from itertools import groupby, accumulate
from operator import sub
N, K = map(int, input().split())
S = input()
A = list(map(lambda p: (p[0], len(list(p[1]))), groupby(S, lambda s: s=="1")))
M = len([() for t,_ in A if not t])
B = [0] + list(accumulate(l for _,l in A))
R = B[K * 2 + int(A[0][0])::2] + ([] if A[-1][0] else [B[-1]])
L = ([] if A[0][0] else [B[0]]) + B[int(not A[0][0])::2]
print(max(map(sub, R, L)) if M > K else len(S))

Measured memory_bytes: 15884
<?php
fscanf(STDIN, "%d %d %d", $x, $a, $b);
$factor = $a-$b;
if ($factor >= 0){
    print("delicious\n");
} else {
    if (abs($factor) <= $x){
        print("safe\n");
    } else {
        print("dangerous\n");
    }
}
?>

Measured memory_bytes: 4728
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
using namespace std;

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

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

    string ans;

    if (e - a > k)
    {
        ans = ":(";
    }
    else
    {
        ans = "Yay!";
    }
    
    cout <<  ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll          long long int
#define ld          double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define all(a)      a.begin(),a.end()
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        3005
#define LOG         30
#define mod         1000000007
using namespace std;
 
ll dp[MAXN][MAXN];
string s="";
 
 
// ll solve(string s1,string s2,ll n,ll m){
//     if(n==0 || m==0){
//         return 0;
//     }
//     if(dp[n][m]!=-1){
//         return dp[n][m];
//     }
//     if(s1[n-1]==s2[m-1]){
//         dp[n][m]=1+solve(s1,s2,n-1,m-1);
//     }
//     else{
//         dp[n][m]=max(solve(s1,s2,n-1,m),solve(s1,s2,n,m-1));   
//     }
//     return dp[n][m];
// }
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    string s1,s2;
    cin>>s1>>s2;
    ll n=s1.size();
    ll m=s2.size();
    //cout<<solve(s1,s2,n,m)<<endl;
    memset(dp,0,sizeof(dp));
    ll i,j;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(i==0 || j==0){
                dp[i][j]=0;
            }
            else{
                if(s1[i-1]==s2[j-1]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }
                else{
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
    }
    // for(i=0;i<=n;i++){
    //     for(j=0;j<=m;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    i=n;
    j=m;
    while(i>0 && j>0){
        if(s1[i-1]==s2[j-1]){
            s+=s2[j-1];
            i--;
            j--;
        }
        else{
            if(dp[i-1][j]>dp[i][j-1]){
                i--;
            }
            else{
                j--;
            }
        }
    }
    reverse(s.begin(),s.end());
    //lcs(s1,s2,n,m);
    cout<<s;
}

Measured memory_bytes: 70784
H, W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]
N = 0
ans = []
for x in range(W):
  for y in range(H-1):
    if a[y][x]%2 == 1:
      a[y][x] -= 1
      a[y+1][x] += 1
      ans.append([y+1,x+1,y+2,x+1])
      N += 1
for x in range(W-1):
  if a[H-1][x]%2 == 1:
    a[H-1][x] -= 1
    a[H-1][x+1] += 1
    ans.append([H,x+1,H,x+2])
    N += 1
print(N)
for i in ans:
  print(" ".join(map(str,i)))

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

vector<int> graph[2001];
int N, K, A, B;

int dfs(int mae, int ima, int kyori, int km){
    if(kyori>km){
        return 0;
    }else{
        int ret = 1;
        for(int tsugi: graph[ima]){
            if(tsugi == mae) continue;
            ret += dfs(ima, tsugi, kyori+1,km);
        }
    return ret;
    }
}


int main(){
    cin >> N >> K;
    REP(i,N-1){
        cin >> A >> B;
        A--; B--;
        graph[B].push_back(A);
        graph[A].push_back(B);
    }
    int ans = N;
    if(K%2==0){
        REP(i,N){
            ans = min(ans, N-dfs(-1,i,0,K/2));
        }
    }else{
        REP(i,N){
            for(int j: graph[i]){
                ans = min(ans,N-(dfs(j,i,0,(K-1)/2)+dfs(i,j,0,(K-1)/2)));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  ll n, W;
  cin >> n >> W;
  ll v[n], w[n], m[n];
  rep(i,n) cin >> v[i] >> w[i] >> m[i];
  vector<ll> vp, wp;
  rep(i,n) {
    ll cur = 1;
    while(m[i] > 0) {
      vp.push_back(v[i]*min(cur,m[i]));
      wp.push_back(w[i]*min(cur,m[i]));
      m[i] -= cur;
      cur *= 2;
    }
  }
  int l = vp.size();
  vector<vector<ll>> dp(l+1,vector<ll>(W+1));
  rep(i,l) {
    rep(j,W+1) {
      if(j > 0) dp[i+1][j] = max({dp[i+1][j],dp[i][j],dp[i+1][j-1]});
      if(j-wp[i] >= 0) dp[i+1][j] = max(dp[i+1][j],dp[i][j-wp[i]]+vp[i]);
    }
  }
  cout << dp[l][W] << endl;
  return 0;
}


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

xlist=[1]
for d in range(1,10**9):
  if 6**d>100000:
    break
  xlist.append(6**d)
for d in range(1,10**9):
  if 9**d>100000:
    break
  xlist.append(9**d)
xlist.sort()
#print(xlist)

dp=[0]*(N+1)
for i in range(1,N+1):
  min_dp=10**9
  for x in xlist:
    if i-x<0:
      break
    min_dp=min(min_dp,dp[i-x])
  dp[i]=min_dp+1
  
#print(dp)
print(dp[-1])

Measured memory_bytes: 3828
H,W = map(int,input().split())
a = [input() for i in range(H)]
i = 0
while i<H:
    if not '#' in a[i]:
        del a[i]
        H -= 1
        i -= 1
    i += 1
a = list(map(list,zip(*a)))
i = 0
while i<W:
    if not '#' in a[i]:
        del a[i]
        W -= 1
        i -= 1
    i += 1
a = (list(map(list,zip(*a))))
for i in range(H):
    print(''.join(a[i]))


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

using namespace std;

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

int main()
{
  int n;
  cin >> n;
  vector<pair<ll, ll>> sushi(n), mp(n);
  for (int i = 0; i < n; ++i)
  {
    cin >> sushi[i].first >> sushi[i].second;
    mp[i].first = sushi[i].first + sushi[i].second, mp[i].second = i;
  }
  sort(mp.begin(), mp.end(), greater<pair<ll, ll>>());
  ll a = 0, t = 0;
  for (int i = 0; i < n; ++i)
  {
    if (i & 1)
    {
      a += sushi[mp[i].second].second;
    }
    else
    {
      t += sushi[mp[i].second].first;
    }
  }
  cout << t - a << endl;
}


Measured memory_bytes: 3328
fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    handle.read_line(&mut buf).unwrap();
    buf.clear();
    handle.read_line(&mut buf).unwrap();
    let data: Vec<usize> = buf.trim().split_whitespace()
        .map(|a| a.parse().unwrap()).collect();

    let mut max_count = 0;
    let mut count = 0;
    let mut read_zero = true;
    for i in data {
        if read_zero {
            if i == 1 {
                count = 1;
                read_zero = false;
            }
        } else {
            if i == 1 {
                count += 1;
                continue;
            } else {
                if max_count < count {
                    max_count = count;
                }
                count = 0;
                read_zero = true;
            }
        }
    }
    if read_zero == false {
        if max_count < count {
            max_count = count;
        }
    }
    println!("{}", max_count + 1);
}


Measured memory_bytes: 5028
N, D = gets.split.map(&:to_i)

dots = Array.new
N.times do
  dots.push(gets.split.map(&:to_i))
end

def kyori(dot_a, dot_b, d)
  sum = 0
  d.times do |i|
    sum += (dot_a[i] - dot_b[i])**2
  end
  sum ** (1/2.0)
end

count = 0
N.times do |i|
  (i+1..N-1).each do |j|
    k = kyori(dots[i], dots[j], D)
    if k.to_s =~ /^[+-]?[0-9]*[\.]?[0]+$/
      count += 1
    end
  end
end
p count

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;

int A[26], work[26];

int main(){
  ios_base::sync_with_stdio(false); 
  cin >> N;
  memset(A, 101, sizeof(A));
  for(int i = 0; i<N; ++i){
    string s;
    cin >> s;
    memset(work, 0, sizeof(work));
    for(int j=0; j<(int)s.length(); ++j){
      ++work[s[j] - 'a'];
    }
    for(int j=0; j<26; ++j){
      A[j] = min(work[j], A[j]);
    }
  }
  string res = "";
  for(int i=0; i<26; ++i){
    for(int j=0; j<A[i]; ++j)
      cout << char(i+'a');
  }
  cout << "\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;
typedef pair<int,int> P;
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; }

  unsigned GetDigit(unsigned num){
      unsigned digit=0;
      while(num!=0){
          num /= 10;
          digit++;
      }
      return digit;
  }

int main(void){
  ll n; cin >> n;
  ll sum = 1;
  ll a[n];
  ll keta = 0;
  rep(i,n){
    cin >> a[i];
    if(a[i] == 0){
      cout << 0 << endl;
      return 0;
    }
    keta += GetDigit(a[i]) -1;
  }
  if(keta > 18){
    cout << -1 << endl;
    return 0;
  }
  rep(i,n){
    sum *= a[i];
    if(sum > 1000000000000000000){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 4416
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from operator import itemgetter

n = readint()
a = []
for i in range(n):
    x,l = readints()
    a.append([x-l,x+l])

a.sort(key = itemgetter(1))

ans = 1
now = a[0][1]
for l,r in a[1:]:
    if now<=l:
        ans += 1
        now = r
print(ans)

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

#define MAX_INPUT 10
int main() {

	char input[MAX_INPUT + 1];
	// get input like "5 7 5"
	fgets(input, MAX_INPUT, stdin);

	// assign 3 numbers
	int num1 = atoi(&input[0]);
	int num2 = atoi(&input[2]);
	int num3 = atoi(&input[4]);

	int count = 0;
	if (num1 == num2) {
		count++;
	}
	if (num1 == num3) {
		count++;
	}
	if (num2 == num3) {
		count++;
	}

	if (count == 1) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char **argv) {
  int n, ret, i, j, x, tmp, k;
  int a[100000];

  ret = scanf("%d", &n);
  if (errno != 0) perror("scanf: n");
  if (ret < 1) exit(1);

  for (i = 0; i < n; ++i) {
    ret = scanf("%d", &a[i]);
    if (errno != 0) perror("scanf: a[i]");
    if (ret < 1) break;
  }
  x = a[n - 1];

  for (i = -1, j = 0; j < n - 1; ++j) {
    if (a[j] > x) continue;

    tmp = a[++i];
    a[i] = a[j];
    a[j] = tmp;
  }
  tmp = a[++i];
  a[i] = a[n - 1];
  a[n - 1] = tmp;
  k = i;

  for (i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    if (i == k) printf("[");
    printf("%d", a[i]);
    if (i == k) printf("]");
  }
  printf("\n");

  exit(0);
}


Measured memory_bytes: 2144
#include <stdio.h>
#include <stdlib.h>
#define STR_LENGTH (6)
int main(int argc, char* argv[])
{
	//ABC160 C
	int i;
	int k, n;
	int *a;
	int kyori = 0x7fffffff;
	int m;//目的地
	// 1周 Kメートルの円
	// N軒の家
	// 北端からA1メートルのとこに家、北端からA2メートルのとこに家　繰り返し
	// K N
	// A1 A2 A3 A4 A5
	scanf("%d %d\n", &k, &n);

	a = (int *)malloc(sizeof(int) * n);

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

	i = 0;
	//右
	m = n - 1;
	if (kyori > a[m] - a[i]) {
		kyori = a[m] - a[i];
	}
	//左
	m = 1;
	if (kyori > a[m] - a[i] + k) {
		kyori = a[m] - a[i] + k;
	}

	for (i = 1; i < n - 1; i++) {
		//右
		m = i - 1;
		if (kyori > a[i] - a[m] + k) {
			kyori = a[i] - a[m] + k;
		}

		//左
		m = i + 1;
		if (kyori > a[i] - a[m] + k) {
			kyori = a[i] - a[m] + k;
		}

	}

	i = n - 1;
	m = i - 1;
	//右
	if (kyori > a[i] - a[m] + k) {
		kyori = a[i] - a[m] + k;
	}

	m = 0;
	//左
	if (kyori > a[i] - a[m]) {
		kyori = a[i] - a[m];
	}

	printf("%d", kyori);

	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define int64 long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  double n,k;
  cin>>n>>k;
  double ans=0;
  rep1(i,n+1){
    if(i<k){
      ans+=pow(0.5,ceil(log2(k/i)))/n;
    }else{
      ans+=1/n;
    }
  }
  cout<<setprecision(12)<<ans;
}

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

int main() {
  
  int A=0, B=0;
  
  cin >> A >> B;
  
  int times = A+B;
  
  if(B==0) {
    
    cout << A << endl;
    
  } else if(24<=times) {
    
    cout << times-24 << endl;
    
  } else {
    
    cout << times << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	vector<int> v,w;
	string s;
	int i;
	cin>>s;
	v.push_back(-1);
	bool ch=true;
	for(i=0;i<s.length();i++){
		if(s[i]!='A'&&s[i]!='G'&&s[i]!='T'&&s[i]!='C'){
			v.push_back(i);
			ch=false;
		}
	}
	v.push_back(s.length());
	for(i=0;i<v.size()-1;i++){
		w.push_back(v[i+1]-v[i]-1);
	}
	sort(w.begin(),w.end());
	if(ch)cout<<s.length()<<endl;
	else cout<<w[w.size()-1]<<endl;
	
	
//////////////////////////////////////////////////////
	return 0;
}







Measured memory_bytes: 256
def main():
    n = int(input())
    A = list(map(int,input().split()))
    B = [0]*(len(A))
    #print(B)

    A1 = A
    A1.sort(reverse = True)

    C = [0]*(A1[0] + 1)
    #要素の数をCに記憶
    for i in range(n):
        C[A[i]] += 1
    #print(C)

    #累積和をとるよ
    for i in range(len(C)):
        if i == 0:
            continue
        else:
            C[i] += C[i-1]
    #print(C)

    for i in range(n-1,-1,-1):
        B[ C[ A[i] ] - 1 ] = A[i]
        C[ A[i] ] -= 1

    return B

B = main()
B = map(str,B)
print(' '.join(B))



Measured memory_bytes: 224380
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 



int main(){
    int N;
    cin >> N;
    int a[N];
    REP(i,N) cin >> a[i];
    int num=0;
    int res=1;
    int tmp=0;
    bool exist=false;
    for(int i=0;i<N;++i){
        ++tmp;
        if(a[i]==res){
            --tmp;
            num+=tmp;
            tmp=0;
            ++res;
            exist=true;
            continue;
        }
    }
    num+=tmp;
    if(exist){
        cout << num;
    }
    else{
        cout << -1;
    }
}

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

using namespace std;

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

    int nV, nE, cap;
    cin >> nV >> nE >> cap;
    vector<vector<pair<int, int>>> edges(nV + 1); // to, cost
    for (int i = 0; i < nE; ++i) {
        int u, v, cost;
        cin >> u >> v >> cost;
        edges[u].emplace_back(v, cost);
        edges[v].emplace_back(u, cost);
    }
    const int INF = 1e6;
    vector<vector<int>> dist(nV + 1, vector<int>(nV + 1, INF));

    auto dijkstra = [&](int source) {
        priority_queue<pair<int, int>> pq; // cost, to
        vector<bool> used(nV + 1, false);
        pq.emplace(cap, source);
        while (!pq.empty()) {
            const auto cur = pq.top();
            pq.pop();
            int v = cur.second;
            int rem = cur.first;
            dist[source][v] = 1;
            if (!used[v]) {
                used[v] = true;
                for (const auto& to : edges[v]) {
                    if (dist[source][to.first] == INF && rem - to.second >= 0) {
                        pq.emplace(rem - to.second, to.first);
                    }
                }
            }
        }
    };

    for (int v = 1; v <= nV; ++v) {
        dijkstra(v);
    }
    for (int k = 1; k <= nV; ++k) {
        for (int i = 1; i <= nV; ++i) {
            for (int j = 1; j <= nV; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    int nQ;
    cin >> nQ;
    for (int q = 0; q < nQ; ++q) {
        int from, to;
        cin >> from >> to;
        int d = dist[from][to] == INF ? -1 : dist[from][to] - 1;
        cout << d << '\n';
    }

    return 0;
}

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

int main() {
	int t, n, d;
	cin >> t;
	
	unsigned long long ans = 0;
	
	while(t-- > 0){
		cin >> n >> d;
		ans = (n - 1) * 127;
		if(n % 2 == 0){
			ans += 127 - d;
		}else{
			ans += d;
		}
		
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
const LL mod=1000000007;
const LL LINF=1LL<<61;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    LL n;cin >> n;
    LL k;cin >> k;
    vector<LL> a,b,c;
    for (int i = 0; i < n; i++) {
        LL t;cin >> t;
        if(t<0) b.pb(-t);
        else if(t>0) a.pb(t);
        else c.pb(t);
    }
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));
    LL l=-LINF,r=LINF;
    while(abs(r-l)>1){
        LL m = (r + l) / 2;
        LL cnt = 0;
        LL az = a.size(),bz = b.size(),cz = c.size();
        if(m <= 0){
            cnt += az * (az-1) / 2 + bz * (bz - 1) / 2 + (az+bz)*cz + (cz-1)* cz / 2;
            for (int i = 0; i < az; i++) {
                auto t = upper_bound(ALL(b),abs(m)/a[i]) - b.begin();
                cnt += t;
            }
        }
        else{
            for (int i = 0; i < az-1; i++) {
                auto t = a.end() - lower_bound(a.begin()+i+1,a.end(),(m+a[i]-1)/a[i]);
                cnt += t;
            }
            for (int i = 0; i < bz-1; i++) {
                auto t = b.end() - lower_bound(b.begin()+i+1,b.end(),(m+b[i]-1)/b[i]);
                cnt += t;
            }
        }
        if(n*(n-1)/2-k<cnt) l = m;
        else r = m;
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 2548
package main

import "fmt"

func main() {
	var n int
	m := make(map[string]int)
	fmt.Scan(&n)
	for ; n > 0; n-- {
		var s string
		fmt.Scan(&s)
		m[s]++
	}

	for _, s := range []string{"AC", "WA", "TLE", "RE"} {
		fmt.Println(s, " x ", m[s])
	}
}


Measured memory_bytes: 6332
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int L;
struct edge{
	int f,t,c;
	edge(){}
	edge(int f,int t,int c):f(f),t(t),c(c){}
};
vector<edge> ans;
int main(){
	cin >> L;
	int s = 0;
	while((1<<(s+1))<=L)s++;
	for(int i=1;i<=s;i++){
		ans.pb(edge(i,i+1,1<<(i-1)));
		ans.pb(edge(i,i+1,0));
	}
	for(int i=0;i<s;i++){
		if((L>>i)&1){
			ans.pb(edge(i+1,s+1,(L>>(i+1))<<(i+1)));
		}
	}
	cout << s+1 << ' ' << ans.size() << endl;
	for(int i=0;i<ans.size();i++){
		cout << ans[i].f << ' ' << ans[i].t << ' ' << ans[i].c << endl;
	}
	return 0;
}

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

struct info{
	int ninzu;
	int score[1001];
	double ave;
	double hensa;
};

double keisan(int *score, double ave ,int ninzu){
	int i;
	double sigma,hensa;
/*tes*/	double sigma_totyu;
	sigma = 0;
	sigma_totyu = 0;
	
	for(i=0; i<ninzu; i++){
		sigma_totyu = pow( (double)(*score) - ave, 2.0);
		sigma += sigma_totyu;
		score++;
	}
	hensa = sqrt(sigma / ninzu);
	
	return hensa;
}

int main(){
	
	int i, j;
	struct info class[100] ={0};
	int clsNum, score;
	
	for(i=0; i<1000; i++){
		class[i].ave = 0;			/*要素初期化*/
		scanf("%d", &class[i].ninzu);		/*クラスの人数入力*/
		if(class[i].ninzu == 0)	break;		/*終了条件=人数０人*/
		for(j=0; j<class[i].ninzu; j++){
			scanf("%d", &class[i].score[j]);
			class[i].ave += class[i].score[j];	/*平均値=点数の合計を格納し、ループ後に人数で割る*/
		}
		class[i].ave /= class[i].ninzu;
		class[i].hensa 
			= keisan(&class[i].score[0], class[i].ave, class[i].ninzu);
	}
	
	clsNum = i;
	
	for(i=0; i<clsNum; i++)	printf("%.8f\n",class[i].hensa);
	
	return 0;
}



Measured memory_bytes: 2204
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define Rep(i, N) for(int i = 0; i < N; i++)

char ch[] = {'m', 'c', 'x', 'i'};
int value[] = {1000, 100, 10, 1};


int to_val(string s) {
  
  int ret = 0;
  Rep(i, s.size()) {
    int v = 1;
    if('2' <= s[i] && s[i] <= '9') {
      v = s[i] - '0', i++;
    }
    Rep(j, 4) {
      if(s[i] == ch[j]) ret += value[j] * v;
    }
  }

  return ret;
}
  
signed main()
{
  int N;
  
  cin >> N;
  Rep(i, N) {
    string a, b;

    cin >> a >> b;
    
    int val = to_val(a) + to_val(b);
    
    string ans;
    
    Rep(j, 4) {
      if(val >= value[j]) {
	if(val >= value[j] * 2) {
	  ans += '0' + val / value[j];
	}
	ans += ch[j];
	val -= (val / value[j]) * value[j];
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3128