akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
 
#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
 
#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 mp make_pair
#define ins insert
 
using namespace std;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<vi> p(n);
    rep(i,m){
        int a,b; cin>>a>>b; a--; b--;
        p[a].pb(b);
    }
    int ans=0;
    int mi=101010;
    rep(i,n){
        if (i==mi){
            ans++;
            mi=101010;
        }
        for(auto e:p[i]) chmin(mi,e);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8676
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define int long long
#define mod 924844033
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN=800001;
int n,inv[MAXN],head[MAXN],fac[MAXN],infac[MAXN],Cnt,cnt[MAXN],siz[MAXN];
int C(int n,int m){return (((fac[n]*infac[m])%mod)*infac[n-m])%mod;}
struct node{
    int u,v,nex;
}x[MAXN<<1];
void add(int u,int v){
    x[Cnt].u=u,x[Cnt].v=v,x[Cnt].nex=head[u],head[u]=Cnt++;
}
int ksm(int a,int b){
    int ans=1;
    while(b){
        if(b&1) ans*=a,ans%=mod;
        a*=a,a%=mod;
        b>>=1;
    }return ans;
}
void dfs(int u,int fath){
    siz[u]=1;
    for(int i=head[u];i!=-1;i=x[i].nex){
        if(x[i].v==fath) continue;
        dfs(x[i].v,u);
        siz[u]+=siz[x[i].v];
        cnt[siz[x[i].v]]++;
    }
    cnt[n-siz[u]]++;
    return;
}
int N,M,flip[MAXN],f[MAXN],g[MAXN];
void NTT(int *f,int opt){
    for(int i=0;i<N;i++) if(i<flip[i]) swap(f[i],f[flip[i]]);
    for(int p=2;p<=N;p<<=1){
        int len=p>>1,buf=ksm(5,(mod-1)/p);
        if(opt==-1) buf=ksm(buf,mod-2);
        for(int be=0;be<N;be+=p){
            int tmp=1;
            for(int l=be;l<be+len;l++){
                int t=f[l+len]*tmp;t%=mod;
                f[l+len]=(f[l]-t+mod)%mod,f[l]=(f[l]+t)%mod;
                tmp*=buf,tmp%=mod;
            }
        }
    }
    if(opt==-1){
        int inv=ksm(N,mod-2);
        for(int i=0;i<N;i++) f[i]*=inv,f[i]%=mod;
    }return;
}
signed main(){
//    freopen("6.in","r",stdin);
    memset(head,-1,sizeof(head));
    inv[1]=1;for(int i=2;i<=200000;i++) inv[i]=((mod-mod/i)*inv[mod%i])%mod;
    fac[0]=1;for(int i=1;i<=200000;i++) fac[i]=(fac[i-1]*i)%mod;
    infac[0]=1;for(int i=1;i<=200000;i++) infac[i]=(infac[i-1]*inv[i])%mod;
    n=read();
    for(int i=1;i<n;i++){
        int u=read(),v=read();
        add(u,v),add(v,u);
    }
    dfs(1,0);
    N=n,M=n;
    for(int i=0;i<=N;i++) f[i]=(cnt[i]*fac[i])%mod;
    for(int i=0;i<=M;i++) g[i]=infac[n-i];
    M+=N;
    for(N=1;N<=M;N<<=1);
    for(int i=0;i<N;i++) flip[i]=((flip[i>>1]>>1)|(i&1?N>>1:0));
    NTT(f,1),NTT(g,1);
    for(int i=0;i<N;i++) f[i]*=g[i],f[i]%=mod;
    NTT(f,-1);
    for(int i=1;i<=n;i++){
        int a=(n*C(n,i))%mod,b=(infac[i]*f[n+i])%mod;
        printf("%lld\n",(((a-b)%mod)+mod)%mod);
    }return 0;
}

Measured memory_bytes: 65408
import Control.Monad

solver::[Integer]->Integer
solver (x:[]) = x
solver (x:y:rest) = solver ((div (x*y) (gcd x y)):rest)

main::IO()
main=do
  nc<-getLine
  let n = read nc
  ss<-forM [1..n] (\_-> getLine)
  let ls = map read ss ::[Integer]
  print (solver ls)

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

#define MAX 100

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> A(MAX, vector<char>(MAX));
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			cin >> A[h][w];
		}
	}
	for (auto h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			if (A[h][w] == '#') {
				break;
			}
			if (w == W - 1) {
				A.erase(A.begin() + h);
				H--;
				h--;
			}
		}
	}
	for (auto w = 0; w < W; w++) {
		for (int h = 0; h < H; h++) {
			if (A[h][w] == '#') {
				break;
			}
			if (h == H - 1) {
				for (int i = 0; i < H; i++) {
					A[i].erase(A[i].begin() + w);
				}
				W--;
				w--;
			}
		}
	}
	for (int h = 0; h < H; h++) {
		for (int w = 0; w < W; w++) {
			cout << A[h][w];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X = int(readline())
for a in range(-119,121):
    for b in range(-119,121):
        if (a**5-b**5) == X:
            print(a,b)
            sys.exit()

Measured memory_bytes: 9180
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N = int(sys.stdin.readline())
T, A = list(map(int, sys.stdin.readline().split()))
H = list(map(int, sys.stdin.readline().split()))

H = np.array(H)
H = abs(A - (T - H * 0.006))
print(H.argmin() + 1)


Measured memory_bytes: 13740
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <stdio.h>
#include <vector>
#include <functional>
#include <unordered_set>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

const int N = 2e5 + 10;
const long long INF = 1LL << 60;
long long a[N];
long long dp[N][6]; //0 even odd even 0

void relax(long long& a, long long b) {
	a = min(a, b);
}

long long odd(long long x) {
	return 1 - x % 2;
}

long long even(long long x) {
	if (x == 0) {
		return 2;
	}
	return x % 2;
}

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i <= n + 1; ++i) {
		for (int j = 0; j < 5; ++j) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 5; ++j) {
			int val = a[i];
			if (j == 0) {
				relax(dp[i + 1][0], dp[i][0] + val);
				relax(dp[i + 1][1], dp[i][0] + even(val));
			} else if (j == 1) {
				relax(dp[i + 1][1], dp[i][1] + even(val));
				relax(dp[i + 1][2], dp[i][1] + odd(val));
			}
			else if (j == 2) {
				relax(dp[i + 1][2], dp[i][2] + odd(val));
				relax(dp[i + 1][3], dp[i][2] + even(val));
			}
			else if (j == 3) {
				relax(dp[i + 1][3], dp[i][3] + even(val));
				relax(dp[i + 1][4], dp[i][3] + val);
			}
			else if (j == 4) {
				relax(dp[i + 1][4], dp[i][4] + val);
			}
			relax(dp[i][j + 1], dp[i][j]);
			relax(dp[i + 1][j + 1], dp[i + 1][j]);
		}
	}
	cout << dp[n][4] << "\n";
	return 0;
}

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

