akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;

struct node{
    int index;
    int pre;
    int size;
}prevs[100010];

void init(int n){
    for(int i = 1; i <= n; i ++){
        prevs[i].index= 1;
        prevs[i].pre = i;
        prevs[i].size = 1;
    }
}

int getF(int x){
    if(x == prevs[x].pre) return x;
    return prevs[x].pre = getF(prevs[x].pre);
}

bool isSame(int x, int y){
    return getF(x) == getF(y);
}

void unions(int x, int y){
    int rootX = getF(x);
    int rootY = getF(y);
    if(rootX == rootY) return;
    if(prevs[rootX].index > prevs[rootY].index){
        prevs[rootX].size += prevs[rootY].size;
        prevs[rootY].pre = rootX;
    }
    else{
        if(prevs[rootX].index == prevs[rootY].index) prevs[rootY].index ++;
        prevs[rootY].size += prevs[rootX].size;
        prevs[rootX].pre = prevs[rootY].pre;
    }
}

int fri[100010];
int unfri[100010];
int main(){
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);
    init(n);
    for(int i = 0; i < m; i ++){
        int x, y;
        scanf("%d %d", &x, &y);
        fri[x] ++;
        fri[y] ++;
        unions(x, y);
    }
    for(int i = 0; i < k; i ++){
        int x, y;
        scanf("%d %d", &x, &y);
        if(isSame(x, y)){
            unfri[x] ++;
            unfri[y] ++;
        }
    }
    for(int i = 1; i <= n; i ++){
        printf("%d ", prevs[getF(i)].size - fri[i] - unfri[i] - 1);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    ll x,y;
    cin>>x>>y;
    if(x%y==0){
        cout<<-1<<endl;
        return 0;
    }
    ll z=x/__gcd(x,y)*y;
    cout<<z+x<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;


vector<vector<int>> g;
int N,M;
vector<int> p;
vector<bool> v;
void dfs(int nowv){
    bool ok = 1;
    for(int i=0;i<g[nowv].size();i++){
        int next = g[nowv][i];
        if(v[next])continue;
        v[next] = 1;
        p.push_back(next);
        dfs(next);
        return ;
    }
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> N >> M;
    g.resize(N);
    v.resize(N);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    p.push_back(0);
    v[0] = 1;
    dfs(0);
    reverse(ALL(p));
    dfs(0);
    cout << p.size() << endl;
    for(auto x:p)cout << x+1 << " ";
    cout << endl;
}

Measured memory_bytes: 9720
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   int p,q,r,ans;
   cin>>p>>q>>r;
   ans=min(p+q,p+r);
   ans=min(ans,q+r);
   cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int b[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n - 1; ++i)
        cin >> b[i];

    int sum = b[0] + b[n - 2];
    for (int i = 1; i < n; ++i)
        sum += min(b[i], b[i - 1]);
    cout << sum;
}


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

int main() {
    while (1) {
        int H, W;
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (i == 0 || i == H - 1 || j == 0 || j == W - 1) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

const int MAXN = 1005;

int x[MAXN], y[MAXN];

int n, chk;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> x[i] >> y[i];
	chk = ((x[1] + y[1]) % 2 + 2) % 2;
	for (int i = 2; i <= n; i++)
		if (chk != ((x[i] + y[i]) % 2 + 2) % 2)
		{
			cout << -1 << endl;
			exit(0);	
		}
	cout << (chk == 0 ? 32 : 31) << endl;
	if (chk == 0)
		cout << 1 << " ";
	for (int i = 30; i >= 0; i--)
		cout << (1 << i) << " ";
	cout << endl;
	for (int i = 1; i <= n; i++)
	{
		int X = x[i], Y = y[i];
		if (chk == 0)
		{
			cout << "R";
			--X;
		}
		int val = (1 << 30) - 1;
		for (int j = 30; j >= 0; j--, val >>= 1)
		{
			if (1ll * abs(X + (1 << j)) + abs(Y) <= val)
			{
				cout << "L";
				X += (1 << j);
			}
			else if (1ll * abs(X - (1 << j)) + abs(Y) <= val)
			{
				cout << "R";
				X -= (1 << j);
			}
			else if (1ll * abs(X) + abs(Y + (1 << j)) <= val)
			{
				cout << "D";
				Y += (1 << j);
			}
			else if (1ll * abs(X) + abs(Y - (1 << j)) <= val)
			{
				cout << "U";
				Y -= (1 << j);
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Deque;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FSugoroku solver = new FSugoroku();
        solver.solve(1, in, out);
        out.close();
    }

    static class FSugoroku {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            char[] inputS = in.next().toCharArray(); // len n+1
            boolean[] s = new boolean[n + 1];
            for (int i = 0; i < n; i++) {
                s[i] = inputS[i] == '1';
            }

            Deque<Integer> answer = new ArrayDeque<>();

            int cur = n;
            int last = Integer.MAX_VALUE;
            outer:
            while (cur > 0) {
                for (int i = Math.max(0, cur - m); i < cur; i++) {
                    if (!s[i]) {
                        answer.addFirst(cur - i);
                        last = cur;
                        cur = i;
                        continue outer;
                    }
                }
                out.println(-1);
                return;
            }

            out.println(Util.join(answer));
        }

    }

    static class Util {
        public static String join(Iterable i) {
            StringBuilder sb = new StringBuilder();
            for (Object o : i) {
                sb.append(o);
                sb.append(" ");
            }
            if (sb.length() > 0) {
                sb.deleteCharAt(sb.length() - 1);
            }
            return sb.toString();
        }

    }

    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());
        }

    }
}



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

