akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<bitset>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  string a, b;
  cin>>a>>b;
  if(a.length() > b.length())
  {
    puts("GREATER");
    return 0;
  }
  else if(a.length() < b.length())
  {
    puts("LESS");
    return 0;
  }
  rep(i, 0, a.length())
  {
    if(a[i] > b[i])
    {
      puts("GREATER");
      return 0;
    }
    else if(a[i] < b[i])
    {
      puts("LESS");
      return 0;
    }

  }
  puts("EQUAL");
  return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)
#define INF 10000000
#define MOD (long)1e9+7

using namespace std;

void solve(void){
    int n, m;
    cin >> n >> m;
    long long ans = 1;
    if (abs(n-m) > 1) ans = 0;
    else if(n == m){
        Rep(1, n, i) {
            ans *= i;
            ans %= MOD;
        }
        ans *= ans * 2;
        ans %= MOD;
    }
    else {
        Rep(1, min(m, n), i) {
            ans *= i;
            ans %= MOD;
        }
        ans *= ans;
        ans %= MOD;
        ans *= max(m, n);
        ans %= MOD;
    }
    printf("%lld\n", ans);
}

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


Measured memory_bytes: 256
N=gets.to_i
A=gets.split.map(&:to_i)

absmax=0
absmax_index=0
A.each_with_index do |a,i|
    if a.abs>absmax
        absmax=a.abs
        absmax_index=i
    end
end

puts "#{2*N-2}"
N.times do |i|
    puts "#{absmax_index+1} #{i+1}" if absmax_index!=i
end

if A[absmax_index]<0
    range=(N-1).downto(0).to_a
else
    range=(0).upto(N-1).to_a
end

range.each_cons(2) do |from,to|
    puts "#{from+1} #{to+1}"
end

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

const int NIL = -1;

struct Node{
    int left, right, parent;
};

class PrintTree{
public:
    void preorder(Node* tree, int id)
    {
        if(id == NIL) return;
        cout << " " << id;
        preorder(tree, tree[id].left);
        preorder(tree, tree[id].right);
    }

    void inorder(Node* tree, int id)
    {
        if(id == NIL) return;
        inorder(tree, tree[id].left);
        cout << " " << id;
        inorder(tree, tree[id].right);
    }

    void postorder(Node* tree, int id)
    {
        if(id == NIL) return;
        postorder(tree, tree[id].left);
        postorder(tree, tree[id].right);
        cout << " " << id;
    }
};


int main()
{
    Node tree[25];
    PrintTree print;
    int n, id, l, r;
    cin >> n;
    for(int i=0;i<n;++i) tree[i].parent = NIL;
    for(int i=0;i<n;++i)
    {
        cin >> id;
        cin >> l >> r;
        tree[l].parent = tree[r].parent = id;
        tree[id].left = l;
        tree[id].right = r;
    }

    int root;
    for(int i=0;i<n;++i)
    {
        if(tree[i].parent == NIL)
        {
            root = i;
            break;
        }
    }

    cout << "Preorder" << endl;
    print.preorder(tree, root);
    cout << endl;
    cout << "Inorder" << endl;
    print.inorder(tree, root);
    cout << endl;
    cout << "Postorder" << endl;
    print.postorder(tree, root);
    cout << endl;

}



Measured memory_bytes: 3124
X[]={0,1,0,-1},Y[]={-1,0,1,0},f[109][109],g[109][109][4];char s[109],*D="NESW";
main(h,w,z,x,y,c,i,j,k){long long l;for(;scanf("%d%d%lld",&h,&w,&l),h;printf("%d %d %c\n",y,x,D[z])){
	memset(f,1,sizeof(f)),memset(g,0,sizeof(g));
	for(i=0;i<h;i++)for(scanf("%s",s),j=0;j<w;j++){
		for(k=0;k<4;k++)if(s[j]==D[k])x=j+1,y=i+1,z=k;
		if(s[j]!='#')f[i+1][j+1]=0;
	}
	for(c=0;l;l--,c++){
		if(g[y][x][z]&&(l%=c-g[y][x][z])==0)break;
		for(g[y][x][z]=c;f[y+Y[z]][x+X[z]];z=(z+1)%4);
		x+=X[z],y+=Y[z];
	}
}exit(0);}

Measured memory_bytes: 844
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
  
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, x;
    cin >> n >> x;
    int l[n + 5], ans = 1, sum = 0;
    reps(i,n){
      cin >> l[i];
      sum += l[i];
      if( sum <= x ){
	ans ++;
      }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
object Main{
  def reg(a:Int,b:Int):Unit = {
    print(a*b)
    print(" ")
    println(2*(a+b))
  }
  def main(args:Array[String])={
    var sc = new java.util.Scanner(System.in)
    val a = sc.nextInt
    val b = sc.nextInt
    reg(a,b)
  }
}

Measured memory_bytes: 44892
W, H, N = map(int, input().split())

t = [[1] * W for _ in range(H)]
for _ in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for h in range(H):
            for w in range(x):
              t[h][w] = 0
    elif a == 2:
        for h in range(H):
            for w in range(x, W):
              t[h][w] = 0
    elif a == 3:
        for h in range(y):
            for w in range(W):
              t[h][w] = 0
    elif a == 4:
        for h in range(y, H):
            for w in range(W):
              t[h][w] = 0
print(sum(sum(l) for l in t))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MN = 2e5 + 5;
int N, Q, inc[MN], cnt[MN];
vector<int> adj[MN];

void dfs(int u, int p, int d) {
    cnt[u] += d;
    for (int v : adj[u])
        if (v ^ p) dfs(v, u, d + inc[v]);
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> N >> Q;
    for (int i = 1, u, v; i < N; i++) cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u);
    for (int i = 0, p, x; i < Q; i++) cin >> p >> x, inc[p] += x;
    dfs(1, 0, inc[1]);
    for (int i = 1; i <= N; i++) cout << cnt[i] << " ";
    return 0;
}

