akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////
/////////////////////////
//#include<bits/stdc++.h>
using namespace std;
#define Base1   101LL
#define Base2   10000079LL
#define Base3   10000103LL
#define MOD1    1000000007LL
#define MOD2    1000000009LL
#define MOD3    1000000021LL
#define mx 100000//Number of charter of main string
#define mx1 25000// Number off character of total charcater
#define mx2 500// Number of pattern and number of ch of each pattern
 
 int main(){
     int n;
     I(n);
     string s;
     cin>>s;
     int res=0;
     for(int i=0;i<s.size()-2;i++){
         if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')res++;
     }
     cout<<res<<endl;

     return 0;
 }

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

const int N = 2e5 + 9;
const long long inf = 1e16;
long long a[N];
struct ST {
    #define lc (n << 1)
    #define rc ((n << 1) | 1)
    long long t[4 * N], lazy[4 * N];
    ST() {
        for (int i = 0; i < 4 * N; i++) t[i] = inf;
        memset(lazy, 0, sizeof lazy);
    }
    inline void push(int n, int b, int e) {
        if (lazy[n] == 0) return;
        t[n] = t[n] + lazy[n];
        if (b != e) {
            lazy[lc] = lazy[lc] + lazy[n];
            lazy[rc] = lazy[rc] + lazy[n];
        }
        lazy[n] = 0;
    }
    inline long long combine(long long a,long long b) {
        return min(a, b);
    }
    inline void pull(int n) {
        t[n] = min(t[lc], t[rc]);
    }
    void build(int n, int b, int e, int k) {
        lazy[n] = 0;
        if (b == e) {
            t[n] = a[b] + k * b;
            return;
        }
        int mid = (b + e) >> 1;
        build(lc, b, mid, k);
        build(rc, mid + 1, e, k);
        pull(n);
    }
    void upd(int n, int b, int e, int i, int j, long long v) {
        push(n, b, e);
        if (j < b || e < i) return;
        if (i <= b && e <= j) {
            lazy[n] = v;
            push(n, b, e);
            return;
        }
        int mid = (b + e) >> 1;
        upd(lc, b, mid, i, j, v);
        upd(rc, mid + 1, e, i, j, v);
        pull(n);
    }    
    void set(int n, int b, int e, int i, int j, long long v) {
        push(n, b, e);
        if (j < b || e < i) return;
        if (i <= b && e <= j) {
            t[n] = v;
            return;
        }
        int mid = (b + e) >> 1;
        set(lc, b, mid, i, j, v);
        set(rc, mid + 1, e, i, j, v);
        pull(n);
    }
    long long query(int n, int b, int e, int i, int j) {
        push(n, b, e);
        if (i > e || b > j) return inf + inf;
        if (i <= b && e <= j) return t[n];
        int mid = (b + e) >> 1;
        return combine(query(lc, b, mid, i, j), query(rc, mid + 1, e, i, j));
    }
}t1, t2;
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, q, x, y; cin >> n >> q >> x >> y;
	int last = y;
	for (int i = 1; i <= n; i++) a[i] = inf;
	a[x] = 0;
	t1.build(1, 1, n, 1);
	t2.build(1, 1, n, -1);
	while (q--) {
		int x; cin >> x;
		long long z = min(t2.query(1, 1, n, 1, x) + x, 
			t1.query(1, 1, n, x, n) - x);
		long long p1 = t1.query(1, 1, n, last, last) - last;
		long long p2 = t2.query(1, 1, n, last, last) + last;
		if (last > 1) t1.upd(1, 1, n, 1, last - 1, abs(x - last));
		if (last < n) t1.upd(1, 1, n, last + 1, n, abs(x - last));
		if (last > 1) t2.upd(1, 1, n, 1, last - 1, abs(x - last));
		if (last < n) t2.upd(1, 1, n, last + 1, n, abs(x - last));
		t1.set(1, 1, n, last, last, min(z, p1 + abs(x - last)) + last);
		t2.set(1, 1, n, last, last, min(z, p2 + abs(x - last)) - last);
		last = x;
	}
	long long ans = inf;
	for (int i = 1; i <= n; i++) {
		ans = min(ans, t1.query(1, 1, n, i, i) - i);
		ans = min(ans, t2.query(1, 1, n, i, i) + i);
	}
	cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 30092
#include <stdio.h>