#ifdef LOCAL
    #define D(a) cerr << #a << " = " << a << endl
#else 
    #define D(a) 8 
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define all(a) (a).begin(),(a).end()
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

const int M = 1e9 + 7;
int add(int a, int b){ return a+b < M ? a+b : a+b-M; }
int mul(int a, int b){ return int(ll(a)*b % M); }
int normal(ll a){ return int(((a % M) + M) % M); } // For neg numbers

int main() {
	fastio;
	
    int n, m; cin >> n >> m;
    int sx = 0, sy = 0;
    forsn(i, 1, n+1) {
        ll x; cin >> x;
        sx = add(sx, normal(x * (2*i-1-n)));
    }
    forsn(i, 1, m+1) {
        ll y; cin >> y;
        sy = add(sy, normal(y * (2*i-1-m)));
    }
    cout << mul(sx, sy) << endl;
	return 0;
}


Measured memory_bytes: 3616
def partition(A,p,r):
    x=A[r]
    i=p-1
    for j in xrange(p,r):
        if A[j]<=x:
            i+=1
            A[i],A[j]=A[j],A[i]
    A[i+1],A[r]=A[r],A[i+1]
    return i+1

n=input()
A=map(int,raw_input().split())
base_i=partition(A,0,n-1)
base="["+str(A[base_i])+"]"
A[base_i]=base
A=map(str,A)
print(" ".join(A))

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

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)(s1[0] - 32) << (char)(s2[0] - 32) << (char)(s3[0] - 32) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

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

		FastScanner sc = new FastScanner();
		int n = sc.nextInt();

		int a[] = new int[n];
		int b[] = new int[n];
		int c[] = new int[n - 1];

		for (int j = 0; j < n; j++) {
			a[j] = sc.nextInt();
		}

		for (int j = 0; j < n; j++) {
			b[j] = sc.nextInt();
		}

		for (int j = 0; j < n - 1; j++) {
			c[j] = sc.nextInt();
		}

		int result = Arrays.stream(b).sum();
		for (int i = 0; i < n - 1; i++) {
			result += (a[i] + 1 == a[i + 1] ? c[a[i] - 1] : 0);
		}

		System.out.println(result);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }
            b = readByte();
        }
    }
    public int nextInt() {
		return (int) nextLong();
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 27860
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=100010;
const ll mod=1e9+7;

//snuke
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
  mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
  mint operator+(const mint a) const { mint res(*this); return res+=a; }
  mint operator-(const mint a) const { mint res(*this); return res-=a; }
  mint operator*(const mint a) const { mint res(*this); return res*=a; }
  mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
  // for prime mod
  mint inv() const { return pow(mod-2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const { mint res(*this); return res/=a; }
}; 

vector<vector<mint>> dp(mx, vector<mint>(2,0));
string s;

int main(){
  cin >> s;
  int n=s.size();
  dp[0][0]=1;
  for(int idx=0; idx<n; idx++){	//j==1 ok j==0 ??
    int keta=(int)(s[idx]-'0');
    dp[idx+1][1] += dp[idx][1]*3;
    if(keta==1){ dp[idx+1][1] += dp[idx][0]; }
    if(keta==1){ dp[idx+1][0] += dp[idx][0]*2; }
    else       { dp[idx+1][0] += dp[idx][0]; }
  }
  mint ans = dp[n][0]+dp[n][1];  
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 5888
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long sum = -n;
    while(n-- > 0){
      sum+=sc.nextInt();
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 25580
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	s = readline() |> chomp
	t = readline() |> chomp
	d = String[]
	for i in 1:length(s)-length(t)+1
		f = 0
		for j in 1:length(t)
			if s[i+j-1]!=t[j] && s[i+j-1]!= '?'
				f = 1
			end
		end
		if f == 0
			push!(d,replace(s[1:i-1]*t*s[i+length(t):length(s)],"?" => "a"))
		end
	end
	if length(d) == 0
		println("UNRESTORABLE")
	else
		d = sort(d)
		println(d[1])
	end
end

main()

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

int main() {
	long long k, n, t = 0, sum1 = 0, sum2 = 0;
	bool flag = false;
	string s;

	cin >> s;
	cin >> k;
	n = s.size();

	rep(i, n-1) {
		if (s[i] != s[i+1]) flag = true;
	}

	if (!flag) {
		cout << n * k / 2;
		return 0;
	}

	rep(i, n-1) {
		if (s[i] == s[i+1]) {
			sum1++;
			i++;
		}	
	}

	s += s;
	n = s.size();
	rep(i, n-1) {
		if (s[i] == s[i+1]) {
			sum2++;
			i++;
		}
	}

	t = sum1 + (sum2 - sum1) * (k-1);
	cout << t;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        System.out.print("2018");
        for(int i=4;i<10;i++)
        {
            System.out.print(s.charAt(i));
        }
        System.out.println("");
    }
}

Measured memory_bytes: 22868
#include <iostream>

using namespace std;

int main()
{
    int a, b , k ;

    cin >>  k  >> a  >> b ;

     for( int i  = a ; i <= b ; i++  )
     {
        if( i%k == 0){cout << "OK" ; return 0;}

     }
     cout << "NG" ;

    return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a < b)
		printf("a < b\n");
	else if(a > b)
		printf("a > b\n");
	else
		printf("a == b\n");

	return 0;
}

Measured memory_bytes: 580
from math import radians, sin, cos
a, b, h, m = [int(x) for x in input().split()]
theta = radians(30 * h + 0.5 * m)
phi = radians(6 * m)
print(((a * sin(theta) - b * sin(phi)) ** 2 +  (a * cos(theta) - b * cos(phi)) ** 2) ** 0.5)

Measured memory_bytes: 9576
#include<stdlib.h>
/*int int_cmp(const int *a, const int *b){
  if (*a < *b)
    return (-1);
  else if (*a > *b)
    return (1);
  return (0);} */
p(int*a,int*b){return*a-*b;}
int main () {
int f[1001];
int F[1001];
int N,i,V,d,count;
N=1001;
f[0]=2;
f[1]=3;
 for(i=2;i<1001;i++){f[i]=(f[i-1]+f[i-2])%N;}
for(;~scanf("%d%d",&V,&d);){
  count = 1;
  for(i=0;i<V;i++)F[i]=f[i];
  qsort(F,V,4,p);
  for(i=1;i<V;i++)
    if( F[ i] - F[ i - 1] > d - 1)
      count++;
  printf( "%d\n" , count);
 }
 return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define td(v) v.begin(),v.end()
#define sz(v) (int)v.size()
//#define M   1000000007 // 1e9 + 7
//#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}


const int N = 100100;
int cor[N];
vector<pii> g[N];
int vis[N];
int cor0,cor1=0;
void dfs(int v){
  vis[v] = 1;
  for(auto e : g[v]){
    if(vis[e.ff])continue;
    cor[e.ff] = cor[v]^e.ss;
    dfs(e.ff);
  }
  if(cor[v]==0)cor0++;
  else cor1++;
}
int res;
int pai[N];
int f(int x){
  return pai[x] = (pai[x]==x?x:f(pai[x]));
}
void merge(int a,int b){
  if(f(a)==f(b))return;
  res--;
  pai[f(a)] = f(b);
}

int32_t main(){
 fastio;
 int n,m;
 cin>>n>>m;
 res = n;
 for(int i=1;i<=n;i++)pai[i] = i;
 for(int i=1;i<=m;i++){
   int x,y,z;
   cin>>x>>y>>z;
   merge(x,y);
 }
 cout <<res << endl;
  // Math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const string NO = "IMPOSSIBLE";

void solve(long long A, long long B){
    if((A+B)%2 == 1) cout << NO << endl;
    else cout << (abs(A-B)/2+min(A,B)) << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

arr=[]
for i in range(N):
    s, p = list(input().split())
    p=int(p)
    arr.append([s,p,i+1])

arr = sorted(arr, key=lambda x:x[0])
arr.append(['zzzzzz',100,100])
tmp=arr[0][0]
arr2=[]
for x in arr:
    if tmp==x[0]:
        arr2.append(x[1:3])
    else:
        arr2=sorted(arr2, key=lambda x:x[0], reverse=True)
        for y in arr2:
            print(y[1])
        arr2=[x[1:3]]
        tmp=x[0]




Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(scan.next());
        }
        int q = Integer.parseInt(scan.next());
        int[] m = new int[q];
        for (int i = 0; i < q; i++) {
            m[i] = Integer.parseInt(scan.next());
        }
        scan.close();

        boolean[] mbool = new boolean[q];
        Arrays.fill(mbool, false);

        for (int bit = 0; bit < (1 << n); bit++) {
            int sum = 0;
            for (int i = 0; i < n; i++) {
                if ((bit & (1 << i)) != 0) {
                    sum += a[i];
                }
            }

            for (int i = 0; i < q; i++) {
                if (sum == m[i]) {
                    mbool[i] = true;
                }
            }
        }

        for (int i = 0; i < q; i++) {
            if (mbool[i]) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }

}



Measured memory_bytes: 27768
a,b = list(map(int,input().split()))
i = 0 #問題設定においてBが1の時、電源タップを差し込む必要がないので使わない時も考慮
tap = 1 #差し込み口の数
while tap < b:
    tap += a-1
    i += 1
print(i)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main()
{
  vector<bool> close(1<<(5*5), false);
  vector<int> cls(1000000);
  int cls_cnt=0;

  for (int n; cin>>n, !(n==0); ){

    vector<vector<int> > pats(33);
    vector<vector<int> > tmp(n, vector<int>(n, 0));

    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	for (int k=i; k<n; k++){
	  for (int l=j; l<n; l++){
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=1;
	    int bd=0;
	    for (int a=0; a<n; a++){
	      for (int b=0; b<n; b++){
		bd=(bd<<1)|tmp[a][b];
	      }
	    }
	    pats[__builtin_clz(bd)].push_back(bd);
	    for (int a=i; a<=k; a++)
	      for (int b=j; b<=l; b++)
		tmp[a][b]=0;
	  }
	}
      }
    }

    int bd=0;
    for (int i=0; i<n; i++){
      for (int j=0; j<n; j++){
	int t; cin>>t;
	bd=(bd<<1)|t;
      }
    }

    int cls_cur=0;
    close[bd]=true;
    cls[cls_cnt++]=bd;
    for (;;){
      int dep=cls[cls_cur]>>25;
      int cbd=cls[cls_cur]&0x1ffffff;
      cls_cur++;
      const vector<int> &ps=pats[__builtin_clz(cbd)];
      int sz=ps.size();
      for (int i=0; i<sz; i++){
	int nbd=cbd^ps[i];
	if (nbd==0){
	  for (int i=0; i<=dep; i++)
	    cout<<"myon";
	  cout<<endl;
	  goto _exit;
	}
	if (close[nbd]) continue;
	close[nbd]=true;
	cls[cls_cnt++]=((dep+1)<<25)|nbd;
      }
    }
  _exit:;
    for (int i=0; i<cls_cnt; i++)
      close[cls[i]&0x1ffffff]=false;
    cls_cnt=0;
  }
  return 0;
}

Measured memory_bytes: 8908
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    long long k,cnt=0;
    cin>>s>>k;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            cnt++;
            if(cnt>=k){
                cout<<1<<endl;
                return 0;
            }
        }
        else{
            cout<<s[i]<<endl;
            return 0;
        }
    }    
    return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