class DisjointSet {

public:
	int size;
	vector<int> p, w, r;
	
	DisjointSet(){}
	DisjointSet(int n){
		size = n;
		p.resize(size, 0);
		r.resize(size, 0);
		w.resize(size, 0);
		for(int i=0;i<size;i++){
			makeSet(i);
		}
	}

	void makeSet(int x){
		p[x]=x;
		r[x]=0;
		w[x]=0;	
	}
	
	void relate(int x, int y, int z){
		int xp = findSet(x);
		int yp = findSet(y);
		link(xp, yp, z-w[x]+w[y]);
	}

	void link(int x, int y, int cost){
		if(r[x]>r[y]){
			p[y]=x;
			w[y]-=cost;
		} else {
			p[x]=y;
			w[x]+=cost;
			if(r[x]==r[y]){
				r[y]++;
			}
		}
	}
	
	bool same(int x, int y){
		return findSet(x)==findSet(y);
	}
	
	int sum(int x){
		int sum=0;
		int cur=x;
		while(cur!=p[cur]){
			sum+=w[cur];
			cur=p[cur];
		}
		return sum;
	}
	
	int findSet(int x){
		if(p[x]!=x){
			int tmp=findSet(p[x]);
			w[x]+=w[p[x]];
			p[x]=tmp;
		}
		return p[x];
	}
};