int main(void)
{
  int n, r, cnt = 0, max = 0;
  
  scanf("%d%d", &n, &r);
  for (int i = 1; i < n; i++) {
    int h;
    scanf("%d", &h);
    if (r >= h) {
      cnt++;
      if(max < cnt)
        max = cnt;
    } else {
      cnt = 0;
    }
    r = h;
  }
  
  printf("%d", max);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int a,b;
    cin>>a>>b;
    if ( a >= 13 ){
        cout<<b<<endl;
    }
    else if ( a < 13 && a > 5 ){
        cout<<b/2<<endl;
    }
    else{
        cout<<"0"<<endl;
    }
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n[4];
int main(){
    cin>>n[0]>>n[1]>>n[2]>>n[3];
  
    sort(n, n+4);
    if(n[0]==1 && n[1]==4 && n[2]==7 && n[3]==9) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a, b, c, d = 0;
	scanf("%d %d %d",&a, &b, &c);
	for(int i=a;i<=b;i++)
	{
		if(c%i==0)
		{
			d++;	
		}
	}
	printf("%d\n",d);
	return 0;
}


Measured memory_bytes: 2092
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin>>n,n){
    ll w,h;
    cin>>w>>h;
    bool hoge[w+10][h+10]={};
    for(int i=0;i<n;i++){
      ll a,b;cin>>a>>b;
      hoge[--a][--b]=true;
    }
    ll s,t;cin>>s>>t;
    ll ans=0;
    for(int i=0;i<=w-s;i++){
      for(int j=0;j<=h-t;j++){
	ll cnt=0;
	for(int ii=i;ii<i+s;ii++){
	  for(int jj=j;jj<j+t;jj++){
	    cnt+=hoge[ii][jj];
	  }
	}
	ans=max(ans,cnt);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



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

int main(){
    string S;
    cin >> S;
    if(S[5]=='1'){
        cout << "TBD";
    }
    else if(S[6]>'4'){
        cout << "TBD";
    }
    else{
        cout << "Heisei";
    }
    cout << endl;
}

Measured memory_bytes: 256
import sys

n, m = map(int, input().split())
links = [set() for _ in range(n)]
counts = [0] * n
for line in sys.stdin:
    s, t = map(int, line.split())
    s -= 1
    t -= 1
    links[s].add(t)
    counts[s] += 1

# Expected number of edges passing from i to N
expected = [0.] * n
exp_get = expected.__getitem__

# i から伸びる辺を1本消すことで削減できる"iからNまでの辺数の期待値"の最大量
reducible = [0.] * n

for i in range(n - 2, -1, -1):
    nxt_exp = list(map(exp_get, links[i]))
    sum_exp = sum(nxt_exp)
    cnt = counts[i]

    expected[i] = sum_exp / cnt + 1

    if cnt > 1:
        reduced_exp = (sum_exp - max(nxt_exp)) / (cnt - 1) + 1
        reducible[i] = expected[i] - reduced_exp
    else:
        reducible[i] = 0.

# Probability of visiting i when starting from 1
probability = [0.] * n
probability[0] = 1.

for i in range(n - 1):
    jp = probability[i] / counts[i]
    for j in links[i]:
        probability[j] += jp

print(expected[0] - max(p * r for p, r in zip(probability, reducible)))


Measured memory_bytes: 21248
import Data.List

main = do
  n <- readLn
  xs <- fmap (map read . words) getLine
  mapM_ print (solve n xs)


solve :: Int -> [Int] -> [Int]
solve n xs =
  [m | x <- xs, let m = if x <= m1 then m2 else m1]
  where
    ys = sort xs
    m1 = ys!!(n`div`2-1)
    m2 = ys!!(n`div`2)

Measured memory_bytes: 102140
#!/usr/bin/env python3


def solve(N, M, C, B, A):
    ans = 0
    for Ai in A:
        if sum(Aij * Bi for Aij, Bi in zip(Ai, B)) + C > 0:
            ans += 1
    return ans


if __name__ == '__main__':
    N, M, C = map(int, input().split())
    B = list(map(int, input().split()))
    A = []
    for _ in range(N):
        Ai = list(map(int, input().split()))
        A.append(Ai)

    ans = solve(N, M, C, B, A)
    print(ans)


Measured memory_bytes: 3064
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=1005;
const int maxm=20005;
int n,w[maxn],s[maxn],v[maxn],p[maxn];
ll dp[maxn][maxm],mx[maxm];

bool cmp(int a,int b){
	return w[a]+s[a]<w[b]+s[b];
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	REP(i,n)scanf("%d%d%d",&w[i],&s[i],&v[i]),p[i]=i;
	sort(p+1,p+1+n,cmp);
	REP(i,20000)mx[i]=-Inf;
	mx[0]=0;
	ll ans=0;
	REP(i,n){
		int x=p[i];
		for(int j=w[x];j<=20000;j++){
			if(j-w[x]<=s[x]&&mx[j-w[x]]>=0)dp[i][j]=mx[j-w[x]]+v[x];
			ans=max(ans,dp[i][j]);
		}
		for(int j=w[x];j<=20000;j++)
			mx[j]=max(mx[j],dp[i][j]);
	}
	printf("%lld\n",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 154624
import functools
import fractions
MOD = 10**9+7


def sieve(n):
    result = [0] * (n+1)
    result[0] = result[1] = -1
    #primes = []
    for i in range(2, n+1):
        if(result[i]):
            continue
        # primes.append(i)
        result[i] = i
        for j in range(i*i, n+1, i):
            if not result[j]:
                result[j] = i
    return result


def is_prime(table, x):
    return table[x] == x


def factor(table, x):
    result = {}
    while(x != 1):
        p = str(table[x])
        if p not in result:
            result[p] = 1
        else:
            result[p] += 1
        x //= int(p)
    return result


def main():
    n = int(input())
    x = list(map(int, input().split()))

    table = sieve(10**6)
    max_table = {}
    for i in range(n):
        f = factor(table, x[i])
        for j in f:
            if j not in max_table:
                max_table[j] = f[j]
            else:
                max_table[j] = max(max_table[j], f[j])

    lcm = 1
    for p in max_table:
        lcm *= int(p)**max_table[p] % MOD

    ans = 0
    for i in range(n):
        ans += lcm//x[i]
    print(ans % MOD)


main()


Measured memory_bytes: 16868
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n = int(input())
xd = []
# Add sentinel
places = [(10**12, 0)]
for _ in range(n):
    x, d = [int(item) for item in input().split()]
    xd.append((x, d))

xd.sort(reverse=True)
dp = [0] * (n + 1)
dp[0] = 1
for i, (x, d) in enumerate(xd):
    frm = x
    too = x + d 
    too_idx = i
    while too > places[-1][0]:
        _, too_idx = places.pop()
    places.append((frm, too_idx))
    dp[i + 1] = dp[i] + dp[too_idx]
    dp[i + 1] %= MOD

print(dp[-1])

Measured memory_bytes: 48108
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FOR_EACH(i, v) for (auto&& i : v)

class Edge {
public:
	int to;
	int a;
	int b;

	Edge(int to_, int a_, int b_)
	{
		to = to_;
		a = a_;
		b = b_;
	}
};

void dijkstra(int vertexNum, vector<list<Edge>>& edge, int start, vector<long long>& distance, bool type)
{
	priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pQueue;
	FOR(i, vertexNum) {
		distance[i] = -1LL;
	}
	distance[start] = 0LL;

	pQueue.push(make_pair(0LL, start));
	while (!pQueue.empty()) {
		pair<long long, int> p = pQueue.top();
		pQueue.pop();
		if (distance[p.second] != -1LL && distance[p.second] < p.first) {
			continue;
		}

		for (list<Edge>::iterator it = edge[p.second].begin(); it != edge[p.second].end(); it++) {
			int cost = type ? it->a : it->b;

			if (distance[it->to] == -1LL || distance[it->to] > distance[p.second] + cost) {
				distance[it->to] = distance[p.second] + cost;
				pQueue.push(make_pair(distance[it->to], it->to));
			}
		}
	}
}

const long long INITIAL_YEN = 1000000000000000LL;
int n;
int m;
int s;
int t;

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

	cin >> n >> m >> s >> t;
	vector<list<Edge>> edge(n);
	vector<long long> distanceA(n);
	vector<long long> distanceB(n);
	FOR(i, m) {
		int u;
		int v;
		int a;
		int b;
		cin >> u >> v >> a >> b;
		edge[u - 1].push_back(Edge(v - 1, a, b));
		edge[v - 1].push_back(Edge(u - 1, a, b));
	}

	dijkstra(n, edge, s - 1, distanceA, true);
	dijkstra(n, edge, t - 1, distanceB, false);

	list<long long> ans;
	ans.push_back(distanceA[n - 1] + distanceB[n - 1]);
	FOR(i, n - 1) {
		ans.push_back(min(ans.back(), distanceA[n - i - 2] + distanceB[n - i - 2]));
	}

	for (list<long long>::reverse_iterator it = ans.rbegin(); it != ans.rend(); it++) {
		cout << INITIAL_YEN - *it << ENDL;
	}

	return 0;
}

Measured memory_bytes: 19540
#include <bits/stdc++.h>
#define N 10
using namespace std;
int main() {
  long long c[N][N], H, W, A, answer = 0;
  cin >> H >> W;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> c[i][j];
    }
  }
  long long C[N][N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      C[i][j] = c[i][j];
    }
  }
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        C[i][j] = min(C[i][j],C[i][k]+C[k][j]);
      }
    }
  }
  while (H--) {
    for (int w = 0; w < W; w++) {
      cin >> A;
      if (A != -1) {
        long long cost = C[A][1];
        for (int i = 0; i < N; i++) {
          cost = min(cost,C[A][i]+C[i][1]);
        }
        answer += cost;
      }
    }
  }
  cout << answer;
}