#define MAX_N 21

int main() {
	string a,b,c;
	cin >> a >> b >> c;
	char d[4] = {a[0],b[0],c[0],'\0'};
	string f = d;
	transform (f.begin (), f.end (), f.begin (), ::toupper);
	cout << f;
    return 0;
 }

Measured memory_bytes: 888
import java.io.FileInputStream;
import java.util.NoSuchElementException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;

public class Main {
	
	public static void main(String[] args) throws IOException {
		//FastScanner sc = new FastScanner(new FileInputStream("input.txt"));
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		int ans = 0;
		for(int i = 0; i < N; i++){
			long a = sc.nextLong();
			while(a % 2 == 0){
				ans++;
				a /= 2;
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sample401
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= 9; j++ )
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
                }
            }
        }
    }
}

Measured memory_bytes: 5588
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    const ll INF = 1e18;
    int a, b, q; cin >> a >> b >> q;
    vll s(a), t(b);
    rep(i, a) cin >> s[i];
    rep(i, b) cin >> t[i];
    while(q--){
        ll x; cin >> x;
        auto tr = lower_bound(all(t), x);
        auto sr = lower_bound(all(s), x);
        ll TR = (tr == t.end()) ? INF : *tr - x;
        ll SR = (sr == s.end()) ? INF : *sr - x;
        ll TL = (tr == t.begin()) ? INF : x - *(--tr);
        ll SL = (sr == s.begin()) ? INF : x - *(--sr);
        // cout << SL << " " << TL << " : " << SR << " " << TR << endl;
        ll ans = min({max(TR, SR), max(TL, SL), TR + 2*SL, 2*TR + SL, TL + 2*SR, 2*TL + SR});
        cout << ans << endl;
    }
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 4792
#include<iostream>
#include"bits/stdc++.h"
#include<math.h>
#include<string.h>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\n"
#define MOD 1000000007
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
void solve()
{
	int n,flag=0;
	cin>>n;
	while(n>0)
	{
		int x=n%10;
		if(x==7)
			{
				flag=-1;
			}
		n=n/10;
	}
	if(flag==-1)
		cout<<"Yes";
	else
		cout<<"No";
}
void solve1()
{
	ll n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		if(i%3==0)
			continue;
		if(i%5==0)
			continue;
		sum+=i;
	}
	cout<<sum;
}
void solve2()
{
	int k;
}
int main()
{
	fastio();
	
	//solve();
	solve1();
	return 0;
}

