akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	static class Pair{
		int w,v;
		public Pair(int a, int b){
			this.w = a;
			this.v = b;
		}
	}
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		final int MAX = 310;
		final int MOD = 1000000007;

		//入力
		int n = sc.nextInt();
		long w = sc.nextLong();
		Pair[] pairs = new Pair[n];
		for(int i = 0; i < n; i++){
			Pair a = new Pair(sc.nextInt(), sc.nextInt());
			pairs[i] = a;
		}
		sc.close();

		//準備
		int base = pairs[0].w;
		for(int i = 0; i < n; i++){
			pairs[i].w -= base;
		}
		int[][] dp = new int[n+1][MAX];
		for(int i = 0; i < MAX; i++){
			for(int j = 0; j < n+1; j++){
				dp[j][i] = -1;
			}
		}
		dp[0][0] = 0;

		//処理
		for(int i = 0; i < n; i++){
			for(int j = n; j > 0; j--){
				for(int k = 0; k < MAX; k++){
					if(k - pairs[i].w >= 0 && dp[j-1][k - pairs[i].w] >= 0){
						dp[j][k] = Math.max(dp[j][k], dp[j-1][k - pairs[i].w] + pairs[i].v);
					}
				}
			}
		}

		int ans = 0;
		for(int i = 1; i < n+1; i++){
			for(int j = 0; j < MAX; j++){
				if((long)i * base + j <= w){
					ans = Math.max(ans, dp[i][j]);
				}
			}
		}

		//出力	
		out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  ll N;
  cin >>N;
  ll dp[100];
  dp[0]=2;
  dp[1]=1;
  repl(i,2,100) {
    dp[i]=dp[i-1]+dp[i-2];
  }
  cout << dp[N]<< endl;
}
  

Measured memory_bytes: 384
inputStr = raw_input()
for i in range(0, len(inputStr)):
  if(inputStr[i] == ' '):
    surface = int(inputStr[:i]) * int(inputStr[i+1:])
    edge = (int(inputStr[:i]) + int(inputStr[i+1:])) * 2
    print(str(surface) + ' ' + str(edge))

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

// Aの個数、Bの個数はmod3で同一視しても良い(?)
// mod3で同一視した上で個数を一致させれば良い
// 並べ替えが自由に出来ることが実験からわかるので、位置については考えなくてよい
// AB -> AAA -> BBAA -> BAAAA -> BA という操作が出来るので.

int main(){
    string s, t;
    cin >> s >> t;
    int slen = s.length()+1, tlen = t.length()+1;
    vector<int> ssum(slen, 0), tsum(tlen, 0);
    for(int i = 1; i < slen; i++) ssum[i] = ssum[i-1]+(s[i-1]=='A');
    for(int i = 1; i < tlen; i++) tsum[i] = tsum[i-1]+(t[i-1]=='A');
    
    bool wf[9][9] = {};
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            wf[i*3+j][(i+2)%3*3+(j+2)%3] = true;
        }
    }

    for(int k = 0; k < 9; k++){
        for(int i = 0; i < 9; i++){
            for(int j = 0; j < 9; j++){
                if(wf[i][k] && wf[k][j])    wf[i][j] = true;
            }
        }
    }

    int q;
    cin >> q;
    while(q-- > 0){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int sa = ssum[b]-ssum[a-1];
        int sb = b-a+1-sa;
        int ta = tsum[d]-tsum[c-1];
        int tb = d-c+1-ta;
        sa %= 3, sb %= 3, ta %= 3, tb %= 3;
        cout << (wf[sa*3+sb][ta*3+tb] ? "YES" : "NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
import Control.Monad

main :: IO ()
main = do
  mn <- getLine
  if mn == "0 0"
    then return ()
    else do
      let [m,n] = map read . words $ mn
      ls <- replicateM n getLine
      putStrLn (solve m ls)
      main

solve :: Int -> [String] -> String
solve m ls = format (update (cycle [1..m]) [1..m] 1 ls)
  where
    format :: [Int] -> String
    format [] = []
    format [x] = show x
    format (x:xs) = (show x) ++ " " ++ (format xs)
    update :: [Int] -> [Int] -> Int -> [String] -> [Int]
    --update order surviveL count responseL
    update _ [x] _ _ = [x]
    update _ surviveL _ [] = surviveL
    update (x:xs) surviveL count (response:responseL)
      | elem x surviveL = update xs (judge count response x surviveL) (count+1) responseL
      | otherwise = update xs surviveL count (response:responseL)
      where
        judge :: Int -> String -> Int -> [Int] -> [Int]
        judge c r x s
          | c `mod` 15 == 0 && r == "FizzBuzz" = s
          | c `mod` 5 == 0 && r == "Buzz" = s
          | c `mod` 3 == 0 && r == "Fizz" = s
          | c `mod` 3 /= 0 && c `mod` 5 /= 0 && show c == r = s
          | otherwise = rem x s
          where
            rem :: Int -> [Int] -> [Int]
            rem _ [] = []
            rem x (y:ys)
              | x == y = ys
              | otherwise = y:(rem x ys)

Measured memory_bytes: 9236
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt();
		int H = sc.nextInt();
		int N = sc.nextInt();

		Field field = new Field(W, H);

		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();
			field.draw(x, y, a);
		}

		System.out.println(field.calcWhiteArea());
	}

	static class Field {
		final int W, H;
		final boolean[] fieldArray;

		public Field(int W, int H) {
			this.fieldArray = new boolean[W * H];
			this.W = W;
			this.H = H;
			for (int i = 0; i < W * H; i++) {
				fieldArray[i] = true;
			}
		}

		public void draw(int x, int y, int a) {
			switch (a) {
			case 1:
				drawRect(0, x, 0, H);
				break;
			case 2:
				drawRect(x, W, 0, H);
				break;
			case 3:
				drawRect(0, W, 0, y);
				break;
			case 4:
				drawRect(0, W, y, H);
				break;
			}
		}

		private void drawRect(int x1, int x2, int y1, int y2) {
			for (int x = x1; x < x2; x++) {
				for (int y = y1; y < y2; y++) {
					drawPoint(x, y);
				}
			}
		}

		private void drawPoint(int x, int y) {
			this.fieldArray[x * H + y] = false;
		}

		public int calcWhiteArea() {
			int ans = 0;
			for (int i = 0; i < W * H; i++) {
				if (this.fieldArray[i]) {
					ans++;
				}
			}
			return ans;
		}
	}
}