Measured memory_bytes: 3608
open Batteries
open Printf
let () =
  let n = Scanf.scanf "%d " (fun a -> a) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let ma = List.max a_lst in
  let mi = List.min a_lst in

  Printf.printf "%d\n" @@
  ma - mi


Measured memory_bytes: 1152
import java.util.*;

import java.io.*;
 
public class Main{

    public static int stringToInt(char i, int[] a){
        if(i == 'A') return a[0];
        if(i == 'B') return a[1];
        if(i == 'C') return a[2];
        return 0;
    }
 
	public static void main(String[] $){
		Scanner s = new Scanner(System.in);
        String S = s.next();
        for(int i = 0; i < S.length(); i++){
            System.out.print("x");
        }
        System.out.println();
        
	}
} 

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

    int  main(void) {
        string S;
        cin >> S;

        unordered_map<char, int > map;
        map['N'] = 0;
        map['W'] = 0;
        map['E'] = 0;
        map['S'] = 0;

        int l;
        l = S.length();
        for (int i = 0; i < l; i++)
            map[S[i]]++;

        bool nsflag = false;
        bool ewflag = false;
        string ret = "No";

        if(map['N']+map['S'] == 0 || map['N']*map['S'] != 0)
            nsflag = true;
        if(map['E']+map['W'] == 0 || map['W']*map['E'] != 0)
            ewflag = true;
        if(ewflag && nsflag)
            ret = "Yes";
        cout << ret << endl;
        
        return 0;
    }


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