Measured memory_bytes: 3652
n,m = map(int,input().split())
x = []
y = []
for _ in range(m):
    a,b = map(int,input().split())
    if a == 1:
        x.append(b)
    elif b == n:
        y.append(a)
if len(set(x+y)) < len(x)+len(y):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 24896
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
using ll = long long;
using P = pair<int, int>;

// --------------------------------------------------------------------------------

int f(int x)
{
    if (x == 0)
        return 1;
    return f(x - 1) * 2;
}

void solve()
{
    int n, m;
    cin >> n >> m;
    int ans = f(m) * (1800 * m + 100 * n);
    cout << ans << endl;
}

// --------------------------------------------------------------------------------

int main()
{
    // srand((unsigned)time(NULL));
    // int bt = clock();
    solve();
    // double et = 1.0 * (clock() - bt) / CLOCKS_PER_SEC;
    // printf("Execution Time: %.4lf sec\n", et);
    return 0;
}

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

int main() {
  int A, B, C;
  scanf("%d%d%d", &A, &B, &C);

  if (B / A >= C) {
    printf("%d", C);
  } else {
    printf("%d", B / A);
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > T(N), A(N);
	rep(i, N) cin >> T[i];
	rep(i, N) cin >> A[i];
	vector< int > m(N, 1), M(N, LINF);
	m[0] = T[0];
	M[0] = T[0];
	chmax(m[N - 1], A[N - 1]);
	chmin(M[N - 1], A[N - 1]);
	for (int i = 1; i < N; i++) {
		if (T[i] > T[i - 1]) {
			chmax(m[i], T[i]);
			chmin(M[i], T[i]);
		} else {
			chmin(M[i], T[i]);
		}
	}
	for (int i = N - 2; i >= 0; i--) {
		if (A[i] > A[i + 1]) {
			chmax(m[i], A[i]);
			chmin(M[i], A[i]);
		} else {
			chmin(M[i], A[i]);
		}
	}
	int ans = 1;
	rep(i, N) {
		if (M[i] - m[i] + 1 < 0)
			ans = 0;
		(ans *= (M[i] - m[i] + 1)) %= MOD;
	}
	cout << max(ans, 0LL) << endl;
	return 0;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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;
}

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    res[n]++;
  }
  return res;
}

