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

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)
#define leng(n) (int)(log10(n)+1)


typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
Vi accum(Vi v){Vi ret((v).size());ret[0]=v[0];REP(i,1,(v).size()) ret[i]=ret[i-1]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

Vi yakusuu(int n){
    Vi ret;
    for(int i=1 ; i*i<=n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n/i);
        }
    }
    sort(ALL(ret));
    return ret;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
    int n,k;
    cin>>n>>k;
    Vi a(n);
    REP(i,0,n) cin>>a[i];

    int sum=0;
    REP(i,0,n) sum+=a[i];

    Vi yaku=yakusuu(sum);
    reverse(ALL(yaku));

    int ans=1;
    REP(i,0,yaku.size()){
        int d=yaku[i];
        Vi b(n);
        REP(i,0,n){
            b[i]=a[i]%d;
        }
        sort(ALL(b));
        Vi sumb1(n),sumb2(n);
        sumb1[0]=b[0];
        REP(i,1,n){
            sumb1[i]=sumb1[i-1]+b[i];
        }
        sumb2[n-1]=d-b[n-1];
        REPR(i,n-2,-1){
            sumb2[i]=sumb2[i+1]+(d-b[i]);
        }
        int tmp;
        REP(i,0,n) if(sumb1[i]==sumb2[i+1]) tmp=sumb1[i];
        // cout<<d<<":"<<tmp<<endl;
        if(tmp<=k){
            chmax(ans,d);
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    int m=0;
    int c[101];
    foreach(s;stdin.byLine())
        m=max(m,++c[s.to!int()]);
    foreach(i,v;c)
        if(v==m)
            writeln(i);
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.1415926535897932;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int n;
vector<pi> ans;

int main() {
    cin >> n;
    if (n%2 == 0) {
        rep(i,n) {
            for (int j = i+1; j < n; j++) {
                if (i == j) continue;
                if (i+j == n-1) continue;
                ans.push_back(pi(i+1,j+1));
            }
        }
    } else {
        rep(i,n-1) {
            for (int j = i+1; j < n-1; j++) {
                if (i == j) continue;
                if (i+j == n-2) continue;
                ans.push_back(pi(i+1,j+1));
            }
        }
        rep(i,n-1) ans.push_back(pi(i+1,n));
    }
    cout << ans.size() << endl;
    rep(i,ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    ll A, B, C;
    cin >> N >> A >> B >> C;
    vector<ll> D(N);
    for (int i = 0; i < N; i++) {
        cin >> D[i];
    }
    sort(D.begin(), D.end(), greater<ll>());
    ll ans = 0;
    ll s = 0;
    for (int i = 0; i < N; i++) {
        s += D[i];
        ans = max(ans, (C + s) / (A + (i + 1) * B));
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3164
#include<cstdio>
#include<algorithm>
using namespace std;

int N;
int A[100];

void SelectionSort(){
	int cnt = 0;
	for(int i = 0; i < N; i++){
		int mini = i;
		for(int j = i; j < N; j++){
			if(A[j] < A[mini]){
				mini = j;
			}
		}
		if(i != mini){
			swap(A[i], A[mini]);
			cnt++;
		}
	}
	for(int i = 0; i < N; i++){
		printf("%d", A[i]);
		if(i == N - 1) printf("\n");
		else printf(" ");
	}
	printf("%d\n", cnt);
}

int main(void){
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &A[i]);
	}
	SelectionSort();
	return 0;
}

Measured memory_bytes: 2712
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define badi_val 1000000007
int n;
int pd[1100];
const long long mod=1e9+7;
int main(){
	long long n;
  	cin >> n;
  	long long ans = 1;
 	for(int i = 1 ; i <= n ;i++){
      ans = (ans * i) % mod;
    }
  	cout << ans%mod << endl;
 	return 0; 
 	return 0; 
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
 
public class Main {
    public static void main(String[] args) {

        Scanner sc  = new Scanner(System.in);

     
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        int C = Integer.parseInt(sc.next());

        int sum = 0;
        int flag = 0;
       
        for(int i=0;i<100;i++){
            sum += A;
            
            if(sum%B==C)flag++;
            
        }
            
        if(flag > 0) System.out.print("YES");
        else System.out.print("NO");
            

        System.out.println();
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 101;

int n, cnt[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    int mn = n, mx = 0;
    for(int i = 0 ; i < n ; i++){
        int x;
        cin >> x;
        cnt[x]++;
        mn = min(mn, x);
        mx = max(mx, x);
    }
    if(mn != (mx + 1) / 2) finish("Impossible");
    if(mx % 2 == 0 && cnt[mn] != 1) finish("Impossible");
    if(mx % 2 && cnt[mn] != 2) finish("Impossible");
    for(int i = mn ; i <= mx ; i++){
        if(cnt[i] == 0) finish("Impossible");
    }
    cout << "Possible" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007LL
typedef long long ll;

int n;
ll dp[21][51][51][28];
string str[51];

ll solve(int v,int f,int t,int lb){
	if(dp[v][f][t][lb]!=-1)return dp[v][f][t][lb];
	if(f==t)return 1;
	if(str[f].size()==v){
		if(lb==0){
			return solve(v,f+1,t,lb+1);
		}
		else return 0;
	}
	for(int i=f+1;i<t;i++){
		if(str[i].size()==v)return 0;
	}
	ll ans=0;
	for(int i=max(lb,1);i<27;i++){
		for(int j=f;j<t;j++){
			if(str[j][v]!='?' && (str[j][v]-'a')!=(i-1))break;
			ans+=solve(v+1,f,j+1,0)*solve(v,j+1,t,i+1)%MOD;
			ans%=MOD;
		}
	}
	dp[v][f][t][lb]=ans;
	return ans;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >> str[i];
	}
	memset(dp,-1,sizeof(dp));
	printf("%lld\n",solve(0,0,n,0));
	return 0;
}

Measured memory_bytes: 15264
#include <bits/stdc++.h>
#include <map>
#include <string>

using namespace std;

int main()
{
	int N;
	cin >> N;

	map<string, int> m;
	for (int i = 0; i < N; i++)
	{
		string _s;
		cin >> _s;
		m[_s] += 1;
	}

	int max_v = 0;
	for (const auto& x : m)
	{
		int v = x.second;
		if (v > max_v) {
			max_v = v;
		}
	}

	for (auto it = m.begin(); it != m.end(); it++) {
		if (it->second == max_v) {
			cout << it->first << endl;
		}
	}
}


Measured memory_bytes: 25216
#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()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;
int main(){
	int n,m;
	std::cin >> n>>m;
	std::vector<int> b(m);
	rep(i,n){
		int k;
		std::cin >> k;
		std::vector<int> a(k);
		rep(j,k)std::cin >> a[j];
		rep(j,k)b[a[j]-1]++;
	}
	int counter=0;
	rep(i,m)if(b[i]==n)counter++;
	std::cout << counter << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>

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

using namespace std;

typedef long long int lli;

int main () {
    int n;
    while (cin >> n, n) {
        vector<string> v(n);
        REP (i, 0, n) {
            string str;
            cin >> str;
            string ans = str.substr(0, 1);
            REP (i, 0, str.size() - 1) {
                char c = str[i];
                if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
                    ans += str.substr(i + 1, 1);
                }
            }
            v[i] = ans;
        }
        int ans = -1;
        REP (k, 1, 60) {
            set<string> pre;
            REP (i, 0, n) pre.insert(v[i].substr(0, k));
            if ((int)pre.size() == n) ans = k;
            if (ans != -1) break;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3028
#include<stdio.h>
int main()
{
	int n,i,q,x,y,z,d=0;
	int a[120]={0},b[120]={0},c[120]={0};
	scanf("%d",&n);
	scanf("%d",&x);
	for(i=0;i<x;i++){
		scanf("%d",&q);
		a[q]=1;
	}
	scanf("%d",&y);
	for(i=0;i<y;i++){
		scanf("%d",&q);
		b[q]=1;
	}
	scanf("%d",&z);
	for(i=0;i<z;i++){
		scanf("%d",&q);
		c[q]=1;
	}
	for(i=0;i<=n;i++){
		if(a[i]==0&&c[i]==1||a[i]==1&&b[i]==1&&c[i]==1){
			d++;
		}
	}
	printf("%d\n",d);
	return 0;
}


Measured memory_bytes: 2112
def main():
    # parse
    N, i = parse()
    # compute
    result = compute(N, i)
    # show result
    print(result)

def compute(N, i):
    return N + 1 - i

def parse():
    vars = split_stdin(get_stdin())
    return int(vars[0]), int(vars[1])

def get_stdin():
    return input()

def split_stdin(stdin_val, delim = ' '):
    return [x for x in stdin_val.split(delim) if x != '']

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 1000000
#define INF   1000000000

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll to[MAX_N];
ll d[MAX_N];
bool visited[MAX_N];

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

    ll X;
    cin >> X;

    ll ans_a, ans_b;

    for (ll a = 0; a < 1000; a++) {
      ll a5 = pow(a, 5);
      ll tmp = X - a5;

      for (ll b = -1000; b < 1000; b++) {
	if (-pow(b, 5) == tmp) {
	  ans_a = a;
	  ans_b = b;
	  break;
	}
      }
    }

    cout << ans_a << " " << ans_b << endl;
    
    return 0;
}


Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)


ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}

bool isPrime(ll x){
  ll root_x = (ll)sqrt((double)x);
  bool prime = true;
  for(ll i=2;i<=root_x;++i){
    if(x%i==0){
      prime = false;
      break;
    }
  }
  return prime;
}

int main() {
  ll a,b;cin>>a>>b;
  ll c = gcd(a,b);
  set<ll> st;
  st.insert(1LL);
  if(isPrime(c)){
    st.insert(c);
  } else{
    ll root_c = (ll)sqrt((double)c);
    for(ll i=2;i<=root_c;++i){
      if(c%i==0){
        if(isPrime(i))st.insert(i);
        if(isPrime(c/i))st.insert(c/i);
      }
    }
  }
  cout << st.size()<<endl;
  return 0;
}


Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))};
const main=()=>{
  let [a,b]=tnn(2)
  to(a>b?'GREATER':a<b?'LESS':'EQUAL')
}
main()


Measured memory_bytes: 7372
#include<stdio.h>
int main(){
  char s[4];
  int i,count=0;
  scanf("%s",s);
  for(i=0;i<3;i++)
    if(s[i]=='R')
      count++;
  if(count==2 && s[1]=='S')
    count--;
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAX 10000000

int b[110];

int solve(int a[110][110], int n){
	b[0] = 0;
	for(int i = 0;i < n;i++){
		for(int j = 1;j < n;j++){
			//if(j == 4)cout << b[4] << i << " " << endl;
			if(a[i][j] != -1)b[j] = min(b[j], a[i][j]+b[i]);
			//if(j == 4)cout << b[4] << i << " " << endl;
		}
	}
	//cout << endl;
	return 0;
}

int main(){
	int a[110][110], n;
	fill((int*)a, (int*)(a+110), -1);
	fill(b, b+110, MAX);
	cin >> n;
	for(int i = 0;i < n;i++){
		int u, k, c, d;
		cin >> u >> k;
		for(int j = 0;j < k;j++){
			cin >> c >> d;
			a[u][c] = d;
		}
	}
	
	
	
	for(int i = 0;i < 2*n;i++)solve(a, n);
	//solve(a, n);
	for(int i = 0;i < n;i++){
		cout << i << " " << b[i] << endl;
	}
	
	return 0;
}
/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
*/

Measured memory_bytes: 3140
'use strict';
const p = s => console.log(s);

// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  let N = input[0].split(" ")[0];
  let M = input[0].split(" ")[1];
  let tmp = input[1].split(" ");
  let sum =0;
  let cnt=0;
  let result = 'No';

  let A = [];
  for (let i= 0; i < N; i++) {
    A.push(parseInt(tmp[i],10));
    sum += parseInt(tmp[i],10);
  }

  for (let i=0; i < N; i++) {
    if( A[i] >= (sum/(4*M))) cnt++;
    if( cnt > M -1) {
        result = "Yes";
        break;
    }
  }
  p(result);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

using ll = long long;

class BIT {
public:
    // 要素数Nで初期化
    explicit BIT(int N) : V_NUM(N) {
        data.resize(N);
    }

    // [1, i]の総和を求める
    int query(int i) {
        int ret = 0;
        while (i > 0) {
            ret += data[i];
            i -= (i & -i);
        }
        return ret;
    }

    // data[i]にv可算
    void update(int i, int v) {
        while (i < V_NUM) {
            data[i] += v;
            i += (i & -i);
        }
    }

    int V_NUM;
    vector<int> data;
};

int main() {
    int N;
    cin >> N;

    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    auto b = a;
    sort(b.begin(), b.end());
    map<int, int> dic;
    for (int i = 0; i < N; ++i) {
        dic[b[i]] = i + 1;
    }

    reverse(a.begin(), a.end());
    BIT bit(N + 1);
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += bit.query(dic[a[i]]);
        bit.update(dic[a[i]], 1);
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 14504
class BIT():
 
    __slots__ = ["n", "data"]
 
    def __init__(self, li):
        self.n = len(li) + 1
        self.data = [0] + li
        for i in range(1, self.n):
            if i + (i & -i) < self.n:
                self.data[i + (i & -i)] += self.data[i]
 
    def add(self, i, a):
        i += 1
        while i < self.n:
            self.data[i] += a
            i += i & -i
        
    def acc(self, i):
        res = 0
        while i > 0:
            res += self.data[i]
            i -= i & -i
        return res
    
    def fold(self, l, r):
        res = 0
        while l < r:
            res += self.data[r]
            r -= r & -r
        while r < l:
            res -= self.data[l]
            l -= l & -l
        return res

import bisect
n = int(input())
TF = []
for _ in range(n):
  s = input()
  if "." not in s:
    s += "."
  a, b = s.split(".")
  k = len(b)
  c = int(a+b)
  t = 0
  while c%2 == 0:
    c //= 2
    t += 1
  f = 0
  while c%5 == 0:
    c //= 5
    f += 1
  TF.append((t-k, f-k))
TF.sort()
ans = 0
U = 50
bit = BIT([0]*100)
temp = n
for t, f in TF:
  r = bisect.bisect_left(TF, (-t, -U))
  while temp > r:
    temp -= 1
    nt, nf = TF[temp]
    bit.add(nf+U, 1)
  ans += n-temp - bit.acc(-f+U)
for t, f in TF:
  if min(t, f) >= 0:
    ans -= 1
ans //= 2
print(ans)

Measured memory_bytes: 94844
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

const int kMaxn = 2e5 + 5;
const int MOD = 1e9 + 7;
int T, N, M, K;
int uf[kMaxn];
int find_set(int x);
void union_set(int x, int y);
int buck[kMaxn];

int main() {
  //
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= N; i++) uf[i] = i;
  for (int i = 1; i <= M; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    union_set(x, y);
  }
  int ans = 1;
  for (int i = 1; i <= N; i++) {
    buck[find_set(i)]++;
    ans = max(ans, buck[find_set(i)]);
  }
  printf("%d\n", ans);
  return 0;
}

int find_set(int x) { return (uf[x] == x) ? uf[x] : uf[x] = find_set(uf[x]); }

void union_set(int x, int y) {
  int fx = find_set(x), fy = find_set(y);
  uf[fy] = fx;
}

Measured memory_bytes: 4788
def feed_runrun(answer, burger_dimension, appetite):
    if appetite == 0:
        return answer

    burger_size = 2 ** (burger_dimension + 2) - 3
    # 食べきれない
    if appetite < burger_size:
        return feed_runrun(answer, burger_dimension - 1, appetite - 1)
    # 食べきれる
    amount_of_p = 2 ** (burger_dimension + 1) - 1
    if appetite >= burger_size + 1:
        return feed_runrun(answer + amount_of_p + 1, burger_dimension, appetite - burger_size - 1)
    return feed_runrun(answer + amount_of_p, burger_dimension, appetite - burger_size)


n, x = map(int, input().split())
print(feed_runrun(0, n, x))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};

//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};

ll arr[200005];
int main()
{
//    READ;
    deque<ll>d;
    int n;
    ll x,y,v1,v2,v3,v4;
    ll ans=0;
    sf(n);
    for(int i=0;i<n;i++)
    {
        sl(arr[i]);
    }
    sort(arr,arr+n);
    int i=0,j=n-1;
    d.push_front(arr[j]);
    d.push_back(arr[i]);
    ans=abs(arr[j]-arr[i]);
    i++,j--;
//    cout<<ans<<endl;
    int c=0;
    ll v[4];
    int id=0,jd=0,sm=0,pi=0;
    while(i<=j)
    {
        id=0,jd=0,sm=0,pi=0;
        x=d.front();
        y=d.back();
        v[0]=v1=abs(arr[j]-x);
        v[1]=v2=abs(arr[j]-y);
        v[2]=v3=abs(arr[i]-x);
        v[3]=v4=abs(arr[i]-y);
        sort(v,v+4);
        if(v[3]==v1)
        {
            d.push_front(arr[j]);
            j--;
        }
        else if(v[3]==v2)
        {
            d.pb(arr[j]);
            j--;
        }
        else if(v[3]==v3)
        {
            d.push_front(arr[i]);
            i++;
        }
        else
        {
            d.pb(arr[i]);
            i++;
        }
        ans+=v[3];
//        cout<<x<<"<-  -> "<<y<<endl;
    }
    cout<<ans<<endl;



    return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
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(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<pair<ll,ll>> ab;
    rep(i,n){
        ll a,b;cin>>a>>b;
        ab.emplace_back(a,b);
    }
    priority_queue<pair<ll,ll>> pq;
    rep(i,n){
        pq.emplace(ab[i].first+ab[i].second,i);
    }
    ll res =0;
    rep(i,n){
        if(i%2==0){
            res += ab[pq.top().second].first;
        }else{
            res -= ab[pq.top().second].second;
        }
        pq.pop();
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4848
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Buffer(make([]byte, 0), 1e6) // maxTokenSize
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	/* --- code --- */
	a, bs := nextInt64(), next()
	bs = strings.ReplaceAll(bs, ".", "")
	b, _ := strconv.ParseInt(bs, 10, 64)
	ans := a * b / 100

	fmt.Println(ans)

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

func max64(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

func min64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


Measured memory_bytes: 1756
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define PI (3.141592653589)
using ll = long long;
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed;
    cout.precision(10);
    // Those who forgive themselves, and are able to accept their true nature...THEY ARE THE STRONG ONES

    int n;
    cin >> n;
    map<string, int> mp;
    for(int i = 0;i < n;i++)
    {
        string a;
        cin >> a;
        mp[a]++;
    }
    int mx = 0;
    for(auto i : mp)
    {
        mx = max(mx, i.second);
    }
    for(auto i : mp)
    {
        if(i.second == mx)
        {
            cout << i.first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 23808
import math
 
K = int(input())
summ = 0
 
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            tmp = math.gcd(i, j)
            summ+=math.gcd(tmp,k)
 
print(summ)

Measured memory_bytes: 67732
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    --a;
    --b;
    --c;
    --d;
    bool ok = true;
    if (c < d)
    {
        for (int i = a; i <= c - 1; ++i)
            if (s[i] == '#' && s[i + 1] == '#')
                ok = false;
        for (int i = b; i <= d - 1; ++i)
            if (s[i] == '#' && s[i + 1] == '#')
                ok = false;
    }
    if (d < c)
    {
        for (int i = b; i <= d - 1; ++i)
            if (s[i] == '#' && s[i + 1] == '#')
                ok = false;
        bool jest = false;
        for (int i = b; i <= d; ++i)
            if (s[i] == '.' && s[i - 1] == '.' & s[i + 1] == '.')
                jest = true;
        if (!jest)
            ok = false;
        for (int i = a; i <= c - 1; ++i)
            if (s[i] == '#' && s[i + 1] == '#')
                ok = false;
    }
    if (ok)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


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

int main() {
  int N = 0, A = 0;
  cin >> N;
  A = N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) cin >> d.at(i);
  sort(d.begin(),d.end());
  for (int i = 0; i < N-1; i++){
  	if(d.at(i) == d.at(i+1)){
    	--A;
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int isPrime(int);

int main(){

  int n,p,f=0,i;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&p);
    if(isPrime(p)==1)f++;
  }
  
  printf("%d\n",f);

  return 0;
}

int isPrime(int p){
  int i;

  if(p<2)return 0;
  else if(p==2)return 1;
  else if(p%2==0)return 0;
  for(i=3;i*i<=p;i++){
    if(p%i==0)return 0;
  }
  return 1;
}

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

void solve(long long N, long long M, std::vector<long long> p,
           std::vector<std::string> S) {
  vector<int> penalty(N);
  vector<bool> answered(N);

  int cnt_AC = 0;
  int cnt_penalty = 0;

  for (int i = 0; i < M; i++) {
    int q_num = p[i];

    if (answered[q_num] != true) {
      if (S[i] == "AC") {
        cnt_penalty += penalty[q_num];
        cnt_AC++;
        answered[q_num] = true;
      } else {
        penalty[q_num]++;
      }
    }
  }

  cout << cnt_AC << " " << cnt_penalty << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> p(M);
  std::vector<std::string> S(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &p[i]);
    std::cin >> S[i];
  }
  solve(N, M, std::move(p), std::move(S));
  return 0;
}


Measured memory_bytes: 6912
n = int(input())
x = [int(i) for i in input().split(" ")]

x = zip(x, [i for i in range(0, n)])
x = sorted(x, key=lambda k: k[0])
r = [0] * n

for i in range(0, n):
    if i < n // 2:
        r[x[i][1]] = x[n // 2][0]
    else:
        r[x[i][1]] = x[n // 2 - 1][0]

for i in r:
    print(i)

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

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

  

  
  	if(n[0]==n[1]&&n[1]==n[2]){
    	cout<<"Yes"<<endl;
    }
  
 	else if(n[2]==n[3]&&n[1]==n[2]){
    	cout<<"Yes"<<endl;
    }
  
  	else{
    	cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll D, T, S;
        cin >> D >> T >> S;
        if (S * T >= D) {
                cout <<"Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    getline(cin,S);
    int n=S.length();
    n=n-1;
    if(S[n]=='s')
    {
        cout<<S<<"es"<<endl;
    }
    else
    {
        cout<<S<<"s"<<endl;
    }
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int g[]={0,1,2,1,3,1,3,1,1,3,1,3,1};
int main(){
	int x,y;
	cin>>x>>y;
	if(g[x]==g[y])puts("Yes");
	else puts("No");
	}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List
import Data.Array
import Data.Maybe
import Data.Bits
import Data.Ord
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Debug.Trace


listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)

getWords = getLine >>= return . words

readIntBS = fst . fromJust . BS.readInt


main :: IO ()
main = do
  s <- getLine
  k <- readLn :: IO Integer

  let c = fromIntegral $ length $ takeWhile (=='1') s

  putStrLn $ [
    if k <= c then
      '1'
    else
      s !! (fromIntegral c)
      ]

  return ()

Measured memory_bytes: 508
#include <iostream>
#include <vector>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back

int unused_from, unused_to;


#define MAX_V 100000
vector<int> G[MAX_V];
vector<int> Grev[MAX_V];
bool used[MAX_V]={};
int ord[MAX_V],lowlink[MAX_V];
int k=0;

void dfs(int v,int prev){   //make ord and lowlink
    used[v] = true;
    ord[v]=lowlink[v]=k;
    k++;
    
    rep(i,Grev[v].size()){
        int to = Grev[v][i];
        if((v==unused_from&&to==unused_to)||(v==unused_to&&to==unused_from))continue;
        if(!used[to]){
            dfs(to,v);
            lowlink[v] = min(lowlink[v],lowlink[to]);
        }
        else if(used[to]&&to!=prev){    //use back edge
            lowlink[v] = min(lowlink[v],ord[to]);
        }
    }
}

vector<pii> enumerateBridge(int e,vector<pii> edges){   //????????????
    vector<pii> ret;
    
    rep(i,e){
        int a = edges[i].first, b = edges[i].second;
        if((a==unused_from&&b==unused_to)||(a==unused_to&&b==unused_from))continue;
        if(ord[a]>ord[b])swap(a,b);
        if(ord[a]<lowlink[b])ret.pb(pii(edges[i].first,edges[i].second));
    }
    return ret;
}



bool hasLoop(int v){
    vector<int> in_deg(v,0);
    rep(i,MAX_V){
        rep(j,G[i].size()){
            int from = i, to = G[i][j];
            if(from==unused_from&&to==unused_to)continue;
            in_deg[to]++;
        }
    }
    
    stack<int> st;
    vector<int> list;
    
    rep(i,v)if(in_deg[i]==0)st.push(i);
    
    while(st.size()){
        int q = st.top();
        st.pop();
        list.pb(q);
        
        rep(i,G[q].size()){
            int to = G[q][i];
            if(q==unused_from&&to==unused_to)continue;
            in_deg[to]--;
            if(in_deg[to]==0)st.push(to);
        }
    }
    
    if(list.size()!=v)return true;
    return false;
    
}


int main(){
    int v,e;
    cin>>v>>e;
    vector<pii> edges;
    
    rep(i,e){
        int a,b;
        cin>>a>>b;
        a--,b--;
        edges.pb(pii(a,b));
        G[a].pb(b);
        Grev[a].pb(b),Grev[b].pb(a);
    }
    
    
    dfs(0,-1);
    vector<pii> bridge_list = enumerateBridge(e,edges);
    map<pii,bool> mp;
    rep(i,bridge_list.size())mp[bridge_list[i]]=true;
    
    
    rep(i,MAX_V){
        rep(j,G[i].size()){
            unused_from = i;
            unused_to = G[i][j];
            
            rep(i,MAX_V)used[i]=false;
            k=0;
            dfs(0,-1);
            vector<pii> brg = enumerateBridge(e,edges);
            
            if( not mp[pii(unused_from,unused_to)] && brg.size()>=2 && not hasLoop(v)){
                //                cout<<unused_from+1<<" "<<unused_to+1<<endl;  //1????????????????????????????????????
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 8060
#include <cstdio>

using i64 = long long;

// constexpr int maxn = 300;
constexpr int U = 90000;
constexpr int mod = 998244353;

inline int io() {
	static int v;
	return scanf("%d", &v), v;
}
#define io io()

inline int fpow(int v, int n) {
	int pw = 1;
	for (; n; n >>= 1, v = (i64)v * v % mod)
		if (n & 1) pw = (i64)pw * v % mod;
	return pw;
}

int main() {
	static int f[U + 1], g[U + 1];
	const int n = io;
	int sum = 0;
	f[0] = 1; g[0] = 1;
	for (int i = 1; i <= n; ++i) {
		const int a = io;
		sum += a;
		for (int j = sum; j >= a; --j)
			f[j] = (2ll * f[j] + f[j - a]) % mod,
			g[j] = (g[j] + g[j - a]) % mod;
		for (int j = a - 1; j >= 0; --j)
			f[j] = 2ll * f[j] % mod;
	}

	i64 ans = fpow(3, n);
	for (int l = (sum + 1) >> 1; l <= sum; ++l)
		ans -= 3ll * f[l] % mod;
	if (not (sum bitand 1)) ans += 3ll * g[sum >> 1];
	printf("%lld", (ans % mod + mod) % mod);

	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define el "\n"
#define ll long long
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define M 1000000007
#define all(v) v.begin(), v.end()

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,l;
  cin>>n>>l;
  ll sm=0;
  ll a[n+1]={0},mn=INT_MAX;
  for(int i=1;i<=n;i++){
      a[i]=l+i-1;
      sm+=a[i];
  }
  ll ind=-1;
      for(int i=1;i<=n;i++){
          if(abs(a[i])<mn){
              mn=abs(a[i]);
              ind=i;
          }
      }
  cout<<sm-a[ind];
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b) {
  int tmp;
  if(a < b) { tmp = a; a = b; b = tmp; }
  while(b != 0)
  {
    a %= b;
    tmp = a; a = b; b = tmp;
  }
  return a;
}

int main()
{
  int n; scanf("%d", &n);
  printf("%d\n", n*2/gcd(n, 2));
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

int LIS(vector<int> a){
  int n = a.size();
  vector<int> dp(n, 1LL << 60); //長さをiとしたときの末尾の最小値
  for(int i = 0; i < n; i++){
    int j = lower_bound(dp.begin(),dp.end(),a[i]) - dp.begin();
    dp[j] = a[i];
  }
  return lower_bound(dp.begin(),dp.end(),1 << 30) - dp.begin();
}

const int INF = 1LL << 60;

signed main(){

  int n; cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  vector<vector<int>> g(n);
  for(int i = 0; i < n-1; i++){
    int u, v; cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  vector<int> ans(n), dp(n, INF);
  auto dfs = [&](auto&& dfs, int u, int par)->void{
    int pos = lower_bound(dp.begin(), dp.end(), a[u]) - dp.begin();
    int pre = dp[pos];
    dp[pos] = a[u];
    ans[u] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    for(int v : g[u]){
      if(v == par) continue;
      dfs(dfs, v, u);
    }
    dp[pos] = pre;
  };

  dfs(dfs, 0, -1);

  for(int p : ans) cout << p << endl;

  return 0;
}

Measured memory_bytes: 33208
#include<iostream>
#include<queue>
#include<vector>
#include<string>
#include<map>
using namespace std;
#define rep(i,n) for ( int i = 0; i < (int)n; i++)
#define INFTY (1<<21)
#define NMAX 12 // nshop = 10
#define IMAX 15
#define SMAX 32768 // (1<<IMAX)

class State{
    public:
    int pos, state, cost;
    State(int p=0, int s=0, int c=0): pos(p), state(s), cost(c){}

    bool operator < ( const State &s) const{
	return cost > s.cost;
    }
};

int G[NMAX+1][NMAX+1], nshop, nitem;
vector<pair<string, int> > S[NMAX]; // shop

pair<string, int> L[IMAX]; // list
map<string, int> N_I; // name to index


int getCheapest( string name ){
    int cheapest = INFTY;
    for ( int i = 1; i <= nshop; i++ ){
	rep(j, S[i].size()){
	    if ( S[i][j].first == name && S[i][j].second < cheapest ) cheapest = S[i][j].second;
	}
    }
    return cheapest;
}


int dijkstra(){
    priority_queue<State> PQ;
    int D[NMAX][SMAX];
    bool V[NMAX][SMAX];
    rep(i, nshop+1) rep(j, (1<<nitem)) { D[i][j] = INFTY; V[i][j] = false; }

    PQ.push(State(0, 0, 0));
    D[0][0] = 0;

    State u, v;
    while( !PQ.empty() ){
	u = PQ.top(); PQ.pop();
	//	cout << u.pos << " " << u.state << " " << u.cost << endl;
	if ( u.pos == 0 && u.state == (1<<nitem)-1 ) return u.cost;

	rep(adj, nshop+1){
	    if ( G[u.pos][adj] == INFTY ) continue;
	    v = u;
	    int nstate = v.state;
	    for ( int i = 0; i < nitem; i++ ){ // is it possible to bye item i in shop adj??
		bool possible = false;
		for ( int j = 0; j < S[adj].size(); j++ ){
		    if ( S[adj][j].first == L[i].first && S[adj][j].second == L[i].second) possible = true;
		}
		if ( possible ) nstate |= (1<<i);
	    }
	    v.state = nstate;
	    v.pos = adj;
	    if ( D[u.pos][u.state] + G[u.pos][adj] < D[v.pos][v.state] ){
		D[v.pos][v.state] = D[u.pos][u.state] + G[u.pos][adj];
		v.cost = D[v.pos][v.state];
		PQ.push(v);
	    }
	}
    }

    return INFTY;
}

void print(){
    // print list
    for ( int i = 0; i < nitem; i++ ){
	cout << L[i].first << " " << L[i].second << endl;
    }
}

main(){
    int k, v, m, s, t, c;
    string name;
    while( cin >> nshop && nshop ){
	S[0].clear();
	for ( int i = 1; i <= nshop; i++ ){
	    S[i].clear();
	    cin >> k;
	    rep(j, k){
		cin >> name >> v; S[i].push_back(make_pair(name, v));
	    }
	}
	cin >> nitem;
	int total = 0;
	N_I = map<string, int>();
	rep(i, nitem){
	    cin >> L[i].first;
	    L[i].second = getCheapest(L[i].first);
	    total += L[i].second;
	    N_I[L[i].first] = i;
	}
	rep(i, nshop+1) rep(j, nshop+1) G[i][j] = INFTY;
	cin >> m;
	rep(i, m){
	    cin >> s >> t >> c;
	    G[s][t] = G[t][s] = c;
	}
	//	print();
	int cost = dijkstra();
	if ( cost == INFTY ) cout << "impossible" << endl;
	else cout << total << " " << cost << endl;
    }
}

Measured memory_bytes: 0
def InsertionSort(A, N):

    print(*A)

    for i in range(1, N):
        v = A[i]
        j = i - 1

        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1

        A[j + 1] = v

        print(*A)

N = int(input())
A = [int(a) for a in input().split()]

InsertionSort(A, N)

Measured memory_bytes: 8100
#include <iostream>
#include <vector>

/*動的計画法で解く*/
int main(){
	int a, b;
	while(std::cin >> a >> b){
		if(a == 0 && b == 0){
			break;
		}
		int n;
		std::cin >> n;
		std::vector<std::vector<int> > dp(a, std::vector<int>(b, 1));
		//工事中の点に0をいれる
		int x, y;
		for(int i = 0; i < n; ++i){
			std::cin >> x >> y;
			//端が工事中になればその北と東を全て0にする
			if(y == 1){
				for(int i = x - 1; i < a; ++i){
					dp[i][y - 1] = 0;
				}
			}
			if(x == 1){
				for(int i = y - 1; i < b; ++i){
					dp[x - 1][i] = 0;
				}
			}
			//端じゃないときはその点だけ0にする
			else{
				dp[x - 1][y - 1] = 0;
			}
		}
		//(2,2)から処理する
		for(int i = 1; i < a; ++i){
			for(int j = 1; j < b; ++j){
				if(dp[i][j] != 0){
					dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
				}
			}
		}
		std::cout << dp[a - 1][b - 1] << std::endl;
	}
}

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

int main() {
  string s;
  cin >> s;
  int a = s.size() - 1, z = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      a = min(a, i);
    }
    if (s[i] == 'Z') {
      z = max(z, i);
    }
  }
  cout << z - a + 1 << "\n";
  return 0;
}

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

int main() {

  long long int n, x;
  cin >> n >> x;

  long long int ans = n;

  n -= x;
  if ( n < x ) swap( n, x );

  while( x > 0 ) {

    ans += ( n / x ) * x * 2;
    long long int k = x;
    x = n % x;
    n = k;

  }

  cout << ans - n << endl;

  return 0;

}


Measured memory_bytes: 256
import numpy as np
h,w = list(map(int, input().split())) 
canvas = np.array([[np.nan]*w]*h).astype(int)

for i in range(h):
    s = input()
    for j in range(w):
        if( s[j] == '.'):
            canvas[i, j] = 0
        elif (s[j]=='#'):
            canvas[i, j] = 1

ret = True
for i in range(h):
    for j in range(w):
        if( canvas[i, j] == 1):

            check = False
            ch = i-1
            cw = j
            if( (0 <= ch & ch < h) & (0 <= cw & cw < w)):  
                if( canvas[ch,cw] == 1):
                    check = True
            ch = i
            cw = j-1
            if( (0 <= ch & ch < h) & (0 <= cw & cw < w)):  
                if( canvas[ch,cw] == 1):
                    check = True
            ch = i
            cw = j+1
            if( (0 <= ch & ch < h) & (0 <= cw & cw < w)):  
                if( canvas[ch,cw] == 1):
                    check = True
            ch = i+1
            cw = j
            if( (0 <= ch & ch < h) & (0 <= cw & cw < w)):  
                if( canvas[ch,cw] == 1):
                    check = True  
            if check == False:
                ret = False
                break
    if ret == False:
        break
if ret:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 12504
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0; lli a = 0ll, b = 0ll, c = 0ll, d = 0ll;
	cin >> n >> a >> b >> c >> d;
	auto check = [&](int f, int s)
	{
		lli mi = 1ll * c * f - 1ll * d * s;
		lli mx = 1ll * d * f - 1ll * c * s;
		return (mi <= (b - a) && mx >= (b - a));
	};
	for (int i = 0; i < n; ++i)
		if (check(i, n - 1 - i))
		{
			cout << "YES"; return 0;
		}
	cout << "NO" << endl;
}

Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(10**6)
n = int(input())
p = list(map(int, input().split()))
c = [[] for _ in range(n)]
is_leaf = [True for _ in range(n)]
for i in range(n):
	p[i] -= 1
	c[p[i]].append(i)
	is_leaf[p[i]] = False

if sum(is_leaf) == 0:
	if n%2 == 0:
		print("POSSIBLE")
	else:
		print("IMPOSSIBLE")
	sys.exit()

for i in range(n):
	if is_leaf[i]:
		cur = i
		break

visited_set = {cur}
visited_list = [cur]
while p[cur] not in visited_set:
	visited_list.append(p[cur])
	visited_set.add(p[cur])
	cur = p[cur]

root = p[cur]

grundy = [-1 for _ in range(n)]
g_set = [set() for _ in range(n)]

def dfs(x):
	res = 0
	for v in c[x]:
		dfs(v)
		g_set[x].add(grundy[v])
	while res in g_set[x]:
		res += 1
	grundy[x] = res
	return res

loop = [False for _ in range(n)]
loop[root] = True
ind = len(visited_list)-1
while visited_list[ind] != root:
	loop[visited_list[ind]] = True
	ind -= 1
#print(loop)

for i in range(n):
	if loop[i]:
		for x in c[i]:
			if not loop[x]:
				dfs(x)
				g_set[i].add(grundy[x])

cand = []
num = 0
while num in g_set[root]:
	num += 1
cand.append(num)
num += 1
while num in g_set[root]:
	num += 1
cand.append(num)

for x in cand:
	cur = root
	grundy[root] = x
	while True:
		num = 0
		while num in g_set[p[cur]] or num == grundy[cur]:
			num += 1
		grundy[p[cur]] = num
		if p[cur] == root:
			break
		cur = p[cur]
	if grundy[root] == x:
		#print(grundy)
		print("POSSIBLE")
		sys.exit()

print("IMPOSSIBLE")

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

if N == 1:
    print('Yes')
    print(2)
    print('1 1')
    print('1 1')
    
elif N == 3:
    print('Yes')
    print(3)
    print('2 1 2')
    print('2 2 3')
    print('2 3 1')
    
elif N == 2:
    print('No')

else:
    k = int((2*N)**0.5)+1
    if k * (k-1) != 2*N:
        print('No')
    else:
        print('Yes')
        print(k)
        
        counter = 1
        node = []
        for i in range(k):
            for j in range(i+1,k):
                node.append([counter,i,j])
                counter += 1
        nd = [[] for _ in range(k)]
        for n in node:
            nd[n[1]].append(n[0])
            nd[n[2]].append(n[0])
        for i in range(k):
            ans = str(k-1)
            for j in nd[i]:
                ans += ' {}'.format(j)
            print(ans)

Measured memory_bytes: 21492
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		   map<int,int> cnt;
           rep(i,0,3){
            int a,b;
             cin>>a>>b;
             cnt[a]++;
             cnt[b]++;
           }
           int p=0,q=0;
           for(auto v:cnt){
				if(v.second==1)p++;
                if(v.second==2)q++;
           }
           YES(p==2&&q==2);
}


Measured memory_bytes: 3624