int main(){
	int n, q;
	cin >> n >> q;
	DisjointSet ds(n);
	for (int i=0;i<q;i++) {
		int c, x, y, z;
		cin >> c >> x >> y;
		if (c == 0) {
			cin >> z;
			ds.relate(x, y, z);
		} else {
			if (!ds.same(x, y)){
				cout << "?" << endl;
			} else {
				int sumX = ds.sum(x);
				int sumY = ds.sum(y);
				cout << sumX - sumY << endl;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3876
const MOD: u64 = 1e9 as u64 + 7;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let k: u64 = sc.read();
    let a: Vec<u64> = sc.vec(n);
    let mut before = vec![0; n];
    let mut after = vec![0; n];
    for i in 0..n {
        for j in 0..n {
            if a[j] > a[i] && j < i {
                before[i] += 1;
            }
            if a[j] > a[i] && i < j {
                after[i] += 1;
            }
        }
    }

    let mut ans = 0;
    for i in 0..n {
        let b = (k * (k + 1) / 2) % MOD;
        let b = (before[i] * b) % MOD;

        let a = (k * (k - 1) / 2) % MOD;
        let a = (a * after[i]) % MOD;
        ans += a + b;
        ans %= MOD;
    }
    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

typedef tree<
        pair<int, int>,
        null_type,
        less<pair<int, int>>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{*
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
*/


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

    int n;
    cin>>n;
    vector<int> a(n);
    ll sum = 0;
    for (int i = 0; i<n; i++) {cin>>a[i]; sum+=a[i];}
    if (sum%2) cout<<"NO"; else cout<<"YES";



}



Measured memory_bytes: 3696
from sys import stdin

def main():

    input = stdin.readline

    A,B,C = map(int,input().split())

    judge = False

    if(A==B) or (B==C) or (C==A):
        if(A==B==C):
            print("No")
        else:
            print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

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

using namespace std; 

int main()   
{
	int n;
	cin >> n;
	while (n)
	{
		int a = (int)(sqrt(n));
		if (a * a == n)
		{
			cout << n;
			return 14 / 88;
		}
		n--;
	}
	return 14 / 88;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+9;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;ans%=mod;}b/=2;a*=a;a%=mod;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
const int INF=0x3f3f3f3f;
#define PII pair<int,int>
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
#define ld long double
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}

int main()
{
    int n,m,k;
    si(n);si(m);si(k);

    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            int b=i*(m-j) + j*(n-i);

            if(b==k){
                cout<<"Yes\n";
                return 0;
            }
        }
    }

    cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
import java.util.Set;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CWriteAndErase {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            Set<Integer> s = new HashSet<>();
            int n = in.ints();
            for (int i = 0; i < n; i++) {
                int a = in.ints();
                if (s.contains(a)) {
                    s.remove(a);
                } else {
                    s.add(a);
                }
            }
            out.println(s.size());
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



Measured memory_bytes: 44376
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	private void execute() {
		try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){
			String [] nm = in.readLine().split(" ");
			final int N = Integer.parseInt(nm[0]);
			final int M = Integer.parseInt(nm[1]);
			City[] cities = new City[M];
			int [] order = new int [N];

			for (int i = 0; i < M; i++) {
				String [] py = in.readLine().split(" ");
				City c = new City(i, Integer.parseInt(py[0]), Integer.parseInt(py[1]));
				cities[i] = c;
			}

			Arrays.sort(cities, new Comparator<City>() {
				@Override
				public int compare(City o1, City o2) {
					// TODO Auto-generated method stub
					return o1.established - o2.established;
				}
			});
			
			for (int i = 0; i < M; i++) {
				cities[i].order = ++order[cities[i].prefId-1];
			}
			Arrays.sort(cities);
			for (int i = 0; i < M; i++) {
				System.out.println(cities[i].cityCode());
			}			
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	class City implements Comparable<City> {
		private static final String CODE_FORMAT = "%06d%06d";
		int id;
		int prefId;
		int established;
		int order;

		@Override
		public int compareTo(City that) {
			// TODO Auto-generated method stub
			return this.id - that.id;
		}

		public City(int id, int prefId, int established) {
			this.id = id;
			this.prefId = prefId;
			this.established = established;
		}

		public String cityCode() {
			return String.format(CODE_FORMAT, prefId, order);
		}

	}
}


Measured memory_bytes: 112948
import math

# # 動作確認用にファイルから入力
# with open('input_itp1_10_c_1.txt', mode='r') as fin:
#     while True:
#         n = int(next(fin))
#         if n == 0:
#             break
#         data = [int(i) for i in next(fin).split()]
#         mean = sum(data) / n
#         tmp = 0
#         for i in data:
#             tmp += (i - mean)**2
#         print('%f' % (math.sqrt(tmp / n)))

while True:
    n = int(input())
    if n == 0:
        break
    data = [int(i) for i in input().split()]
    mean = sum(data) / n
    tmp = 0
    for i in data:
        tmp += (i - mean)**2
    print('%f' % (math.sqrt(tmp / n)))



Measured memory_bytes: 5712
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
    string s;
    int m,h;
    while(1){
        cin >> s;
        if(s == "-") break;
        cin >> m;
        for(int i=0;i<m;i++){
            cin >> h;
            s = s.substr(h,s.size()-h) + s.substr(0,h);
        }
        cout << s << endl;
    }
}



Measured memory_bytes: 3180
#include <stdio.h>

typedef struct{
	int max;
	int order;
}MAX;

void max_order(int a[], int size, MAX *ret){
	int max, order;
	max=a[--size];
	order=size;
	while(size){
		size--;
		if(max<a[size]){
			max=a[size];
			order=size;
		}
	}
	ret->max=max;
	ret->order=order;
}

int main(){
	int N, i, j, chain=0, ord;
	MAX data;
	scanf("%d", &N);
	int a[N], b[N], c;
	for(i=0;i<N;i++){
		scanf("%d", &a[i]);
	}
	for(i=0;i<N;i++){
		c=a[i];
		b[i]=0;
		while(c%2==0){
			b[i]++;
			c/=2;
		}
	}
	
	for(i=0;;i++){
		max_order(b, N, &data);
		if(data.max==0){
			break;
		}
		b[data.order]--;
	}
	printf("%d", i);
}

Measured memory_bytes: 256
suits = [ 'S', 'H', 'C', 'D' ]
cards = []
suits.each { |shcd|
	for i in ( 1 .. 13 )
		cards.push( sprintf( "%s %d", shcd, i ) )
	end
}

n = gets.to_i
for i in ( 0 ... n )
	pattern, num = gets.split( " " )
	cards.delete( sprintf( "%s %s", pattern, num ) )
end

cards.each { |card|
	print( "#{card}\n" )
}

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

using namespace std;

int main() {
    int n;
    string s;
    
    cin>>n>>s;
    if(s.length() < 2 || s.length() % 2 != 0)
    {
         cout<<"No";
            return 0;
    }
    
    for(int i=0;i<=(n/2)-1;i++)
    {
        if(s[i] != s[i+(n/2)])
        {
            
            cout<<"No";
            return 0;
        }
    }
    
    cout<<"Yes";
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    vector<pii> edge[N];
    rep(i, N-1){
        int a, b;
        cin >> a >> b;
        a--, b--;
        edge[a].push_back(pii(b, i));
        edge[b].push_back(pii(a, i));
    }
    int M;
    cin >> M;
    ll es[M];
    fill_n(es, M, 0);
    rep(i, M){
        int u, v;
        cin >> u >> v;
        u--, v--;
        queue<int> que;
        vector<int> path[N];
        bool used[N];
        fill_n(used, N, false);
        que.push(u);
        used[u] = true;
        while(!que.empty()){
            int j = que.front();
            que.pop();
            rep(k, edge[j].size()){
                int p = edge[j][k].first;
                if(!used[p]){
                    used[p] = true;
                    que.push(p);
                    path[p] = path[j];
                    path[p].push_back(edge[j][k].second);
                }
            }
        }
        rep(j, path[v].size()){
            es[i] |= 1ll<<path[v][j];
        }
    }
    ll ans = 0;
    rep(bit, 1<<M){
        ll eset = 0;
        rep(i, M){
            if(bit & 1<<i) eset |= es[i];
        }
        int white = __builtin_popcountll(eset);
        ll now = 1ll<<(N-1-white);
        if(__builtin_popcount(bit)%2) ans -= now;
        else ans += now;
    }
    cout << ans << endl;
}


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

const int N = 1e5 + 7;

vector <int> ad[N];
int n, m;
bool mrk[N];
deque <int> d;

int main() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		ad[x].push_back(y);
		ad[y].push_back(x);
	}
	for (int i = 1; i <= n; i++) {
		if (ad[i].size() > 0) {
			d.push_front(i);
			d.push_back(ad[i][0]);
			mrk[i] = mrk[ad[i][0]] = 1;
			break;
		}	
	}	
	bool s = 1;
	while (s) {
		s = 0;
		int v = d.front();
		for (auto u: ad[v]) {
			if (!mrk[u]) {
				s = 1;
				d.push_front(u);
				mrk[u] = 1;
				break;
			}
		}
		v = d.back();
		for (auto u: ad[v]) {
			if (!mrk[u]) {
				s = 1;
				d.push_back(u);
				mrk[u] = 1;
				break;
			}
		}
	}
	cout << d.size() << endl;
	for (auto i: d) 
		cout << i << " ";
	return 0;
}