ll N;
map<ll, ll> facs;

int main() {
  cin >> N;
  if (N == 1) {
    cout << 1;
    return 0;
  }
  repe(i, 2, N) {
    auto mp = prime_factor(i);
    for (auto e : mp) {
      facs[e.first] += e.second;
    }
  }

  ll ans = 1;
  for (auto e : facs) {
    ans *= e.second + 1;
    ans %= MOD;
  }
  cout << ans;
}


Measured memory_bytes: 3568
wht = $stdin.gets.split(' ').map { |i| i.to_i }

pp = $stdin.gets.to_i

c = []
pp.times do
  c.push $stdin.gets.split(' ').map { |i| i.to_i }
end

f = []
wht[1].times do
  f.push $stdin.gets.split(' ').map { |i| i.to_i }
end

g = Array.new( wht[1] ).map{ Array.new( wht[0], 0 ) }

c.each do |cc|
  w = cc[0]
  h = cc[1]

  if f[h][w] == 1 then
    g[h][w] += 1
  end
end

p g.map{ |e| e.sum }.sum



Measured memory_bytes: 6916
package main

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

var sc *bufio.Scanner

func nextString() string {
	sc.Scan()
	i := sc.Text()
	return i
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func printList(a []int) {
	for i, v := range a {
		fmt.Print(v)
		if i == len(a)-1 {
			fmt.Print("\n")
		} else {
			fmt.Print(" ")
		}
	}
}

func babbleSort(a []int) ([]int, int) {
	count := 0
	flag := true
	for flag {
		flag = false
		for i := len(a) - 1; i >= 1; i-- {
			if a[i] < a[i-1] {
				a[i], a[i-1] = a[i-1], a[i]
				flag = true
				count++
			}
		}
	}
	return a, count
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	for i, _ := range a {
		a[i] = nextInt()
	}
	a, count := babbleSort(a)
	printList(a)
	fmt.Println(count)
}



Measured memory_bytes: 1108
#include<iostream>

using namespace std;

int cats[100005];

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

    int max = 0, min = 100005;
    for(int i=1; i<=N; i++){
        int a;
        cin >> a;

        cats[a]++;
        if(a > max) max = a;
        if(a < min) min = a;
    }

    if(max - min > 1) cout << "No" << endl;
    else if(max == min){
        if(max == N-1 || 2*max <= N) cout << "Yes" << endl;
        else cout << "No" << endl;
    }else if(max - min == 1){
        if(cats[min] + 1 <= max && max <= cats[min] + (cats[max]/2)) cout << "Yes" << endl;
        else cout << "No " << endl;
    }
}