int main() {
    int N; cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H.at(i);
    }
    int j = 0, cnt = 0, M = 0;
    
    for (int i = 1; i < N; i++) {
        if (H.at(i) <= H.at(j)) {
            cnt++;
            M = max(M, cnt);
        }
        else {
            cnt = 0;
        }
        j++;
    }
    cout << M << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()

int main() {
   int a,b;
   cin >> a >> b;
   cout << (b-a)*(1+b-a)/2-b << endl;
}

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

int main()
{
  string s;

  cin >> s;
  if(s.size() == 3){
    cout << s[2] << s[1] << s[0] << endl;
    return 0;
  }
  else cout << s << endl;
  return 0;
}

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

const int INF = (int)1e9;

signed main(void)
{
	int n, cnt, ans[26]; cin >> n;
	string s[n];
	string alpha = "abcdefghijklmnopqrstuvwxyz";

	rep(i, 26) ans[i] = INF;
	rep(i, n) cin >> s[i];
	rep(k, 26)
	{
		rep(j, n)
		{	
			cnt = 0;
			rep(i, s[j].size())
			{
				if (alpha[k] == s[j][i])
					cnt++;
			}
			ans[k] = min(ans[k], cnt);
		}
	}
	rep(i, 26)
		rep(j, ans[i])
			cout << alpha[i];
	cout << endl;
	return 0;
}


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

char s[2000];  // scan
char w[2000];     // word
int i,j,len,f=0;

void judge(){
  int lng=strlen(w);  // word length
  
  if(lng>=3&&lng<=6){  // 3<=lng<=6
    if(f)
      printf(" ");
    printf("%s",w);  // print
    f++;
  }
}

int alpha(char abc){

  if(abc==' '||abc=='.'||abc==',')  // cut
    return 0;
  else
    return 1;
}

void pick(){
  
  j=0;  // init (w:index)
  
  // scan -> word
  for(i=0;i<len;i++){
    if(alpha(s[i])){
      w[j++]=s[i];   // copy
      if(i==len-1){  // true word
	w[j]='\0';   // final charactor
	judge();     // print
	j=0;         // init
      }
    }
    else{         // false(cut) word
      w[j]='\0';
      judge();
      j=0;
    }
  }
}