Measured memory_bytes: 10320
#include <cstdio>
#include <cstring>
#include <stdint.h>

char str[200005];

int main(){
  scanf("%s",str);
  int N=strlen(str);
  int j=N-1;
  int64_t cnt=0;
  for(int i=0;i<N;i++){
    if(str[i]=='B'){
      cnt+=j-i;
      j--;
    }
  }
  printf("%ld\n",cnt);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <functional>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
#define fi first
#define se second
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

  ll K; cin>>K;
  ll res = 0;

  reps(i,1,K+1) reps(j,1,K+1) {
    ll val = gcd(i,j);
    reps(k,1,K+1) res+=gcd(val,k);
  }

  cout<<res<<endl;

  return 0;
}


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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;
using li=list<int>;
using lil=list<ll>;
using lis=list<string>;
using fli=forward_list<int>;
using fll=forward_list<ll>;
using fls=forward_list<string>;
using si=stack<int>;
using sl=stack<ll>;
using ss=stack<string>;
using qi=queue<int>;
using ql=queue<ll>;
using qs=queue<string>;
using pqi=priority_queue<int>;
using pql=priority_queue<ll>;
using pqs=priority_queue<string>;
using dqi=deque<int>;
using dql=deque<ll>;
using dqs=deque<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define repr(i, n) for(int i = (n); i >= 0; i--)
#define repr2(i, a, n) for(int i = (n); i >= (a); i--)

template<typename T,typename U>
void Inparray(T &f,U n){for(int i=0;i<n;i++) cin>>f[i];}