Measured memory_bytes: 3888
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll MAXN=1e6+10;
ll aval[MAXN],bval[MAXN],cval[MAXN];
bool cmp(ll a,ll b){
    return a>b;
}
ll cnt;
ll val[MAXN];
int main(){
    ll x,y,a,b,c;
    scanf("%lld %lld %lld %lld %lld",&x,&y,&a,&b,&c);
    for(int i=1;i<=a;i++) scanf("%lld",&aval[i]);
    for(int i=1;i<=b;i++) scanf("%lld",&bval[i]);
    for(int i=1;i<=c;i++) scanf("%lld",&cval[i]);
    sort(aval+1,aval+a+1,cmp);
    sort(bval+1,bval+b+1,cmp);
    sort(cval+1,cval+c+1,cmp);
    for(int i=1;i<=x;i++) val[++cnt]=aval[i];
    for(int i=1;i<=y;i++) val[++cnt]=bval[i];
    sort(val+1,val+cnt+1);
    int j=1;
    ll sum=0;
    for(int i=1;i<=cnt;i++){
        if(cval[j]>val[i]){
            sum+=cval[j];
            j++;
        }else{
            sum+=val[i];
        }
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 11904
using System;
using System.IO;


    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().ToCharArray();
            bool yes = false;

            if((str[2] == str[3]) && (str[4] == str[5]))
            {
                yes = true;
            }

            MyConsoleWrightLine(yes ? "Yes":"No");
        }

        private static void MyConsoleWrightLine(string str)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            Console.WriteLine(str);

            Console.Out.Flush();
        }

}


Measured memory_bytes: 13140
#include <stdio.h>
#include <algorithm>
#include <cassert>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <tuple>

#define rep(i, l, r) for (ll i = (l); i <= (r); i++)
#define irep(i, r, l) for (ll i = (r); i >= (l); i--)
#define vec(t) vector<t>

using namespace std;
using ll = long long;
using veci = vec(ll);
using vecll = vec(ll);

