akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

template<class Abel> struct UnionFind {
    vector<int> par; //親ノード
    vector<int> rank; //高さ
    vector<Abel> diff_weight;

    UnionFind(int N = 1, Abel SUM_UNITY = 0){
        init(N, SUM_UNITY);
    } 

    void init(int N = 1, Abel SUM_UNITY = 0){
        par.resize(N);
        rank.resize(N);
        diff_weight.resize(N);

        for(int i = 0; i < N; ++i){
            par[i] = i;
            rank[i] = 0;
            diff_weight[i] = SUM_UNITY;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        else{
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = root(par[x]);
        }
    }

    bool is_same(int x,int y){ 
        return root(x) == root(y); 
    }

    Abel  weight(int x){
        root(x);
        return diff_weight[x];
    }

    Abel diff(int x,int y){
        return weight(y) - weight(x);
    }

    bool merge(int x,int y,int w = 0){
        w += weight(x);
        w -= weight(y);

        x = root(x);
        y = root(y);
        if(x == y) return false;

        if(rank[x] < rank[y]) swap(x,y), w = -w;
        if(rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> p(N);
    for(int i=0;i<N;++i) cin >> p[i];

    UnionFind<int> tree(N+1);

    for(int i = 0; i < M; ++i){
        int x,y;
        cin >> x >> y;
        tree.merge(x,y);
    }

    int ans = 0;

    for(int i=0;i<N;++i) ans += tree.is_same(i+1,p[i]);

    cout << ans << endl;
}

Measured memory_bytes: 1792
use proconio::input;
use std::cmp::min;

fn main() {
    input! {
        n: i32,
    }

    let mut ans = 100000;
    for i in 0 .. 11 {
        let price = i * 1000;
        if price < n { continue };
        ans = min(ans, price - n);
    }

    println!("{}", ans);
}


Measured memory_bytes: 2136
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

#define X first
#define Y second

void solve() {

}

int main () {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int x = 100000;
    int X, Y;
    cin >> X >> Y;
    int res = max(0, 3 - X + 1) * x + max(0, 3 - Y + 1) * x;
    if (X == 1 && Y == 1) {
        res += 4 * x;
    }
    cout << res;
    return 0;
}


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

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

int dist[30][30],maxv,h,w;
char c[30][30];

int main()
{
  ios::sync_with_stdio(false);
  cin>>h>>w;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>c[i][j];
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++) if(c[i][j]=='.'){
      memset(dist,-1,sizeof(dist));
      dist[i][j]=0;
      queue<pair<int,int> > q;
      q.push(make_pair(i,j));
      while(!q.empty()){
        pair<int,int> t=q.front();
        q.pop();
        for(int dir=0;dir<4;dir++){
          int nx=dx[dir]+t.first,ny=dy[dir]+t.second;
          if(nx<=0||ny<=0||nx>h||ny>w) continue;
          if(dist[nx][ny]!=-1) continue;
          if(c[nx][ny]=='#') continue;
          dist[nx][ny]=dist[t.first][t.second]+1;
          q.push(make_pair(nx,ny));
        }
      }
      for(int ii=1;ii<=h;ii++){
        for(int jj=1;jj<=w;jj++) if(c[ii][jj]=='.'){
          maxv=max(maxv,dist[ii][jj]);
        }
      }
    }
  }
  cout<<maxv<<endl;
  return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = Input.Cin<int>();
        long[] A = new long[N];
        long[] B = new long[N];
        for (int i = N - 1; i != -1; i--) { A[i] = Input.Cin<long>(); B[i] = Input.Cin<long>(); }
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            long nowA = A[i] + ans;
            if (nowA % B[i] == 0) continue;
            long c = (long)Math.Floor(nowA / (B[i] + .0)) + 1;
            ans += c * B[i] - nowA;
        }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    public static T Cin<T>()
    {
        if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        if (typeof(T) == typeof(int)) return (T)(object)int.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(long)) return (T)(object)long.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(string)) return (T)(object)(queue.Dequeue());
        else if (typeof(T) == typeof(double)) return (T)(object)double.Parse(queue.Dequeue());
        else return (T)(object)("");
    }
    public static T Line<T>()
    {
        foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        int c = queue.Count();
        if (typeof(T) == typeof(int[]))
        {
            int[] ret = new int[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<int>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(long[]))
        {
            long[] ret = new long[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<long>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(string[]))
        {
            string[] ret = new string[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<string>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(double[]))
        {
            double[] ret = new double[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<double>();
            return (T)(object)ret;
        }
        else return (T)(object)(0);
    }
}

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

using namespace std;

int main(){
    long long a[26], i, len;
    long long res=0;
    string s;
    cin >> s;
    len=s.length();
    memset(a, 0, sizeof a);
    for(i=0; i<s.length(); i++){
        a[s[i]-'a']++;
    }
    for(i=0; i<26; i++){
        res+=a[i]*(len-a[i]);
    }
    cout << res/2+1;
    return 0;
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

ll bigmod(ll a, ll b, ll m){
  a%=m;
  ll res = 1;
  while(b > 0){
    if(b&1) res=(res*a)%m;
    a = (a*a)%m;
    b >>= 1;
  }
  return res;
}

int main(){
  int n;  cin >> n;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; ++i){
    cin >> a[i];
    mp[a[i]]++;
  }
  for (int i = n-1; i > 0 ; i-=2){
    if(mp[i]!=2) {
      cout << 0 << endl;
      return 0;
    }
  }
  if(n&1 and mp[0]!=1){
    cout << 0 << endl;
    return 0;
  }
  cout << bigmod(2, n/2, 1e9+7) << endl;

  return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>
int main(){

  int c,i,j,n,a[100],count=0;
  scanf("%d",&n);

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

  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(a[j-1]>a[j]){
	c=a[j];
	a[j]=a[j-1];
	a[j-1]=c;
	count++;
      }
    }
  }

for(i=0;i<n;i++){
  if(n-1>i)printf("%d ",a[i]);
  else printf("%d",a[i]);
   }
        printf("\n%d\n",count);
  
    
  return 0;
}



Measured memory_bytes: 2140
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
	long n = long.Parse(ReadLine());
	long sqn = (long) Math.Sqrt(n);

	for (long i = sqn; i >= 1; i--)
	{
	    if (n%i == 0)
	    {
		long x = i;
		long y = n / x;
		//WriteLine($"x={x}, y={y}");
		WriteLine(x + y - 2);
		return;
	    }
	}
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int a,b,k;
	cin >> a >> b >> k;
	int cnt = 0;
	for( int i = max(a,b) ; i >= 1 ; i-- ){
		if( !(a % i) && !(b % i) ){
			cnt++;
			if(cnt == k ) cout << i << endl;
		}
	}
	ret 0;
}

Measured memory_bytes: 256
"""
dp[i][j] ... j ~ j + i までまとめた時の最小コスト
dp[0][j] = 0
dp[i][j] = min(dp[k][j] + dp[i - k][j + k + 1] +\
               top[j] * bottom[j + k] * top[j + k + 1] * bottom[j + i] for k in range(i))
"""
INF = 10 ** 20
n = int(input())
top = []
bottom = []
for _ in range(n):
  a, b = map(int, input().split())
  top.append(a)
  bottom.append(b)
dp = [[INF] * (n + 1) for _ in range(n + 1)]
for j in range(n):
  dp[0][j] = 0

for i in range(1, n):
  for j in range(n - i):
    dp[i][j] = min(dp[k][j] + dp[i - k - 1][j + k + 1] +\
                  top[j] * bottom[j + k] * top[j + k + 1] * bottom[j + i] for k in range(i))
print(dp[n - 1][0])



Measured memory_bytes: 5648
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1400000;
char cn[CM], * ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (72 - dig >> 3);
	return tmp;
}
char* di = cn;
inline void putint(int X) {
	if (X < 10) {
		*di++ = '0' + X;
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	fread(cn, 1, CM, stdin);
	int N = getint();
	rep(i, N - 1) A[getint()]++;

	rep1(i, N) putint(A[i]);

	fwrite(cn, 1, di - cn, stdout);


	Would you please return 0;
}

Measured memory_bytes: 3520
require 'pp'

n = gets.chomp!.to_i
a_n = gets.chomp!.split(" ").map(&:to_i)

x = {0 => 0, 2 => 0, 4 => 0}.merge(a_n.group_by {|a|
    if a % 4 == 0
        4
    elsif a% 2 == 0
        2
    else
        0
    end
}.map {|k, v|
    [k, v.length]
}.to_h)

sum = 0
# 4の倍数だけでカバーできる数
if x[4] * 2 + 1 >= n
    puts "Yes"
else
    remain = n - (x[4] * 2)
    if x[2] >= remain
        puts "Yes"
    else
        puts "No"
    end
end


Measured memory_bytes: 9692
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define ms_valtype int

//比較関数
int compare_ms(ms_valtype a, ms_valtype b){
	return b - a;
}

//昇順
void sort_sub(ms_valtype *origin, int left, int right, ms_valtype *tmp){
	if(right - left > 1){
		int i, j, k, half = (left + right) / 2;
		sort_sub(origin, left, half, tmp);
		sort_sub(origin, half, right, tmp);
		for(i = left; i < right; i++){
			tmp[i] = origin[i];
		}
		for(i = left, j = left, k = half; i < right; i++){
			if(k == right){
				origin[i] = tmp[j];
				j++;
			}
			else if(compare_ms(tmp[j], tmp[k]) <= 0 && j < half){
				origin[i] = tmp[j];
				j++;
			}
			else{
				origin[i] = tmp[k];
				k++;
			}
		}
	}
}

void sort(ms_valtype *origin, int N){
	ms_valtype *tmp = (ms_valtype *)malloc(sizeof(ms_valtype) * N);
	sort_sub(origin, 0, N, tmp);
	free(tmp);
}

signed main(){
	int N, i, ans = 0;
	scanf("%lld", &N);
	int *p = (int *)malloc(sizeof(int) * 2 * N);
	for(i = 0; i < 2 * N; i++){
		scanf("%lld", &p[i]);
	}
	sort(p, 2 * N);
	for(i = 1; i <= 2 * N; i++){
		ans += p[i - 1] * (2 * N - i);
	}
	printf("%.12lf\n", (double)ans / (2 * N - 1));
	return 0;
}

Measured memory_bytes: 3328
//Catchharsh
    //I Luv Kunj017
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (ll x,ll n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    int main()
    {   
         IOS;
         ll n,m,i,j,k;
         cin>>n;
         vector<ll> v(n);
         for(i=0;i<n;i++)
          cin>>v[i];
        int f=0;
        for(i=0;i<n;i++)
        {
          for(j=i+1;j<n;j++)
          {
            int temp=0;
              for(k=1;k<n;k++)
              {
                 if(v[k]<v[k-1])
                  temp=1;
              }
              if(temp==0)
                f=1;
              temp=0;
              swap(v[i],v[j]);
              for(k=1;k<n;k++)
              {
                 if(v[k]<v[k-1])
                  temp=1;
              }
             if(temp==0)
              f=1;
            swap(v[i],v[j]);
          }
        }
        if(f==1)
          cout<<"YES";
        else
          cout<<"NO";
  }


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  string s;
  cin>>s;
  int ans;
  string t[7]={"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
  REP(i, 7){
    if(s==t[i]){
      ans=i+1;
      break;
    }
  }
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
B = [int(x) for x in input().split()]
A=Counter(B)
V, C = zip(*A.most_common())
count=0
i=0
dict={}
for x in C:
  count+=x*(x-1)/2
  dict[V[i]]=x
  i+=1
for x in B:
  ans=count-dict[x]+1
  print(int(ans))

Measured memory_bytes: 37024
#include<bits/stdc++.h>
using namespace std;
#define l1 long long
int main(){
    long long int n,k,c=1,t=0,p=0; cin>>n; string str="",ptr="",ztr="";
    for(int i=1;i<=n;i++){
        str+='0'+i;
    }
    for(int i=0;i<n;i++){ cin>>k;
        ptr+='0'+k;
    }
    for(int i=0;i<n;i++){ cin>>k;
        ztr+='0'+k;
    }
     do { //cout<<str<<"\n";
       if(str==ptr)t=c;
       if(str==ztr)p=c;
       c++;
       if(p!=0 && t!=0)break;
  } while ( next_permutation(str.begin(),str.end()));
   cout<<abs(p-t);
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

#define forn(i,n) for(int i = 0;i<int(n);i++)
#define ll long long

using namespace std;

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  int N;
  cin>>N;
  map<int,int> a;
  forn(i,N){
    a.insert(pair<int,int>(i+1,0));
  }
  forn(i,N-1){
    map<int,int>::iterator it;
    int tmp;
    cin>>tmp;
    it=a.find(tmp);
    it->second++;
  }
  map<int,int>::iterator it;
  for(it = a.begin();it!=a.end();it++){
    cout<<it->second<<endl;
  }
}


Measured memory_bytes: 12996
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h,w=map(int,input().split())
a=[input() for i in range(h)]

cnt=0

itta=[[10**9]*w for i in range(h)]

d=deque()
# aaa=d.append
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            d.append([i,j])
            itta[i][j]=0

# print(d)
# print(itta)

while d:
    cnt+=1
    for l in range(len(d)):
        nh,nw=d.popleft()
        for i in range(4):
            d1,d2=direction[i]
            if 0<=nh+d1<h and 0<=nw+d2<w:
                if itta[nh+d1][nw+d2]==10**9:
                    itta[nh+d1][nw+d2]=cnt
                    d.append([nh+d1,nw+d2])
    # print(d)

# print(itta)
print(cnt-1)

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

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define INF (1 << 30)
#define REP(i, m, n) for(int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)


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

    int n, k; cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    int ans = INF;
    rep(i, n-k+1) {
        ans = min(ans, abs(h[i]-h[i+k-1]));
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i < n; i++)
#define reps(i, n) for(ll i=1; i <= n; i++)
#define INF 1e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;
using P=pair<int,int>;
using Pl=pair<ll,ll>;

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


int main() {
  ll m,n;cin >> n >> m;
  vector<Pl> d;
  ll ans=0,c=0;
  rep(i,n){
    ll a,b;cin >> a >> b;
    d.pb(mp(a,b));
  }
  sort(ALL(d));

  rep(i,n){
    rep(j,d[i].second){
      if(c>=m)break;
      c++;
      ans += d[i].first;
    }
  }
  cout << ans;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define N 5010
#define mod 998244353
int c[N][N];
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
int Ans[N];
int main() {
    int k=read(),n=read();
    c[0][0]=1;
    for (int i=1;i<N;i++) {
        c[i][0]=1;
        for (int j=1;j<=i;j++) {
            c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
        }
    }
    // cout<<c[5][2]<<endl;
    for (int i=2;i<=k+1;i++) {
        int t=i/2,w=1,ans=0;
        for (int j=0;j<=t && (j<<1)<=n;j++) {
            (ans+=1LL*c[t][j]*c[n-2*j+k-1][k-1]*w%mod)%=mod,w*=-1;
        }
        printf("%d\n",Ans[i]=(ans+mod)%mod);
    }
    for (int i=k;i>=2;i--) printf("%d\n",Ans[i]);
    return 0;
}

Measured memory_bytes: 96768
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
// #include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main() //input->compute->output
{
        int N, K, X, Y;
        cin >> N >> K >> X >> Y;

        cout << X * min(N,K) + Y * max(N - K, 0) << endl;
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    string s; cin >> s;
    string a,b;
    ll n = s.size();
    rep(i,n){
        s.pop_back();
        a = s.substr(0,s.size()/2);
        b = s.substr(s.size()/2,(s.size()+1)/2);
        //cout << a << endl;
        //cout << b << endl;
        if(a==b){
            cout << a.size()*2 << endl;
            return 0;
        }
    }
}


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

// ABC051B - Sum of Three Integers
int main(){
  int k, s;
  cin >> k >> s;

  int num = 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) {
        ++num;
      }
    }
  }

  cout << num << endl;
  return 0;
}


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

int64_t parent[100010];

int64_t root(int a) {
	if (parent[a] < 0) return a;
	return parent[a] = root(parent[a]);
}

void unite(int a, int b) {
	if (root(a) == root(b)) return;
	parent[root(a)] += parent[root(b)]; parent[root(b)] = root(a);
	return;
}

int main() {
	int n, m; cin >> n >> m;
	vector<pair<int, int>> bridge(m);
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		bridge.at(i) = make_pair(a - 1, b - 1);
	}
	for (int i = 0; i < n; i++) parent[i] = -1;
	int64_t ans[100010];
	ans[m] = (int64_t) n * (n - 1) / 2;
	for (int i = m - 1; i > 0; i--) {
		int a = bridge.at(i).first, b = bridge.at(i).second;
		if (root(a) == root(b)) ans[i] = ans[i + 1];
		else {
			ans[i] = ans[i + 1] - parent[root(a)] * parent[root(b)];
			unite(a, b);
		}
	}
	for (int i = 1; i <= m; i++) {
		cout << ans[i] << endl;
	}
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef __int128 ll;
#define x first
#define y second
#define pii pair<int , int>
#define mp make_pair
#define pb push_back
#define sz(a) (int)(a.size())
const int INF = 1000 * 1000 * 1000 + 7;
const ll LINF = INF * (ll)INF;
const int mod = 998244353;
const int MAX = 2000005;
ll sq(ll x)
{return x * x;
}
int main()
{
	ios_base::sync_with_stdio(0);
	int A, B, C;
	cin >> A >> B >> C;
	ll a = A, b = B , c = C;
	if(4 * a * b >= sq(c - a - b) || c <= a + b)
	{
		cout << "No";
		return 0;
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  char M, P;
  string N, O;
  cin >> M;
  
  N = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  O = "abcdefghijklmnopqrstuvwxyz";
  
 for (int i = 0; i < 26; i++){
   char x = N.at(i);
    if(M == x){
      P = 'A';
    }
  }
  for (int j = 0; j < 26; j++){
    char y = O.at(j);
    if(M == y){
      P = 'a';
    }
  }
  
  cout << P << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;



int main()
{
   int64_t a,b,x;
   scanf("%lld",&x);
   for(a=-500;a<=500;a++)
    for(b=-500;b<=500;b++)
   {
      if(pow(a,5)-pow(b,5)-x==0){cout<<a<<" "<<b<<endl;return 0;}
   }

    return 0;
}

Measured memory_bytes: 4160
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


h, w, k = LI()
A = SRL(h)
flg = 0
for a in range(h):
    for b in range(w):
        if A[a][b] == 'S':
            sy, sx = a, b
            A[sy][sx] = 0
            flg = 1
            break
    if flg:
        break

q = deque([(sy, sx)])
L = []
min_dist = min(sy, h - sy - 1, sx, w - sx - 1)
while q:
    y, x = q.popleft()
    for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        nx, ny = x + i, y + j
        if 0 <= nx < w and 0 <= ny < h and A[ny][nx] == '.':
            A[ny][nx] = A[y][x] + 1
            min_dist = min(min_dist, min(ny, h - 1 - ny, nx, w - 1 - nx))
            if A[ny][nx] < k:
                q += [(ny, nx)]


print(1 - (- min_dist // k))

Measured memory_bytes: 113372
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,sum=0;
	cin>>n;
	
	int arr[n];
	for(int i=0; i<n; i++)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	
	int pre_sum =arr[0];
	int mn=sum - arr[0];
	
	for(int i=1; i<n-1; i++)
	{
		pre_sum+=arr[i];
		int num=abs(pre_sum-(sum-pre_sum));
		if(mn>num){
		mn=num;
	}
		
	}
	cout<<mn<<endl;
	return 0;
	
}


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

int main(){
  int x;cin >> x;
  if(x >= 400 && 599 >= x)cout << 8;
  if(x >= 600 && 799 >= x)cout << 7;
  if(x >= 800 && 999 >= x)cout << 6;
  if(x >= 1000 && 1199 >= x)cout << 5;
  if(x >= 1200 && 1399 >= x)cout << 4;
  if(x >= 1400 && 1599 >= x)cout << 3;
  if(x >= 1600 && 1799 >= x)cout << 2;
  if(x >= 1800 && 1999 >= x)cout << 1;
  return 0;
}

Measured memory_bytes: 3620
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

Pa arr[100000];
int main() {
	cin >> N >> M;
	rep(i, M){
		cin >> A >> B;
		arr[i] = Pa(B, A);
	}
	sort(arr, arr+M);
	int curr = -1, cnt = 0;
	rep(i, M){
		if(curr <= arr[i].second){
			curr = arr[i].first;
			cnt++;
		}
	}
	cout << cnt;
}


Measured memory_bytes: 1792
_ = gets.chomp

monsters = gets.chomp.split(" ").map(&:to_i)


while monsters.size > 1 do
  min_m = monsters.min
  min_m_index = monsters.index(min_m)

  monsters.each_with_index do |monstor, index|
    if index != min_m_index
      monsters[index] = monstor % min_m
    end
  end

  monsters.delete(0)
end

p monsters.first

Measured memory_bytes: 9476
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << x << endl;
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
typedef long long ll;
//ll power_mod(ll a, ll k){ll ans = 1;a %= MOD;while(k){if(k % 2) ans *= a;a = (a * a) % MOD;k /= 2;ans %= MOD;}return ans;}
//ll power(ll a, ll k){ll ans = 1;while(k){if(k % 2)ans *= a;a = a * a;k /= 2;}return ans;}
//ll CalcAppNum(ll n){ll ans = 0;for(ll i=1,j; i<=n; i=j+1) {j = min(n, n / (n/i));ans += (j - i + 1) *(n/i);}return ans;}    //计算1-n约束个数和
template<class T>inline void read(T &res) {char c;T flag=1;while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;}
template<class T>inline void prin(T x) {if(x>9)prin(x/10);putchar(x%10+'0');}
const int MOD = 2333;
const int MAX = 1e7;
const int MAXN = 1e7+10;
const int inf = 2e5 + 100;
long double PI =3.14159265358979323846;
//INT_MAX

int main()
{
    ll a, b;
    while(cin >> a >> b) {
        cout << a / __gcd(a, b) * b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce
K = int(input())


# gcd
def gcd_base(x, y):
    return math.gcd(x, y)


# 3つ以上
def gcd_list(numbers):
    return reduce(gcd_base, numbers)


ans = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd_list([a, b, c])
print(ans)


Measured memory_bytes: 69688
a,b,c = map(int,input().split())
if a < b:
    if b < c:
        print(str(a)+' '+str(b)+' '+str(c))
    elif a < c:
        print(str(a) + ' ' + str(c) + ' ' + str(b))
    else:
        print(str(c) + ' ' + str(a) + ' ' + str(b))
elif a < c:
    print(str(b) + ' ' + str(a) + ' ' + str(c))
elif c < b:
    print(str(c) + ' ' + str(b) + ' ' + str(a))
else:
    print(str(b) + ' ' + str(c) + ' ' + str(a))
        


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int h, w;
	int a[501][501] = {};
	vector<pair<pair<int, int>, pair<int, int>>> ans;
	cin >> h >> w;
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < h; ++i)
	{
		if (i % 2)
		{
			for (int j = w-1; j > 0; --j)
			{
				if(a[i][j] % 2)
				{
					a[i][j] -= 1;
					a[i][j-1] += 1;
					ans.push_back(make_pair(make_pair(i, j), make_pair(i, j-1)));
				}
			}
			if(a[i][0] % 2 && i != h - 1)
			{
				a[i][0] -= 1;
				a[i+1][0] += 1;
				ans.push_back(make_pair(make_pair(i, 0), make_pair(i+1, 0)));
			}
		}
		else
		{
			for (int j = 0; j < w - 1; ++j)
			{
				if(a[i][j] % 2)
				{
					a[i][j] -= 1;
					a[i][j+1] += 1;
					ans.push_back(make_pair(make_pair(i, j), make_pair(i, j+1)));
				}
			}
			if(a[i][w-1] % 2 && i != h - 1)
			{
				a[i][w-1] -= 1;
				a[i+1][w-1] += 1;
				ans.push_back(make_pair(make_pair(i, w-1), make_pair(i+1, w-1)));
			}
		}
	}
	cout << ans.size() << endl;
	for (auto it = ans.begin(); it != ans.end(); ++it)
	{
		cout << (*it).first.first+1 << " " << (*it).first.second+1 << " " << (*it).second.first+1 << " " << (*it).second.second+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 5104
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var values = Console.ReadLine();
            var a1 = values.Substring(0, 1);
            var a2 = values.Substring(1, 1);
            var a3 = values.Substring(2, 1);
            values = Console.ReadLine();
            var b1 = values.Substring(0, 1);
            var b2 = values.Substring(1, 1);
            var b3 = values.Substring(2, 1);

            if (a1 == b3 && a2 == b2 && a3 == b1)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

        }
    }
}

Measured memory_bytes: 13140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    rep1(i,9)rep1(j,9){
        if(i*j == N){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}



Measured memory_bytes: 3656
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void solve(){
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  ll a = q * 4ll;
  ll b = h * 2ll;
  ll c = min(a, min(b, s));
  cout << min(c * n, (n%2ll * c + (n - n%2ll)/2ll*d));
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 


*/

Measured memory_bytes: 3544
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n,m;
	cin>>n>>m;
	vll _x(n);
	vll _y(m);
	rep(i,n) cin>>_x[i];
	rep(i,m) cin>>_y[i];
	vll x(n-1);
	vll y(m-1);
	rep(i,n-1){
		x[i] = _x[i+1] - _x[i];
	}
	rep(i,m-1){
		y[i] = _y[i+1] - _y[i];
	}
	ll sum = 0;
	ll tmp = 0;
	rep(i,n-1){
		tmp += x[i] * i + x[i];
		sum += tmp;
		tmp %= MOD;
		sum %= MOD;
		// cout<<sum<<" "<<tmp<<endl;
	}
	ll sum2 = 0;
	tmp = 0;
	rep(i,m-1){
		tmp += y[i] * i + y[i];
		sum2 += tmp;
		tmp %= MOD;
		sum2 %= MOD;
		// cout<<"hn "<<sum2<<" "<<tmp<<endl;
	}
	cout<<sum%MOD*sum2%MOD<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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

int main() {
	int a,b; cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	} else {
		cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<pair<int,int> > a;
	for(int i=0;i<n;i++){
		int x,l;
		cin>>x>>l;
		a.pb(mp(x,l));
	}
	sort( a.begin(), a.end() );
	int rtm = -inf;
	int ans = 0;
	for(int i=0;i<n;i++){
		int lef = a[i].first - a[i].second;
		int rig = a[i].first + a[i].second;
		if( rtm <= lef ){
			ans++;
			rtm = rig;
		}
		else if( rtm > rig ){
			rtm = rig;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2420
function main(input) {
  var arr = input.replace(/\r?\n/g, "").split(" ");
  const A = arr[0], B = arr[1], C = arr[2];
  var flg = false;
  if (A == B && B != C) flg = true;
  if (B == C && C != A) flg = true;
  if (C == A && A != B) flg = true;
  if (flg) console.log("Yes");
  else console.log("No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21828
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();

int main(){
    LL N;
    LL i;
    LL a;
    LL num;
    cin >> N;
    num = 0;
    for(i=0;i<N;i++){
        cin >> a;
        if( a == num + 1){
            num++;
        }
    }
    if( num == 0){
        cout << -1 << endl;
    }else{
        cout << N - num << endl;
    }
    return 0;
}

void process(){
    
}

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

typedef struct {	/* 構造体の宣言 */
	long a;
	long b;
} drink;

int quick( const void *p, const void *q ) {
    return ((drink*)p)->a - ((drink*)q)->a;
}

int main(void) {
  long n, m;
  long ans = 0, kari = 0, k = 0;
	drink lst[100002];

  if(scanf("%ld %ld", &n, &m) == 1);

  for(int i = 0; i < n; i++) {
    if(scanf("%ld %ld", &lst[i].a, &lst[i].b) == 1);
  }

	long kazu = sizeof lst / sizeof( drink );

	qsort(lst, n, sizeof(drink), quick);

  kari = 0;
  while(kari <= m) {
    ans = ans + lst[k].a * lst[k].b;
    kari = kari + lst[k].b;
    k++;
  }

  k--;
  if(kari != m) {
		ans = ans - (lst[k].a * (kari - m));
  }



  printf("%ld", ans);

  return 0;
}


Measured memory_bytes: 3324
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	private void run_case() {
		int n = reader.ni();
		int[] cnt = new int[n+5];
		for (int i=0; i<n-1; i++) {
			int boss = reader.ni();
			cnt[boss] ++;
		}

		for (int i=1; i<=n; i++) {
			out.println(cnt[i]);
		}
		return;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


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

int main(){
    string a, b, c;
    cin >> a >> b >> c;
    if(a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.length() > k) {
        rep(i, k){
            cout << s.at(i);
        }
        cout << "..." << endl;
    }
    else {
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    int k = -1;
    for (int i = 0; i <= n; ++i) {
        if (i * (i + 1) == 2 * n) {
            k = i;
            break;
        }
    }
    if (k == -1) {
        cout << "No"
             << "\n";
        return 0;
    }
    vvi s(k + 1, vi(k, 0));
    int col = 0;
    int row = 0;
    for (int i = 1; i <= n; ++i) {
        s[row][col] = i;
        col++;
        if (col == k) {
            row++;
            col = row;
        }
    }
    col = 0;
    row = 1;
    for (int i = 1; i <= n; ++i) {
        s[row][col] = i;
        row++;
        if (row == k + 1) {
            col++;
            row = col + 1;
        }
    }
    cout << "Yes"
         << "\n";
    cout << k + 1 << "\n";
    for (int i = 0; i < k + 1; ++i) {
        cout << k << " ";
        print(s[i]);
    }
    return 0;
}

Measured memory_bytes: 2176
from collections import defaultdict

roots = defaultdict(list)
for k in range(2, 10 ** 6 + 1):
    ki = k * k
    while ki <= 10 ** 12:
        roots[ki].append(k)
        ki *= k


def factors(n):
    fhead = []
    ftail = []
    for x in range(1, int(n ** 0.5) + 1):
        if n % x == 0:
            fhead.append(x)
            if x * x != n:
                ftail.append(n // x)
    return fhead + ftail[::-1]


def solve(N):
    works = set()
    # Answer seems to be anything of the form: N = (K ** i) * (j * K + 1)

    # Try every divisor of N as K ** i
    for d in factors(N):
        # If i == 1, then K == d
        k = d
        if (N // d) % k == 1:
            assert k <= N
            works.add(k)
        if d == 1:
            # If i == 0, then K ** 0 == 1, so K = (N - 1) // j, so anything that is a factor of N - 1 works
            works.update(factors(N - 1))
        elif d in roots:
            # For i >= 2, see if it's in the list of precomputed roots
            for k in roots[d]:
                if k > N:
                    break
                if (N // d) % k == 1:
                    works.add(k)
    works.discard(1)
    return len(works)


(N,) = [int(x) for x in input().split()]
print(solve(N))


if False:

    def brute(N, K):
        while N >= K:
            if N % K == 0:
                N = N // K
            else:
                N = N - K
        return N

    for N in range(2, 10000):
        count = 0
        for K in range(2, N + 1):
            temp = brute(N, K)
            if temp == 1:
                print(N, K, temp)
                count += 1
        print("##########", N, count, solve(N))
        assert count == solve(N)



Measured memory_bytes: 229284
def fib(n):
    a, b = 0, 1
    for i in range(n):
        a, b = b, a + b
    return b
n, m = (int(i) for i in input().split())
stops = [int(input())-1 for i in range(m)]
stops.append(n) # ここに止まらないといけない
current = 0
count = 1
for s, stop in enumerate(stops):
    steps = stop - current
    if steps < 0:
        count = 0
        break
    else:
        count *= fib(steps)


    current = stop + 2
print(count % 1000000007)

Measured memory_bytes: 7056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122


int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    for (int i = 100; i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            cnt++;
            if (cnt == k) {
                cout << i << endl;
                return 0;
            }
        }
    }
}


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

using namespace std;

#define debug(x) cout << #x << "::" << x << endl;
#define debug2(x, y) cout << #x << "::" << x << " " << #y << "::" << y << endl;
#define debug3(x, y, z) cout << #x << "::" << x << " " << #y << "::" << y <<" "<< #z << "::" << z << endl;

#define For(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
const ll mod = 1e9 + 7;
const int MAX = 5 * 1e3 + 5;
typedef pair<int, int> pii;

void add(ll &a, ll b)
{
    a = (a + b) % mod;
    if (a < 0) a += mod;
}

int main() {

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

    vector<int> a(n);
    For(i,0,n) cin>>a[i];

    For(i,1,k+1){
        For(j,0,n){
            if(a[j] <= i && !dp[i-a[j]]){
                dp[i] = true;
                break;
            }
        }
    }

    if(dp[k]) cout<<"First";
    else cout<<"Second";
    cout<<endl;

    return 0;

}

Measured memory_bytes: 640