template<typename T,typename U>
void Printarray(T f,U n){for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];}
template<typename T,typename U>
void Printarray2(T f,U n){for(int i=0;i<n;i++) cout<<f[i]<<endl;}
template<typename T,typename U,typename V>
void Printarray3(T f,U a,V b){
  rep(i,a){
    rep(j,b){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}
template<typename T,typename U>
void Printarray4(T f,U n){
  rep(i,n){
    rep(j,n){
      cout<<f[i][j];
    }
    cout<<endl;
  }
}

void flagfunc(bool flag,string A,string B){flag ? cout<<A<<endl : cout<<B<<endl;}
void flag2func(bool flag){flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;}
void flag3func(bool flag){flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;}

int gcd(int a, int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}
int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int k;cin>>k;
  int cnt=0;
  rep2(a,1,k+1){
    rep2(b,1,k+1){
      rep2(c,1,k+1){
        cnt+=gcd(gcd(a,b),c);
      }
    }
  }
  cout<<cnt<<endl;
}


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

int main(){
    int64_t N, K;
    cin >> N >> K;
    int64_t n2 = N/2;
    int64_t n1 = N-n2;
    vector<vector<int64_t>> SAB;
    for(int i=0; i<N; i++){
        int j = (i<n1 ? i+N+n2 : i+n2);
        SAB.push_back({2*K+i+j, K+i, K+j});
    }
    sort(SAB.begin(), SAB.end());
    vector<vector<int64_t>> ans(N);
    for(int i=0; i<N; i++){
        int64_t c = K + 2*N + i;
        if(SAB[i][0] > c){
            cout << -1 << endl;
            return 0;
        }
        ans[i] = {SAB[i][1], SAB[i][2], c};
    }
    for(auto& v : ans) cout << v[0] << " " << v[1] << " " << v[2] << endl;
}


Measured memory_bytes: 13360
#include <iostream>
#include <algorithm>
#define MAX 100001
#define ATV_A 0
#define ATV_B 1
#define ATV_C 2
#define ATV_N 3
int n, maiorFelicidade[MAX][4], felicidadeDaAtividade[4][MAX];
int maximaFelicidade(int dia, int escolhida)
{
    if(dia > n)
        return 0;
    if(maiorFelicidade[dia][escolhida])
        return maiorFelicidade[dia][escolhida];
    int maximo = -1;
    if(escolhida != ATV_A)
        maximo = std::max(maximo, felicidadeDaAtividade[ATV_A][dia] + maximaFelicidade(dia + 1, ATV_A));
    if(escolhida != ATV_B)
        maximo = std::max(maximo, felicidadeDaAtividade[ATV_B][dia] + maximaFelicidade(dia + 1, ATV_B));
    if(escolhida != ATV_C)
        maximo = std::max(maximo, felicidadeDaAtividade[ATV_C][dia] + maximaFelicidade(dia + 1, ATV_C));
    return maiorFelicidade[dia][escolhida] = maximo;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin >> n;
    for(int i = 1; i <= n; i++)
    {
        std::cin >> felicidadeDaAtividade[ATV_A][i] >>
                    felicidadeDaAtividade[ATV_B][i] >>
                    felicidadeDaAtividade[ATV_C][i];
    }
    std::cout << maximaFelicidade(1, ATV_N) << '\n';
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 5e5+10;
const int mod = 1e9+7;

using namespace std;

int bit[maxn][30];

void update(int x,int c,int val){
	for(;x<maxn;x+=x&-x){
		bit[x][c]+=val;
	}
}

int query(int x,int c){
	int s=0;
	for(;x>0;x-=x&-x){
		s+=bit[x][c];
	}
	return s;
}

int query(int l,int r,int c){
	return query(r,c) - query(l-1,c);
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,q;
	string s;
	cin>>n>>s;
	for(int i=0;i<n;++i){
		update(i+1,s[i]-'a',1);
	}
	cin>>q;
	while(q--){
		int t,l;
		cin>>t>>l;
		if(t==1){
			char c;
			cin>>c;
			update(l,s[l-1]-'a',-1);
			s[l-1] = c;
			update(l,s[l-1]-'a',1);
		}
		else{
			int r,ans=0;
			cin>>r;
			for(int i=0;i<30;++i){
				if(query(l,r,i)>0)
					++ans;
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 59548
import java.lang.Math.*

fun main(args : Array<String>){
    val s = readLine()!!.toCharArray()
    var cnt = IntArray(2){0}
    for(i in 0 until s.size){
        if(s[i]=='0') {
            cnt[0]++
        }else{
            cnt[1]++
        }
    }
    println(cnt.min()!! *2)
}


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

int main() {
  long long n;
  cin >> n;
  for(long long i=(long long)sqrt(n)+1; i>0; i--){
    if(n % i == 0){
      cout << (n/i-1) + (i-1) << endl;
      return 0;
    }
  }
}


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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

// constexpr int INF = 1e9;
constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;

ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  return gcd(b, a%b);
}
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
  }
  vector<ll> G(N+1), RG(N+1);
  G[0] = A[0];
  FOR(i, 1, N){
    G[i] = gcd(A[i], G[i-1]);
  }
  RG[N-1] = A[N-1];
  REPR(i, N-2){
    RG[i] = gcd(A[i], RG[i+1]);
  }
  ll ans = max(G[N-2], RG[1]);
  FOR(i, 1, N-1){
    ans = max(ans, gcd(G[i-1], RG[i+1]));
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int N,W;
  cin >>N>>W;
  long int w[N+1],v[N+1];
  for(int i=1;i<=N;i++){
  	cin >> w[i]>>v[i];
  }
  vector<vector<long int>> mem(N+1, vector<long int>(W+1, 0));
  for(int i=1;i<=N;i++){
  	for(int j=1;j<=W;j++){
    	if(j>=w[i]){
        long int p=mem[i-1][j-w[i]]+v[i];  
        mem[i][j]=max(p,mem[i-1][j]);
        }
    	else{mem[i][j]=mem[i-1][j];}
    }
  }
	cout<<mem[N][W]<<endl;
}

Measured memory_bytes: 80256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	m := make(map[string]int, len(s))
	for _, a := range s {
		m[string(a)]++
	}
	for _, v := range m {
		if v%2 != 0 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <utility>
#include <cctype>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

#define C const
#define R register
#define fast ios::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define ld long double
#define ull unsigned long long
#define eps 1e-8
#define pi 3.141592653589793
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define PII pair<int,int>
#define sqr(a) ((a)*(a))
#define ls rt<<1
#define rs rt<<1|1
#define lowbit(i) ((i)&(-(i)))
#define FOR(i,a,b) for(R int i=(a);i<=(b);++i)
#define REP(i,a,b) for(R int i=(a);i>=(b);--i)
#define FOR_edge(i)  for(R int i=head[u];i;i=e[i].nxt)

using namespace std;

const int dx[]={1,-1,0,0};
const int dy[]={0,0,-1,1};

void judge() {
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
inline char nc() {
	static char buf[1000001],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
template <typename T> inline T Read() {
	R T s=0,w=1;
	R char c=nc();
	while(c<'0'||c>'9'){if(c=='-')w=-1;c=nc();}
	while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+c-48,c=nc();
	return s*w;
}
template <typename T> inline void Read(R T &s) {
	s=0;
	R T w=1;
	R char c=nc();
	while(c<'0'||c>'9'){if(c=='-')w=-1;c=nc();}
	while(c>='0'&&c<='9')s=(s<<1)+(s<<3)+c-48,c=nc();
	s*=w;
}
template <typename T> inline void write(R T x) {
	if(x<0)  putchar('-'),x=-x;
	if(x>9)  write(x/10);
	putchar(x%10+'0');
}
template <typename T> inline void print(C T &x,C char &end) {
	write(x);
	putchar(end);
}

template <typename T> inline T gcd(C T &x,C T &y){return(y==0?x:gcd(y,x%y));}
template <typename T> inline void Swap(R T &x,R T &y){x^=y;y^=x;x^=y;}
template <typename T> inline void Swap_com(R T &x,R T &y){C T t=x;x=y;y=t;}
template <typename T> inline T POW(T x,T p,T mod) {
	R T res=1;
	while(p) {
		if(p&1)  res=(res*x)%mod;
		x=(x*x)%mod;  p>>=1;
	}
	return res;
}

///////////////////////////////////////////////////////////////////////////////
/////////////////////////////       Program       /////////////////////////////
/////////////////////////////        Heads        /////////////////////////////
/////////////////////////////    Don not touch    /////////////////////////////
///////////////////////////////////////////////////////////////////////////////

#define read Read<int>
#define readll Read<ll>

vector<int> a;
int f[100005];

int main() {
//	judge();
	int n;  cin>>n;
	a.push_back(1);
	for(int i=6;i<=n;i*=6)  a.push_back(i);
	for(int i=9;i<=n;i*=9)  a.push_back(i);
	sort(a.begin(),a.end());
	f[0]=0;
	for(int i=1;i<=n;++i)  f[i]=inf;
	for(int i=0;i<(int)a.size();++i) {
		for(int j=a[i];j<=n;++j)
			f[j]=min(f[j],f[j-a[i]]+1);
	}
	cout<<f[n];
	return 0;
}

Measured memory_bytes: 640
(defun main ()
  (let* ((n (read))
         (m (read))
         (x (read))
         (a (make-array `(,(1+ n) ,(1+ m))))
         (p (expt 2 n))
         (sum (make-array `(,p ,(1+ m)) :initial-element 0))
         (result nil))
    ;;
    (loop :for i :from 1 :to n
          :do (loop :for j :from 0 :to m
                    :do (setf (aref a i j) (read))))
    ;;
    (loop :for spec :from 0 :to (1- p)
          :for bs := (format nil (format nil "~~~A,'0B" n) spec)
          :do  (progn
                 (loop :for i :from 1 :to n
                       :when (char= (char bs (1- i)) #\1)
                       :do (loop :for j :from 0 :to m
                                 :do (incf (aref sum spec j) (aref a i j))))
                 (let ((f (loop :for j :from 1 :to m
                                :sum (if (< (aref sum spec j) x) 1 0))))
                   (if (= f 0)
                       (setf result (if result 
                                        (min result (aref sum spec 0))
                                        (aref sum spec 0)))))))
    ;;
    (if result
        (format t "~A~%" result)
        (format t "-1~%"))))
(main)


Measured memory_bytes: 30080
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u64,
        l: u64,
        mut list: [String; n],
    }
    list.sort();
    println!(
        "{}",
        list.iter()
            .fold(String::new(), |acc, s| acc + &s.to_string())
    );
}


Measured memory_bytes: 4352
import java.util.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		int dataset = Integer.parseInt(sc.nextLine());
		while(dataset-- > 0){
			String s = sc.nextLine();
			boolean isOK = false;
			for(int a = 1; a <= 26; a++){
				for(int b = 1; b <= 26; b++){
					boolean isvalid = true;
					int [] hash = new int[26];
					for(int i = 0; i <= 25; i++){
						hash[(i * a + b ) % 26]++;
						if(hash[i]==2){
							isvalid = false;
							break;
						}
					}
					if(isvalid){
						StringBuilder sb = new StringBuilder(s);
						for(int i = 0; i < sb.length(); i++){
							int c = sb.charAt(i) - 'a';
							if(sb.charAt(i) == ' ') continue;
							sb.setCharAt(i, (char)((c * a + b) % 26 + 'a'));
						}
						boolean res = containsthat(sb.toString());
						if(res){
							isOK = true;
							System.out.println(sb.toString());
							break;
						}
					}
				}
				if(isOK){
					break;
				}
			}
		}
	}

	private boolean containsthat(String string) {
		String [] s = string.split(" ");
		for(int i = 0; i < s.length; i++){
			if(s[i].equals("this") || s[i].equals("that")){
				return true;
			}
		}
		return false;
	}

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

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

using namespace std;

int ans, N, x;
map<int, int> m;

int main(){
	cin >> N;
	for(int i = 0; i < N; ++i){
		cin >> x;
		m[x]++;
	}
	for(auto itr = m.begin(); itr != m.end(); itr++){
		if(itr->second % 2 == 1) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4864
using System;
using System.Collections.Generic;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine();

            var sn = 0;

            for (int i = 0; i < n.Length; i++)
            {
                sn += int.Parse(n[i].ToString());
            }

            if(int.Parse(n)%sn==0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

int main() {
    int n;
    int a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i = 0; i <= n; i++) {
        int sum = 0;
        int j = i;
        while(j > 0) {
            sum += j % 10;
            j /= 10;
        }
        if(a <= sum && sum <= b) ans += i;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

const int N = int(1e5) + 7;

void init(){

}

void solve(){
    int n; scanf("%d", &n);
    int c = 0;
    vector<int> v;
    for(int i = 0; i < n; i++){
        int a;
        scanf("%d", &a);
        if(a <= 0){
            c++;
            v.push_back(-a);
        }
        else v.push_back(a);
    }
    ll sum = 0;
    for(auto i : v)
        sum += i;
    if(c%2 == 1)
        sum -= 2*(*min_element(v.begin(), v.end()));
    printf("%lld\n", sum);
}

const bool mtc = false;

int main(){
    int t;
    if(mtc){
        scanf("%d", &t);
        while(t--) solve();
    }
    else solve();
}


Measured memory_bytes: 892
#include <stdio.h>
#define n_max 101
void push(int);
int pop();
void bfs(int);

int queue[1000];
int n,head=0,tail=0;
int adj[n_max][n_max];
int d[n_max],used[n_max];

int main(){
  int i,j;
  int u,k,num;
  
  scanf("%d",&n);//ヴァーテックスの数
  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&k);//頂点のナンバーと、その頂点からのびる線の数
    for(j=0;j<k;j++){
      scanf("%d",&num);
      adj[u][num]=1;
    }
  }

  for(i=1;i<=n;i++)d[i]=0;//すべてのdを初期化
  
  bfs(1);
  for(i=2;i<=n;i++){
    if(d[i]==0)d[i]=-1;
  }
  
  for(i=1;i<=n;i++) printf("%d %d\n",i,d[i]);
  
  return 0;
}


void push(int x){
  queue[head]=x;
  head++;
}

int pop(){
  int x;
  x=queue[tail];
  tail++;
  return x;
}

void bfs(int x){
  int i,p;
  
  push(x);
  used[x]=1;
  while(head!=tail){
    p=pop();
    for(i=1;i<=n;i++){
      if(adj[p][i]==1 && used[i]==0){
	push(i);
	d[i]=d[p]+1;
	used[i]=1;
      }
    }
  }
}



Measured memory_bytes: 2112
#include<iostream>
#include<vector>
#include<algorithm>
const int INF = 10e5;
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> dp(N,0),arr(N);
	for (auto& it : arr) cin >> it;
	for (int i = 1; i < N; i++) {
		dp[i] = min(i - 1 >= 0 ? dp[i - 1] + abs(arr[i - 1] - arr[i]) : INF, ((i-2>=0) ? dp[i - 2] + abs(arr[i - 2] - arr[i]) : INF));
	}
	cout << dp[N - 1]<<'\n';
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a <= b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first; printf("\n"); }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first; printf(" "); put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first; printf("\n"); putn(rest...); }

void dfs(vector<vector<int>>& path, ll temp);

int main() {
	int n,q;
	cin >> n >> q;
	vector<ll> a(n - 1), b(n - 1), p(q), x(q);
	vector<vector<int>> path(n);
	vector<ll> cnt(n, 0);
	vector<ll> temp(n, 0);
	vector<bool> vi(n, false);
	REP(i, n-1) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		path[a[i]].push_back(b[i]);
		path[b[i]].push_back(a[i]);
	}
	REP(i, q) {
		cin >> p[i] >> x[i];
		p[i]--;
		cnt[p[i]] += x[i];
	}
	queue<int> qu;
	qu.push(0);
	vi[0] = true;
	while (!qu.empty()) {
		int p = qu.front();
		qu.pop();
		REP(i, path[p].size()) {
			if (!vi[path[p][i]]) {
				vi [path[p][i]] = true;
				cnt[path[p][i]] += cnt[p];
				qu.push(path[p][i]);
			}
			
		}
	}
	put(cnt);
	return 0;
}

Measured memory_bytes: 24180
#include <stdio.h>


int main(void){
    int s, a, b, ym, my;
    ym = 0;
    my = 0;
    scanf("%d", &s);
    a = s / 100;
    b = s % 100;
    if(b > 0 && b < 13){
        ym = 1;
    }
    if(a > 0 && a < 13){
        my = 1;
    }
    switch(ym){
        case 0:
            switch(my){
                case 0:
                    printf("NA\n");
                    break;
                case 1:
                    printf("MMYY\n");
                    break;
            }
            break;
        case 1:
            switch(my){
                case 0:
                    printf("YYMM\n");
                    break;
                case 1:
                    printf("AMBIGUOUS\n");
                    break;
            }
        break;
    }

    return 0;
}

Measured memory_bytes: 128
a,b,k = map(int,input().split())
ans = []

for i in range(k):
    if a + i > b:
        break
    ans.append(a+i)

#print(ans)
for j in range(k):
    if b-j<a:
        break
    ans.append(b-j)
v = set(ans)
w = list(v)
w.sort()
#print(w)

for l in w:
    print(l)


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

#define int long long
#define ll long long
#define f1(i,a,b) for(int i=a;i<b;i++)
#define f2(i,a,b) for(int i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;

    vector<pair<int,int>> ans;
    f1(i,0,a)
    {
        cin>>temp;
        ans.pb(mp(temp, 1));
    }

    f1(i,0,b)
    {
        cin>>temp;
        ans.pb(mp(temp, 2));
    }

    f1(i,0,c)
    {
        cin>>temp;
        ans.pb(mp(temp, 3));
    }

    sort(ans.begin(), ans.end(), greater<pair<int,int>> ());

    int sum = 0, buff = 0;
    f1(i,0,a+b+c)
    {
        if(x + y + buff <= 0)
        break;

        if(ans[i].ss == 1 && x > 0)
        {
            sum += ans[i].ff;
            x--;
        }
        else if(ans[i].ss == 2 && y > 0)
        {
            sum += ans[i].ff;
            y--;
        }
        else if(ans[i].ss == 3)
        {
            sum += ans[i].ff;
            buff--;
        }
    }

    cout<<sum<<endl;

    return 0;
}

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

int main(){
  int x,n;
  cin >> x >> n;
  if(n==0){
    cout << x << endl;
    return 0;
  }
  vector<int> num(200);
  int match = 0;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    int kyori = abs(a-x);
    if(a==x){
      match = 1; 
    }else if(a<x){
      num.at(2*(kyori-1))=1;
    }else if(a>x){
      num.at(2*(kyori-1)+1)=1;
    }
  }
  for(int i=0;i<n;i++){
    if(match==0){
      cout << x << endl;
      return 0;
    }else if(num.at(i)==0){
      if(i%2==0){
        cout << x - (i+2)/2 << endl;
        return 0;
      }else{
        cout << x + (i+1)/2 << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3600
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const input = stdin.split('\n')

const [n, k] = input[0].split(' ').map(Number)
const s = input[1]

const sl = s.split('')

// 連続してる数-1
const ans = () => {
  let seq = 0
  let seqs = []

  for (let i = 1; i < n; i++) {
    if (sl[i] === sl[i - 1]) {
      seq++
    } else {
      seqs.push(seq)
      seq = 0
    }
  }
  seqs.push(seq)

  const hps = seqs.reduce((p, c) => p + c)

  console.log(Math.min(n - 1, hps + 2 * k))
}

ans()


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

int main(){
  int blue,red;
  cin>>blue;
  vector<string> b_line(blue);
  for(int i=0;i<blue;i++){
    cin>>b_line.at(i);
  }
  cin>>red;
  vector<string> r_line(red);
  for(int i=0;i<red;i++){
    cin>>r_line.at(i);
  }
  int money=1;
  int result=0;
  for(int i=0;i<blue;i++){
    for(int j=0;j<blue;j++){
      if(b_line.at(i)==b_line.at(j)){
        bool judge=true;
        if(i==j){
          judge=false;
        }
        if(judge==true){
          money++;
        //cout<<money<<endl;
        }
      }
    }
    for(int j=0;j<red;j++){
      if(b_line.at(i)==r_line.at(j)){
        money--;
      }
    }
   // cout<<money<<endl;
    result=max(result,money);
    money=1;
  }
  cout<<result<<endl;
}

Measured memory_bytes: 256
d = int(input())
m=[]
for _ in range(d):
    x=list(map(int,input().split()))
    m.append(x)

dp=[[-1,-1,-1] for i in range(d)]
dp[0][0]=0
dp[0][1]=0
dp[0][2]=0
n=d
for i in range(1,n):
    for j in range(3):
        dp[i][j] = max(dp[i-1][j-1]+m[i-1][j-1],dp[i-1][j-2]+m[i-1][j-2])

ans = max(dp[n-1][0]+m[n-1][0],dp[n-1][1]+m[n-1][1],dp[n-1][2]+m[n-1][2])

# print(md)
print(ans)

Measured memory_bytes: 49988
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    int N, M;
    cin >> N >> M;
    vector<string> grid(N);
    for (int i = 0; i < N; i++) cin >> grid[i];

    atcoder::mcf_graph<ll, ll> graph(N*M+2);

    int K = 0;
    int pre = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (grid[i][j] == 'o') {
                graph.add_edge(N*M, i*M+j, 1, 0);
                K++;
                pre += N*M-(i+j);
            }
            if (grid[i][j] == '#') continue;
            graph.add_edge(i*M+j, N*M+1, 1, N*M-(i+j));
            if (i < N-1 && grid[i][j] != '#') {
                graph.add_edge(i*M+j, (i+1)*M+j, 1e9, 0);
            }
            if (j < M-1 && grid[i][j] != '#') {
                graph.add_edge(i*M+j, i*M+j+1, 1e9, 0);
            }
        }
    }

    auto mcm = graph.flow(N*M, N*M+1, K);
    cout << pre-mcm.second << endl;
}

Measured memory_bytes: 4288
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

typedef long long ll;

int main(){
	ll n,m,a,b,p,q; scanf("%lld%lld%lld%lld%lld%lld",&n,&m,&a,&b,&p,&q);

	ll ans=m;
	if(a==1 && b==1){
		ans=min(ans,llabs(n*(p+q)-m));
		ll i=m/(p+q);
		for(int j=-3;j<=3;j++) if(0<=i+j && i+j<=n) ans=min(ans,llabs((i+j)*(p+q)-m));
	}
	else{
		int N;
		ll num[40];
		for(int k=0;;k++){
			long double tmp=p*pow(a,k)+q*pow(b,k);
			if(k==n || tmp>2e12){
				N=k;
				break;
			}
			num[k]=tmp;
		}
		if(N%2==1) num[N++]=0;

		vector<ll> half1,half2;
		rep(S,1<<N/2){
			bool ok1=true,ok2=true;
			ll sum1=0,sum2=0;
			rep(i,N/2) if(S>>i&1) {
				sum1+=num[i];
				sum2+=num[i+N/2];
				if(sum1>2e12) ok1=false;
				if(sum2>2e12) ok2=false;
			}
			if(ok1) half1.push_back(sum1);
			if(ok2) half2.push_back(sum2);
		}
		half1.push_back(0);
		half2.push_back(0);

		sort(half1.begin(),half1.end());
		sort(half2.begin(),half2.end());

		rep(i,half1.size()){
			int j=lower_bound(half2.begin(),half2.end(),m-half1[i])-half2.begin();
			if(j<half2.size()) ans=min(ans,llabs(half1[i]+half2[ j ]-m));
			if(j>0)            ans=min(ans,llabs(half1[i]+half2[j-1]-m));
		}
	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 38068
#include<iostream>
#include<string>
using namespace std;
int main(){
	int R,G,B,N;
	cin>>R>>G>>B>>N;
	int x=N/R;
	int y=N/G;
	int ans=0;
	for (int i=0;i<x+1;i++){
		for (int j=0;j<y+1;j++){
			if ((N-i*R-j*G)%B==0 && (N-i*R-j*G)>=0){
				ans=ans+1;
			}
		}
	}
	cout<<ans<<endl;
		

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
int N;
ll a[100000];
ll b[100000];
ll d[100000];
int main(){
	cin>>N;
	rep(i,N) cin>>a[i];
	rep(i,N) cin>>b[i];
	ll K = 0;
	rep(i,N){
		K += b[i]-a[i];
	}
	ll two = 0;
	rep(i,N){
		ll d = b[i]-a[i];
		if(d>0) two += (d+1)/2;
	}
	if(two>K) puts("No");
	else puts("Yes");
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

int main ()
{
    string S; cin >> S;
    string keyence = "keyence";

    if (S == keyence) {
        cout << "YES" << endl;
        return 0;
    }

    for (int i = 1; i <= S.size(); i++) {
        for (int j = 0; j <= S.size() - i; j++) {
            string T;
            for (int k = 0; k < S.size(); k++) {
                if (k < j || j + i <= k) {
                    T.push_back(S[k]);
                }
            }
            if (T == keyence) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int x,y;
	cin>>x>>y;
	int flag=0;
	for(int i=0; i<=x; i++)
	{
		int temp=i*2+(x-i)*4;
		if(temp==y){
			flag=1;
			break;
		}
	}
	if(flag)
	 cout<<"Yes";
	else
	 cout<<"No";
	return 0;
}

Measured memory_bytes: 3668
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

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

int main() {
    int R;
    cin >> R;
    cout << 2 * R * PI << endl;
}


Measured memory_bytes: 3788
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static int P;
    static int Q;
    static int pPos;
    static int qPos;
    static int perpeturation;
    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        P = 0;
        Q = 0;
        pPos = 0;
        qPos = 0;
        perpeturation = 0;
        for(int i = 0; i < N; i++) {
            int tmp = scan.nextInt();
            P += tmp*Math.pow(10, N-1-i);
        }
        for(int i = 0; i < N; i++) {
            int tmp = scan.nextInt();
            Q += tmp*Math.pow(10, N-1-i);
        }

        boolean isUsed[] = new boolean[N];
        dfs(N, N, isUsed, 0);

        os.println(Math.abs(pPos-qPos));
    }

    public static void dfs(int N, int leftTimes, boolean isUsed[], int sum) {
        for(int i = 0; i < N; i++) {
            if(!isUsed[i]){
                int tmp = 10*sum + i+1;
                if(leftTimes == 1){
                    perpeturation++;
                    if(tmp == P)
                        pPos = perpeturation;
                    if(tmp == Q)
                        qPos = perpeturation;
                    return;
                }
                isUsed[i] = true;
                dfs(N, leftTimes-1, isUsed, tmp);
                isUsed[i] = false;
            }
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct mint {
    const int mod = 1e9 + 7;
    long long x;
    
    mint (long long x = 0) : x((x % mod + mod) % mod) {
        
    }
    
    mint& operator=(const long long a) {
        x = a % mod;
        return *this;
    }
    
    mint& operator=(const mint a) {
        x = a.x % mod;
        return *this;
    }
    
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    
    mint& operator-=(const mint a) {
        if ((x += (mod - a.x)) >= mod) x -= mod;
        return *this;
    }
    
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    
    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;
    }
};

long long mod_pow(long long x, long long n, long long mod = 1e9 + 7) {
    long long ans = 1;
    while(n > 0) {
        if ((n % 2) == 0) {
            x = (x * x) % mod;
            n >>= 1;
        }
        else {
            ans = (ans * x) % mod;
            n--;
        }
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<mint> cnt(k + 1, 0);
    mint ans = 0;
    rreps(i, 1, k + 1) {
        mint tmp = mod_pow(k / i, n);
        ll cv = i * 2;
        while(cv <= k) {
            tmp -= cnt[cv];
            cv += i;
        }
        cnt[i] = tmp;
        ans += tmp * i;
    }
    cout << ans.x << endl;
    return 0;
}


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

int Ai[90000];
int Aj[90000];
int magic[90000] = {0};
int q[100000];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, D, num, Q, L, R;
    cin >> H >> W >> D;
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            cin >> num;
            Ai[num] = i;
            Aj[num] = j;
        }
    }
    for (int i=D+1; i<=H*W; i++){
        magic[i] = abs(Ai[i-D] - Ai[i]) + abs(Aj[i-D] - Aj[i]) + magic[i-D];
    }
    cin >> Q;
    for (int i=0; i<Q; i++){
        cin >> L >> R;
        if (R == L){
            q[i] = 0;
        }
        else{
            q[i] = magic[R] - magic[L];            
        }
    }
    for (int i=0; i<Q; i++){
        cout << q[i] << endl;
    }
}

Measured memory_bytes: 2560
L = [[0,0],[1,-1],[1,0],[1,1],[2,-2],[2,-1],[2,0],[2,1],[2,2],[3,-1],[3,0],[3,1],[4,0]]
M = [[0,0],[0,1],[0,2],[1,0],[1,1],[1,2],[2,0],[2,1],[2,2]]
S = [[0,0],[1,-1],[1,0],[1,1],[2,0]]

def rev_drop(mat, drops, n)
  return false if drops.size > n
  10.times{|y|
    10.times{|x|
      if mat[y][x] > 0
        # p [x, y]
        flag = true
        nmat=mat.map(&:dup)
        L.each{|dy, dx|
          if y+dy<0 || 9<y+dy || x+dx<0 || 9<x+dx || nmat[y+dy][x+dx] == 0
            flag = false
            break
          end
          nmat[y+dy][x+dx] -= 1
        }
        if flag
          return true if rev_drop(nmat, drops + [[x, y+2, 3]], n)
        end
        flag = true
        nmat=mat.map(&:dup)
        M.each{|dy, dx|
          if y+dy<0 || 9<y+dy || x+dx<0 || 9<x+dx || nmat[y+dy][x+dx] == 0
            flag = false
            break
          end
          nmat[y+dy][x+dx] -= 1
        }
        if flag
          return true if rev_drop(nmat, drops + [[x+1, y+1, 2]], n)
        end
        flag = true
        nmat=mat.map(&:dup)
        S.each{|dy, dx|
          if y+dy<0 || 9<y+dy || x+dx<0 || 9<x+dx || nmat[y+dy][x+dx] == 0
            flag = false
            break
          end
          nmat[y+dy][x+dx] -= 1
        }
        if flag
          return true if rev_drop(nmat, drops + [[x, y+1, 1]], n)
        end
        return false
      end
    }
  }
  drops.each{|drop|
    puts drop.join(" ")
  }
  return true
end

n = gets.to_i

mat = []
10.times{|i|
  mat[i] = gets.split.map(&:to_i)
}

rev_drop(mat, [], n)

Measured memory_bytes: 8844
import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]

def dfs(v,prev = -1):
    for u in graph[v]:
        if u == prev:
            continue
        point[u] += point[v]
        dfs(u,v)

N, Q = list(map(int,input().split()))
graph = [[] for _ in range(N)]
point = [0]*N

for i in range(N-1):
    a,b = list(map(int,input().split()))
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in range(Q):
    p,x = list(map(int,input().split()))
    p -= 1
    point[p] += x

dfs(0)
print(*point)


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

int main() {
  int N;
  cin >> N;
  vector<string>S(N);
  for(int i=0; i<N; i++)cin >> S.at(i);
  
  sort(S.begin(), S.end());
  int count=1;
  int maxim=1;
  
  for(int i=0; i<N-1; i++){
    if(S.at(i)==S.at(i+1))count++;
    else count =1;
    maxim = max(count, maxim);
  }
  
  count =1;
  
  for(int i=0; i<N-1; i++){
    if(S.at(i)==S.at(i+1))count++;
    else count=1;
    if(count==maxim)cout << S.at(i) << endl;
  }
  
  if(maxim==1)cout << S.at(N-1) << endl;
}

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

int main()
{
    int N, K, x;
    int ans = 0;
    cin >> N >> K;
    for (int i = 0; i < N; ++i)
    {
        cin >> x;
        ans += 2 * min(abs(x), abs(x - K));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long


int main() {
	int a, b;
	cin >> a >> b;
	cout << max(max(a + b, a - b), a * b) << endl;
	return 0;
}

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

int main(int argc, char const *argv[])
{	
	int a,b,k;
	int p = 0;
	vector<int> v(101);
	cin >> a >> b >> k;
	for (int i = 1; i <= 100; ++i)
	{
    // この表現は読みづらいかも
    // if(!(a % i) && !(b % i)){
		if(a % i ==0 && b % i == 0){
      // どっちでも割り切れたときにvの前からi番目に格納する
			v[p] = i;
			++p;
		}	
	}
	cout << v[p - k] << endl;
	return 0;
}

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

int main(){
	vector<int> x(10);
	for(auto &a:x){
		cin >> a;
	}
	sort(x.begin(),x.end(),greater<int>());
	for(int i = 0; i < 3; i++){
		cout << x[i] << endl;
	}
	
	return 0;
}			

Measured memory_bytes: 3144