akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int n,m,u,v,vis[100007],id[100007];
long long c,dis[100007],d,ans=1e16,now=0;
vector < pair <int,long long> > edge[100007];
priority_queue < pair <long long,int> , vector < pair <long long,int> > , greater < pair <long long,int> > > pr;
int cmp(int a,int b){
    return (dis[a]<dis[b] || (dis[a]==dis[b] && a<b));
}
signed main(){
    //ios_base::sync_with_stdio(0);
    cin>>n>>m>>c;
    for(int i=1;i<=m;i++){
        cin>>u>>v>>d;
        edge[u].pb(mp(v,d));
        edge[v].pb(mp(u,d));
        now+=d;
    }
    for(int i=1;i<=n;i++) dis[i]=1e16;
    dis[1]=0;
    pr.push(mp(0,1));
    while(!pr.empty()){
        long long val=pr.top().fi;
        int u=pr.top().se;
        pr.pop();
        if(dis[u]!=val) continue;
        for(int i=0;i<(int)edge[u].size();i++){
            int v=edge[u][i].fi;
            long long l=edge[u][i].se;
            if(dis[v]>val+l){
                dis[v]=val+l;
                pr.push(mp(dis[v],v));
            }
        }
    }
    for(int i=1;i<=n;i++) id[i]=i;
    sort(id+1,id+1+n,cmp);
    ans=now;
    vis[1]=1;
    vis[n+1]=1e16;
    id[n+1]=n+1;
    for(int i=2;i<=n;i++){
        int j=id[i];
        //cout<<dis[j]<<endl;
        for(int ii=0;ii<edge[j].size();ii++){
            v=edge[j][ii].fi;
            d=edge[j][ii].se;
            if(vis[v]==0) continue;
            now-=d;
        }
        vis[j]=1;
        if(dis[j]==dis[id[i+1]]) continue;
        ans=min(ans,now+c*dis[j]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 18916
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	long double pi = acos(-1);
	long double y, ans = 0;
	long double a, b, x;
	
	cin>>a>>b>>x;
	
	y = (a * a * b) / 2;
	
	if(y > x) {
		long double h = (2 * x) / (a * b);
		cout<<90 - (atan(h/b) / pi)  * 180<<endl;
	} else {
		long double z = 2 * (x / (a * a)) - b;
		cout<<90 - (atan(a/(b-z)) / pi) * 180<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int A=scanner.nextInt();
		int B=scanner.nextInt();
		String s=scanner.next();
		int i=0;
		for (i = 0; i < A+B+1; i++) {
			char c=s.charAt(i);
			if (c>=48&&c<=57&&i!=A) {
				continue;
			}else if(i==A&&c=='-'){
				continue;
			}else {
				break;
			}
		}
		if (i!=A+B+1) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

vector<int> inv, fac, finv;

inline void precalc(int N) {
    inv.resize(N), fac.resize(N), finv.resize(N);
    inv[1] = 1;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < N; ++i) {
        inv[i] = MOD - (ll)(MOD / i) * inv[MOD % i] % MOD;
        fac[i] = (ll)fac[i - 1] * i % MOD;
        finv[i] = (ll)finv[i - 1] * inv[i] % MOD;
    }
}

inline ll binomial(int n, int r) {
    return ((ll)fac[n] * finv[r] % MOD) * finv[n - r] % MOD;
}

ll extGCD(ll a, ll b, ll &p, ll &q) {
    if (!b) {
        p = 1, q = 0;
        return a;
    }
    ll d = extGCD(b, a % b, q, p);
    q -= a / b * p;
    return d;
}

ll modinv(ll a, ll m) {
    ll x, y;
    extGCD(a, m, x, y);
    return (x % m + m) % m;
}

int N;
Graph<int> G;
vector<int> siz;
vector<ll> dp;

void dfs(int v, int p = -1) {
    dp[v] = 1;
    siz[v] = 1;
    for (auto nv : G[v]) {
        if (nv == p)
            continue;
        dfs(nv, v);
        (dp[v] *= dp[nv] * finv[siz[nv]] % MOD) %= MOD;
        siz[v] += siz[nv];
    }
    (dp[v] *= fac[siz[v] - 1]) %= MOD;
}

void dfs2(int v, int p = -1, ll d_par = 1) {
    if (~p) {
        (dp[v] *= d_par) %= MOD;
        (dp[v] *= finv[N - siz[v]]) %= MOD;
        (dp[v] *= finv[siz[v] - 1]) %= MOD;
        (dp[v] *= fac[N - 1]) %= MOD;
    }
    for (auto nv : G[v]) {
        if (nv == p)
            continue;
        ll tmp = (dp[v] * fac[siz[nv]] % MOD) * modinv(dp[nv], MOD) % MOD;
        tmp = (tmp * fac[N - 1 - siz[nv]] % MOD) * finv[N - 1] % MOD;
        dfs2(nv, v, tmp);
    }
}

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

    cin >> N;
    G.resize(N);
    for (int i = 1; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    precalc(N + 1);
    dp.resize(N);
    siz.resize(N);
    dfs(0);
    dfs2(0);
    for (auto i : dp)
        cout << (i < 0 ? i + MOD : i) << '\n';

    return 0;
}


Measured memory_bytes: 18676
import math

S = int(input())

x = math.ceil(math.sqrt(S))

diff = x * x - S
if diff <= 10 ** 9:
    print(0, 0, x, 1, diff, x)
else:
    p = int(math.sqrt(diff))
    print(0, 0, x + p, 1, diff - p * p, x - p)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
const  int MAX = 100000;
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P){
    int i = 0;
    for(int j = 0; j < k; j++){
        llong s = 0;
        while(s + T[i] <= P){
            s += T[i];
            i++;
            if(i == n)return n;
        }
    }
    return 1;
}

int solve(){
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while(right - left > 1){
        mid = (left + right) / 2;
        int v = check(mid);
        if(v >= n) right = mid;
        else left = mid;
    }

    return right;
}

int main(){
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> T[i];
    llong ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main() {
    long long n;
    cin >> n;
    vector<long long> a(n);
    rep(i, n) {
        cin >> a.at(i);
    }

    // 全体 - k番目との組の数 で求める値が得られる

    // 値:個数 のmap
    map<long long, long long> mp;
    rep(i, n) {
        long long value = a.at(i);
        mp[value] += 1;
    }

    // 値:値ごとの組み合わせの数
    map<long long, long long> cmb_mp;
    for (auto itr : mp) {
        cmb_mp[itr.first] = itr.second * (itr.second - 1) / 2;
    }

    // 全体は全て足す
    long long whole = 0;
    for (auto itr : cmb_mp) {
        whole += itr.second;
    }

    // 答え
    rep(i, n) {
        long long value = a.at(i);
        long long part = mp.at(value) - 1;

        cout << whole - part << endl;
    }
}


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

int main() {
	
	int a , b;
	
	cin>>a>>b;
	
	if(b >= a)
	cout<<"0\n";
	
	else if(b*2 >= a)
	cout<<"0\n";
	
	else if( a >= b*2)
	cout<<a - (b*2) <<endl;
	
	return 0;
}

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

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >>s;
	if(s == "SUN")
		cout << "7\n";
	else if(s == "MON")
		cout << "6\n";
		else if(s == "TUE")
		cout << "5\n";
		else if(s == "WED")
		cout << "4\n";
		else if(s == "THU")
		cout << "3\n";
		else if(s == "FRI")
		cout << "2\n";
		else if(s == "SAT")
		cout << "1\n";
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int S = Integer.parseInt(br.readLine());
		System.out.print(S/3600 + ":");
		System.out.print(S%3600/60 + ":");
		System.out.println(S%3600%60);
	}
}


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

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << endl;
#define endl "\n"
#define MOD (int) 1e9+7
#define inf (int) (1e18)

void solve(){
    ll n;
    cin>>n;
    if(n%1000==0){
        cout<<"0\n"; 
        return;
    }
    ll tp=n/1000;
    tp=n-tp*1000;
    tp=1000-tp;
    cout<<tp<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t=1;
    // cin >> t;
    for(long int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(void)
{
	int a,b,c,ans;
	scanf("%d %d %d",&a,&b,&c);
	if(a==1 && b==0 && c==0){
		printf("Close\n");
	}
	else if(a==0 && b==1 && c==0){
		printf("Close\n");
	}
	else if(a==1 && b==1 && c==0){
		printf("Open\n");
	}
	else if(a==0 && b==0 && c==1){
		printf("Open\n");
	}
	else if(a==0 && b==0 && c==0){
		printf("Close\n");
	}
	return 0;
}


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

namespace AtCoderPractice
{
    class Program
    {
        static void Main(string[] args)
        {
            //char[] s = Console.ReadLine().ToCharArray();
            //int[] countList = new int[s.Length];
            char[] s = (Console.ReadLine() + "R").ToCharArray();
            int[] countList = new int[s.Length];

            var stack = new List<int>();
            int i = 0;
            while (i < s.Length - 1)
            {
                //Console.WriteLine("i = {0}の評価スタート", i);
                bool isSameChar = s[i] == s[i + 1];

                if (isSameChar)
                {
                    // 次のマスと同じなら、偶奇逆の結果なのが分かるで遅延
                    //Console.WriteLine("i={0} は i={1} と偶奇逆の結果", i, i + 1);
                    stack.Add(i);

                    i++;
                }
                else
                {
                    //Console.WriteLine("i={0} は 1確定", i);
                    // 自身の評価
                    countList[i]++;

                    // 評価を遅延していたものをすべて吐き出す
                    int j = 0;
                    while (stack.Count > 0)
                    {
                        // stack.pop
                        int pos = stack[stack.Count - 1];
                        stack.RemoveAt(stack.Count - 1);

                        // 結果反映
                        int idx = i + (1 - j % 2);
                        //Console.WriteLine("pos={0}, j={1}, idx={2}", pos, j, idx);

                        countList[idx]++;
                        j++;
                    }
                    stack.Clear();

                    if (s[i] == 'R')
                    {
                        // RLの間は、次のRの直前まで結果を入れて進める
                        j = 1;
                        while (s[i + j] == 'L')
                        {
                            int idx = i + (j % 2);
                            //Console.WriteLine("i={0}, j={1}, idx={2}", i, j, idx);
                            countList[idx]++;
                            j++;
                        }
                        i += j;
                    }
                    else
                    {
                        i++;
                    }
                }
            }

            var lst = new List<int>(countList);
            lst.RemoveAt(lst.Count - 1);
            string repr = string.Join(" ", lst.Select(x => x.ToString()));
            Console.WriteLine(repr);
        }
    }
}


Measured memory_bytes: 15072
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int c[27];
int s[366][27];
int last[26];
ll evaluate(vi t){
  int d = sz(t);
  ll score = 0;
  rep(i,d){
    score+=s[i][t[i]];
    last[t[i]] = (i+1);
    rep(j,26){
      score-=c[j] * ((i+1)-last[j]);
    }
    cout<<score<<endl;
  }
  return score;
}

int main() {
  int d;
  cin >> d;
  vi t(d);
  rep(i,26)cin >> c[i];
  rep(i,d)rep(j,26)cin >> s[i][j];
  rep(i,d){
    cin >> t[i];
    t[i]--;
  }
  evaluate(t);
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<deque>


using namespace std;
using ll = long long;

int n;
string s;

int main(){
  cin >> n;
  cin >> s;
  ll ans = 1;
  for(int i = 0; i < n - 1; ++i){
    if(s[i] != s[i + 1]){
      ans += 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
n,q=map(int,input().split())
T=[[]for i in range(n+1)]
for i in range(n-1):
    a,b=map(int,input().split())
    T[a].append(b)
    T[b].append(a)
tasu=[0]*(n+1)
for i in range(q):
    p,x=map(int,input().split())
    tasu[p]+=x
    
def dfs(a):
    ans=[-1]*(n+1)
    stack=[a]
    ans[a]=tasu[a]
    while stack:
        x=stack.pop()
        moto=ans[x]
        for w in T[x]:
            if ans[w]<0:
                ans[w]=moto+tasu[w]
                stack.append(w)
    return ans
kotae = dfs(1)[1:]
print(*kotae, sep=' ')

Measured memory_bytes: 61048
#include <stdio.h>

int main(void) {
    char buf[31];
    int a, b, n;

    fgets(buf, sizeof(buf), stdin);
    n = sscanf(buf, "%d %d", &a, &b);
    printf("%d %d %.5f\n", a/b, a%b, (double)a/b);

    return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
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 Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int main() {
	int N = getint();
	int A[100000];
	rep(i, N) A[i] = getint();

	int B[100000];
	B[0] = A[0];
	rep1(i, N - 2) B[i] = __gcd(A[i], B[i - 1]);

	int kotae = B[N - 2];
	int C = A[N - 1];
	rep1(i, N - 2) {
		kotae = max(kotae, __gcd(C, B[N - 2 - i]));
		C = __gcd(A[N - i - 1], C);
	}
	kotae = max(C, kotae);

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 1152
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  a,b,c,d=LI()
  return max(a*c,b*d,a*d,b*c)

# main()
print(main())


Measured memory_bytes: 10776
#include<iostream>
#include <cstdio>
#include <cstring>
#define ll long long int
#define ii int
#define jmp cout<<"\n"
#define vl vector<ll>
#define pb push_back
#define printv(v) for(auto x:v) cout<<x<<" "; jmp;
#define endll "\n"
#define SORT(v) sort(v.begin(),v.end())
#define REV(x)  reverse(x.begin(),x.end())
#define ff first
#define ss second
#define iin insert
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
const ll N = 1e5 + 5;
const ll inf = 0x3f3f3f3f;
ll dp[N];
ll w[N], val[N];
void solve()
{
	ll n, W;
	cin >> n >> W;
	//ll w[n], val[n];
	for (ll i = 0; i < n; i++)
		cin >> val[i] >> w[i];

	memset(dp, inf, sizeof(dp));
	dp[0] = 0;
	for (ll i = 0; i < n; i++)
	{
		for (ll j = 1e5; j >= w[i]; j--)
			dp[j] = min(dp[j], (dp[j - w[i]] + val[i]));
	}
	ll ans;
	for (ll i = 1e5; i >= 0; i--)
	{	if (dp[i] <= W)
		{
			ans = i ;
			break;
		}
	}
	cout << ans;
}
int main()
{

	solve();
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
		int a,b,c,d,e;
	
	scanf("%d\n%d\n%d\n%d\n%d",&a,&b,&c,&d,&e);
	if(a<40){
		a=40;
	}
	if(b<40){
		b=40;
	}
	if(c<40){
		c=40;
	}
	if(d<40){
		d=40;
	}
	if(e<40){
		e=40;
	}
	a=(a+b+c+d+e)/5;
	
	printf("%d\n",a);
	// your code goes here
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll t;
  // cin>>t;
  t=1;
  while(t--){
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n), dp(k+1,0);
    forn(i,0,n)
      cin>>a[i];
    forn(i,0,k+1){
      forn(j,0,n){
        if(i-a[j] >= 0 && dp[i-a[j]] == 0){
          dp[i] = 1;
          break;
        }
      }
    }
    ll ans = dp[k];
    if(ans == 1)
      cout<<"First\n";
    else
      cout<<"Second\n";
  }
  return 0;
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll N;
  cin>>N;
  vector<bool> vec(1000000000);
  for(ll i=0;i<N;i++){
    ll a;
    cin>>a;
    if(vec.at(a-1)==true){cout<<"NO"<<endl;return 0;}
    vec.at(a-1)=true;
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 122368
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<int, int>  ii;
typedef pair<double, double>  iidb;
typedef pair<int, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9+7;
const double PI = acos(-1);
#define initseg ll new_nodo=(pnodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 1010
#define offset 3000
#define ptr nodo*


using namespace std;
int cant[tam*tam];
int marca[tam][tam];
int main()
{
	int h,w;
	cin>>h>>w;
	int n;
	cin>>n;
	forr(i,0,n)
	{
		cin>>cant[i];
	}	
	vector<ii> vect;
	int ini,add;
	forr(i,0,h)
	{
		if (i%2)
			ini=w-1,add=-1;
		else
			ini=0,add=1;
		while(ini>=0 && ini<=w-1)
		{
			vect.pb({i,ini});
			ini+=add;
		}
	}
	int pos=0;
	forr(i,0,n)
	{
		while(cant[i]--)
		{
			marca[vect[pos].fi][vect[pos].se]=i+1;
			pos++;
		}
	}
	forr(i,0,h)
	{
		forr(j,0,w)
		cout<<marca[i][j]<<" ";
		cout<<endl;
	}
}

Measured memory_bytes: 4120
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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;
}

int main(){
  cout << fixed << setprecision(15);
  int n; cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  
  ll ans = 0;
  sort(all(v));
  for (int i = 0; i < n; i++){
    for (int j = 0; j < i; j++){
      if (i == j) continue;
      for (int k = 0; k < j; k++){
        if (i == k || j == k) continue;
        if (v[k] + v[j] > v[i]) ans++;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
int main(){
  int n,A[N],i,j,v,count=0,b;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<n;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v)
      {
	A[j+1] = A[j];
	j--;
	count++;
      }
    A[j+1] = v;
  }
  for(b=0;b<n-1;b++) printf("%d ",A[b]); printf("%d",A[n-1]);
    printf("\n");
    printf("%d",count);
    printf("\n");
    return 0;
  }



Measured memory_bytes: 2124
n = int(input())
x = [int(each) for each in input().split(' ')]
# 総当たりでやってみて、その結果をリストに入れておく
candidate = []
for i in range(min(x), max(x)+1):
    result = 0
    for person in x:
        result += (person-i)**2
    candidate.append(result)

print(min(candidate))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define LL long long int
#define N int(1e5+1)
using namespace std;
int main()
{
	int n;
	string s1,s2;
	cin>>n>>s1>>s2;
	for(int i=0;i<n;i++)
		cout<<s1[i]<<s2[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define INF 2e9
#define mod 1000000007
#define y1 solai
#define fi first
#define se second
typedef long long ll;
void read(ll &x)
{
	scanf("%lld",&x);
}
void read(ll &x, ll &y)
{
	scanf("%lld%lld",&x,&y);
}
void read(ll &x, ll &y, ll &z)
{
	scanf("%lld%lld%lld",&x,&y,&z);
}
void print(ll x)
{
	printf("%lld ",x);
}
void println(ll x)
{
	printf("%lld\n",x);
}
const ll N=16000000;
ll n,a,b;
int main()
{
	//freopen("c.cpp","r",stdin);
 
	cin>>n>>a>>b;
	for(ll i=1;i<=1000000;i++)
	{
		if(i&1)
		{
			if((a==1&&b==2)||(a==n&&b==n-1))
			{
				cout<<"Borys";
				return 0;
			}
			if(a<b&&a+1!=b)
				a++;
			else
				a--;
		}
		else
		{
			if((b==1&&a==2)||(b==n&&a==n-1))
			{
				cout<<"Alice";
				return 0;
			}
			if(b>a&&b-1!=a)
				b--;
			else
				b++;
		}
	}
	assert(0);
}
//25505464

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int ans = (n -1) * (m - 1);
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
#include<unordered_map>

#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8

#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	ios::sync_with_stdio(false);
	int n,a,b;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	int c=0;
	int ca=0;
	REP(i,n) {
		if(s[i]=='a') {
			if(c<a+b) {
				++c;
				cout<<"Yes"<<"\n";
			} else {
				cout<<"No"<<"\n";
			}
		}
		else if(s[i]=='b') {
			if(c<a+b&&ca<b) {
				++c;
				++ca;
				cout<<"Yes"<<"\n";
			} else {
				cout<<"No"<<"\n";
			}
		} else cout<<"No"<<"\n";
	}
	cout<<flush;
}


Measured memory_bytes: 848
#include "bits/stdc++.h"
#define ll long long
#define vi vector <int>
#define vii vector <vi>
using namespace std;

const int mod = 1e9 + 7;
const int mnx = 1e6 + 9;

ll n;
ll a[mnx];

int main(){
    cin >> n;

    ll cnt = 0;

    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] == cnt + 1){
            cnt++;
        }
    }
    if(cnt == 0){
        cout << -1;
    } else cout << n - cnt << '\n';

    return 0;
}















































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

using namespace std;

int main()
{
	int n, y;
	int i, j;
	int write = 0;

	cin >> n >> y;

	if (n * 10000 < y) {
	}
	else {
		
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n-i; j++) {
				if ((10000 * i + 5000 * j + 1000 * (n - i - j) == y) && (0 <= n-i-j)) {
					cout << i << " " << j << " " << n - i - j << endl;
					write = 1;
					break;
				}
			}
			if (write) {
				break;
			}
		}
	}
	
	if (write == 0) {
		cout << "-1 -1 -1" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// Copyright 2017 wu_qing
#include <cstdio>
#include <algorithm>
const int N = 1e5 + 10;
int n, a[N], b[N], l;
bool flag;
int main() {
    scanf("%d%d", &n, &l);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    for (int i = 1; i < n; i++)
        b[i] = a[i] + a[i + 1];
    for (int i = 1; i < n; i++)
        if (b[i] >= l) {
            flag = true;
            printf("Possible\n");
            for (int j = 1; j < i; j++)
                printf("%d\n", j);
            for (int j = n - 1; j > i; j--)
                printf("%d\n", j);
            printf("%d\n", i);
            break;
        }
    if (!flag)
        printf("Impossible\n");
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX=110;
char map[MAX][MAX];
int n,m;
int fx[]={1,-1,0,0};
int fy[]={0,0,1,-1};
void dfs(int x,int y,char ch)
{
    map[x][y]='+';
    for(int i=0;i<4;++i)
    {
        int tx=x+fx[i];
        int ty=y+fy[i];
        if(tx>=1&&tx<=n&&ty>=1&&ty<=m&&map[tx][ty]==ch)
            dfs(tx,ty,ch);
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        if(n==0&&m==0)
            break;
        int ans=0;
        for(int i=1;i<=n;++i)
        {
            scanf("%s",map[i]+1);
        }
        for(int i=1;i<=n;++i)
        {
            for(int j=1;j<=m;++j)
            {
                if(map[i][j]!='+')
                {
                    ans++;
                    dfs(i,j,map[i][j]);
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1668
n,k = map(int, input().split())
P = list(map(int, input().split()))

sum_k = sum(P[:k])
temp_sum_k = sum_k 

for i in range(n-k):
  temp_sum_k = temp_sum_k+P[i+k]-P[i]
  if sum_k < temp_sum_k:
    sum_k = temp_sum_k

print((sum_k+k)/2)

Measured memory_bytes: 25060
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 LN             PIC X(30).
01 N              PIC 9(10).
01 M              PIC 9(10).
01 ans            PIC 9(10).
01 zs             PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT LN.
  UNSTRING LN DELIMITED BY SPACE INTO N M.
  COMPUTE ans = N * (N - 1) / 2 + M * (M - 1) / 2.
  MOVE ans TO zs.
  DISPLAY zs.
  STOP RUN.


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

int main() {
	int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];  
    }
    long long ans = 0;
    int cnt_neg = 0;
    int min_num = INT_MAX;
    
    for (int i = 0; i < n; ++i) {
        if (A[i] < 0) {
            ++cnt_neg;  
        }
        ans += abs(A[i]);
        min_num = min(min_num, abs(A[i]));
    }
  //cout << "cnt = " << cnt_neg << endl;  
  //cout << "min = "<<min_num << endl;
    if (cnt_neg % 2 == 1) {
    	ans -= min_num;
        ans -= min_num;
    }
    cout << ans << endl;  
    return 0;
}

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

#define fastio 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ld long double
#define forn(low,high,i) for(i = low; i < high; i++)
#define forrev(high,low,i) for(i = high; i >= low; i--)
#define all(v) v.begin(),v.end()
#define decimal_digits cout << fixed << setprecision(15);

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int inf = 1e9;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int bit32 = log2(inf) + 3;
const int bit64 = log2(INF) + 3;

inline int add(long long a, long long b){a += b; if(a >= mod) a -= mod; return a;}
inline int sub(long long a, long long b){a -= b; if(a < 0) a += mod; return a;}
inline int mul(long long a, long long b){a %= mod; b %= mod; return (int)((long long) a * b % mod);}
inline int modexpo(long long a, long long b){int res = 1; while(b > 0){ if(b & 1) res = mul(res, a); a = mul(a, a); b /= 2;} return res;}
inline int divide(long long a, long long b){return mul(a, modexpo(b, mod - 2));}
inline int inv(long long a){return modexpo(a, mod - 2);}

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

void pre(){ // Reset each global variable (esp. for graphs)
  
}

void solve(){
  string s;
  cin >> s;
  if(s[0] == '7' or s[1] == '7' or s[2] == '7')
    cout << "Yes\n";
  else
    cout << "No\n";
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL); 

  pre();

  int t = 1, T;
  // cin >> t;
  T = t;
  while(t--){
    // cout << "Case #" << T - t << ": ";
    solve();
  }

  ktj();
}


Measured memory_bytes: 3800
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		String[] number = br.readLine().split(" ");

		int x = Integer.parseInt(number[0]);
		int y = Integer.parseInt(number[1]);

		if(x < y){
			int tmp = x;
			x = y;
			y = tmp;
		}

		while(y != 0) {
			int calResult = x % y;

			if(calResult == 0){
				break;
			}

			x = y;
			y = calResult;
		}
		System.out.println(y);
	}
}

Measured memory_bytes: 24264
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

int main()
{
	LL n;
	cin >> n;

	cout << fixed << setprecision(10) << ((n+1)/2)/((LD)n);
}

Measured memory_bytes: 256
/*
 * 0160.cpp
 *
 *  Created on: 2011/07/29
 *      Author: isa
 */

#include <iostream>

using namespace std;

int chk(int sum, int w){
	if(sum <= 60 && w <= 2){
		return 600;
	}else if(sum <= 80 && w <= 5){
		return 800;
	}else if(sum <= 100 && w <= 10){
		return 1000;
	}else if(sum <= 120 && w <= 15){
		return 1200;
	}else if(sum <= 140 && w <= 20){
		return 1400;
	}else if(sum <= 160 && w <= 25){
		return 1600;
	}else{
		return 0;
	}
}

int main(void){
	int n,x,y,z,w;
	while(cin >> n && n){
		int ret=0;
		for(int i=0;i<n;i++){
			cin>>x>>y>>z>>w;
			ret += chk(x+y+z,w);
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int flg2 = 0;
		int[] c = new int[N];
		int[] flg = new int[N];
		int[] bufn = new int[N];
		int i,s,j,dust;
		int buf;
		int ans = -1;
		for(i = 0;i < M;i++){
			s = sc.nextInt();
			c[s-1] = sc.nextInt();
			if(flg[s-1] == 0){
				bufn[s-1] = c[s-1];
				flg[s-1] = 1;
			}else if(bufn[s-1] != c[s-1]){
				flg2 = 1;
			}
			if(N != 1 && flg[0] == 1 && c[0] == 0){
				flg2 = 1;
			}
		}
		if(flg2 == 0){
			ans = 0;
			for(i = 0;i < N;i++){
				buf = 1;
				for(j = 0;j < i;j++){
					buf *= 10;
				}
				ans += (c[N-1-i] * buf);
				if(N != 1 && i == (N-1) && c[0] == 0){
					ans += buf;
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>                                     
using namespace std;                                 
                                                 
#define ll long long                           
#define MOD 1000000007                      
                                           
int main() {                             
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);     

	int n;
	cin>>n;
	double pi=3.14;
	double ans=2*pi*n;
	cout<<ans<<endl;

	return 0;
}      

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

int total=0;

int main()
{
	string s;
	getline(cin,s);
	for (int i=0;i<=(s.size()-1)/2;i++)
	{
		if (s[i]!=s[s.size()-1-i])  total++;
	}
	cout<<total<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

vector<vector<char>> toGrid(string s) {
  vector<vector<char>> grid;
  s = s + '/';
  int n = s.size();
  vector<char> add;
  for (int i = 0; i < n; i++) {
    if (s[i] == '/') {
      grid.push_back(add);
      add.resize(0);
    } else {
      if (s[i] == 'b') {
        add.push_back('b');
      } else {
        int cnt = s[i] - '0';
        while (cnt--) 
          add.push_back('.');
      }
    }
  }

  return grid;
}

string toJfan(vector<vector<char>> grid) {
  int h = grid.size();
  int w = grid[0].size();
  string ret = "";
  for (int i = 0; i < h; i++) {
    int cnt = 0;
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == 'b') {
        if (cnt > 0) {
          ret += (char)(cnt + '0');
        }
        ret += 'b';
        cnt = 0;
      } else cnt++;
    }
    if (cnt > 0) {
      ret += (char)(cnt + '0');
    }

    if (i != h - 1) {
      ret += '/';
    }
  }

  return ret;
}

bool solve() {
  string s; cin >> s;
  if (s == "#") return false;
  
  // jfan -> grid
  auto grid = toGrid(s);
  
  /*
  for (int i = 0; i < grid.size(); i++) {
    for (int j = 0; j < grid[i].size(); j++) {
      cout << grid[i][j] << " ";
    }
    cout << endl;
  }
  */

  int i, j, ii, jj;
  cin >> i >> j >> ii >> jj;
  i--;
  j--;
  ii--;
  jj--;

  grid[i][j] = '.';
  grid[ii][jj] = 'b';

  string jfan = toJfan(grid);
  cout << jfan << endl;
  return true;
}

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



Measured memory_bytes: 3152
import math
def combinations_count(n, r,facs):
    return facs[n] // (facs[n - r] * facs[r])


N,K = list(map(int, input().split(" ")))
R = N-K
facs = [1 for _ in range(6000)]
facs[1] = 1
for i in range(1,3000):
    facs[i+1]  = facs[i] * (i+1)

NUM = 10**9 + 7
for q in range(1,K+1):
    spaces = R+1


    #端を使わないパターン

    choice = combinations_count(spaces,q,facs)
    walls = q -1
    minus = 2
    if walls == 0:
        minus = 0
    places = K - 1
    walls =  q-1
    distr = 1
    distr *= max(combinations_count((K-1),walls,facs),1)

    ans = choice * max(distr,1)

    print(ans % NUM)

  #(wallsが全部端っこのパターンを-2)(walls が0なら-2は無い)



    #R個のballをK + 1箇所に分配
    #両方共端のパターンは除外


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

int main() {
    int A,B;
    cin >> A >> B;
    int ans = 0;
    for(int i = A; i <= B; i++) {
        string S = to_string(i);
        if(S[0] == S[4]) {
            if(S[1] == S[3]) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define MUL 1000002
#define int long long

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    //what do i want to do
    //just go to adjacent stuff with 0 cost and transfer line for 1 cost
    //it's not that difficult...
	gp_hash_table<long long,vector<int> > adj; //<p,c>,q
    vector<int> clist[m+5];
    for (int i=0; i<m; i++){
        int p,q,c;
        cin >> p >> q >> c;
        long long fsp = p,fsq=q;
        long long se = c;
        long long tm1 = fsp*MUL + se;
        long long tm2 = fsq*MUL + se;
        adj[tm1].push_back(q);
        adj[tm2].push_back(p);
        clist[p].push_back(c);
        clist[q].push_back(c);
    }
    gp_hash_table<long long,int> dis;
    gp_hash_table<long long,int> vis;
    int vil[n+5]; memset(vil,0,sizeof(vil));
    deque<long long> q;
    for (auto kk : adj){
    	long long fsk = kk.first/MUL;
        if (fsk == 1){
        	dis[kk.first]=1; 
        	q.push_back(kk.first);
        }
    }
    while(!q.empty()){
        long long vc = q.front();
        long long v=vc/MUL, c=vc%MUL; q.pop_front();
        if(vis.find(vc)!=vis.end()) continue;
        vis[vc]=1;
        if (vil[v]) goto ahc;
        vil[v]=1;
        for(int i : clist[v]){
        	long long kt = v*MUL + i;
            //pair<int,int> np = make_pair(v,i);
            if (dis.find(kt)==dis.end()) dis[kt]=dis[vc]+1;
            else dis[kt]=min(dis[kt],dis[vc]+1);
            q.push_back(kt);
            //cout<<'a'<<endl;
        }//O(NM) edges
        ahc: ;
        for (int i : adj[vc]){
        	long long kt = i*MUL + c;
            //pair<int,int> np = make_pair(i,c);
            if (dis.find(kt)==dis.end()) dis[kt]=dis[vc];
            else dis[kt]=min(dis[kt],dis[vc]);
            q.push_front(kt);
            //cout<<'b'<<endl;
        }
        //cout<<vc.first<<' '<<vc.second<<endl;
    }
    int an=1e9;
    for (auto tk : dis){
    	long long tv = tk.first/MUL;
    	int tt = tv;
        if(tt==n){
        	an = min(an,tk.second);
        } 
    }
    if(an==1e9)cout<<-1;
    else cout<<an;
}

Measured memory_bytes: 156288
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


class union_find_t {
public:
  union_find_t(int T) : T_(T), parent_(new int[T]), rank_(new int[T]) {
    for (int i = 0; i < T_; i++) {
      parent_[i] = i;
      rank_  [i] = 0;
    }
  };

  ~union_find_t() {
    delete[] parent_;
    delete[] rank_;
  };

public:
  int find(int x) {
    if (parent_[x] == x) {
      return x;
    }
    else {
      return parent_[x] = find(parent_[x]);
    }
  };

  void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y)
      return;

    if (rank_[x] < rank_[y]) {
      parent_[x] = y;
    }
    else {
      parent_[y] = x;

      if (rank_[x] == rank_[y])
        rank_[x] ++;
    }
  };

  bool same(int x, int y) {
    return find(x) == find(y);
  };

public:
  int T_;

  int* parent_;
  int* rank_;
};


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, M, a[111111], x, y;

  std::cin >> N >> M;

  for (int i = 0; i < N; i ++)
    std::cin >> a[i];

  union_find_t uf(N);

  for (int i = 0; i < M; i ++) {
    std::cin >> x >> y;

    x --;
    y --;

    uf.unite(x, y);
  }

  for (int i = 0; i < N; i ++)
    uf.find(i);

  std::map<int, std::vector<int>> map;
  
  for (int i = 0; i < N; i ++)
    map[uf.find(i)].push_back(i);

  int C = 0;

  for (const auto& kv : map) {
    std::vector<int> b, c;

    for (int i = 0, size = kv.second.size(); i < size; i ++)
      b.push_back(a[kv.second[i]] - 1);

    std::sort(ALL(b));

    std::set_intersection(ALL(kv.second), ALL(b), std::back_inserter(c));

    C += c.size();
  }

  std::cout << C << std::endl;

  return 0;
}


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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            if (k == 1)
            {
                Console.WriteLine("0");
            }
            else
            {
                // 残り
                int x = n - k;
                Console.WriteLine(x);
            }
        }
    }
}

Measured memory_bytes: 11092
import sys
input = sys.stdin.readline
import numpy as np

n, k = map(int, input().split())
A = list(map(int, input().split()))
dp = np.zeros(k, dtype=np.int64)
dp[0] = 1
for i in range(n):
  a = A[i]
  dp[a:] += dp.copy()[:-a]

ans = 0
for i in range(n):
  a = A[i]
  for j in range(max(0, k-a), k):
    temp = dp[j::-a*2].sum()
    if j >= a:
      temp -= dp[j-a::-a*2].sum()
    if temp:
      break
  else:
    ans += 1
print(ans)

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

int main(){
    using namespace std;
    int N; cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) cin >> v[i];

    int cnt = 0;
    for (int i = 0; i < N-2; i++)
    {
        if((v[i] < v[i+1] && v[i+1] < v[i+2]) || (v[i] > v[i+1] && v[i+1] > v[i+2])) cnt++;
    }
    cout << cnt << endl;
}


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

int dp[200][1<<16],mask[200];
int l[200];
int main(){
	int n;
	while(scanf("%d",&n),n){
		memset(dp,0,sizeof(dp));
		memset(mask,0,sizeof(mask));
		rep(i,n){
			int m;scanf("%d%d",&m,&l[i]);
			rep(k,m){
				int s,e;scanf("%d%d",&s,&e);s-=6;e-=6;
				for(int j=s;j<e;j++)mask[i]|=1<<j;
			}
		}
		rep(i,n)rep(j,1<<16){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(!(j&mask[i]))dp[i+1][j|mask[i]]=max(dp[i+1][j|mask[i]],dp[i][j]+l[i]);
		}
		int Max=0;
		rep(i,1<<16){
			Max=max(Max,dp[n][i]);
		}
		printf("%d\n",Max);
	}
}

Measured memory_bytes: 54304
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    string S; cin>>S;
    if(S=="SUN") Out("7");
    if(S=="MON") Out("6");
    if(S=="TUE") Out("5");
    if(S=="WED") Out("4");
    if(S=="THU") Out("3");
    if(S=="FRI") Out("2");
    if(S=="SAT") Out("1");
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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



int main()
{
	ll sum = 0;
	int n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n){
		cin>>a[i];
		sum = (sum^a[i]);
	}
	rep(i,n){
		cout<<(sum^a[i])<<" ";
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 4340