using tiii = pair<ll, pair<ll, ll> >;

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

    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vecll A(X), B(Y), C(Z);
    rep(i,0,X-1) cin >> A[i];
    rep(i,0,Y-1) cin >> B[i];
    rep(i,0,Z-1) cin >> C[i];
    sort(A.begin(), A.end()); reverse(A.begin(), A.end());
    sort(B.begin(), B.end()); reverse(B.begin(), B.end());
    sort(C.begin(), C.end()); reverse(C.begin(), C.end());

    set< pair<ll, tiii> > ss;
    set< pair<ll, tiii> > visit;
    pair<ll, tiii> vv = {A[0]+ B[0]+ C[0], {0LL,{0LL,0LL}}};
    ss.insert(vv);
    visit.insert(vv);

    rep(i,1, K) {
        if (ss.empty()) break;
        auto it = ss.rbegin();
        pair<ll, tiii> vv = *it;
        ss.erase( vv );
        cout << vv.first << endl;
        ll x = vv.second.first;
        ll y = vv.second.second.first;
        ll z = vv.second.second.second;
        if (visit.count({ A[x+1LL] + B[y] + C[z], {x+1LL, {y, z}} } ) == 0) {
            if (x<X-1) ss.insert( { A[x+1LL] + B[y] + C[z], {x+1LL, {y, z}} } );
            visit.insert( { A[x+1LL] + B[y] + C[z], {x+1LL, {y, z}} } );
        }

        if (visit.count({ A[x] + B[y+1] + C[z], {x, {y+1, z}} } ) == 0) {
            if (y<Y-1) ss.insert( { A[x] + B[y+1] + C[z], {x, {y+1, z}} } );
            visit.insert( { A[x] + B[y+1] + C[z], {x, {y+1, z}} } );
        }
        if (visit.count({ A[x] + B[y] + C[z+1], {x, {y, z+1}} } ) == 0) {
            if (z<Z-1) ss.insert( { A[x] + B[y] + C[z+1], {x, {y, z+1}} } );
            visit.insert( { A[x] + B[y] + C[z+1], {x, {y, z+1}} } );
        }

    }

}

Measured memory_bytes: 1152
fn main() {
    proconio::input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64,
    }

    let ac = a * c;
    let ad = a * d;
    let bc = b * c;
    let bd = b * d;
    println!("{}", ac.max(ad.max(bc.max(bd))));
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