Measured memory_bytes: 24192
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int a, b;
	cin >> a >> b;
	for(int i=1; i<=8e4; ++i) {
		int a2=i*8/100, b2=i*10/100;
		if(a2==a&&b2==b) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
}

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

using ll = long long;
#define mod 1000000007
#define init ios::sync_with_stdio(0), cin.tie(0);
typedef vector<int> vi;
typedef pair<int, int> pi;
#define MS(x, y) memset(x, y, sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair

int main()
{
    init;
    int n;
    cin >> n;
    vi ar(n + 1);
    unsigned long long cnt = 0;
    for (int i = 1; i <= n; i++)
        for (int j = i; j <= n; j += i)
        {
            cnt += j;
        }
    cout << cnt;
}

Measured memory_bytes: 42236
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
    std.range, std.container, std.bigint, std.ascii, std.typecons;

// }}}
// nep.scanner {{{
class Scanner
{
    import std.stdio : File, stdin;
    import std.conv : to;
    import std.array : split;
    import std.string : chomp;

    private File file;
    private char[][] str;
    private size_t idx;

    this(File file = stdin)
    {
        this.file = file;
        this.idx = 0;
    }

    private char[] next()
    {
        if (idx < str.length)
        {
            return str[idx++];
        }

        char[] s;
        while (s.length == 0)
        {
            s = file.readln.chomp.to!(char[]);
        }

        str = s.split;
        idx = 0;

        return str[idx++];
    }

    T next(T)()
    {
        return next.to!(T);
    }

    T[] nextArray(T)(size_t len)
    {
        T[] ret = new T[len];

        foreach (ref c; ret)
        {
            c = next!(T);
        }

        return ret;
    }

    void scan()()
    {
    }

    void scan(T, S...)(ref T x, ref S args)
    {
        x = next!(T);
        scan(args);
    }
}
// }}}

void main()
{
    auto cin = new Scanner;
    char[] s;
    cin.scan(s);

    foreach (i; 0 .. 1 << s.length - 1)
    {
        int sum = s.front - '0';
        char[] op;
        foreach (j; 0 .. s.length - 1)
        {
            if ((i >> j) & 1)
            {
                op ~= '+';
                sum += s[j + 1] - '0';
            }
            else
            {
                op ~= '-';
                sum -= s[j + 1] - '0';
            }
        }
        if (sum == 7)
        {
            s ~= '7';
            op ~= '=';
            foreach (j; 0 .. 9)
            {
                if (j & 1)
                {
                    write(op[j / 2]);
                }
                else
                {
                    write(s[j / 2]);
                }
            }
            writeln;
            break;
        }
    }
}


Measured memory_bytes: 256
import sys
from itertools import product
def I(): return int(sys.stdin.readline().rstrip())


def ext_gcd(a, b):
    if b:
        d, y, x = ext_gcd(b, a % b)
        y -= (a // b) * x
        return d, x, y
    return a, 1, 0


# V = [(X_i, Y_i), ...]: X_i (mod Y_i)
def remainder(V):
    x = 0; d = 1
    for X, Y in V:
        g, a, b = ext_gcd(d, Y)
        x, d = (Y*b*x + d*a*X) // g, d*(Y // g)
        x %= d
    return x, d


def prime_factorization(n):
    res = {}
    for i in range(2,int(n**.5)+1):
        if n % i == 0:
            r = 0  # nがiで何回割り切れるか
            while n % i == 0:
                n //= i
                r += 1
            res[i] = r
    if n != 1:
        res[n] = 1
    return res


N = I()

prime_fac = prime_factorization(N)
if 2 in list(prime_fac.keys()):
    prime_fac[2] += 1
else:
    prime_fac[2] = 1

# prime_fac = 2*N の素因数分解
# 2*N|k*(k+1)
# 中国剰余定理を用いる

A = list(prime_fac.keys())
l = len(A)

ans = 2*N

for a in list(product([-1,0],repeat=l)):
    V = [(a[i],A[i]**prime_fac[A[i]]) for i in range(l)]
    x,d = remainder(V)
    if x != 0:
        ans = min(ans,x)

print(ans)


Measured memory_bytes: 71420
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)

using namespace std;

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

    int N, M;
    cin >> N >> M;

    map<int, int> m;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        if (a != 1) m[a]++;
        if (b != 1) m[b]++;
    }

    bool ok = true;
    FOR(i, 2, N) {
        if (m[i] % 2 != 0)
        {
            ok = false;
        }
    }
    string ans = ok ? "YES" : "NO";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int ans = 1;
    for (int i = 0; i < N; i++) {
      if (ans * 2 > ans + K) {
        ans += K;
      } else {
        ans *= 2;
      }
    }
    System.out.println(ans);
  }
}


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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define fastio ios::sync_with_stdio(false); cin.tie(0)