int main(){
  
  while(scanf("%s",s)!=EOF){
    len=strlen(s);
    pick();
  }
  puts("");
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF 1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    int n;
    int w;
    int h;
    cin >> n >> w >> h;
    VI ew(w + 1, 0);
    VI sn(h + 1, 0);
    for (int i = 0; i < n; i++ ) {
        int x;
        int y;
        int iw;
        cin >> x >> y >> iw;
        int x_start = x - iw;
        if (x_start < 0) {
            x_start = 0;
        }
        int x_end = x + iw;
        if (x_end > w) {
            x_end = w;
        }
        int y_start = y - iw;
        if (y_start < 0) {
            y_start = 0;
        }
        int y_end = y + iw;
        if (y_end > h) {
            y_end = h;
        }
        /*
        for (int i = x_start; i <= x_end; i++) {
            ew[i]++;
        }
        for (int i = y_start; i <= y_end; i++) {
            sn[i]++;
        }
        */
        ew[x_start]++;
        ew[x_end]--;
        sn[y_start]++;
        sn[y_end]--;
        /*
           for (int i = 0; i < w; i++) {
           cout << ew[i] << " ";
           }
           cout << endl;
           for (int i = 0; i < h; i++) {
           cout << sn[i] << " ";
           }
           cout << endl;
        */
    }

    for (int i = 1; i < w; i++) {
        ew[i] += ew[i - 1];
    }
    for (int i = 1; i < h; i++) {
        sn[i] += sn[i - 1];
    }

    bool xcheck = true;
    bool ycheck = true;
    for (int i = 0; i < w; i++) {
        if (ew[i] == 0) {
            xcheck = false;
        }
    }
    for (int i = 0; i < h; i++) {
        if (sn[i] == 0) {
            ycheck = false;
        }
    }
    if (xcheck == true || ycheck == true) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long
int n,l,r,r1,l1,a[100001],b[100001],f;
main(){
  cin>>n;
  n*=2;
  int a[n];
  r(i,n)cin>>a[i];
  sort(a,a+n);
  int ans=0;
  for(int i=0;i<n-1;i+=2){
    ans+=a[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
using namespace std ;

int main() {
	int tot[3] = {0}, x, n ;
	scanf("%d", &n) ;
	rep(i, 1, n) {
		scanf("%d", &x) ;
		if (x % 2) {
			++ tot[0] ;
		} else
		if (x % 4) {
			++ tot[1] ;
		} else ++ tot[2] ;
	}
	if (tot[1]) {
		if (tot[2] >= tot[0]) printf("Yes\n") ; 
			else printf("No\n") ;
	} else {
		if (tot[2] >= tot[0] - 1) printf("Yes\n") ; 
			else printf("No\n") ;
	}
	return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MOD=1e9+7;
static const ll MAX=101010;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/




int main(void) {
  ll i, j, k;
  
  ll H, W, K;
  cin >> H >> W >> K;
  string s[15];
  
  for(i=1; i<=H; i++) {
    cin >> s[i];
    s[i]='.'+s[i];
  }
  
  ll cnt[15][1111]={};
  for(i=1; i<=H; i++) for(j=1; j<=W; j++) cnt[i][j]=cnt[i][j-1]+(s[i][j]=='1');
  for(j=1; j<=W; j++) for(i=1; i<=H; i++) cnt[i][j]+=cnt[i-1][j];
  
  ll ans=INF;
  for(ll S=0; S<1<<(H-1); S++) {
    ll t=0;
    vector<ll> v;
    v.push_back(0);
    for(i=0; i<H-1; i++) {
      if(S>>i&1) {
        t++;
        v.push_back(i+1);
      }
    }
    v.push_back(H);
    
    ll tc[15][1111]={};
    for(i=1; i<v.size(); i++) {
      for(j=1; j<=W; j++) {
        tc[v[i]][j]=cnt[v[i]][j]-cnt[v[i-1]][j];
      }
      tc[v[i]][W+1]=INF;
    }
    
    ll ma=0;
    for(i=1; i<v.size(); i++) for(j=1; j<=W; j++) chmax(ma, tc[v[i]][j]-tc[v[i]][j-1]);
    if(ma>K) continue;
    
    ll p=0;
    while(1) {
      ll mi=INF;
      for(i=1; i<v.size(); i++) {
        ll u=v[i];
        ll itr=upper_bound(tc[u], tc[u]+W+2, K+tc[u][p])-tc[u];
        itr--;
        chmin(mi, itr);
      }
      
      if(mi>=W) break;
      
      t++;
      p=mi;
    }
    
    chmin(ans, t);
    
  }
  
  pt(ans);
  
}




Measured memory_bytes: 512
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef double d;
int main()
{
    string s;
    cin>>s;
    ll c=0;
    for(ll i=0;i<3;i++)
    {
        if(s[i]=='o')
        {
            c++;
        }
    }
    ll ans=700+c*100;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int a, b;
    cin >> a >> b;

    cout << (a < 10 && b < 10 ? a * b : -1) << "\n";
    return 0;
}

Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64)(k:i64));
    f(n, 1, k).to_string()
}

fn f(n: i64, x: i64, k: i64) -> i64 {
    if n == 0 {
        x
    } else {
        std::cmp::min(f(n - 1, x * 2, k), f(n - 1, x + k, k))
    }
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "4\n3" => "10",
    test2: "10\n10" => "76",
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<bitset>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

int main(){
  int n;
  cin >> n;
  long long a[n];
  for(int i=0; i < n; i++){
    cin >> a[i];
  }
  long long maxv = -1000000000, minv = a[0];
  for(int i = 1; i < n; i++){
    maxv = max(maxv, a[i] - minv);
    minv = min(minv, a[i]);
  }
  cout << maxv << endl;
  return 0;
}


Measured memory_bytes: 4656
N = int(input())
W = []
for i in range(N):
    W.append(input())

from collections import Counter
counter = Counter(W).most_common()

Ans = "Yes"
if counter[0][1]>1:
    Ans = "No"
else:
    for i in range(N-1):
        if W[i][-1] != W[i+1][0]:
            Ans = "No"

print(Ans) 


Measured memory_bytes: 3436
y,m,d = map(int,input().split('/'))

if y<2019:
    print('Heisei')
elif 2019<y:
    print('TBD')
else:
    if m<4:
        print('Heisei')
    elif 4<m:
        print('TBD')
    else:  
        if d<=30:
            print('Heisei')
        else:
            print('TBD')


Measured memory_bytes: 2940
from itertools import combinations
N,K=map(int,input().split())
M=(N-1)*(N-2)//2
if K>M:
  print(-1);exit()

print( N-1+M-K )
for i in range(2,N+1):
  print(1,i)

for i,a in enumerate( list(combinations(range(2, N+1), 2)) ):
  if i==M-K:
    break
  print(*a)
  
  

Measured memory_bytes: 42992
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;


int main()
{
	int N, K, R, S, P;
	string T;
	cin >> N >> K >> R >> S >> P >> T;
	int ans = 0;
	string L = "";
	for (int i = 0; i < N; i++) {
		if (i - K >= 0) {
			if (T[i] == 'r' && L[i - K] != 'p') {
				ans += P;
				L += 'p';
			}
			else if (T[i] == 's' && L[i - K] != 'r') {
				ans += R;
				L += 'r';
			}
			else if (T[i] == 'p' && L[i - K] != 's') {
				ans += S;
				L += 's';
			}
			else {
				L += '.';
			}
		}
		else {
			if (T[i] == 'r') {
				ans += P;
				L += 'p';
			}
			if (T[i] == 's') {
				ans += R;
				L += 'r';
			}
			if (T[i] == 'p') {
				ans += S;
				L += 's';
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3744
//boom diggy diggy boom boom
/*
freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      */
#include<bits/stdc++.h>
#define ull unsigned long long int 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define ll long long 
#define ld long double 

int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n,int r){int res=1;if(r>n-r)r=n-r;for(int i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}int max(int a,int b){int ans=a>b?a:b;return ans;}

using namespace std;

int main()
{
   int n;
   cin>>n;
   double dp[n+1]={};

   dp[0]=1;
   for (int i = 0; i < n; ++i)
   {
    double p;
       cin>>p;
     for (int j = i+1; j >=0 ; --j)
     {
       dp[j]=(j==0 ? 0 : dp[j-1]*p) + dp[j]*(1-p);
     }
   }
   double ans=0;
   for (int i = n/2+1; i <= n; ++i)
   {
     ans+=dp[i];
   }
   cout<<setprecision(10)<<ans;
return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

namespace ABC123A
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var point = new int[5];
            point[0] = int.Parse(Console.ReadLine());
            point[1] = int.Parse(Console.ReadLine());
            point[2] = int.Parse(Console.ReadLine());
            point[3] = int.Parse(Console.ReadLine());
            point[4] = int.Parse(Console.ReadLine());
            var k = int.Parse(Console.ReadLine());

            for (int i = 0; i < point.Length - 1; i++)
            {
                if (point[i + 1] - point[0] > k)
                {
                    Console.WriteLine(":(");
                    return;
                }
            }

            Console.WriteLine("Yay!");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;
typedef pair<ll,ll> P;



int main(){
    ll a,b,c;cin>>a>>b>>c;
    ll k;cin>>k;
    while(a>=b&&k){
        b*=2;
        k--;
    }
    while(b>=c&&k){
        c*=2;
        k--;
    }
    if(a<b&&b<c){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

    









Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

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

    solution();

    return 0;
}

void solution()
{
  int x;
  cin >>x;
  x == 1 ? cout << 0 : cout << 1;
}

Measured memory_bytes: 3636
import sys
from collections import deque
def input():
    return sys.stdin.readline()[:-1]
A = input()

total = 0
total_each = deque()
S1 = deque()
S2 = deque()
for j,a in enumerate(A):
    #print('j = {}, S2 = {}'.format(j,S2))
    if a == '\\':
        S1.append(j)
    elif a=='/':
        try:
            i = S1.pop()
            val_new = j-i
            total += val_new
            
            if len(S2)==0:
                S2.append((i,val_new))
                continue
            
            while True:
                if len(S2)>0:
                    a,val = S2[-1]
                    if a<i:
                        S2.append((i, val_new))
                        break
                    elif i<a:
                        _ = S2.pop()
                        val_new = val + val_new
                else:
                    S2.append((i,val_new))
                    break
        except:
            pass
print(total)
ans = [len(S2)]
for _ in range(len(S2)):
    a,val = S2.popleft()
    ans.append(val)
print(*ans)


Measured memory_bytes: 6748
#include <cstdio>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;

typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int INF = 1e18;
const int M = 1e9 + 7;
//__int128


signed main()
{
#ifndef ONLINE_JUDGE
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int s;
    cin >> s;
    int x1 = (int)(sqrt(s)), y2 = x1;
    if(x1 * x1 < s) {
    	x1++; y2++;
    }
    if(x1 * x1 - x1 >= s) {
    	--y2;
    }
    int n = x1 * y2 - s;
    int x2 = 0, y1 = 0;
    if(n > 0) {
    	x2 = 1, y1 = 1;
    	int t = n;
	    for(int i = 2; i * i <= n; ++i) {
	    	while(t % i == 0) {
	    		t /= i;
	    		x2 * x2 < s ? x2 *= i : y1 *= i;
	    	} 
	    }
	    if(t > 1) {
	    	x2 * x2 < s ? x2 *= t : y1 *= t;
	    }
	}
	cout << 0 << ' ' << 0 << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 *
 * Author: r3gz3n
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <utility>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define ll long long


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


const int MAX = 1e5 + 5;
ll x[MAX];

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		int n;
		ll a, b, ans = 0;
		in >> n >> a >> b;
		rep(i, 0, n, 1) {
			in >> x[i];
			if (i > 0) {
				if (a*(x[i] - x[i-1]) < b) ans += a*(x[i] - x[i-1]);
				else ans += b;
			}
		}
		out << ans << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




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

using namespace std;

int main()
{
    string S;

    cin >> S;

    if (S[2] == S[3] && S[4] == S[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc095/tasks/abc095_a
# Ruby 1st Try

s1,s2,s3 = gets.chomp('\n').split('')
answer = 700
if s1 == 'o'
    answer = answer + 100
end
if s2 == 'o'
    answer = answer + 100
end
if s3 == 'o'
    answer = answer + 100
end

puts(answer)

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll h,w;
    cin>>h>>w;
    ll ans=h*w;
    if(h== 1 ||w== 1)
        cout<< 1 <<endl;
    else
        cout<<(ans+1)/2;
    return 0;
}


Measured memory_bytes: 3640
from collections import Counter, deque, defaultdict
n, k = map(int, input().split())
A = list(map(int, input().split()))
t = defaultdict(int)
for x in A:
    t[x]+=1
B = []
for x in t.values():
    B.append(x)
B.sort()
if(len(B)<=k):
    print(0)
    exit()
    
ans = 0
for i in range(0, len(B)):
    ans+=B[i]
    if len(B)-(i+1) <= k:
        break
print(ans)


Measured memory_bytes: 35156
#include <iostream>
int main(int argc, char *argv[])
{
    using namespace std;
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,h;
    cin >> a>>b>>h;
    cout << (a+b)*(h>>1) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define possible {cout << "POSSIBLE\n"; return 0;}
#define impossible {cout << "IMPOSSIBLE\n"; return 0;}

using namespace std;

const int Nmax = 2e5 + 5;
int n, i, x, go[Nmax], j, val[Nmax];
bool used[Nmax], active[Nmax];
vector<int> v[Nmax];

bool dfs(int node)
{
    if(active[node]) return 1;
    used[node] = 1;
    active[node] = 1;

    for(auto it : v[node])
        if(dfs(it)) return 1;

    active[node] = 0;
    return 0;
}

void grundy(int node)
{
    for(auto it : v[node])
        if(val[it] == -1) grundy(it);

    for(int i = 0; i <= v[node].size(); ++i) used[i] = 0;
    for(auto it : v[node]) used[val[it]] = 1;

    for(int i = 0; val[node] == -1; ++i)
        if(!used[i]) val[node] = i;
}

int main()
{
   // freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);
    cin.sync_with_stdio(false);

    cin >> n;
    for(i=1; i<=n; ++i)
    {
        cin >> x;
        v[x].push_back(i);
        val[i] = -1;
    }

    for(i=1; i<=n; ++i)
        if(!used[i]) dfs(i);

    for(i=1; i<=n; ++i)
        if(active[i])
            for(auto it : v[i])
                if(!active[it]) grundy(it);
                    else go[i] = it;

    for(i=1; i<=n; ++i)
        if(active[i])
        {
            for(j=0; j<v[i].size(); ++j) used[j] = 0;
            for(auto it : v[i])
                if(!active[it]) used[val[it]] = 1;

            for(j=0; ; ++j)
                if(!used[j]) break;
            val[i] = j;

            grundy(go[i]);
            if(val[go[i]] != val[i]) possible

            for(j=go[i]; j!=i; j = go[j]) val[j] = -1;

            ++val[i];
            grundy(go[i]);
            if(val[go[i]] == val[i] - 1) possible

            impossible
      }

    return 0;
}


Measured memory_bytes: 19968
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


string s;

int main(){
	cin >> s;
	
	bool b = 0,c = 0;
	if(!(s[0] <= '1') || (s[0] == '1' && s[1] >= '3') || (s[0] == '0' && s[1] == '0')){
		b = 1;
	}
	if(!(s[2] <= '1') || (s[2] == '1' && s[3] >= '3') || (s[2] == '0' && s[3] == '0')){
		c = 1;
	}
	
	if(b&&c) cout << "NA" << endl;
	else if(b) cout << "YYMM" << endl;
	else if(c) cout << "MMYY" << endl;
	else cout << "AMBIGUOUS" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   Int v, e;
   std::cin >> v >> e;
   std::vector<Int> ss(e), ts(e);
   rep(i, e) std::cin >> ss[i] >> ts[i];
   std::vector<std::vector<Int>> nexts(v);
   rep(i, e) {
      Int s = ss[i], t = ts[i];
      nexts[s].emplace_back(t);
   }
   std::vector<Int> xs(v, -1);
   Int id = 0;
   std::function<void(Int,Int)> dfs = [&](Int i, Int prev) {
      if( xs[i] != -1 ) return;
      xs[i] = -2;
      for(Int k : nexts[i]) {
         guard( k != prev );
         if( xs[k] == -1 ) {
            dfs(k, i);
         }
      }
      xs[i] = id; id += 1;
   };
   rep(i, v) dfs(i, -1);
   bool cycle = false;
   rep(i, e) {
      Int s = ss[i], t = ts[i];
      if( xs[s] < xs[t] ) cycle = true;
   }
   puts(cycle?"1":"0");
}



Measured memory_bytes: 3164
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define int ll
using namespace std;
const int N=1000100,P=1e9+7;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
ll sum;
int n,ans,a[N],ct;
signed main(){
	//freopen("1.out","w",stdout);
	int i,k;
	n=read();
	for(i=1;i<=n;i++)
		sum+=a[i]=read();
	if(sum%(1ll*n*(n+1)/2))goto fuck;
	k=sum/(1ll*n*(n+1)/2);a[n+1]=a[1];
	for(i=1;i<=n;i++){
		a[i]=a[i+1]-a[i]-k;
		a[i]=-a[i];
		if(a[i]<0)goto fuck;
		if(a[i]%n)goto fuck;
		ct+=a[i]/n;
	}
	if(ct!=k)goto fuck;
	puts("YES");
	return 0;fuck:puts("NO");;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
#define MAX (80 * 80 * 2 * 2)
#define BASE (MAX >> 1)
int main() {
	int h = ri(), w = ri();
	int a[h][w];
	for (auto &i : a) for (auto &j : i) j = ri();
	for (auto &i : a) for (auto &j : i) j -= ri();
	bool dp[h][w][MAX + 1];
	memset(dp, 0, sizeof(dp));
	dp[0][0][BASE + a[0][0]] = true;
	dp[0][0][BASE - a[0][0]] = true;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			for (int k = 0; k <= MAX; k++) {
				if (!dp[i][j][k]) continue;
				if (i + 1 < h) {
					dp[i + 1][j][k + a[i + 1][j]] = true;
					dp[i + 1][j][k - a[i + 1][j]] = true;
				}
				if (j + 1 < w) {
					dp[i][j + 1][k + a[i][j + 1]] = true;
					dp[i][j + 1][k - a[i][j + 1]] = true;
				}
			}
		}
	}
	int res = 1000000000;
	for (int i = 0; i <= MAX; i++) if (dp[h - 1][w - 1][i]) res = std::min(res, std::abs(i - BASE));
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 160256
import numpy as np
n,k=map(int,input().split())
a=np.array(list(map(int,input().split())))
a.sort()
p=a[a>0]
z=a[a==0]
m=a[a<0]
l=-10**18
r=10**18
while r-l>1:
  mid=(r+l)//2
  cnt=0
  if mid>=0:
    cnt+=len(z)*n
  cnt+=a.searchsorted(mid//p,side='right').sum()
  cnt+=(n-a.searchsorted(-(-mid//m),side='left')).sum()
  cnt-=np.count_nonzero(a*a<=mid)
  cnt//=2
  if cnt>=k:
    r=mid
  else:
    l=mid
print(r)

Measured memory_bytes: 32316
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
ll A = 'a';
ll Z = 'z';
void  solve(string key ,ll now,ll D) {
	if (now == N) {
		cout << key << endl;
	}
	else { 
		for (ll i = A; i <=A+D+1; i ++) {
			string origin = key;
			key += i;
			if (i == A+D+1) {
				solve(key, now + 1, D+1);
			}
			else {
				solve(key, now + 1, D);
			}
			key = origin;
		}
	}
}
int main() {
	cin >> N;
	solve("",0,-1);
}


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

int main() {
		
	// recieve |V| and |E|
	int V, E; 
    cin >> V >> E;
	vector<vector<pair<int, int>>> G(V);
	
	for(int i = 0; i < E; i++) {
		// recieve edges
		int u, v, d;
        cin >> u >> v >> d;
		u--; v--;
		G[u].push_back({v, d});
		G[v].push_back({u, d});
	}
	
	int Tmax;
    cin >> Tmax;

	// recieve info
	for(int i = 0; i < Tmax; i++) {
		int Nnew;
        cin >> Nnew;
		for(int j = 0; j < Nnew; j++) {
			int new_id, dst;
            cin >> new_id >> dst;
		}
	}

  // insert your code here to get more meaningful output
	// all stay
	for(int i = 0; i < Tmax; i++) cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256