template <class T>
void cout_vec2(const vector<vector<T>> &vec){
  rep(i,vec.size()){
    rep(j,vec[i].size()){
      cout<<vec[i][j]<<' ';
    }
    cout<<endl;
  }
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<vector<int>> g(n);
  vector<double> dp(n,0);
  rep(i,m){
    int s,t;
    cin>>s>>t;
    s--,t--;
    g[s].push_back(t);
  }
  double ans=1e18;
  rep(i,n){//部屋iからの道を塞ぐ
    for(int j=n-2;j>=0;j--){
      double p=g[j].size();
      double sum=0.0;
      double ma=0;
      for(auto itr:g[j]){
        sum+=dp[itr];
        ma=max(dp[itr],ma);
      }
      if(j==i){
        p--;
        sum-=ma;
        if(p==0) continue;
      }
      dp[j]=sum/p+1;
      //cout<<j<<' '<<sum<<' '<<p<<endl;
    }
    if(dp[0]==0) continue;
    ans=min(ans,dp[0]);
    //cout_vec(dp);
  }
  cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <algorithm>
typedef long long int64;
static const int MAXN = 3e5 + 4;
static const int MODULUS = 1e9 + 7;
#define _  %  MODULUS
#define __ %= MODULUS

int n, m, k;

int64 fact[MAXN * 3], fact_inv[MAXN * 3];

inline int64 fpow(int64 base, int exp)
{
    int64 ans = 1;
    for (; exp; exp >>= 1, (base *= base)__) if (exp & 1) (ans *= base)__;
    return ans;
}
void preprocess()
{
    fact[0] = 1;
    for (int i = 1; i < MAXN * 3; ++i) fact[i] = fact[i - 1] * i _;
    fact_inv[MAXN * 3 - 1] = fpow(fact[MAXN * 3 - 1], MODULUS - 2);
    for (int i = MAXN * 3 - 2; i >= 0; --i) fact_inv[i] = fact_inv[i + 1] * (i + 1)_;
}
inline int64 binom(int n, int m)
{
    if (n < m) return 0; else return fact[n] * fact_inv[m]_ * fact_inv[n - m]_;
}

/*inline int64 _f(int s)
{
    int64 ans = 0;
    for (int t = std::max(0, s - k); t <= m; ++t) (ans += binom(s, t))__;
    //printf("%2d | %2d | %2d\n", s, std::max(0, s - k), m);
    return ans;
}*/

int64 f[MAXN * 3];

int main()
{
    preprocess();
    scanf("%d%d%d", &n, &m, &k);

    f[0] = 1;

    if (m < k) { int t = m; m = k; k = t; }
    for (int i = 1; i <= k; ++i) f[i] = (f[i - 1] + f[i - 1])_;
    for (int i = k + 1; i <= m + k; ++i)
        f[i] = (f[i - 1] + f[i - 1] - binom(i - 1, i - 1 - k) - binom(i - 1, m) + MODULUS * 2)_;

    int64 ans = 0;
    //for (int i = 0; i <= m + k; ++i) printf("%2d | %lld | %lld\n", i, f[i], _f(i));
    for (int s = n + 1; s <= n + m + k + 1; ++s) {
        (ans += binom(s - 2, n - 1) * f[s - n - 1]_ * fpow(3, n + m + k + 1 - s))__;
    }
    printf("%lld\n", ans);

    return 0;
}


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

struct UnionFind {
    vector<int> par;  // par[i]: parent of i

    UnionFind(int N) : par(N+1) {  // initialize by making every node a root node
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {  // find the root of a given node
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

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

    bool same(int x, int y) {  // return true if x and y belong to the same tree
        return root(x) == root(y);
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    UnionFind uf(n);
    rep(i, m) {
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (uf.same(p[i], i + 1)) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
constexpr int mod = 1e9 + 7;

int dp[2020];

int calc(int t){
  if(t < 3) return 0;
  if(t == 3) return dp[3] = 1;
  if(dp[t] != -1) return dp[t];
  int res = 1;
  for(int i = 3; i <= t - 3; i++){
    res += calc(t - i);
    res %= mod;
  }
  return dp[t] = res;
}

signed main(){
  int s;
  cin >> s;
  if(s < 3){
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for(int i = 0; i <= s; i++) dp[i] = -1;
  cout << calc(s) << endl;
}

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

using i32 = int;
using i64 = long long;

#define REP(i, stop) for (register int i = 0; i < stop; ++i)
#define ALL(v) (v).begin(), (v).end()

template<typename T>
T read() {
  T a = 0;
  for(;;) {
    char c = getchar();
    if (c & 16) {
      a = a * 10 + c - 48;
    } else {
      return a;
    }
  }
}

i64 A[1000], B[1000], C[1000];
signed main() {
//  i32 x, y, z, k;
//  scanf("%d%d%d%d", &x, &y, &z, &k);
  i32 X = read<i32>(),
      Y = read<i32>(),
      Z = read<i32>(),
      K = read<i32>();
//  REP(i, x) scanf("%lld", &A[i]);
//  REP(i, y) scanf("%lld", &B[i]);
//  REP(i, z) scanf("%lld", &C[i]);
  REP(i, X) A[i] = -read<i64>();
  REP(i, Y) B[i] = -read<i64>();
  REP(i, Z) C[i] = -read<i64>();
  sort(A, A + X);
  sort(B, B + Y);
  sort(C, C + Z);
  using P = pair<i64, i64>;
  set<P> Q;
  Q.insert({A[0] + B[0] + C[0], 0});
  REP(_, K) {
    i64 p = -(*Q.begin()).first;
    i64 q = (*Q.begin()).second;
    printf("%lld\n", p);
    Q.erase(Q.begin());
    i32 u = q & 1023;
    i32 v = q >> 10 & 1023;
    i32 w = q >> 20 & 1023;
    i64 u1 = q + 1;
    i64 v1 = q + (1 << 10);
    i64 w1 = q + (1 << 20);
    if (u + 1 < X) Q.insert({A[u + 1] + B[v] + C[w], u1});
    if (v + 1 < Y) Q.insert({A[u] + B[v + 1] + C[w], v1});
    if (w + 1 < Z) Q.insert({A[u] + B[v] + C[w + 1], w1});
  }
}

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

int main() {
  int A[3][3];
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j)
      std::cin >> A[i][j];
  
  int N; std::cin >> N;
  std::vector<int> b(N);
  for (int i = 0; i < N; ++i) std::cin >> b[i];

  for (int p : b)
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j)
        if (A[i][j] == p) A[i][j] = 0;

  bool ans = false;
  /* 縦 */
  for (int i = 0; i < 3; ++i) {
    if (A[0][i] + A[1][i] + A[2][i] == 0) ans = true;
  }

  /* 横 */
  for (int i = 0; i < 3; ++i) {
    if (A[i][0] + A[i][1] + A[i][2] == 0) ans = true;
  }

  /* 斜め */
  if (A[0][0] + A[1][1] + A[2][2] == 0) ans = true;
  if (A[0][2] + A[1][1] + A[2][0] == 0) ans = true;

  if (ans) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
   
  return 0;

}


Measured memory_bytes: 3600