int main(){
    fastio;
    int r, g, b, n, ans = 0, sisa, total, total2;
    cin >> r >> g >> b >> n;

    for(int i = 0 ; i <= n/r ; i++){
        total = i*r;
        sisa = n - total;
        for(int j = 0 ; j <= sisa/g ; j++){
            total2 = j*g + total;
            if((n - total2) % b == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=405,mod=1e9+7;
int f[N][N][N/3],g[N][N][N/3],x[N][N],y[N][N];
int a[N],b[N],p[N],q[N];
int n,res;

void add(int &x,int y){
	x=(x+y>=mod?x+y-mod:x+y);
}
int mul(int x,int y){
	return (ll)x*y%mod;
}

int main(){
	read(n);
	rep(i,1,n) read(a[i]),p[a[i]]=i;
	rep(i,1,n) read(b[i]),q[b[i]]=i;
	per(i,n,0) per(j,n,0){
		x[i][j]=(i==n||q[a[i+1]]>j?i:x[i+1][j]);
		y[i][j]=(j==n||p[b[j+1]]>i?j:y[i][j+1]);
	}
	f[0][0][0]=1;
	rep(i,0,n-1) rep(j,0,n-1) rep(k,0,n/3){
		if(f[i][j][k]){
			//printf("## %d %d  %d     %d\n",i,j,k,f[i][j][k]);
			if(a[i+1]!=b[j+1]){
				int I=x[i+1][j+1],J=y[i+1][j+1];
				add(f[I][J][k+1],f[i][j][k]);
			}
			if(k){
				int I=x[i+1][j],J=y[i+1][j];
				add(f[I][J][k-1],mul(k,f[i][j][k]));
			}
			if(k&&a[i+1]!=b[j+1]){
				int I=x[i][j+1],J=y[i][j+1];
				add(g[I][J][k-1],mul(k,f[i][j][k]));
			}
		}
		if(g[i][j][k]){
			if(a[i+1]!=b[j+1]){
				int I=x[i+1][j+1],J=y[i+1][j+1];
				add(f[I][J][k+1],g[i][j][k]);
			}
			if(k&&a[i+1]!=b[j+1]){
				int I=x[i][j+1],J=y[i][j+1];
				add(g[I][J][k-1],mul(k,g[i][j][k]));
			}
		}
	}
	res=f[n][n][0];
	for(int i=3;i<=n;i+=3)
		res=(ll)res*(i-1)*(i-2)%mod;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 173568
#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 h,w;
    cin >> h >> w;
    vector<string> c(h);
    rep(i,0,h) cin >> c[i];

    int ans=0;
    rep(x,0,w-1){
        vector<vector<int>> dp(h+1,vector<int>(h+1,inf)),memo(h+1,vector<int>(h+1,-1));
        function<int(int,int)> cost=[&](int y1,int y2){
            if(memo[y1][y2]!=-1) return memo[y1][y2];
            if(y1+1<=h  and y2+1<=h) return memo[y1][y2]=cost(y1+1,y2+1)-(c[y1][x]==c[y2][x+1]);
            int res=0;
            rep(y,1,h+1){
                if(y1-y<0 or y2-y<0) break;
                if(c[y1-y][x]==c[y2-y][x+1]) ++res;
            }
            return memo[y1][y2]=res;
        };
        dp[h][h]=0;
        for(int y1=h; y1>=0; --y1){
            for(int y2=h; y2>=0; --y2){
                if(y1+1<=h) dp[y1][y2]=dp[y1+1][y2]+cost(y1+1,y2);
                if(y2+1<=h) dp[y1][y2]=min(dp[y1][y2],dp[y1][y2+1]+cost(y1,y2+1));
            }
        }
        ans+=dp[0][0];
    }
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cassert>
#include<vector>
#define ll long long
#define MOD 1000000007
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,m;
ll dp[310][310][310];
int x[310],l[310],r[310];
vector<int>q[310];
bool check(int i,int r,int g,int b){
	int tmp;
//	cout<<"	check "<<i<<' '<<r<<' '<<g<<' '<<b<<'\n';
	for(int j=0;j<q[i].size();j++){
		tmp=(l[q[i][j]]<=r)+(l[q[i][j]]<=g)+(l[q[i][j]]<=b);
		if(tmp!=x[q[i][j]]) return 0;
	}
//	cout<<"	pass!\n";
	return 1;
}
int main(){
	n=read();m=read();int i,j,k,lim;
	for(i=1;i<=m;i++){
		l[i]=read();r[i]=read();x[i]=read();
		q[r[i]].push_back(i);
	}
	dp[0][0][0]=1;
	ll ans=0;
//	垃圾填表法，刷表法万岁(ノ￣▽￣)
//	for(lim=1;lim<=n;lim++){
//		cout<<"begin "<<lim<<'\n';
//		//red max
//		i=lim;
//		for(j=0;j<lim;j++){
//			for(k=0;k<lim;k++){
//				if((j&&j==k)||(!check(lim,i,j,k))) continue;
//				dp[i][j][k]=dp[i-1][j][k];
//				if(j) dp[i][j][k]+=dp[i][j-1][k];
//				if(k) dp[i][j][k]+=dp[i][j][k-1];
//				dp[i][j][k]%=MOD;
//				cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k]<<'\n';
//			}
//		}
//		//green max
//		j=lim;
//		for(i=0;i<lim;i++){
//			for(k=0;k<lim;k++){
//				if((i&&i==k)||(!check(lim,i,j,k))) continue;
//				dp[i][j][k]=dp[i][j-1][k];
//				if(i) dp[i][j][k]+=dp[i-1][j][k];
//				if(k) dp[i][j][k]+=dp[i][j][k-1];
//				dp[i][j][k]%=MOD;
//				cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k]<<'\n';
//			}
//		}
//		//blue max
//		k=lim;
//		for(i=0;i<lim;i++){
//			for(j=0;j<lim;j++){
//				if((j&&j==i)||(!check(lim,i,j,k))) continue;
//				dp[i][j][k]=dp[i][j][k-1];
//				if(i) dp[i][j][k]+=dp[i-1][j][k];
//				if(j) dp[i][j][k]+=dp[i][j-1][k];
//				dp[i][j][k]%=MOD;
//				cout<<i<<' '<<j<<' '<<k<<' '<<dp[i][j][k]<<'\n';
//			}
//		}
//	}
//	for(i=0;i<n;i++){
//		for(j=0;j<n;j++){
//			ans=(ans+dp[n][i][j]+dp[i][n][j]+dp[i][j][n])%MOD;
//		}
//	}
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			for(k=0;k<=n;k++){
				lim=max(i,max(j,k));
				if(!dp[i][j][k]||!check(lim,i,j,k)){
					dp[i][j][k]=0;continue;
				}
				if(lim==n){
					ans=(ans+dp[i][j][k])%MOD;continue;
				}
				dp[lim+1][j][k]=(dp[lim+1][j][k]+dp[i][j][k])%MOD;
				dp[i][lim+1][k]=(dp[i][lim+1][k]+dp[i][j][k])%MOD;
				dp[i][j][lim+1]=(dp[i][j][lim+1]+dp[i][j][k])%MOD;
			}
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 227584
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <climits>
int main()
{
    long N,K;
    std::cin >> N >> K;
    long x[100000+1];
    for(long i=1; i<=N; i++){
        std::cin >> x[i];
    } 

    std::vector<long> time;
    for(long i=1; i<=N-K+1;i++){
        long left=i;
        long right=i+K-1;
        time.push_back(std::min(abs(x[left]),abs(x[right]))+x[right]-x[left]);
    }
    std::sort(time.begin(),time.end());
    std::cout << time[0] << std::endl;
    return 0;
}

Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for (int i=0; i<(n); ++i)
#define rrep(i,n) for (int i=1; i<=(n); ++i)
#define drep(i,n) for (int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i=s; i<t; ++i)
//#define pu push_back
//#define po pop_back
#define pi (acos(-1))
#define fast ios::sync_with_stdio(false); cin.tie(0)
//#define pii pair<int,int>
//#define pll pair<ll,ll>
//#define vec vector
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int, int> P;
const int INF = 1001001001;

// Gcd & Lcm
ll gcd (ll a, ll b) {
  return b ? gcd(b, a%b) : a;
}
ll lcm (ll a, ll b) {
  return a/gcd(a,b)*b;
}

int main(void) {
  int x1,x2,x3,x4,x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  if (x1==0) cout << 1 << endl;
  if (x2==0) cout << 2 << endl;
  if (x3==0) cout << 3 << endl;
  if (x4==0) cout << 4 << endl;
  if (x5==0) cout << 5 << endl;
}



Measured memory_bytes: 3584
n, k = map(int, input().split())

MOD = 10**9 + 7

data = []
for i in range(n+1):
  data.append(i)

ans = 0

# あらかじめ累積和を求めておく
sum_data = [0] * (n + 1)
for i in range(1, n + 1): # 1..4
  sum_data[i] = sum_data[i - 1] + i

# sum_data: [0 1 3 6]

# 処理系
for i in range(k, (n+1) + 1): # 1..3
  # min
  min_ = sum_data[i-1]

  # max
  if n+1 - i - 1 == -1:
    max_ = sum_data[-1]
    # print("max :", max_)
  else:
    max_ = sum_data[-1] - sum_data[n+1 - i - 1]
    # print("max :", max_)

  diff = (max_ - min_ + 1)
  ans += diff

print(ans % MOD)


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

int main(){
  int N,M;
  cin>>N>>M;
  ll a=1,i=0,b;
  vector<pair<ll,int>> C(N+M);
  for(;i<N;i++){
    cin>>b;
    C[i]={b,a};
  }
  for(;i<N+M;i++){
    cin>>a>>b;
    C[i]={b,a};
  }
  ll ans=0;
  sort(C.begin(),C.end());
  i=M+N-1;
  for(;;i--){
    if(C[i].second<=N){
      ans+=C[i].first*C[i].second;
      N-=C[i].second;
    }else{
      ans+=N*C[i].first;
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
import sys
import math
from collections import deque
import copy

H, W = map(int, input().split())
maps2 = deque([deque(["#" for _ in range(W + 2)])])
MAX = 0

for _ in range(H):
    temp = deque(input())
    temp.appendleft("#")
    temp.append("#")
    maps2.append(temp)
maps2.append(deque(["#" for _ in range(W + 2)]))

for i in range(1, H + 1):
    for l in range(1, W + 1):
        if maps2[i][l] != "#":
            maps = copy.deepcopy(maps2)
            pos = [[i, l, 0]]
            maps[i][l] = "a"
            while len(pos) > 0:

                y, x, depth = pos.pop(0)
                if depth > MAX:
                    MAX = depth

                if maps[y + 1][x] == ".":
                    pos.append([y + 1, x, depth + 1])
                    maps[y + 1][x] = "a"
                if maps[y][x + 1] == ".":
                    pos.append([y, x + 1, depth + 1])
                    maps[y][x + 1] = "a"
                if maps[y - 1][x] == ".":
                    pos.append([y - 1, x, depth + 1])
                    maps[y - 1][x] = "a"
                if maps[y][x - 1] == ".":
                    pos.append([y, x - 1, depth + 1])
                    maps[y][x - 1] = "a"
print(MAX)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll l, r, d; cin >> l >> r >> d;
    ll res=0;
    FOR(i, l, r+1){
        if(i%d==0) res += 1;
    }
    cout << res << endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
signed main(){
  int n,l,t;
  cin>>n>>l>>t;
  int x[n],w[n];
  for(int i=0;i<n;i++) cin>>x[i]>>w[i];
  {
    bool f=1;
    for(int i=0;i<n-1;i++) f&=w[i]==w[i+1];
    if(f){
      int y[n];
      for(int i=0;i<n;i++){
	if(w[i]==1) y[i]=(x[i]+t)%l;
	else y[i]=(x[i]-t+(t/l+1)*l)%l;
	cout<<y[i]<<endl;
      }
      return 0;
    }
  }

  
  int y[n];
  for(int i=0;i<n;i++){
    if(w[i]==1) y[i]=(x[i]+t)%l;
    else y[i]=(x[i]-t+(t/l+1)*l)%l;
  }
  int pos=y[0];
  sort(y,y+n);
  
  int p=0;
  for(int i=1;i<n;i++){
    if(w[0]==w[i]) continue;
    if(w[0]==1){
      int q=0;
      if(2*t>=(x[i]-x[0])) q=(2*t-(x[i]-x[0]))/l+1;
      (p+=q)%=n;
    }else{
      int q=0;
      if(2*t>=(x[0]+l-x[i]%l)) q=(2*t-(x[0]+l-x[i]%l))/l+1;
      (p+=n-q)%=n;
    }
  }
  map<int,vector<int> > m;
  for(int i=0;i<n;i++)
    if(w[0]==1) m[y[i]].insert(m[y[i]].begin(),i);
    else m[y[i]].push_back(i);
  
  //cout<<m[pos][0]<<" "<<p<<endl;
  for(int i=0;i<n;i++) cout<<y[(m[pos][0]+i+n-p)%n]<<endl;
  return 0;
}


Measured memory_bytes: 14464
n,l=map(int,input().split())
a=list(map(int,input().split()))
m=-1
for i in range(n-1):
	if a[i]+a[i+1]>=l:
		m=i
if m==-1:
	print('Impossible')
else:
	print('Possible')
	for i in range(m):
		print(i+1)
	for i in range(n-2,m,-1):
		print(i+1)
	print(m+1)

Measured memory_bytes: 14060
N = int(input())
p = [list(map(int, input().split())) for _ in range(N)]
table = [[0] * N for _ in range(N)]
for i in range(N-1):
  for j in range(i+1, N):
    table[i][j] = table[j][i] = ((p[i][0] - p[j][0]) ** 2 + (p[i][1] - p[j][1]) ** 2) ** 0.5

dist = 0
cnt = 0
import itertools
for permutation in itertools.permutations(list(range(N))):
  i = 0
  while i < N - 1:
    dist += table[permutation[i]][permutation[i+1]]
    i += 1
  cnt += 1
print(dist / cnt)

Measured memory_bytes: 40428
#ABC074C
A, B, C, D, E, F=map(int, input().split())
A=100*A
B=100*B
count_A=F//A
count_B=F//B
count_C=F//C
count_D=F//D
max=-1
ans=[0]*2
total=0
density=0
for i in range(count_A+1):
    for j in range(count_B+1):
        if i*A+j*B<=F and 0<i*A+j*B:
            for k in range(count_C+1):
                if i*A+j*B+k*C<=F:
                    for l in range(count_D+1):
                        total=i*A+j*B+k*C+l*D
                        if total!=0:
                            density=(k*C+l*D)/total
                            if total<=F and density<=E/(100+E) and max<density:
                                max=density
                                ans[0]=total
                                ans[1]=k*C+l*D
                                if density==E/(100+E):
                                    print(' '.join(map(str, ans)))
                                    exit()
print(' '.join(map(str, ans)))


Measured memory_bytes: 3064
#include<stdio.h>

long long p(long long x,long long y){
	long long ans=1;
	for(long long i=0;i<y;i++)ans*=x;
	return ans;
}

int main(){
	long long N,P;
	scanf("%lld%lld",&N,&P);
	
	if(N==1){
		printf("%lld\n",P);
		return 0;
	}
	
	long long ans=1;
	
	for(long long i=2;i*i<=P;i++){
		long long c=0;
		while(P%i==0){
			c++;
			P/=i;
		}
		if(c>=N)ans*=p(i,c/N);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

struct UnionFind {
    parent: Vec<usize>,
    size: Vec<usize>,
}

impl UnionFind {
    fn new(n : usize)-> UnionFind {
        let mut par = Vec::with_capacity(n);
        for i in 0..n {
            par.push(i);
        }
        UnionFind {
            parent: par,
            size: vec![1; n]
        }
    }

    fn union(&mut self, l: usize, r: usize) {
        let mut lp = self.get_par(l);
        let mut rp = self.get_par(r);

        if lp != rp {
            self.parent[lp] = rp;
            self.size[rp] += self.size[lp];
        }
        
    }

    fn get_par(&mut self, tar: usize) -> usize {
        let mut par = tar;
        while self.parent[par] != par {
            par = self.parent[par];
        }
        self.parent[tar] = par;
        par
    }

    fn get_par_size(&mut self, tar: usize) -> usize {
        let par = self.get_par(tar);
        self.size[tar]
    }
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0];
    let m = line[1];

    let mut path: Vec<(usize, usize)> = Vec::with_capacity(m);
    for i in 0..m {
        let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = line[0] - 1;
        let b = line[1] - 1;

        path.push((a,b));
    }

    let mut ans: Vec<u64> = Vec::with_capacity(m);
    let mut tmp = n as u64 * (n as u64 -1) / 2;

    path.reverse();

    let mut uf = UnionFind::new(n);

    for &(a, b) in path.iter() {
        ans.push(tmp);
        let l = uf.get_par(a);
        let r = uf.get_par(b);
        if l!=r {
            tmp -= uf.get_par_size(l) as u64 * uf.get_par_size(r) as u64;
            uf.union(l, r);
        }
    }

    for i in (0..m).rev() {
        println!("{}", ans[i]);
    }
}


Measured memory_bytes: 9468
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  string s; cin >> s;
  ll w; cin >> w;
  REP(i,SZ(s)){
    if(i%w==0) cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
int main(){
  int n,k,l[100001]={},r[100001]={},t=2001001001,ln=0,rn=0,i,x;
  std::cin>>n>>k;
  for(i=0;i<n;++i){
    std::cin>>x;
    if(x<0){++ln;l[ln]=-x;}
    else if(x>0){++rn;r[rn]=x;}
    else{--k;}
  }
  std::sort(l,l+ln+1);
  if(k==0)t=0;
  else{
    if(ln==0)t=r[k];
    else if(rn==0)t=l[k];
    else for(i=std::max(1,k-rn);i<std::min(ln+1,k);++i)t=std::min(std::min(l[i],r[k-i])*2+std::max(l[i],r[k-i]),t);
  }
  std::cout<<t<<"\n";
}

    

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

struct triple
{
	int first;
	int second;
	int third;
};

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

	int n;
	string s[100000];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}

	ll cnt[5] = {0};
	triple t[10] = {{0,1,2},{0,1,3},{0,1,4},{0,2,3},{0,2,4},{0,3,4},{1,2,3},{1,2,4},{1,3,4},{2,3,4}};

	for(int i = 0; i < n; i++){
		if(s[i][0] == 'M') cnt[0]++;
		else if(s[i][0] == 'A') cnt[1]++;
		else if(s[i][0] == 'R') cnt[2]++;
		else if(s[i][0] == 'C') cnt[3]++;
		else if(s[i][0] == 'H') cnt[4]++;
	}

	ll ans = 0;
	for(int i = 0; i < 10; i++){
		ans += cnt[ t[i].first ] * cnt[ t[i].second ] * cnt[ t[i].third ];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5760
import math
import itertools
n = int(input())
#n, m = map(int, input().split())
#hl = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
total = 0
townnum = [i for i in range(n)]
for v in itertools.permutations(townnum):
    for j in range(1, n):
        cur = l[v[j]]
        bef = l[v[j-1]]
        total += math.sqrt((cur[0]-bef[0])**2+(cur[1]-bef[1])**2)
ans = total/math.factorial(n)
print('{:.9f}'.format(ans))

Measured memory_bytes: 9160
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
                                                                                                     
ll MOD=1000000007;                                                                                     
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,ans=1000; cin>>n;
    vector<ll> a(n,0);
    rep(i,n) cin>>a[i];
    int idx=0;
    rep(i,n-1){
        if(a[i]>=a[i+1]){
            if(idx!=i+1){
                ans=ans/a[idx]*a[i]+ans%a[idx];
            }
            idx=i+1;
        }
    }
    if(idx!=n-1) ans=ans/a[idx]*a[n-1]+ans%a[idx];
    cout<<ans<<endl;
}


Measured memory_bytes: 3628
a, b, c = map(int, input().split())

if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
elif c <= b <= a:
    print(c, b, a)


Measured memory_bytes: 5596
#include <iostream>
using namespace std;
#define ll long long 
int main() {
	ll n,q,count;
      count=0;
     string s;
     cin>>n>>q>>s;
     ll a[n]={0};
      for(ll i=1 ;i<n;i++)
                      {
                            if(s[i-1]=='A'&&s[i]=='C')
                                {
                                    count++;}
                                     a[i]=count;
                  
                       }
                   
   while(q--)
               {  
                  ll l,r;
                  cin>>l>>r;
                   cout<<a[r-1]-a[l-1]<<endl;
               }           
  
}              

Measured memory_bytes: 1792
n, m= map(int, input().split())
A=[]
B=[]
for i in range(n):
    t1, t2= map(int, input().split())
    A.append([t1,t2])
    #B.append(t2)
#print(A)
A=sorted(A, key=lambda x: x[0])
#print(A)
count=0
money=0
for i in A:
    if count+i[1]<m:
        count+=i[1]
        money+=i[0]*i[1]
    else:
        while count<m:
            count+=1
            money+=i[0]
    #print(money)
print(money)



Measured memory_bytes: 21984
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int[] list = new int[5];
		int max = 0;
		int plus = 0;
		for(int i = 0; i < 5; i++) {

			list[i] = Integer.parseInt(scan.nextLine());

			if(list[i] % 10 != 0) {
				plus = 10 - list[i] % 10;
				list[i] += plus;
				max = Math.max(max, plus);
			}
		}

		System.out.println(list[0] + list[1] + list[2] + list[3] + list[4] - max);
	}
}


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

int main(){
    int c[3][3];

    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin>>c[i][j];
        }
    }

    bool ans = false;

    for(int i=0; i<=100; i++){
        bool flag = true;
        int b[3];
        for(int j=0; j<3; j++){
            b[j] = c[0][j] - i;
        }

        int pre,cur;
        pre = c[1][0] - b[0];

        for(int j=1; j<3; j++){
            cur = c[1][j] - b[j];
            if(cur != pre) flag = false; 
        }

        pre = c[2][0] - b[0];

        for(int j=1; j<3; j++){
            cur = c[2][j] - b[j];
            if(cur != pre) flag = false;
        }

        if(flag) ans = true;
    }

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

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  string S;
  cin >> S;
  int minn = INF;
  FOR(i, 3, S.size()+1){
    string str= S.substr(i-3,3);
    int a = stoi(str);
    if(minn > abs(753-a)){
      minn = abs(753-a);
    }
  }
  cout << minn;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int a[100000];
int main(){
	int N,i;
	cin >> N;
	for (i = 0;i<N;i++)
	{
		cin >> a[i];
	}
	map<int,int> mp;
	for (i = 0; i < N; i++) {
		mp[a[i]]++;
	}
	int x,n,ans = 0;
	for (auto p:mp) {
		x = p.first;
		n = p.second;
		if (n < x) {
			ans+=n;
		}
		else ans +=n-x;
	}
	cout << ans << endl;


	


}

Measured memory_bytes: 8424
#include <bits/stdc++.h>
using namespace std;
int n, c, f, i, j, a[200000], vis[1000001], spf[1000001];
int main()
{
    ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
    cin >> n;
    for (i = 0; i < n; i++)
        cin >> a[i], vis[a[i]]++;
    if (vis[1])
    {
        if (vis[1] == 1)
            cout << 1 << '\n';
        else
            cout << 0 << '\n';
        return 0;
    }
    for (i = 2; i <= 1e6; i += 2)
        spf[i] = 2;
    for (i = 3; i < 1e6; i += 2)
        spf[i] = i;
    for (i = 3; i < 998; i += 2)
        if (spf[i] == i)
            for (j = i * i; j < 1e6; j += i)
                if (spf[j] == j)
                    spf[j] = i;
    for (i = 0; i < n; i++)
        if (vis[a[i]] == 1)
        {
            if (a[i] != spf[a[i]])
            {
                for (j = spf[a[i]]; j * j <= a[i]; j++)
                    if (!(a[i] % j))
                        if (vis[a[i] / j] || vis[j])
                        {
                            c++;
                            break;
                        }
            }
        }
        else c++;
    cout << n - c << '\n';
    return 0;
}

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

bool isEven(const int n){
    if(n%2==0){
        return true;
    }else{
        return false;
    }
}
bool isEven(const vector<int>& vec){
    for(int i=0; i<vec.size(); i++){
        if(!isEven(vec[i])){
            return false;
        }
    }
    return true;
}
int min(const vector<int>& vec){
    int min=vec[0];
    for(int i=1; i<vec.size(); i++){
        if(min>vec[i]){
            min=vec[i];
        }
    }
    return min;
}
int numOf2in(int x){
    int n=0;
    while(isEven(x)){
        x/=2;
        n++;
    }
    return n;
}
vector<int> numOf2in(const vector<int>& vec_in){
    vector<int> vec_out(vec_in.size());
    for(int i=0; i<vec_in.size(); i++){
        vec_out[i] = numOf2in(vec_in[i]);
    }
    return vec_out;
}

int main(){
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<A.size(); i++){
        cin >> A[i];
    }
    
    A = numOf2in(A);
    int a = min(A);
    cout << a;
  
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

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

    int N; cin >> N;
    vector<int> A(N); cin >> A;

    ll ans = 0;

    int r = 0;
    rep(i, N) {
        ans += (A[i] + r) / 2;
        r = (A[i] == 0) ? 0 : ((A[i] + r) % 2);
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
int main(){
    int n;
    scanf("%d",&n);
    long long int a[n];
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    priority_queue<llint>q1;
    priority_queue<llint>q2;
    llint s=0;
    map<llint,llint>timemap;
    timemap[0]=0;
    for(int i=0;i<n;i++){
        s+=a[i];
        if(timemap.find(-s)!=timemap.end())timemap[-s]++;
        else timemap[-s]=0;
    }
    s=0;
    llint ans=0;
    ans+=timemap[0];
    for(int i=0;i<n;i++){
        s+=a[i];
        ans+=timemap[-s];
    }
    printf("%lld\n",(ans)/2);
}



Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<int, int, int> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<char> vc;

const int INF = 1e9;
const ll INFLL = 1e16;
const int MOD = 1000000007;
const int MAXN = 3e5;
//const ld eps = 1e-6;
const ld eps2 = 1e-9;
const int MOD2 = 998244353;
const int dosz = 5e5;
const int SZ = (1<<18);
const ld PI = atan2l(0, -1);


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
        // freopen("a.in", "r",stdin);
#else
       // freopen("substrcmp.in", "r", stdin);
       // freopen("substrcmp.out", "w", stdout);
#endif
}

bool used[200000];
int kek[200000];

void solve(){
    int n, m;
    cin >> n >> m;
    int ans1 = 0, ans2 = 0;
    while(m--){
        int t;
        string s;
        cin >> t >> s;
        t--;
        if(s=="AC"){
            if(!used[t]){
                ans1++;
                ans2 += kek[t];
            }
            used[t] = true;
        } else{
            if(!used[t]){
                kek[t]++;
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;

}

signed main() {
    fast_io();
    int q = 1;
    // cout << fixed << setprecision(6);
    // cin >> q;
    // cout << 1 << endl;
    while(q--){
        solve();
    }
    return 0;
}


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

int main(){
    string day[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string S;
    cin >> S;
    for(int i=0; i<7; i++){
        if(day[i] == S){
            cout << 7-i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a) cout<<k<<endl;
    else if(k<=a+b) cout<<a<<endl;
    else cout<<a-k+a+b<<endl;
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if sum(a) < sum(b):
    print(-1)
else:
    cnt = ssum = 0
    d = [a[i]-b[i] for i in range(n)]
    for i in range(n):
        if d[i] < 0:
            cnt += 1
            ssum -= d[i]
    d.sort()
    for i in range(n-1, -1, -1):
        if ssum <= 0:
            break
        ssum -= d[i]
        cnt += 1
    print(cnt)

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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

ll gcd(ll x, ll y)
{
  if (x % y == 0)
  {
    return y;
  }
  return gcd(y, x % y);
}

int main()
{
  string s, t;
  cin >> t >> s;
  cout << "A" << s[0] << "C" <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main(void) {
	int n, k, c, i, g1[200003], g2[200003], d1[200003], d2[200003], rs;
	string s;
	bool ir1[200003] = { false }, ir2[200003] = { false };

	cin >> n >> k >> c >> s;

	i = 0;
	while (i < n) {
		while (i < n && s[i] == 'x') i++;
		if (i == n) break;
		ir1[i] = true;
		i += c + 1;
	}

	i = n - 1;
	while (i >= 0) {
		while (i >= 0 && s[i] == 'x') i--;
		if (i == -1) break;
		ir2[i] = true;
		i -= c + 1;
	}

	if (ir1[0]) {
		d1[0] = 1;
	}
	for (i = 1; i < n; i++) {
		if (ir1[i]) {
			d1[i] = d1[i - 1] + 1;
			g1[i] = i;
		}
		else {
			d1[i] = d1[i - 1];
			g1[i] = g1[i - 1];
		}
	}

	if (ir2[n - 1]) {
		d2[n - 1] = 1;
		g2[n - 1] = n - 1;
	}
	for (i = n - 2; i >= 0; i--) {
		if (ir2[i]) {
			d2[i] = d2[i + 1] + 1;
			g2[i] = i;
		}
		else {
			d2[i] = d2[i + 1];
			g2[i] = g2[i + 1];
		}
	}

	for (i = 0; i < n; i++) {
		if (s[i] == 'x') continue;
		rs = 0;
		if (i > 0) rs += d1[i - 1];
		if (i < n - 1) rs += d2[i + 1];
		if (i > 0 && i < n - 1) {
			if (d1[i - 1] > 0 && d2[i + 1] > 0 && g2[i + 1] - g1[i - 1] <= c) {
				rs--;
			}
		}
		if (rs < k) cout << i + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 5380
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int n, k, s;
  cin >> n >> k >> s;
  vector<int> a(k, s);
  vector<int> b(n - k, (s + 1) % (int)1e9);
  for (auto x : a) cout << x << " ";
  for (auto x : b) cout << x << " ";
  cout << endl;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define pb push_back
#define pf push_fron
#define INF 1e9
#define PI acos(-1)
typedef long long ll;

int a[110];

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	for (int i = 0; i < m; i++)cin >> a[i];
	sort(a, a + m);

	int cntf = 0, cnts = 0;
	for (int i = 0; i < m; i++) {
		if (a[i] < x)cntf++;
		else if (a[i] > x)cnts++;
	}
	cout << ((cntf >= cnts) ? cnts : cntf) << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	// Code for B - Training Camp
	var N int
	fmt.Scanf("%d", &N)

	var ans int = 1
	for i := 1; i <= N; i++ {
		ans *= i
		if ans > int(math.Pow10(9)+7) {
			ans = ans % (int(math.Pow10(9) + 7))
		}
	}
	fmt.Println(ans % (int(math.Pow10(9) + 7)))
}


Measured memory_bytes: 1832
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <set>
using namespace std;
int main() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = s.size();
	set<string> v;
	for (int i = 0;i < n;i++) {
		for (int j = 1;j <= min(k, n - i);j++) {
			string add = s.substr(i, j);
			//cout << add << endl;
			v.insert(add);
		}
	}
	int cnt = 1;
	for (auto i:v) {
		if (cnt == k) {
			cout << i << endl;
			break;
		}
		cnt++;
	}
	return 0;
}

Measured memory_bytes: 1664