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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair



vvi child;

int sub(int n) {
    if (child[n].empty()) return 0;

    vi res;
    for (int ch : child[n]) {
        res.pb(sub(ch));
    }
    sort(ALL(res)); reverse(ALL(res));
    rep(i, res.size()) {
        res[i] += (1+i);
    }
    sort(ALL(res));
    return res.back();
}

int solve(int N, vi& a) {
    child.resize(N);
    rep(i,N) {
        if (i == 0) continue;
        child[ a[i] ].pb(i);
    }
    return sub(0);
}

int main() {
    int N; scanf("%d", &N);
    vi a(N);
    for (int i=1; i<N; ++i) {
        scanf("%d", &a[i]);
        a[i]--;
    }
    cout << solve(N,a) << endl;
    return 0;
}


Measured memory_bytes: 13952
w = input().strip()
C = {}
for i in range(len(w)):
    a = w[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
flag = 0
for a in C:
    if C[a]%2==1:
        flag = 1
        break
if flag==0:
    print("Yes")
else:
    print("No")

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

void solve() {
	int a,b,c;
	cin >> a >> b >> c;
	int maxi = max({ a,b,c});
	int mini = min({ a,b,c});
	int mid = a+b+c-maxi-mini;
	
	if(maxi == 7 && mini == 5 && mid == 5) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
}
		
			
		

int32_t main() {
	IOS;
	solve();
	return 0;
}


Measured memory_bytes: 384
N,M = map(int,input().split())

a = [False]*(N+1)
b = [0]*(N+1)



for i in range(M):
    c = input().split()
    if c[1] == "AC":
        a[int(c[0])] = True
    elif c[1] == "WA" and a[int(c[0])] == False:
        b[int(c[0])] += 1
            

for j in range(N+1):
    if a[j] == False:
        b[j] = 0
        
print(sum(a),sum(b))

Measured memory_bytes: 10456
linha = input()
Nvezes,TempoMax = [int(n) for n in linha.split()]
listaCusto = []
listaTempo = []
minimo = 1001
for aux in range(Nvezes):
    entrada = input()
    custo,tempo = [int(n) for n in entrada.split()]
    listaCusto.append(custo)
    listaTempo.append(tempo)
indiceMenor = listaCusto.index(min(listaCusto))
#print("indice menor: " , indiceMenor)
#print(listaTempo)
#print(listaCusto)
if listaTempo[indiceMenor] <= TempoMax:
    print(min(listaCusto))
elif listaTempo[indiceMenor] > TempoMax:
    for posicao, elemento in enumerate(listaCusto):
        if listaCusto[posicao] < minimo and listaTempo[posicao] <= TempoMax:
            minimo = listaCusto[posicao]
    if minimo == 1001:
         print("TLE")
    else:
        print(minimo)

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#include<math.h>
int a,s,d[200000],f[200000],g[200000],h,x[200000],c[200000],q=0;
int main(void)
{
	int i,j,k;
	scanf("%d %d",&a,&s);
	for(i=0;i<=a;i++){
		g[i]=0;
		x[i]=0;
		c[i]=0;
	}
	i=0;
	j=0;
	while(1){
		if(i==s) break;
		i++;
		scanf("%d %d",&d[j],&f[j]);
		if(d[j]!=1&&f[j]!=a) j--;
		g[d[j]]=1;
		x[f[j]]=1;
		j++;
	}
	/*for(i=0;i<j;i++){
		if(x[d[i]]==0&&g[f[i]]==0){
			d[i]=-1;
			f[i]=-1;
		}
	}*/
	for(i=0;i<j;i++){
			if(d[i]==1)	c[f[i]]++;
			if(f[i]==a) c[d[i]]++;
	}
	//for(i=0;i<=a;i++)	printf("%d\n",c[i]);
	h=0;
	for(i=1;i<=a;i++){
		if(c[i]>=2){
			h=1;
			break;
		}
	}
	if(h==0) printf("IMPOSSIBLE\n");
	else printf("POSSIBLE\n");
	return 0;
}

Measured memory_bytes: 4096
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
input=lambda :sys.stdin.readline().rstrip()

N=int(input())
S=input()
input()
mod=10**9+7
w=0
count=3
flag=0
while w<N:
    if w<N-1 and S[w]==S[w+1]:
        if flag==0:
            count*=2
            count%=mod
        if flag==1:
            count*=3
            count%=mod
        if flag==2:
            count*=2
            count%=mod
        w+=2
        flag=1
    else:
        if flag==2:
            count*=2
            count%=mod
        w+=1
        flag=2

print(count%mod)


Measured memory_bytes: 64236
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int mod=1e9+7;
const double eps=1e-8;
const int INF = 0x3f3f3f3f;
int a[200005],n;
int main()
{
    cin>>n;
    cin>>a[0];
    int minn=a[0];
    ll ans=0;
    for(int i=1; i<n; i++)
    {
        cin>>a[i];
        if(a[i]<minn)
        {
            ans+=minn-a[i];
        }
        else
            minn=max(a[i],minn);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4376
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

ll dp[105][100005];

int main(){
	int n; ll wmax;
	cin >> n >> wmax;
	vector<ll> v(n);
	vector<ll> w(n);
	for( int i = 0; i < n; ++i ) cin >> w[i] >> v[i];
	for( int i = 0; i < n; ++i ){
		for( int j = 0; j <= wmax; ++j ){
			dp[i+1][j] = dp[i][j];
			if( j >= w[i] ) dp[i+1][j] = max( dp[i][j], dp[i][j-w[i]]+v[i] );
		}
	}
	cout << dp[n][wmax] << endl;
	return 0;
}

// 13:31

Measured memory_bytes: 79360
long M=1e9+7,D[1<<20],P[1<<20],s=5e8+4;i,x,p;c[1<<20];main(a){for(gets(D);i<1<<20;)D[i++]=1;for(;~scanf("%d",&a);c[x]=p)P[x^=a]=(P[x]+(D[x]=(D[x]+P[x]*(p-c[x]))%M))%M,x||(p++,s=s*2%M);for(;--i;)s+=P[i];printf("%d",x?D[x]:s%M);}

Measured memory_bytes: 20608
import java.io.*;
import java.util.*;
import static java.lang.Math.min;
import static java.lang.Math.max;
public class Main {
    private static void solver(InputReader sc, PrintWriter out) throws Exception {
      int x = sc.nextInt();
      int n = sc.nextInt();
      Set<Integer> hs = new HashSet<>();
      for(int i=0; i<n; i++) hs.add(sc.nextInt());
      int sub=x,add=x;
      while(true){
          if(!hs.contains(sub)){
              out.println(sub); return;
          }
          if(!hs.contains(add)){
              out.println(add); return;
          }
          sub--; add++;
         // out.println(sub+" "+add);
      }
    }
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}
class Pair implements Comparable<Pair>{
    int x,y;
    Pair(int x, int y){
        this.x = x;
        this.y = y;
    }
    public int compareTo(Pair p){
        return (int)(this.x - p.x);
    }

}

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

int main()
{
    int x, a;
    cin >> x >> a;
    if (x < a)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 10 << endl;
    }
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn not(b: bool) -> bool {
    if b {
        false
    } else {
        true
    }
}

fn fact(n: u64) -> u64 {
    if n == 0 {
        1
    } else {
        (n * fact(n - 1)) % 1000000007
    }
}

fn main() {
    let n: usize = read();
    let h: Vec<u32> = read_vec();
    let mut ans: u32 = 0;
    let mut tmp: u32 = 0;

    for i in 0..(n - 1) {
        if h[i] >= h[i + 1] {
            tmp += 1;
        } else {
            if tmp > ans {
                ans = tmp;
            }
            tmp = 0;
        }
    }
    if tmp > ans {
        ans = tmp;
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
import java.util.Scanner;

class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    String N = sc.next();

    if ((N.charAt(0) == N.charAt(1) && N.charAt(1) == N.charAt(2)) || (N.charAt(2) == N.charAt(3) && N.charAt(1) == N.charAt(2))){
        System.out.println("Yes");
    }
    else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 22740
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=200005;

int n,k,t[N];

int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) t[i%k]++;
	LL ans=0;
	for (int i=1;i<=n;i++)
		if (i%k==0) ans+=(LL)t[0]*t[0];
		else if (i%k*2==k) ans+=(LL)t[k/2]*t[k/2];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define in(x) (read(x))
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ld eps = 1e-9;
const int inf = mod;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a){if(a<0)return -1;if(a>0)return 1;return 0;}


template<typename T> inline void in(T &x){
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
    while (isdigit(ch))  {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

const int maxn = 100010;
int f[maxn];
int main(){
	int n;cin>>n;
	REP(i,1,n+1)cin>>f[i];
	int ans = 0;
	REP(i,1,n+1)if(f[f[i]]==i)ans++;
	ans/=2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include <map>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <tr1/unordered_map>
#define mo 1000000007
#define num(x) (x>='0' && x<='9')
typedef unsigned long long ull;
typedef long long ll;
using namespace std::tr1;
using namespace std;
int read(){
    int p=0, q=1;
    char ch=getchar();
    while (!num(ch))
        (ch=='-'?q=-1:0),
        ch=getchar();
    while (num(ch)) p=p*10+ch-'0', ch=getchar();
    return p*q;
}
int power(ll a, int b){
	ll c=1;
	while (b){
		if (b&1) c=c*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return c;
}
#define N 200005
#define M N*8
int n, m, a[N], b[N];
int f[M], g[M], flag[M], sum[M], p[M];
void pushup(int t){
	f[t]=min(f[t<<1], f[(t<<1)+1]);
	if (p[t<<1]+g[t<<1]<p[(t<<1)+1]+g[(t<<1)+1])
		p[t]=p[t<<1],
		g[t]=g[t<<1];
	else
		p[t]=p[(t<<1)+1],
		g[t]=g[(t<<1)+1];
}
void build(int t, int l, int r){
	if (l==r){
		f[t]=p[t]=-l;
		g[t]=l;
		return;
	}
	int mid=l+r>>1;
	build(t<<1,l,mid);
	build((t<<1)+1,mid+1,r);
	pushup(t);
}
void pushdown(int t, int l, int r){
	if (flag[t]){
		int mid=l+r>>1;
		f[t<<1]=f[(t<<1)+1]=f[t];
		p[t<<1]=p[(t<<1)+1]=f[t];
		g[t<<1]=l;
		g[(t<<1)+1]=mid+1;
		sum[t<<1]=sum[(t<<1)+1]=0;
		flag[t<<1]=flag[(t<<1)+1]=1;
		flag[t]=sum[t]=0;
	}
	if (sum[t]){
		f[t<<1]+=sum[t];
		p[t<<1]+=sum[t];
		sum[t<<1]+=sum[t];
		f[(t<<1)+1]+=sum[t];
		p[(t<<1)+1]+=sum[t];
		sum[(t<<1)+1]+=sum[t];
		sum[t]=0;
	}
}
void add(int t, int l, int r, int le, int ri){
	if (le<=l && r<=ri){
		f[t]++;
		p[t]++;
		sum[t]++;
		return;
	}
	pushdown(t, l, r);
	int mid=(l+r)>>1;
	if (le<=mid) add(t<<1, l, mid, le, ri);
	if (ri>mid) add((t<<1)+1, mid+1, r, le, ri);
	pushup(t);
}
void upd(int t, int l, int r, int le, int ri, int x){
	if (le<=l && r<=ri){
		flag[t]=1;
		sum[t]=0;
		f[t]=p[t]=x;
		g[t]=l;
		return;
	}
	pushdown(t, l, r);
	int mid=(l+r)>>1;
	if (le<=mid) upd(t<<1, l, mid, le, ri, x);
	if (ri>mid) upd((t<<1)+1, mid+1, r, le, ri, x);
	pushup(t);
}
int query(int t, int l, int r, int x){
	if (r<=x) return f[t];
	pushdown(t,l,r);
	int mid=l+r>>1;
	int mi=9999999;
	if (x>mid) mi=min(query((t<<1)+1, mid+1, r, x), mi);
	mi=min(query(t<<1,l,mid,x), mi);
	return mi;
}
int main(){
	n=read(), m=read();
	for (int i=1;i<=n;i++) a[i]=read(), b[i]=read();
	build(1,1,m);
	for (int i=1;i<=n;i++){
		int mi=a[i]>1?query(1,1,m,a[i]-1):999999;
		upd(1,1,m,a[i],b[i],mi+1);
		if (a[i]>1) add(1,1,m,1,a[i]-1);
		if (b[i]<m) add(1,1,m,b[i]+1,m);
		if (f[1]>=999999) puts("-1");
		else printf("%d\n", p[1]+g[1]);
	}
    return 0;
}
/*
4 4
3 4
1 1
2 3
2 4
*/

Measured memory_bytes: 15500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 85;
ll a[N];
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    ll mn = 1000;
    ll cr = 0;
    for(int i=1;i<n;i++){
        if(a[i]<a[i+1]){
            ll x =(mn)/a[i];
            cr+=x;
            mn-=x*a[i];
        }
        else if ( a[i]>a[i+1]){
            mn+=cr*a[i];
            cr = 0;
        }
    }
    mn+=cr*a[n];
    cr = 0;
    cout<<mn<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3688
#include <stdio.h>
#define MIN(a,b) ((a>b)?(b):(a))
int main(void) {
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  printf("%d\n",MIN(a,b)+MIN(c,d));
  return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MN = 100010;

class unionfind {
public:
	vector<int> par;
	vector<ll> sum;
	vector<int> cand;

	void init(int n, vector<ll> X) {
		par.resize(n);
		sum.resize(n);
		cand.resize(n);

		for (int i = 0; i < n; i++) {
			par[i] = i;
			sum[i] = X[i];
			cand[i] = 0;
		}
	}

	int find(int x) {
		if (par[x] == x) return x;
		else {
			int p = find(par[x]);
			if (par[x] != p) {
				cand[p] += cand[par[x]];
				sum[p] += sum[par[x]];
			}
			return par[x] = p;
		}
	}

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

		if (x == y) return true;
		cand[x] += cand[y];
		sum[x] += sum[y];
		par[y] = x; 
		cand[y] = 0; sum[y] = 0;
	}

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

int N, M;
vi g[MN];

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

	vector<ll> X(N);
	rep(i, N) cin >> X[i];
	uf.init(N, X);

	vector<pair<ll, pii>> es;

	rep(i, M) {
		int a, b; ll c; cin >> a >> b >> c; --a; --b;
		g[a].pb(b); g[b].pb(a);
		es.eb(c, mp(a, b));
	}

	sort(ALL(es));

	int ans = 0;

	rep(i, M) {
		int a = es[i].se.fi, b = es[i].se.se;
		ll c = es[i].fi;

		if (uf.same(a, b)) {
			int p = uf.find(a);
			if (uf.sum[p] >= c) {
				++ans;
			} else {
				++uf.cand[p];
			}
		} else {
			int p1 = uf.find(a), p2 = uf.find(b);
			if (uf.sum[p1] + uf.sum[p2] >= c) {
				ans += uf.cand[p1];
				ans += uf.cand[p2];
				++ans;
				uf.cand[p1] = uf.cand[p2] = 0;
				uf.unite(a, b);
			} else {
				uf.unite(a, b);
				++uf.cand[uf.find(a)];
			}
		}
	}

	cout << M - ans << endl;

	return 0;
}

Measured memory_bytes: 9712
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
vector<int> gr[N];
int depth[2][N]; // depth[0] is for chaser. depth[1]  is for runaway.
void dfs(int node, int from, int val, int v[]){
    v[node] = val;
    for(auto it: gr[node]){
        if(it != from) dfs(it, node, val + 1, v);
    }
    return ;
}
int main(){
    int n, x, y, u, v;
    scanf("%d %d %d", &n, &u, &v);
    for(int i = 1; i < n; i++){
        scanf("%d %d", &x, &y);
        gr[x].push_back(y);
        gr[y].push_back(x);
    }
    dfs(u, 0, 0, depth[0]);
    dfs(v, 0, 0, depth[1]);
    int ma = 0;
    for(int i = 1; i <= n; i++){
        if(depth[0][i] < depth[1][i] && depth[1][i] > ma) ma = depth[1][i];
    }
    printf("%d", ma - 1);

}


Measured memory_bytes: 11648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    for (char s : S)
    {
        int tmp = s - 'A';
        tmp += N;
        tmp %= 26;
        cout << char('A' + tmp);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,ll> P;

vector<P> V[110000];

ll dis[110000];

void dfs(int x){

  for(int i=0;i<(int)V[x].size();i++){
    int nx=V[x][i].first;

    if(dis[nx]==-1){
      dis[nx]=dis[x]+V[x][i].second;
      dfs(nx);
    }
  }
}

int main(){
  int N,a,b,pa,x,y;
  ll c;
  cin>>N;
  //cout<<"unko"<<endl;
  for(int i=0;i<N-1;i++){
    cin>>a>>b>>c;
    V[a].push_back(P(b,c));
    V[b].push_back(P(a,c));
  }

  for(int i=1;i<=N;i++){
    if((int)V[i].size()==1){
      pa=i;
      break;
    }
  }
  //cout<<"unko"<<endl;

  int Q,K; cin>>Q>>K;

  for(int i=0;i<110000;i++) dis[i]=-1;
  dis[K]=0;
  dfs(K);
  //cout<<"unko"<<endl;


  for(int i=0;i<Q;i++){
    cin>>x>>y;
    cout<<abs(dis[x])+abs(dis[y])<<endl;;
  }
}


Measured memory_bytes: 14592
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let R = read int
    printfn "%i" (pown R 2)
    0

Measured memory_bytes: 13916
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<char> x={'M','A','R','C','H'};
  vector<int64_t> c(x.size(),0);
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    for(int j=0;j<x.size();j++)
      if(s.at(0)==x.at(j))
        c.at(j)++;
  }
  int64_t a=0;
  for(int i=0;i<c.size();i++)
    for(int j=i+1;j<c.size();j++)
      for(int k=j+1;k<c.size();k++)
        a+=c.at(i)*c.at(j)*c.at(k);
  cout<<a<<endl;
}

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

int main()
{
   
    long long int n;
    cin>>n;
    vector<long long int> dp(3);
    //  for(int i=0;i<3;i++)
    //  {long long int u;
    //  cin>>u;
    //  dp.push_back(u);
    //  }

    for(long long int i=0;i<n;i++)
    {
        long long int a[3];
        cin>>a[0]>>a[1]>>a[2];
        vector<long long int> v;
        v.push_back(0);
        v.push_back(0);
        v.push_back(0);

        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {    if(j!=k)
                   v[k]=max(v[k],a[k]+dp[j]);
            }
            
        }
       dp.clear();
       dp[0]=v[0];
       dp[1]=v[1];
       dp[2]=v[2];
        
        
    }
    cout<<max(max(dp[0],dp[1]),dp[2]);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 100000000000;
typedef pair<int,int> P;
typedef long long ll;
struct Sho {
    int X; 
    int Y; 
    Sho(int x, int y) : X(x), Y(y) { }
};
using Graph = vector<vector<Sho>>;

/*
*/

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N){
    cin >> A[i];
  }

  sort(A.begin(),A.end());
  
 
  ll ans1 = 0;
  ll ans2 = 0;
  if(N%2== 1){
    for(int i = 0;i<N/2 + 1;i++){
      if(i == N/2 || i == N/2 - 1) ans1 -= A[i];
      else ans1 -= A[i]*2;
    }
    for(int i = N/2 + 1;i<N;i++){
      ans1 += A[i]*2;
    }

    reverse(A.begin(),A.end());//降順
    for(int i = 0;i<N/2 + 1;i++){
      if(i == N/2 || i == N/2 - 1) ans2 += A[i];
      else ans2 += A[i]*2;
    }
    for(int i = N/2 + 1;i<N;i++){
      ans2 -= A[i]*2;
    } 
    cout << max(ans1,ans2) << endl;
  }
  
  if(N%2 == 0){
    reverse(A.begin(),A.end());//降順
    ll ans = 0;
    for(int i = 0;i<N/2;i++){
      if(i == N/2-1) ans += A[i];
      else ans += A[i]*2;
    }
    for(int i = N/2;i<N;i++){
      if(i == N/2) ans -= A[i];//引く項のうち最大のやつを1回引く
      else ans -= A[i]*2;
    } 

    cout << ans << endl;
  }
}

Measured memory_bytes: 1152
N = int(input())
A = list(map(int, input().split()))


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


if len(A) < 2:
    print(1)
    exit()

if A[0] < A[1]:
    temp = lcm(A[1], A[0])
else:
    temp = lcm(A[0], A[1])

for i in range(2, N):
    if temp < A[i]:
        temp = lcm(A[i], temp)
    else:
        temp = lcm(temp, A[i])

if temp == A[0]:
    print(N)
    exit()

ans = 0
for a in A:
    ans += temp // a

print(ans % (10 ** 9 + 7))

Measured memory_bytes: 4084
#include <iostream>
#include <numeric>

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    int n, x;
    int ans;
    std::cin >> n >> x;
    std::cin >> ans;
    ans = std::abs(ans-x);
    for(int i = 0; i < n-1; i++){
        int t;
        std::cin >> t;
        t = std::abs(t-x);
        ans = gcd(ans, t);
    }
    std::cout << ans << std::endl;
}


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

a, b, c = [0] * N, [0] * N, [0] * N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())

dp = [[0] * 3 for _ in range(N + 1)]

for i in range(N):
    dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i]
    dp[i + 1][1] = max(dp[i][0], dp[i][2]) + b[i]
    dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c[i]

print(max(dp[N][0], max(dp[N][1], dp[N][2])))


Measured memory_bytes: 34656
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define lb(x,a) lower_bound(all(x),a)
#define ub(x,a) upper_bound(all(x),a)
#define maxe(x,a) max_element(all(x))
#define mine(x,a) min_element(all(x))
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

struct UnionFind {
    vector<int> par,si; 

    UnionFind(int N) : par(N), si(N,1) { 
        rep(i,0,N) par[i] = i;
    }

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

    void unite(int x, int y) {
        x = root(x); 
        y = root(y); 
        if (x == y) return; 
        si[y]+=si[x];
        par[x] = y; 
    }

    bool same(int x, int y) { 
      return root(x)== root(y);
    }
    int size(int x){
       return si[root(x)];
    }

};


void solve(){
 ll n,m;
  cin >> n >> m;
  UnionFind u(n);
  
  while(m--){
   ll a,b;
    cin >> a >> b;
    --a;
    --b;
    u.unite(a,b);
  }
  
  set<ll> s;
  rep(i,0,n) s.insert(u.root(i));
  
  ll ans=s.size()-1;
  cout << ans << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 7932
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    map<char,int> buck;

    string s = get<string>();
    for (char c : s) {
        buck[c]++;
    }

    bool two_per_type = true;
    for (auto pair : buck) {
        if (pair.second != 2)
            two_per_type = false;
    }
    if (buck.size() == 2 && two_per_type)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

def cnt_two(n):
    cnt=0
    if n%2==0:
        cnt+=1
        n//=2
        if n%2==0:
            cnt+=1
    return cnt

a=[cnt_two(i) for i in a]
tot=sum(a)
if 1 in a:
    if tot>=n:
        print('Yes')
    else:
        print('No')
else:
    if tot+1>=n:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 14252
package main

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

func solve() {
	n := scanInt()
	a := make([]int, n)
	for x := 1; x < 110; x++ {
		for y := 1; y < 110; y++ {
			for z := 1; z < 110; z++ {
				num := pow(x, 2) + pow(y, 2) + pow(z, 2) + x*z + y*z + x*y
				if num <= n {
					a[num-1]++
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Println(a[i])
	}
	return
}

var sc = bufio.NewScanner(os.Stdin)

func scanString() string {
	sc.Scan()
	return sc.Text()
}
func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}
func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}
func Permute(nums []int) [][]int {
	n := factorial(len(nums))
	ret := make([][]int, 0, n)
	permute(nums, &ret)
	return ret
}
func permute(nums []int, ret *[][]int) {
	*ret = append(*ret, makeCopy(nums))

	n := len(nums)
	var i, j int
	for {
		for i = n - 2; i >= 0; i-- {
			if nums[i] < nums[i+1] {
				break
			}
		}
		if i < 0 {
			return
		}
		for j = n - 1; ; j-- {
			if nums[j] > nums[i] {
				break
			}
		}
		nums[i], nums[j] = nums[j], nums[i]
		for k, l := i+1, n-1; k < l; {
			nums[k], nums[l] = nums[l], nums[k]
			k++
			l--
		}
		*ret = append(*ret, makeCopy(nums))
	}
}

func factorial(n int) int {
	ret := 1
	for i := 2; i <= n; i++ {
		ret *= i
	}
	return ret
}

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

func makeCopy(nums []int) []int {
	return append([]int{}, nums...)
}
func gcd(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func eratosthenes(n int) []int {
	search := make([]bool, n+1)
	ans := []int{}
	for i := 2; i < n+1; i++ {
		search[i] = true
	}
	for i := 2; i*i < n+1; i++ {
		for j := 2; i*j < n+1; j++ {
			search[i*j] = false
		}
	}
	for i := 2; i < n; i++ {
		if search[i] {
			ans = append(ans, i)
		}
	}
	return ans
}

func main() {
	sc.Split(bufio.ScanWords)
	solve()
}


Measured memory_bytes: 2000
N = int(input())
dp = [[0,0,0] for _ in range(N)]
for i in range(N):
  a, b, c = map(int, input().split())
  if i == 0:
    dp[i][0] = a
    dp[i][1] = b
    dp[i][2] = c
    continue
  dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2])
  dp[i][1] = b + max(dp[i - 1][0],  dp[i - 1][2])
  dp[i][2] = c + max(dp[i - 1][1], dp[i - 1][0])
print(max(dp[N - 1]))

Measured memory_bytes: 22772
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <queue>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pl=pair<ll,ll>;
using vi=vector<int>;
using vl=vector<ll>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vs=vector<string>;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

void solve() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    // print(a);
    // print(c);
    ll ans = max(a*c, max(a*d, max(b*c, b*d)));
    // print(a*c);
    print(ans);
    

}   

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int k,x;
    in>>k>>x;
    cout<<(k*500>=x?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
module Main where

import qualified Data.Map as Map
import Control.Monad

main :: IO ()
main = do
    n <- read <$> getLine
    s <- replicateM n getLine
    m <- read <$> getLine
    t <- replicateM m getLine
    print $ solve s t

solve :: [String] -> [String] -> Int
solve s t =
    let l = ((\x -> (x, 1)) <$> s) ++ ((\x -> (x, -1)) <$> t)
        m = Map.fromListWith (+) l
    in  Map.foldr max 0 $ Map.filter (>0) m

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

string as = "AKIHABARA";

int main(void)
{
  string s;
  cin >> s;
  ll cnt = 0;
  REP(i, as.size()) {
    if(s[i] != as[i]) {
      if(as[i] == 'A') {
	s.insert(cnt, "A");
      } else {
	cout << "NO" << endl;
	return 0;
      }
    }
  }
  if(s.size() == as.size()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
def examA():
    X, Y = LI()
    ans = X + Y//2
    print(ans)
    return

def examB():
    N = I()
    T, A = LI()
    H = LI()
    cur = 10**9; ans = 0
    for i in range(N):
        now = abs(A - (T - H[i]*0.006))
        if cur>now:
            cur = now
            ans = i
    print(ans+1)
    return

def examC():
    N, M = LI()
    PY = [[]for _ in range(M)]
    d = defaultdict(int)
    ans = [[]for _ in range(M)]
    for i in range(M):
        PY[i] = LI()
        PY[i].append(i)
    PY.sort(key=lambda x:x[1])
    for p,y,s in PY:
        d[p] +=1
        cur = str(p).zfill(6) + str(d[p]).zfill(6)
        ans[s] = cur
    for v in ans:
        print(v)
    return

def examD():
    global mod
    H, W, K = LI()
    fibo = [1]*(W+1)
    for i in range(W-1):
        fibo[i+2] = fibo[i+1] + fibo[i]
    dp = [[0]*(W) for _ in range(H+1)]
    dp[0][0] = 1
#    print(fibo)
    for i in range(H):
        for j in range(W):
            dp[i+1][j] += dp[i][j]*fibo[j]*fibo[W-j-1]%mod
            dp[i+1][j] %=mod
            if j-1>=0:
                dp[i+1][j-1] += dp[i][j]*fibo[j-1]*fibo[W-j-1]%mod
                dp[i+1][j-1] %=mod
            if j+1<W:
                dp[i+1][j+1] += dp[i][j]*fibo[j]*fibo[W-j-2]%mod
                dp[i+1][j+1] %=mod
    ans = dp[H][K-1]
    print(ans)
#    print(dp)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examD()


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

int main() {
	int H, W;
	int flag;

	while(1){
		cin >> H >> W;

		if ( H == 0 && W == 0) break;

		for (int i = 0; i < H; i++){
			flag = i % 2;
			for(int j = 0; j < W; j++){
				if(flag == 1){
					cout << '.';
					flag = 0;
				}else{
					cout << '#';
					flag = 1;
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
const int INF = 100000;

int main() {
    int n;
    cin >> n;
    vector <int> h(n);
    vector <int> costs(n, INF);
    for (int i = 0; i < n; i++) {
        cin >> h.at(i);
    }

    costs.at(0) = 0;
    costs.at(1) = abs(h.at(1) - h.at(0));

    for (int i = 2; i < n; i++) {
        int a;
        if (abs(h.at(i-2) - h.at(i)) + costs.at(i-2) < abs(h.at(i-1) - h.at(i)) + costs.at(i-1)) {
            costs.at(i) = abs(h.at(i-2) - h.at(i)) + costs.at(i-2);
        }
        else {
            costs.at(i) = abs(h.at(i-1) - h.at(i)) + costs.at(i-1);
        }
    }

    cout << costs.at(n-1) << endl;

    return 0;

}

Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define debug(x) cout<<x<<endl
#define int long long 
const int mod=1000000007;
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b) { return b?gcd(b,a%b):a;}
inline int read() {int num=0, w=0;char ch=0;while (!isdigit(ch)) {w|=ch=='-';ch = getchar();}while (isdigit(ch)) {num = (num<<3) + (num<<1) + (ch^48);ch = getchar();}return w? -num: num;}
// cin.tie(0);
// ios::sync_with_stdio(false);
// head
// long long *long long 		**
//all 

signed main()
{
	int a,b,c;
	int k=0;
	cin>>a>>b>>c;cin>>k;
	int sum=0;
	while(a>=b){
		b=b*2;
		sum++;
	}
	while(b>=c){
		c=c*2;
		sum++;
	}
	if(sum<=k){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
    return 0;
}

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

public struct Cake
{
    public int w { get; set; }
    public int d { get; set; }
    public int s { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var cakes = new List<Cake>();
            string[] line = Console.ReadLine().Trim().Split(' ');
            var n = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            var d = int.Parse(line[2]);
            if (n == 0 && w == 0 && d == 0) break;
            cakes.Add(new Cake { w = w, d = d, s = w * d });
            for (int i = 0; i < n; i++)
            {
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                var p = int.Parse(line2[0]);
                var s = int.Parse(line2[1]);
                cutCake(cakes, p, s);
            }
            var retlist = cakes.OrderBy(x => x.s).ToArray();
            for (int j = 0; j < retlist.Length; j++)
                if (j == retlist.Length - 1) Console.WriteLine(retlist[j].s);
                else Console.Write("{0} ", retlist[j].s);
        }
    }
    public static void cutCake(List<Cake> c, int p, int s)
    {
        var nw = c[p - 1].w;
        var nd = c[p - 1].d;
        while (true)
        {
            if (s < nw)
            {
                c.RemoveAt(p - 1);
                if (s < nw - s)
                {
                    c.Add(new Cake { d = nd, w = s, s = nd * s });
                    c.Add(new Cake { d = nd, w = nw - s, s = nd * (nw - s) });
                }
                else
                {
                    c.Add(new Cake { d = nd, w = nw - s, s = nd * (nw - s) });
                    c.Add(new Cake { d = nd, w = s, s = nd * s });
                }
                return;
            }
            else if (s - nw < nd)
            {
                c.RemoveAt(p - 1);
                if (s - nw < nd - s + nw)
                {
                    c.Add(new Cake { d = s - nw, w = nw, s = (s - nw) * nw });
                    c.Add(new Cake { d = nd - s + nw, w = nw, s = (nd - s + nw) * nw });
                }
                else
                {
                    c.Add(new Cake { d = nd - s + nw, w = nw, s = (nd - s + nw) * nw });
                    c.Add(new Cake { d = s - nw, w = nw, s = (s - nw) * nw });
                }
                return;
            }
            else s -= (nd + nw);
        }
    }
}

Measured memory_bytes: 10248
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;

const int Amax=1000010;
ll mod=998244353, A[200010], num[Amax]={}, sum[Amax]={}, mult[Amax]={};
vector<vector<int>> yakusu(Amax);

void fillYakusuNum(){
	for(int i=1; i<Amax; ++i){
		num[i]=(num[i]+1)%mod;
		for(int j=1; i*j<Amax; ++j){
			yakusu[i*j].emplace_back(i);
			if(j>1){
				(num[i*j] += mod-(num[i]*j)%mod) %= mod;
			}
		}
	}
}

int main() {
	fillYakusuNum();
	int N;
	cin >> N;
	for(int i=0; i<N; ++i){
		cin >> A[i];
		int sz=yakusu[A[i]].size();
		for(int j=0; j<sz; ++j){
			(sum[yakusu[A[i]][j]] += yakusu[A[i]][sz-j-1]) %= mod;
			(mult[yakusu[A[i]][j]] += A[i]) %= mod;
		}
	}
	ll ans=0;
	for(int i=1; i<Amax; ++i){
		(sum[i] *= num[i]) %= mod;
		(ans += (sum[i]*mult[i])%mod) %= mod;
	}
	for(int i=0; i<N; ++i){
		(ans += mod-A[i]) %= mod;
	}
	if(ans&1) ans=((ans+mod)>>1);
	else ans >>= 1;
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n, k, q;
	int a[100000];
	int p[100000];

	cin >> n >> k >> q;

	for (int i = 0; i < q; ++i)
		cin >> a[i];

	for (int i = 0; i < n; ++i)
		p[i] = k - q;
	
	for (int i = 0; i < q; ++i)
		p[a[i] - 1] += 1;

	for (int i = 0; i < n; ++i)
		if (p[i] > 0)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int N, M, R;
//#define int long long
const int INF = numeric_limits<int>::max();
vector<vector<ll>> Warshall_Floyd(int V, vector<vector<ll>>&dp) {
	for (int k = 0; k < V; k++) {
		for (int i = 0; i < V; i++) {
			for (int j = 0; j < V; j++) {
				if (dp[i][k] == INF || dp[k][j] == INF) {
					continue;
				}
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
	return dp;
}
bool used[1000];
int perm[1000];
int res = INF;
void permutation1(int pos, int n,vector<vector<ll>>&dp, vector<int>&rs) {
	
	if (pos == n) {
		
		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			ans += dp[rs[perm[i]]][rs[perm[i + 1]]];
		}
		res = min(res, ans);
	}
	for (int i = 0; i < R; i++) {
		if (!used[i]) {
			perm[pos] = i;
			used[i] = true;
			permutation1(pos + 1, R,dp,rs);
			used[i] = false;
		}
	}
	
}
signed main() {

	cin >> N >> M >> R;
	vector<int>rs(R);
	for (int i = 0; i < R; i++) {
		int r;
		cin >> r;
		r--;
		rs[i]=r;
	}
	vector<vector<ll>>dp(N, vector<ll>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i == j) {
				dp[i][j] = 0;
			}
			else {
				dp[i][j] = INF;
			}
		}
	}
	for (int i = 0; i < M; i++) {
		int from, to, cost;
		
		cin >> from >> to >> cost;
		from--; to--;
		dp[from][to] = cost;
		dp[to][from] = cost;
	}
	dp = Warshall_Floyd(N, dp);
	/*
	ll ans = 0;

	for (int i = 0; i < R- 1; i++) {
		ans += dp[rs[i]][rs[i + 1]];
	}
	cout << ans << endl;
	*/
	 permutation1(0, R, dp,rs);
	 cout << res << endl;
}

Measured memory_bytes: 896
#include <stdio.h>

int main(void) {
	char b, l[26] = {0};
	
	while(scanf("%c", &b) != EOF){
		if(b >= 'A' && b <= 'z'){
			if(b >= 'a') l[b - 'a']++;
			else l[b-'A']++;
		}
	}
	int i;
	for(i = 0; 26 > i; i++) printf("%c : %d\n", 'a'+ i, l[i]);
	return 0;
}

Measured memory_bytes: 540
#include<iostream>
#include<iomanip>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define mod 1000000007
//#define max 100007
#define itr ::iterator it
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define repp(X,a,Y) for (int (X) = a;(X) < (Y);++(X))
#define set(a, b) memset(a, b, sizeof(a));
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<pii> vii;
typedef vector<string> vs;
#define endl '\n'
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n,k;
  cin>>n>>k;
  vector<int>a(n,0);
  vector<int>dp(n,2147483647);

  for(int i=0; i<n; i++)
    cin>>a[i];

  dp[0] = 0;
  dp[1] = abs(a[1] - a[0]);

  for (int j=2; j<n; j++)
  {
    int step = (j-k < 0)?j:k;
    for (int l=step; l>0 ; l--)
    {
      dp[j]= min(dp[j],dp[j-l] + abs(a[j] - a[j-l]));
    }
  }

  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template<typename ...Args> void read(Args&... args) { (cin >> ... >> args); }
template <typename...Args> void writeln(const Args &... args) { ((cout << args << " "), ...), cout << "\n"; }
template <typename...Args> void write(const Args &... args) { ((cout << args), ...), cout << "\n"; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> typename enable_if<is_same<decltype(declval<T>().size()), size_t>::value, int>::type operator~(const T& ct) { return (int)ct.size(); }
template <typename T, typename... Args> bool ckmax(T &a, const Args&... b) { return (a < max({b...})) ? (a = max({b...}), true) : false; }
template <typename T, typename... Args> bool ckmin(T &a, const Args&... b) { return (a > min({b...})) ? (a = min({b...}), true) : false; }
template <typename T> struct range {
    T u, v; bool inclusive;
    range(const T& _u, const T& _v, const bool& _inclusive = false) : u(_u), v(_v), inclusive(_inclusive) {}
    bool has(const T& w) { return (u <= w) and (inclusive ? (w <= v) : (w < v)); }
};
using vi = vector<long long>;
using vb = vector<bool>;
using pii = pair<long long, long long>;
using vvi = vector<vector<long long>>;
using vpii = vector<pii>;
using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
const long long N = 200'010;
auto soln() {
    long long n; read(n); vector<long long> a(n); for(auto& i : a) { cin >> i; };
    sort(a.rbegin(), a.rend());
    max_heap<long long> x;
    long long ans = 0;
    x.push(a.front());
    for (long long i = 1; i < n; ++i) {
        ans += x.top();
        x.pop();
        x.push(a[i]), x.push(a[i]);
    }
    cout << ans << "\n";
}
signed main() {
    long long t = 1;
    { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
    while (t--)
        soln();
    return 0;
}


Measured memory_bytes: 6904
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N, = map(int, sys.stdin.readline().rstrip().split(" "))
restaurants = []
for i in range(N):
    S,P = sys.stdin.readline().rstrip().split(" ")
    P = int(P)
    restaurants.append((S, -P, i+1))
restaurants.sort()
for S, IP, i in restaurants:
    print(i)

exit(0)

Measured memory_bytes: 3436
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
	int a =sc.nextInt();
	int b =sc.nextInt();
	int h =sc.nextInt();
	int s = (a + b) * h / 2;
	System.out.println(s);
	}
	}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <cmath>
#include <string>
#include <set>
#include <map>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
typedef pair <P,int> P2;

struct UF
{
	int par[SIZE],rank[SIZE];
	
	void init(int n)
	{
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			rank[i]=1;
		}
	}
	int find(int x)
	{
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y])
		{
			par[x]=y;
		}
		else
		{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
	bool same(int x,int y)
	{
		return find(x)==find(y);
	}
};
UF uf;
vector <PP> edge;
P2 p1[SIZE];
P2 p2[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		p1[i]=P2(P(a,b),i);
		p2[i]=P2(P(b,a),i);
	}
	sort(p1,p1+n);
	sort(p2,p2+n);
	for(int i=0;i+1<n;i++)
	{
		P p=p1[i].first,q=p1[i+1].first;
		int ct=min(abs(p.first-q.first),abs(p.second-q.second));
		edge.push_back(PP(ct,P(p1[i].second,p1[i+1].second)));
	}
	for(int i=0;i+1<n;i++)
	{
		P p=p2[i].first,q=p2[i+1].first;
		int ct=min(abs(p.first-q.first),abs(p.second-q.second));
		edge.push_back(PP(ct,P(p2[i].second,p2[i+1].second)));
	}
	sort(edge.begin(),edge.end());
	ll ret=0;
	uf.init(n+2);
	for(int i=0;i<edge.size();i++)
	{
		P p=edge[i].second;
		if(!uf.same(p.first,p.second))
		{
			uf.unite(p.first,p.second);
			ret+=edge[i].first;
		}
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 8308