Measured memory_bytes: 6784
def wall(grid,x,y,d):
    if d==0: return x<4 and grid[y*2][x]=='1'
    if d==1: return y<4 and grid[y*2+1][x]=='1'
    if d==2: return x>0 and grid[y*2][x-1]=='1'
    if d==3: return y>0 and grid[y*2-1][x]=='1'

def move(x,y,d):
    if d==0: return (x+1,y,'R')
    if d==1: return (x,y+1,'D')
    if d==2: return (x-1,y,'L')
    if d==3: return (x,y-1,'U')

path=""
x=y=d=0
grid=[raw_input() for i in range(9)]
while x!=0 or y!=0 or d<2:
    d=(d+3)%4
    while not wall(grid,x,y,d):
        d=(d+1)%4
    (x,y,c)=move(x,y,d)
    path+=c
print path

Measured memory_bytes: 4260
#include<stdio.h>

unsigned long math(unsigned long *a,unsigned long *b);

int main(){

	unsigned long r[5000];
	unsigned long i=0;
	unsigned long A,B;   //A>B
	unsigned long tmp,h1,h2;

	while(scanf("%lu%lu",&A,&B)!=EOF){
		if(A==B){
			printf("%lu ",A/B);
			printf("%lu\n",A*B);
			;
		}else{
			h1=A;h2=B;
			for(;;){	
				r[i]=math(&h1,&h2);

				if(r[i]==0){
					printf("%lu ",r[i-1]);
					printf("%lu\n",(A*B)/r[i-1]);
					break;
				}
				h1=r[i];
				i++;
			}
		}
	}
	return 0;
}

unsigned long
 math(
	unsigned long *a,
	unsigned long *b)
{
	unsigned long tmp,J;
	if(*a<*b){
		tmp=*a;
		*a=*b;
		*b=tmp;
	}
	 J=*a-*b;
	return J;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  ll N;
  cin >> N; 
  if (N&1) {
    cout << 0 << endl; return 0;
  }
  N /= 2;
  ll ans = 0;
  while (N >= 5) {
    ans += N/5;
    N /= 5;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3756
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
    int k;
    string s;
    cin >> k >> s;

    if (s.size() <= k) cout << s << endl;
    else {
        cout << s.substr(0, k) << "..." << endl;
    }
}

Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 木 11/ 9 19:01:14 2017

# Usage
#
"""
from itertools import accumulate

def data_req():
    n_yado, m_ryotei = [int(i) for i in input().split(" ")]
    yado_distance = []
    ryotei = []
    for _ in range(n_yado - 1):
        yado_distance.append(int(input()))
    for _ in range(m_ryotei):
        ryotei.append(int(input()))

    return yado_distance, ryotei


def search(distance, ryotei):
    """search.

    >>> search([2, 1, 1, 3, 2, 1], [2, -1, 3, 2, -3])
    18
    """
    acc = [0] + list(accumulate(distance, lambda x, y: x+y))
    ryotei_index = [0] + list(accumulate(ryotei, lambda x, y: x+y))
    # print(ryotei_index)
    res = []
    for index in enumerate(ryotei_index):
        if index[0] == 0:
            continue
        index = index[0]
        # print(index)
        # print(ryotei_index[index])
        # print(ryotei_index[index - 1])
        dist = abs(acc[ryotei_index[index]] - acc[ryotei_index[index - 1]])
        res.append(dist)
        # print(sum(res))
    # his = []
    #
    # for index in range(len(ryotei_index)):
    #     his.append(acc[ryotei_index[index + 1]] - acc[ryotei_index[index]])
    #
    # return sum(his)
    return sum(res)


if __name__ == '__main__':
    dis, ryotei = data_req()
    print(search(dis, ryotei) % 100000)

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

int main(void){
  int h,w;
  cin>>h>>w;
  //vector< vector<int> > maze(vector<int>(w),h);

  int maze[50][50];
  for(int i = 0 ; i < 50 ; i ++){
    for(int j = 0 ; j < 50 ; j ++){
      maze[i][j] = 0;
    }
  }

  for(int i = 0 ; i < h ; i ++){
    for(int j = 0 ; j < w ; j ++){
      char c;
      cin>>c;
      maze[i][j] = c-'0';
      //cout<<maze[i][j]<<(j==w-1?"\n":" ");
    }
  }
  
  for(int i = 1 ; i < w ; i ++){
    maze[0][i] = maze[0][i-1] + maze[0][i];
  }
  for(int i = 1 ; i < h ; i ++){
    maze[i][0] = maze[i-1][0] + maze[i][0];
  }

  for(int i = 1 ; i < h ; i ++){
    for(int j = 1 ; j < w ; j ++){
      maze[i][j] = min(maze[i-1][j] , maze[i][j-1]) + maze[i][j];
    }
  }
  /*for(int i = 0 ; i < h ; i ++){
    for(int j = 0 ; j < w ; j ++){
      cout<<maze[i][j]<<(j==w-1?"\n":" ");
    }
  }
  //*/
  cout<<maze[h-1][w-1]<<endl;
  
}

Measured memory_bytes: 1168
using System;
using System.Linq;

class AizuOnlineJudge {
    static void Main() {
        var i = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(
            Enumerable.Range(0, int.Parse(Console.ReadLine()))
                .Select(_ => Console.ReadLine())
                .Aggregate(i[0], (c, s) => s == "karero" ? 0 : s == "nobiro" ? Math.Max(c + i[1], 0) : Math.Max(c + i[2], 0))
        );
    }
}



Measured memory_bytes: 20448
def sumofdigits(n):
  s = 0
  while n > 0:
    s += n % 10
    n = n // 10
  return s

n, a, b = map(int, input().split())

f = 0
for i in range(1, n+1):
  s = sumofdigits(i)
  if s >= a and s <= b:
    f += i
print(f)

Measured memory_bytes: 8944
#include<bits/stdc++.h>
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int INF=1e9+5; 
int main()
{
	fastio;
	int n,k;
	cin>>n>>k;
	vector<int> h(n+1);
	for(int i=0;i<n;i++)
		cin>>h[i+1];
	vector<int>dp(n+1,INF);

	dp[1]=0;
	for(int i=2;i<=n;i++)
	{
		for(int j=i-1;j>=max(0,i-k);j--)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n]<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    ll l[m],r[m];
    rep(i,m) cin >> l[i]>>r[i];
    ll ml=l[0],mr=r[0];
    rep(i,m){
        ml=max(ml,l[i]);
        mr=min(mr,r[i]);
    }
    if(mr<ml) cout << 0 << endl;
    else cout << mr-ml+1 << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
divisors = []
for i in range(1, int(pow(n, 0.5)) + 1):
    if n % i == 0:
        divisors.append([i, n // i])
divisors = sorted(divisors, key= lambda x:x[1])
res = 0

for i in divisors[0]:
    res += i - 1

print(res)

Measured memory_bytes: 3560
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

/* define*/
#define Yes(X) puts ( X ? "Yes" : "No")
#define YES(X) puts ( X ? "YES" : "NO")
#define FOR(i, a, b) for ( i = a; i < b ; i++)
#define REP(i, n) for ( i = 0; i < n ; i++)
#define DER(i, n) for ( i = n; n ; i--)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1e9 + 7;

/* alias */
typedef long long ll;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}

/* main */
int i, j, k;

int main() {
	int n, a, b, ma, mb = 1e9 + 1;
	scanf("%d", &n);
	REP(i, n) {
		scanf("%d%d", &a, &b);
		if (mb > b) {
			mb = b;
			ma = a;
		}
	}
	printf("%d", ma + mb);
	return 0;
}

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

#define For(i, j, k) for (int i = j; i <= k; i++)

using namespace std;

const int N = 2e5 + 10;

struct Point {
	int x, y;

	bool operator < (const Point B) {
		return y == B.y ? x < B.x : y < B.y;
	}
}P[N];

int h, w, n;

int main() {

	scanf("%d%d%d", &w, &h, &n);
	For(i, 1, n) scanf("%d%d", &P[i].x, &P[i].y);
	sort(P + 1, P + n + 1);
	
	int ans = w, p = 1;
	int cur = 1;

	For(i, 1, h) {
		while (p <= n && P[p].y == i) {
			if (P[p].x <= cur) {
				while (p + 1 <= n && P[p + 1].x == P[p].x + 1 && P[p + 1].y == i) ++p;
				cur = max(cur, P[p].x + 1);
			} else {
				ans = min(ans, P[p].x - 1);
			}
			++p;
		}
		++cur;
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 1792
import java.io.*;
import java.util.Scanner;

class Main {
   public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       int    x = in.nextInt();
       int    y = in.nextInt();
       int    w;
       
       while(x!=0 || y!=0){
          if(x>y){
             w = x;
             x = y;
             y = w;
          }
        System.out.println(x + " " + y);

        x = in.nextInt();
        y = in.nextInt();
}  

}
}

Measured memory_bytes: 27200
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=0;i<100;i++){
    if(n<=1000*i){
      cout<<1000*i-n;
      break;
    }
    else
      continue;
  }
  return 0;
}

Measured memory_bytes: 3600
n,m = map(int, input().split())
la = []
lw = []
lwa = []
for i in range(n):
  la.append(0)
  lw.append(0)
  lwa.append(0)
for _ in range(m):
  q,a = input().split()
  if a == "WA" and la[int(q)-1] != 1:
    lw[int(q)-1] += 1
  elif a == "AC" and la[int(q)-1] != 1:
    la[int(q)-1] = 1
    lwa[int(q)-1] = lw[int(q)-1]
    
print(sum(la), sum(lwa))

Measured memory_bytes: 5560
import sys
from collections import defaultdict
import heapq
input = sys.stdin.readline
n, limit = map(int, input().split())
dic = defaultdict(list)

for _ in range(n):
    a, b = map(int, input().split())
    dic[a].append(b)

L = []
ans = 0
for i in range(limit+1):
    for val in dic[i]:
        heapq.heappush(L, -val)
    if len(L):
        ans -= heapq.heappop(L)
print(ans)

Measured memory_bytes: 27776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
  }

  vl l(n), r(n);
  rep(i, n-1) {
    l[i+1] = __gcd(l[i], a[i]);
  }

  for(ll i = n-1; i > 0; i--) {
    r[i-1] = __gcd(r[i], a[i]);
  }

  ll ans = 1;
  rep(i, n) {
    cmax(ans, __gcd(l[i], r[i]));
  }

  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))

#ifdef ONLINE_JUDGE
#define link renamelink
#define next renamenext
#define prev renameprev
#endif

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef long double ld;

// #define ONLINE_JUDGE
inline void EnableFileIO(const string& fileName) {
  if (fileName.empty()) return;
#ifdef ONLINE_JUDGE
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
#endif
}

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10, PI = acos(-1);
const int N = 2e5 + 100;

int n, q;
typedef pair<LL, pii> tup;
priority_queue<tup, vector<tup>, greater<tup> > pq;
vector<tup> es;

LL nxt[N];
int fa[N];

int getfa(int k) { return fa[k] == k ? k : fa[k] = getfa(fa[k]); }

int main() {
  // srand((int)time(0));
  // printf("Hello, world!\n");
  // EnableFileIO("");
  ios::sync_with_stdio(false);
  cin.tie(0);

  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) nxt[i] = LINF, fa[i] = i;
  for (int i = 0; i < q; i++) {
    int u, v;
    LL k;
    scanf("%d%d%lld", &u, &v, &k);
    es.pb(mp(k, mp(u, v)));
    nxt[u] = min(nxt[u], k + 1);
    nxt[v] = min(nxt[v], k + 2);
  }
  for (int i = 0; i < n * 3; i++) {
    nxt[(i + 1) % n] = min(nxt[(i + 1) % n], nxt[i % n] + 2);
  }
  for (int i = 0; i < n; i++) {
    es.pb(mp(nxt[i], mp(i, (i + 1) % n)));
    // cerr << i << ' ' << nxt[i] << endl;
  }
  sort(es.begin(), es.end());

  LL ans = 0;
  for (int i = 0; i < es.size(); i++) {
    LL k = es[i].first;
    int u = es[i].second.first, v = es[i].second.second;

    if (getfa(u) == getfa(v)) continue;
    // cerr << k << ' ' << u << ' ' << v << endl;
    ans += k;
    fa[getfa(u)] = getfa(v);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 13672
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxm=2e5+5;
const int mod=1e9+7;
int a[maxm];
int b[maxm];
int n;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int x,y;cin>>x>>y;
        a[i]=x-y;
        b[i]=x+y;
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    int ans=max(a[n]-a[1],b[n]-b[1]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////
ll keta(ll i){
    ll a=0;
    while(i>0){
        i=i/10;
        a++;
    }
    return a;
}

int main(){
    ll n;cin>>n;
    ll ans=inf;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ans=min(ans,max(keta(n/i),keta(i)));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    if b[i]>=a[i]:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0
        c = min(b[i],a[i+1])
        ans += c
        b[i] -= c
        a[i+1] -= c
    else:
        ans += b[i]
        a[i] -= b[i]
        b[i] -= b[i]

print(ans)

Measured memory_bytes: 97716
#include<cstdio>
#include<cmath> 
#include<iostream> 
#include<iomanip>
#include<string>
#include<algorithm>
using namespace std;
int n,k;
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	cin>>n>>k;
    if(n%k>0)
    	cout<<1;
    else
    	cout<<0;
	//fclose(stdin);
	//fclose(stdout);
    return 0;
}

Measured memory_bytes: 256
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))

def main():
    x,a,b = readInts()
    # X+1だとだめです
    if b <= a:
        print('delicious')
    elif a < b <= a + x:
        print('safe')
    else:
        print('dangerous')

if __name__ == '__main__':
  main()


Measured memory_bytes: 5604
def solve(w, h, n, XYA):
    m = [0, w, 0, h]
    for x, y, a in XYA:
        if a == 1 and m[0] < x:
            m[0] = x
        if a == 2 and m[1] > x:
            m[1] = x
        if a == 3 and m[2] < y:
            m[2] = y
        if a == 4 and m[3] > y:
            m[3] = y
        if m[0] >= m[1] or m[2] >= m[3]:
            return 0
    return (m[1] - m[0]) * (m[3] - m[2])

_w, _h, _n = list(map(int, input().split()))
_XYA = [map(int, input().split()) for _ in range(_n)]
print(solve(_w, _h, _n, _XYA))

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int w = Integer.parseInt(sc.next());
    int[] array = new int[w];
    for(int i=0; i<w; i++){
      array[i] = i+1;
    }

    int n = Integer.parseInt(sc.next());
    String blank = sc.nextLine();

    for(int i=0; i<n; i++){
      int[] intArray = Arrays.stream(sc.nextLine().split(","))
                             .mapToInt(Integer::parseInt)
                             .toArray();
      int tmp = array[intArray[0]-1];
      array[intArray[0]-1] = array[intArray[1]-1];
      array[intArray[1]-1] = tmp;
    }
    for(int i=0; i<w; i++){
      System.out.println(array[i]);
    }
  }
}


Measured memory_bytes: 32044
#include <iostream>
#include <vector>
#define rep(i, n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

int n, k;
int p[5000], c[5000];

int main() {
  cin >> n >> k;
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> c[i];
  rep(i, n) p[i]--;
  
  ll ans = -1e18;
  
  // スタート地点を全探索
  rep(i, n) {
    // スタートからの周期を試す
    int now = i;
    ll total = 0;
    vector<int> list;
    for(;;) {
      now = p[now];
      total += c[now];
      list.push_back(c[now]);
      if (now == i) break;
    }
    
    // 周期を試してansを更新
    ll cycle = 0;
    rep(j, list.size()) {
      if (j+1 > k) break;
      cycle += list[j];
      ll cycle_ans = cycle;
        
      // 周期が正であれば可能な限り回す
      if (total > 0) {
        ll e = (k - (j + 1))/ list.size();
        cycle_ans += e*total;
      }
      
      ans = max(ans, cycle_ans);
    }
  }
  cout << ans;
}

Measured memory_bytes: 3692
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use proconio::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

fn main() {
    input! {
        k: usize,
    }
    let mut queue: VecDeque<u64> = (1..10).collect();

    for _ in 0..k - 1 {
        let x = queue.remove(0).unwrap();

        eprintln!("{}", x);
        for i in -1_i32..=1 {
            let d = (x % 10) as i32 + i;
            if d < 0 || d > 9 {
                continue;
            }
            let nx = x * 10 + d as u64;
            queue.push_back(nx);
        }
    }
    println!("{}", queue.get(0).unwrap());
}


Measured memory_bytes: 4052
N = int(input())
lstW = list(map(int, input().split()))

S1 = 0
S2 = sum(lstW)
minVal = S2

for i in range(0, len(lstW)):
    S1 = S1 + lstW[i]
    S2 = S2 - lstW[i]
    val = abs(S1 - S2)
    minVal = min(minVal, val)

print(minVal)

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

using namespace std;

using ll = long long;

#define FOR(i,n,m) for(ll i=(n);i<(m);++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	int n;
	cin>>n;
	if(n==0) {
		cout<<1<<endl;
	} else if(n==1) {
		cout<<2<<endl;
	} else if(n==2) {
		cout<<1<<endl;
	} else {
		cout<<0<<endl;
	}
}


Measured memory_bytes: 3088
n, k = [int(_) for _ in input().split()]
s = []
for i in range(k):
    s.append([int(_) for _ in input().split()])
# print(s)
dp = [0 for i in range(n)]
dp[0] = 1
dp_s = [0 for i in range(n+1)]
dp_s[1] = 1
# print(dp)
# print(dp_s)
# print('*****************')
for i in range(1, n):
    for j in range(len(s)):
        r, l = s[j]
        if i-r >= 0:
            if i-l >= 0:
                dp[i] += dp_s[i-r+1] - dp_s[i-l]
            else:
                dp[i] += dp_s[i-r+1] - dp_s[0]
    dp[i] = dp[i] % 998244353
    # print(dp)
    dp_s[i+1] += dp_s[i] + dp[i]
    dp_s[i+1] = dp_s[i+1] % 998244353
    # print(dp_s)
    # print('*****************')
print(dp[-1])

Measured memory_bytes: 24708
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S;

  int ans = 0;
  rep(i, N-1) {
    if (S[i] == S[i+1]) ans++;
  }

  if (ans == N-1) {
    cout << ans << endl;
    return 0;
  }

  int l = 0;
  int r = 1;
  int cnt = 0;
  while (cnt < K && r < N) {

    if (S[r] == S[l]) {
      r++;
      continue;
    } else {
      bool flag_change = false;
      while (r < N-1) {
        if (S[r] != S[r+1]) {
          ans += 2;
          l = r+1;
          r = r+1;
          cnt++;
          flag_change = true;
          break;
        }
        r++;
      }
      if (!flag_change) {
        r++;
        cnt++;
        ans++;
      }
    }

    
  }


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


Measured memory_bytes: 512
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        char[] s = sc.next().toCharArray();
        int len = s.length;
        if(len == 1){
            System.out.println(s[0]-'0');
            return;
        }
        long ans = 0;
        for(int i = 0; i < (2 << (len-2)); i++){
            StringBuilder sb = new StringBuilder();
            for(int j = 0; j < len-1; j++){
                sb.append(s[j]);
                if((i >> j) % 2 != 0){
                    sb.append('+');
                }
            }
            sb.append(s[len-1]);
            ans += checkFormula(sb.toString().toCharArray());
        }
        System.out.println(ans);
    }
    
    public static long checkFormula(char[] s){
        long ret = 0;
        StringBuilder sb = new StringBuilder();
        for(char c : s){
            if(c == '+'){
                ret += Long.parseLong(sb.toString());
                sb.setLength(0);
            }else{
                sb.append(c);
            }
        }
        ret += Long.parseLong(sb.toString());
        return ret;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


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

using namespace std;
typedef long long ll;
int main(){

    int N,K;
    cin>>N>>K;

    vector<ll> h(N);
    for(int i=0;i<N;i++){
        cin>>h[i];
    }
    sort(h.begin(),h.end(),greater<ll>());

    ll res=1e10;
    for(int i=0;i<=N-K;i++){
        ll tmp = h[i] - h[i+K-1];
        res = min(res,tmp);
    }
    cout<<res;
}

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

int main(){
  int K;
  cin >> K;
  vector<int> A(K);
  A.at(0)=7%K;
  for(int i=0;i<K-1;i++){
    A.at(i+1)=(10*A.at(i)+7)%K;
  }
  for(int i=0;i<K;i++){
    if(A.at(i)==0){
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
      

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

using namespace std;

int main()
{
    float pi=3.141592653589793238462643383279502884197169399375105820974944592307816406286;
    double a;
    int r;
    scanf("%d",&r);
    a=2*pi*r;
    printf("%.20f",a);
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin >> x;
    string hoge[7] = {"mon","tue","wed","thu","fri","sat","sun"};
    x += 3;
    x %= 7;
    cout << hoge[x] << endl;
    return 0;
}


Measured memory_bytes: 3176