akhauriyash/Code-Regression huggingface dataset:
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  string S;
  cin >> S;
  const int64_t N = static_cast<int64_t>(S.length());
  vector<int64_t> A(N);
  for (int64_t i = 0; i < N; ++i) {
    A[i] = static_cast<int64_t>(S[i] - '0');
  }
  const int64_t num_place = N - 1;
  int64_t result = 0;
  for (int64_t b = 0; b < (1L << num_place); ++b) {
    int64_t value = 0;
    bitset<16> bs(b);
    int64_t temp = A[0];
    for (int64_t i = 0; i < num_place; ++i) {
      if (bs[i]) {
        value += temp;
        temp = A[i + 1];
      } else {
        temp *= 10;
        temp += A[i + 1];
      }
    }
    value += temp;
    result += value;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
#include<vector>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long ll;

int main()
{
    string s,t;
    cin>>s>>t;
    string a,b;
    ll l1,l2;
    l1 = s.length();
    l2 = t.length();
    ll z[l1+1][l2+1];
    for(ll i=0;i<=l1;i++){
        for(ll j=0;j<=l2;j++){
            z[i][j]=0;
        }
    }
    for(ll i=1;i<=l1;i++){
        for(ll j=1;j<=l2;j++){
            if(s[i-1]==t[j-1]){
                z[i][j]=z[i-1][j-1]+1;
            }
            else{
                z[i][j]=max(z[i-1][j],z[i][j-1]);
            }
        }
    }
    /*for(ll i=0;i<=l1;i++){
        cout<<"\n";
        for(ll j=0;j<=l2;j++){
            cout<<z[i][j]<<" ";
        }
    }
    cout<<z[l1][l2];*/
    string ans = "";
    ll i=l1,j=l2;
    while(z[i][j]!=0){
            //cout<<i<<" "<<j<<"\n";
        if(z[i][j]==z[i][j-1])
        {
            j--;
            //cout<<i<<" "<<j<<"\n";
        }
        else if(z[i][j]!=z[i][j-1]&&z[i][j]==z[i-1][j]){
            i--;
        }
        else{
            ans+= t[j-1];
            i--;
            j--;
            //cout<<i<<" "<<j<<"\n";
        }
    }
    reverse(ans.begin(), ans.end());
    cout<<ans;
}




Measured memory_bytes: 70656
#!python3

iim = lambda: map(int, input().rstrip().split())

def d10(n):
    a = []
    while n:
        n, m = divmod(n, 10)
        a.append(m)

    return a

def resolve():
    N = tuple(map(int,input()))

    if len(N) == 1:
        print(N[0])
        return

    n = len(N)
    dp = [[[0]*10 for j in range(2)] for i in range(2)]

    k0  = N[0]
    dp[0][0][k0] = 1

    dp0, dp1 = dp
    for i in range(n-1):
        xx = 1 if i else 0

        for k in range(1, 10):
            dp1[1][k] = 10 * dp0[1][k] + xx

        x, y = N[i], dp0[0][k0]
        if i == 0:
            dp1[0][k0] = y
            for k in range(1, k0):
                dp1[1][k] = y
        else:
            dp1[1][k0] += x * y
            dp1[0][k0] = y

        #print(dp1)
        dp0, dp1 = dp1, dp0

    dp2 = [[0]*10 for i in range(10)]
    for i in range(1, 10):
        for j in range(1, 10):
            dp2[i][j] = dp0[1][i]

        for j in range(1, N[-1]+1):
            dp2[i][j] += dp0[0][i]

        dp2[i][i] += 1

    #for x in dp2:
    #    print(x)

    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += dp2[i][j]*dp2[j][i]
    print(ans)




if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<fstream>
#include<utility>
#include<bitset>
#include<map>
#include<deque>
#include<cmath>
#include<random>
#include<string.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

int main() {
	ll ans = 1e18;
	makei(N);
	vll a(N);
	rep(N)cin >> a[i];
	Rep(1, N)a[i] += a[i - 1];
	Rep(1, N) {
		ans = min(ans, abs(a[i - 1] + a[i - 1] - a[N - 1]));
	}
	say(ans);
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
 int w,h,n,i,x,y,a;
 scanf("%d%d%d",&w,&h,&n);
 int x1=0,x2=w,y3=0,y4=h;
 for(i=0;i<n;i++){
  scanf("%d%d%d",&x,&y,&a);
  switch(a){
   case 1:
    if(x1<x) x1=x;
    break;
   case 2:
    if(x2>x) x2=x;
    break;
   case 3:
    if(y3<y) y3=y;
    break;
   case 4:
    if(y4>y) y4=y;
    break;
  }
 }
 int xx=x2-x1,yy=y4-y3;
 printf("%d",xx<0||yy<0?0:xx*yy);
 return 0;
}

Measured memory_bytes: 128
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        m: usize,
        k: usize,
        a: [u64; n],
    }
    let mut dp = a.clone();
    let mut d = vec![(0, 0); n];
    for i in 1..k {
        let mut f = 0;
        let mut b = 0;
        d[b] = (i - 1, dp[i - 1]);
        b += 1;
        for j in i..n {
            if d[f].0  + m + 1 == j {
                f += 1;
            }
            let v = d[f].1 + (i + 1) as u64 * a[j];
            while f < b && d[b - 1].1 <= dp[j] {
                b -= 1;
            }
            d[b] = (j, dp[j]);
            b += 1;
            dp[j] = v;
        }
    }
    let ans = dp[(k - 1)..].iter().max().unwrap();
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
const ld PI = 3.14159265358979323846264338327950L;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int tc = 1;
    //cin >> tc;
    while(tc--) {
        int a, b, h, m;
        cin >> a >> b >> h >> m;
        
        ld ah = 30*h + (ld) m / 2, am = 6*m;
        ld theta = abs(ah - am);
        ld cos_theta = cos(theta * PI / 180.0);
        
        ld res = sqrt(a*a + b*b - 2*a*b*cos_theta);
        cout << fixed << setprecision(16) << res << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4104
#include <iostream>

char c;
int main() {
    std::cin >> c;
    if (c == 'A')
        std::cout << 'T' << std::endl;
    else if (c == 'C')
        std::cout << 'G' << std::endl;
    else if (c == 'T')
        std::cout << 'A' << std::endl;
    else if (c == 'G')
        std::cout << 'C' << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> word(H);
  for (int i = 0; i < H; i++) {
    cin >> word.at(i);
  }
  int black0 = 0;
  int count = 0;
  for (int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if (word.at(i).at(j) == '#') {
        black0++;
      }
    }
  }
  for (int i = 0; i < (1 << H); i++) {
    for(int j = 0; j < (1 << W); j++) {
      int black = black0;
      bitset<8> high(i);
      bitset<8> wide(j);
      for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
          if (word.at(h).at(w) == '#' && (high[h] || wide[w])) {
            black--;
          }
        }
      }
      if (black == K) {
      count++;
      }
    }
  }
  cout << count << endl;
    
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
long long memo[105][100005];
long long w[105],v[105];
long long sum,pos;
long long N,W;
long long knap(long long pos, long long sum){
  if(memo[pos][sum] != -1 ) return memo[pos][sum];
  if(pos == N){
    return 0;
  }else if(sum + w[pos] > W){
    return memo[pos][sum] = knap(pos + 1 , sum);
  } else {
    return memo[pos][sum] = max(knap(pos + 1 , sum) , knap(pos + 1 , sum + w[pos] ) + v[pos]);
  }
}
int main()
{
  cin >> N >> W;
  for(int i=0; i<N; i++){
    cin >> w[i];
    cin >> v[i];
  }
  memset(memo,-1,sizeof(memo));
  sum = 0;
  pos = 0;
  cout << knap(pos,sum) << endl;
  return 0;
}


Measured memory_bytes: 82304
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>H(N);
  for (int i=0;i<N;++i){
    cin>>H[i];
  }
  vector<int>c(N,0);
  for (int i=1;i<N;++i){
    if (i==1){
      c[i]=c[i-1]+abs(H[i-1]-H[i]);
    }
    else c[i]=min(c[i-1]+abs(H[i-1]-H[i]),
                  c[i-2]+abs(H[i-2]-H[i]));
  }
  cout<<c[N-1]<<endl;
}


Measured memory_bytes: 1024
import numpy as np
N, D = map(int, input().split())
X=np.empty((0,D),int)
for i in range(N):
    X=np.append(X, np.array([list(map(int, input().split()))]),axis=0)
ans=0
for i in range(N):
    for j in range(i+1,N):
        
        diff=X[j]-X[i]
        d=np.linalg.norm(diff)
        #print(X[i],X[j],diff)
        if d.is_integer():
            ans+=1
print(ans)

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

int main() {
    string s , t;
    cin >> s >> t;
    int n = s.size() , ans = 0;
    for(int i = 0; i < n; i++){
        if(s.at(i) != t.at(i)){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3848
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919;
const int mod=1000000007;
const int dd[]={0,-1,0,1,0};
using namespace std;
class mod_int{
public:
	int x;
	mod_int():x(0){}
	mod_int(int u):x(u){}
	mod_int operator=(int u){
		x=u;
		return *this;
	}
	mod_int operator+=(mod_int y){
		x+=y.x;
		x=x>=mod?x-mod:x;
		return *this;
	}
	mod_int operator-=(mod_int y){
		x-=y.x;
		x=x<0?x+mod:x;
		return *this;
	}
	mod_int operator*=(mod_int y){
		x*=y.x;
		x%=mod;
		return *this;
	}
	mod_int operator/=(mod_int y){
		mod_int z=1;
		for(int u=1;u<=mod-2;u<<=1){
			if((mod-2)&u)
				z*=y;
			y*=y;
		}
		operator*=(z);
		return *this;
	}
};
mod_int operator+(mod_int x,mod_int y){
	return x+=y;
}
mod_int operator-(mod_int x,mod_int y){
	return x-=y;
}
mod_int operator*(mod_int x,mod_int y){
	return x*=y;
}
mod_int operator/(mod_int x,mod_int y){
	return x/=y;
}
ostream& operator<<(ostream &os,mod_int x){
	return os<<x.x;
}
int a,b,c,d;
signed main(){
	int i,j;
	cin>>a;
	string s[10000];
	string t;
	for(i=0;i<a;i++)
		cin>>s[i];
	cin>>t;
	int x=0,z=0;
	for(i=0;i<a;i++){
		string u=s[i];
		for(auto &xx:u)
			if(xx=='?')
				xx='a';
		if(u>t)
			continue;
		u=s[i];
		for(auto &xx:u)
			if(xx=='?')
				xx='z';
		if(u<t){
			x++;
			continue;
		}
		z++;
	}
	for(i=x+1;i<=x+z+1;i++){
		cout<<i;
		if(i==x+z+1)
			cout<<endl;
		else
			cout<<" ";
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef vector<bool> vbb;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll w, h, n;
        in >> w >> h >> n;
        vector<vbb> rect(h, vbb(w, false));
        for (int i = 0; i < n; i++) {
            ll x, y, a;
            in >> x >> y >> a;
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (a == 1 && j < x) {
                        rect[i][j] = true;
                    }
                    if (a == 2 && j + 1 > x) {
                        rect[i][j] = true;
                    }
                    if (a == 3 && i < y) {
                        rect[i][j] = true;
                    }
                    if (a == 4 && i + 1 > y) {
                        rect[i][j] = true;
                    }
                }
            }
        }
        ll ans = 0;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                ans += rect[i][j] == false;
            }
        }
        out << ans << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
class Simple {
    int N, Ma, Mb;
    int[] a, b, c;
    const int INF = 1234567890;
    void Solve() {
        //intput
        N = io.Int;
        Ma = io.Int;
        Mb = io.Int;
        a = new int[N];
        b = new int[N];
        c = new int[N];
        for (int i = 0; i < N; ++i) {
            a[i] = io.Int;
            b[i] = io.Int;
            c[i] = io.Int;
        }
        //cal
        var dp = new int[50, 500, 500];
        for (int i = 0; i < dp.GetLength(0); ++i)
            for (int j = 0; j < dp.GetLength(1); ++j)
                for (int k = 0; k < dp.GetLength(2); ++k)
                    dp[i, j, k] = INF;
        dp[0, 0, 0] = 0;
        for (int i = 0; i < N; ++i)
            for (int j = 0; j < (N+1)*10+1; ++j)
                for (int k = 0; k < (N+1)*10+1; ++k) {
                    if (dp[i, j, k] == INF) continue;
                    //加える
                    dp[i + 1, j + a[i], k + b[i]] =
                        Math.Min(dp[i + 1, j + a[i], k + b[i]], dp[i, j, k] + c[i]);
                    //加えない
                    dp[i + 1, j, k] = Math.Min(dp[i + 1, j, k], dp[i, j, k]);
                }
        int ans = INF;
        for (int j = 1; j < dp.GetLength(1); ++j)
            for (int k = 1; k < dp.GetLength(2); ++k)
                if (j * Mb == k * Ma)
                    ans = Math.Min(ans, dp[N, j, k]);
        //res
        Console.WriteLine(ans == INF ? -1 : ans);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}

class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


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

par=[-1]*N
num=[0]*N

def find(x):
  if par[x]<0:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

def union(x,y):
  p,q=find(x),find(y)
  if p==q:
    return
  if p>q:
    p,q=q,p
  par[p]+=par[q]
  par[q]=p   

def size(x):
  return -par[find(x)]

def same(x,y):
  return find(x)==find(y)     

for _ in range(M):
  a,b=map(int,input().split())
  a-=1
  b-=1
  union(a,b)
  num[a]+=1
  num[b]+=1

for _ in range(K):
  c,d=map(int,input().split())
  c-=1
  d-=1
  if same(c,d):
    num[c]+=1
    num[d]+=1

for i in range(N):
  print(size(i)-1-num[i],end=" ")

Measured memory_bytes: 11408
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a==b&&b==c)cout << "Yes" << endl;
  else if(b==c&&c==d)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
N , M = map(int,input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
visited = [False] * N
visited[0] = True

def dfs(now):
    ans = 0
    visited[now] = True
    #print(visited)
    if all(visited):
        visited[now] = False
        return 1

    for next_node in graph[now]:
        if visited[next_node]:
            continue
        ans += dfs(next_node)
    visited[now] = False
    return ans


print(dfs(0))

Measured memory_bytes: 43612
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,a[100000],zero=0,one=0,two=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%4==0)two++;
        else if(a[i]%2==0)one++;
        else zero++;
    }
    if(one==0){
        if(zero<=two+1)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    else{
        if(zero<=two)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 640
import math
Alp = [chr(ord('a') + i) for i in range(26)]
N = int(input())
k = int(math.ceil(math.log((25*N/26)+1,26)))
n = int(N-(26*(26**(k-1)-1)/25))
for i in range(k):
  if i<k-1:
    if n%(26**(k-1-i))!=0:
      kre = int(n//(26**(k-1-i)))
    else:
      kre = int(n/(26**(k-1-i))-1)
    print(Alp[kre], end='')
    n -= int((26**(k-1-i))*kre)
  else:
    print(Alp[n-1], end='')


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

const int MAX_N = 400;

int memo[MAX_N];

typedef struct {
	int to, cost;
} edge;
edge makeEdge(int to, int cost) {
	edge e = {to, cost};
	return e;
}

vector<edge> graph[MAX_N];

int dfs(int p) {
	if (memo[p] != -1) {
		return memo[p];
	}
	int res = 0;
	
	for (unsigned i = 0; i < graph[p].size(); i++) {
		res = max(res, graph[p][i].cost + dfs(graph[p][i].to));
	}
	
	return memo[p] = res;
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		graph[a].push_back(makeEdge(b, c));
	}
	
	memset(memo, -1, sizeof(memo));
	cout << dfs(0) << endl;
	return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int n, k;
int calc(int n, int k) {
	if (n%k == 0)
		return n / k;
	int cur = n / k;
	int z = cur + 1;
	return calc(n - (n - cur*k + z - 1) / z*z, k);
}
int main()
{
	int x;
	scanf("%d", &x);
	int res = 0;
	while (x--) {
		scanf("%d%d", &n, &k);
		res ^= calc(n, k);
	}
	if (res)
		puts("Takahashi");
	else
		puts("Aoki");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=205;
const int P=1e9+7;
int m,cnt,top,vi[N][N];
int n,k,nu,now=1,st[N],v[N],nex[N],head[N];
long long fsp(long long x,int y){
	long long ans=1;
	while(y){
		if(y&1)	ans=ans*x%P;
		x=x*x%P,y>>=1;
	}
	return ans;
}
void addedges(int x,int y){
	nex[++now]=head[x];
	head[x]=now,v[now]=y;
}
vector<int>b[N];
int low[N],dfn[N];
long long ans=1,fac[N],inv[N];
long long C(int n,int m){
	return fac[n]*inv[m]%P*inv[n-m]%P;
}
void dfs(int x,int fa){
	low[x]=dfn[x]=++cnt,st[++top]=x;
	for(int i=head[x];i;i=nex[i])
		if((i^1)!=fa){
			if(!dfn[v[i]]){
				dfs(v[i],i),low[x]=min(low[x],low[v[i]]);
				if(low[v[i]]>=dfn[x]){
					if(low[v[i]]>dfn[x])	ans=ans*k%P,top--;
					else{
						b[++nu].push_back(x);
						while(st[top+1]!=v[i])
							b[nu].push_back(st[top--]);
					}
				}
			}
			else	low[x]=min(low[x],dfn[v[i]]);
		}
}
int gcd(int a,int b){
	while(b){
		int t=b;
		b=a%b,a=t;
	}
	return a;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1,x,y;i<=m;i++){
		scanf("%d%d",&x,&y);
		addedges(x,y),++vi[x][y];
		addedges(y,x),++vi[y][x];
	}
	fac[0]=inv[0]=1;
	for(int i=1;i<=m+k;i++){
		fac[i]=fac[i-1]*i%P;
		inv[i]=fsp(fac[i],P-2);
	}
	for(int i=1;i<=n;i++)
		if(!dfn[i])	dfs(i,0);
	for(int i=1;i<=nu;i++){
		int si=b[i].size(),num=0;
		for(int j=0;j<si;j++)
			for(int k=j+1;k<si;k++)
				num+=vi[b[i][j]][b[i][k]];
		if(num==b[i].size()){
			long long res=0;
			for(int j=1;j<=si;j++)
				res=(res+fsp(k,gcd(si,j)))%P;
			ans=ans*res%P*fsp(si,P-2)%P;
		}
		else	ans=ans*C(num+k-1,k-1)%P;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import numpy as np

def main():
    N, W = [int(item) for item in input().split()]
    item = np.array([[int(item) for item in input().split()] for _ in range(N)])

    dp = np.zeros((2, W+1), dtype='int64')

    for i in range(N):
        dp[i%2 ^ 1] = dp[i % 2]
        w, v = item[i]
        np.maximum(dp[i%2][:-w] + v, dp[i%2][w:], out=dp[i%2 ^ 1][w:])
        # print(dp[i+1])
    print(dp[N%2][W])

if __name__ == "__main__":
    main()

Measured memory_bytes: 17920
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
	cin>>n;
	for (int i=0;i<n-1;i++) {
		for (int j=i+1;j<n;j++){
			ll num=i^j;
			ll count=1;
			while(!(num&1))num/=2,count++;
			cout<<count<<" ";
		}
		cout<< endl;
	}
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++ )
#define dump(x) cerr << #x << " = " << (x) << endl;
#define int long long


signed main(void){

    int N, L;
    cin >> N >> L;

    int a[N];
    
    int maxsum = 0;
    int index = 0;
    cin >> a[0];
    rep(i, N - 1) {
        cin >> a[i + 1];
        if (maxsum < a[i] + a[i + 1]) {
            maxsum = a[i] + a[i + 1];
            index = i + 1;
        }
    }
    if (maxsum < L) {
        cout << "Impossible" << endl;
        return 0;
    }
    cout << "Possible" << endl;
    for (int i = 1; i < index; i++) {
        cout << i << endl;
    }
    for (int i = N - 1; i > index; i--) {
        cout << i << endl;
    }
    cout << index << endl;

    return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
    int a,b,c;
	scanf("%d %d",&a,&b);
	if(a==1&&b==2)
	c=3;
	else if(a==2&&b==1)
	c=3;
	else if(a==1&&b==3)
	c=2;
	else if(a==3&&b==1)
	c=2;
	else if(a==2&&b==3)
	c=1;
	else c=1;
	printf("%d\n",c); 
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
string s;bool x,y;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='C') x=true;
		if(s[i]=='F'&&x) y=true;
	}
	if(x&&y) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#ifdef DEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dreplace(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dreplace(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
template<typename T> using V = vector<T>;
constexpr LL LINF=334ll<<53; constexpr int INF=15<<26; constexpr LL MOD=1E9+7;

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

    int n;
    cin >> n;
    VLL a(n),b(n);
    for(int i=0; i<n; ++i){
        cin >> a[i] >> b[i];
    }
    LL ans=0;
    for(int i=n-1; i>=0; --i){
        ans+=(b[i]-(ans+a[i])%b[i])%b[i];
        DBG(ans)
    }
    cout << ans <<endl;

    return 0;
}



Measured memory_bytes: 1792
N = int(input())
*A, = map(int, input().split())

def calc(A):
    if len(A) == 1:
        return [], A[0]
    res = []
    if len(A) % 2 == 0:
        res.append(len(A))
        A = A[:-1]
    if all(a <= 0 for a in A[::2]):
        ma = max(A[::2])
        i = 0
        while A[i] != ma:
            i += 1
            res.append(1)
        j = len(A)
        while i < j-1:
            res.append(j-i)
            j -= 1
        return res, ma

    l = 0; r = len(A)
    while A[0] < 0:
        res.append(1)
        res.append(1)
        A = A[2:]
    v = 0
    while len(A) > 2:
        if A[2] < 0:
            res.append(3)
            if len(A) > 4:
                A = A[:2] + A[4:]
            else:
                A = A[:2]
        else:
            res.append(2)
            A[2] += A[0]
            A = A[2:]
    if len(A) > 1:
        res.append(2)
    return res, A[0]
r, v = calc(A)
if len(A) > 1:
    r0, v0 = calc(A[1:])
    if v < v0:
        r = [1] + r0
        v = v0
print(v, len(r), *r, sep='\n')


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(){
    ll n; cin>>n;
    if(n%2==1)cout<<0<<endl;
    else{
        ll x=10;
        ll ans=0;
        while(x<=n){
            ans+=n/x;
            x*=5;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(ll i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//********************************template END****************************************//

void solve(void){

	int N;
	cin >> N;
	vecll xs(N), ys;
	rep(N, i)
	{
		cin >> xs[i];
		xs[i] -= i;
	}

	ys = xs;
	sort(all(ys));

	if (N & 1)
	{
		ll b = ys[N/2], ans = 0;
		rep(N, i)
		{
			ans += abs(xs[i] - b);
		}
		cout << ans << endl;
		return;
	}

	ll b1 = ys[N/2-1], b2 = ys[N/2];

	ll ans = 0, tmp = 0;

	rep(N, i)
	{
		ans += abs(xs[i] - b1);
		tmp += abs(xs[i] - b2);
	}

	ans = min(tmp, ans);

	cout << ans << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 3328
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	var N int
	fmt.Scan(&N)
	a := make([]int, N+10)
	b := make([]int, N+10)
	c := make([]int, N+10)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		a[i] = nextInt(sc)
		b[i] = nextInt(sc)
		c[i] = nextInt(sc)
	}
	dp := make([][]int, N+10)
	for i := 0; i < len(dp); i++ {
		dp[i] = make([]int, 3)
		for j := 0; j < len(dp[i]); j++ {
			dp[i][j] = 0
		}
	}
	// dp[i+1][j] => i日めに行動j(0:A, 1:B, 2:C)を選んだ場合の最大幸福度
	// dp[i][0], dp[i][1], dp[i][2]が求められている状態で、以下の遷移を考える
	// dp[i][0] -> dp[i+1][1] or dp[i+1][2]
	// dp[i][1] -> dp[i+1][0] or dp[i+1][2]
	// dp[i][2] -> dp[i+1][0] or dp[i+1][1]
	for i := 0; i < N; i++ {
		dp[i+1][0] = max(dp[i][1]+a[i], dp[i][2]+a[i])
		dp[i+1][1] = max(dp[i][0]+b[i], dp[i][2]+b[i])
		dp[i+1][2] = max(dp[i][0]+c[i], dp[i][1]+c[i])
	}
	fmt.Println(max(dp[N][0], max(dp[N][1], dp[N][2])))
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 8704
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class Main  implements Runnable { //Runnableを実装する

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行

    }

    public void run() {
		Scanner sc = new Scanner(System.in);
		//Scanner sc = new Scanner("3 -10000000000 5 -4");
		int n = Integer.parseInt(sc.next());
		//int b = Integer.parseInt(sc.next());
		//int t = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		//String str = sc.next();
		//char c[] = str.toCharArray();
		long a;
		long min= 10000000000l;
		int numofm = 0;
		long ans = 0;
		for (int i = 0; i < n; i++)
		{
			a= Long.parseLong(sc.next());
			if(a<0)
			{
				numofm++;
				if(-a<min)
				{
					min = -a;

				}
				ans = ans-a;
			}
			else
			{
				if(a<min)
				{
					min = a;
				}
				ans = ans+a;
			}
		}
		if(numofm%2==1)
		{
			ans = ans - (2l*min);
		}

		PrintWriter out = new PrintWriter(System.out);
		out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 50884
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int main()
{
	vector< vector<int> > A(3, vector<int>(3));

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> A.at(i).at(j);
		}
	}

	int N;
	cin >> N;

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

	vector< vector<bool> > s(3, vector<bool>(3));
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			int num = A.at(i).at(j);
			if (find(begin(b), end(b), num) != end(b))
			{
				s.at(i).at(j) = true;
			}
		}
	}

	if (s.at(0).at(0) && s.at(1).at(0) && s.at(2).at(0))
	{
		cout << "Yes" << endl;
	}
	else if (s.at(0).at(1) && s.at(1).at(1) && s.at(2).at(1))
	{
		cout << "Yes" << endl;
	}
	else if (s.at(0).at(2) && s.at(1).at(2) && s.at(2).at(2))
	{
		cout << "Yes" << endl;
	}
	else if (s.at(0).at(0) && s.at(0).at(1) && s.at(0).at(2))
	{
		cout << "Yes" << endl;
	}
	else if (s.at(1).at(0) && s.at(1).at(1) && s.at(1).at(2))
	{
		cout << "Yes" << endl;
	}
	else if (s.at(2).at(0) && s.at(2).at(1) && s.at(2).at(2))
	{
		cout << "Yes" << endl;
	}
	else if (s.at(0).at(0) && s.at(1).at(1) && s.at(2).at(2))
	{
		cout << "Yes" << endl;
	}
	else if (s.at(0).at(2) && s.at(1).at(1) && s.at(2).at(0))
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3028
#include <iostream>
#include<vector>
#include <cstring>
#include <cstdio>
#include<cstdint>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
const int MOD = 1e9+7;
#define NIL -1
const int INF = 1 << 29;
int n,m;
int a[50],b[50];
bool graph[50][50];
bool visited[50];
stack<int>s;
void dfs(int r){
    memset(visited,0,sizeof(visited));
    s.push(r);
    while(s.size()){
        int u=s.top();s.pop();
        visited[u]=1;
        rep(v,n){
            if(graph[u][v] && !visited[v]){
                s.push(v);
            }
        }
    }
}
void dfs2(int v){
    visited[v]=1;
    rep(v2,n){
        if(graph[v][v2]==0)continue;
        if(visited[v2]==1)continue;
        dfs2(v2);
    }
}
int solve(){
   int ans=0;
   rep(i,n){
       graph[a[i]][b[i]]=graph[b[i]][a[i]]=0;
       dfs(0);
       bool bridge=false;
       rep(j,n){
           if(!visited[j])bridge=true;
       }
       if(bridge)ans++;
       graph[a[i]][b[i]]=graph[b[i]][a[i]]=1;
   }
   

return ans;
}
int main(){
    memset(graph,0,sizeof(graph));
    cin>>n>>m;
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        graph[a[i]][b[i]]=1;
        graph[b[i]][a[i]]=1;
    }
    int ans=0;
   rep(i,m){
       graph[a[i]][b[i]]=graph[b[i]][a[i]]=0;
       dfs(0);
       bool bridge=false;
       rep(j,n){
           if(!visited[j])bridge=true;
       }
       if(bridge)ans++;
       graph[a[i]][b[i]]=graph[b[i]][a[i]]=1;
   }
   cout<<ans<<endl;

}

Measured memory_bytes: 256
from itertools import permutations
n = int(input())
ps = ''.join(input().split())
qs = ''.join(input().split())
perm = sorted(
    list(map(''.join, (permutations(map(str, list(range(1, n+1))))))))
pi, qi = 0, 0
#print(ps, qs)
# print(len(perm))
for i in range(len(perm)):
    # print(perm[i])
    if perm[i] == ps:
        # print('pi={}'.format(i))
        pi = i+1
    if perm[i] == qs:
        # print('qi={}'.format(i))
        qi = i+1

print(abs(pi-qi))


Measured memory_bytes: 6308
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=1000000007;
inline int kpow(int a,int b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)s=1ll*s*a%mod;
	return s;
}
int n,m,dp[2][1<<16],a[20],jc[1<<16|1],jcv[1<<16|1],ans;
int A(int a,int b){return a<b?0:1ll*jc[a]*jcv[a-b]%mod;}
int main()
{
	scanf("%d %d",&n,&m);
	jc[0]=1;
	for(int i=1;i<=1<<n;++i)jc[i]=1ll*jc[i-1]*i%mod;
	jcv[1<<n]=kpow(jc[1<<n],mod-2);
	for(int i=1<<n;i;--i)jcv[i-1]=1ll*jcv[i]*i%mod;
	for(int i=0;i<m;++i)scanf("%d",&a[i]);
	reverse(a,a+m);
	dp[0][0]=1;
	int t=0;
	for(int i=0;i<m;++i)
	{
		t^=1;memcpy(dp[t],dp[t^1],4<<n);
		for(int j=0;j<1<<n;++j)
			for(int k=0;k<n;++k)
				if(!(j>>k&1))dp[t][j|(1<<k)]=(dp[t][j|(1<<k)]+1ll*A((1<<n)-j-a[i],(1<<k)-1)*(1<<k)%mod*(mod-dp[t^1][j]))%mod;
	}
//	for(int i=0;i<1<<n;++i)printf("%d ",dp[t][i]);printf("\n");
	for(int i=0;i<1<<n;++i)ans=(ans+1ll*dp[t][i]*jc[(1<<n)-1-i])%mod;
//	printf("%d\n",ans);
	ans=1ll*ans*(1<<n)%mod;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxn = 1e5 + 50;
const ll mod = 1e9+7;
ll dp[405][405];
ll sum[405];
ll a[405];
int n;
ll dfs(int l, int r){
    if(l >= r) return (1LL<<60);
    if(dp[l][r]) return dp[l][r];
    if(r-l == 1) return dp[l][r] = a[l] + a[r];
    ll ans = (1LL<<60);
//    cout << ans << endl;
    for(int mid = l; mid <= r; mid++){
        if(mid == l){
            ans = min(ans, a[l] + sum[r] - sum[l] + dfs(mid+1, r));
            continue;
        }
        if(mid == r){
            ans = min(ans, a[r] + sum[r-1] - sum[l-1] + dfs(l, mid-1));
            continue;
        }

        ans = min(ans, min(
            dfs(l, mid) + dfs(mid+1, r) + sum[r] - sum[l-1]
            ,
            dfs(l, mid-1) + dfs(mid, r)  + sum[r] - sum[l-1]
            ));
    }
    return dp[l][r] = ans;
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        sum[i] = sum[i-1] + a[i];
    }
    printf("%lld\n", dfs(1,n));
    return 0;
}

Measured memory_bytes: 1536
x, y = map(int, input().split())
a = {1, 3, 5, 7, 8, 10, 12}
b = {4, 6, 9, 11}
c = {2}
print("Yes" if x in a and y in a else "Yes" if x in b and y in b else "Yes" if x in c and y in c else "No")


Measured memory_bytes: 2940
package main

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

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

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

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

var sc = bufio.NewScanner(os.Stdin)

func calc(nums []int) int {
	if len(nums) == 1 {
		return 0
	}

	if len(nums) == 2 {
		if nums[0] == nums[1] {
			return 1
		} else {
			return 0
		}
	}

	ans0 := 0
	ans1 := 0
	for i := 0; i < len(nums); i++ {

		if i == 0 {
			if nums[0] == 0 {
				ans1++
			} else {
				ans0++
			}
		}

		if i == 1 {
			if nums[1] == 0 {
				ans0++
			} else {
				ans1++
			}
		}

		// 0スタート
		if i != 0 && i != 1 && i%2 != 0 && nums[i] == 0 {
			ans0++
		}
		if i != 0 && i != 1 && i%2 == 0 && nums[i] == 1 {
			ans0++
		}

		//1
		if i != 0 && i != 1 && i%2 != 0 && nums[i] == 1 {
			ans1++
		}
		if i != 0 && i != 1 && i%2 == 0 && nums[i] == 0 {
			ans1++
		}
	}

	return min(ans0, ans1)
}

func main() {
	a := oneInt()

	var V []int
	var C []int
	for i := 0; i < a; i++ {
		V = append(V, oneInt())
	}

	for i := 0; i < a; i++ {
		C = append(C, oneInt())
	}

	var ans int
	for i := 0; i < a; i++ {
		val := V[i] - C[i]
		if val > 0 {
			ans += val
		}
	}

	fmt.Println(ans)
}


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

using namespace std;
const int N = 3e5 + 3, M = 2019;
int n, a[N];
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
#endif
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", a + i);
	sort(a, a + n);
	printf("%d\n", a[n / 2] - a[n / 2 - 1]);
	return 0;
}

Measured memory_bytes: 640
// ABC088D
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <map>
#include <functional>
#include <set>
#include <iterator>
#include <queue>

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

int a, b;

int main() {
   cin >> a >> b;
   printf("%d", (b >= a) ? a : a-1);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<queue>
#include<stack>
#include<math.h>
#define Max 1000000
#define INF 1000000000000000000
using namespace std;



int main(){

	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",(6-(a+b)));
	
	return 0;
}

Measured memory_bytes: 256
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    s_arr = []
    for i in range(N):
        _ =     _in[i+1]   # type:str
        s_arr.append(_)
    M = int(_in[N+1])  # type:int
    t_arr = []
    for i in range(M):
        _ =     _in[i+N+2]   # type:str
        t_arr.append(_)    
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    w_arr = s_arr+t_arr
    w_arr = list(set(w_arr))
    cnt = 0
    for w in w_arr:
        _ = s_arr.count(w)-t_arr.count(w)
        cnt = max(cnt,_)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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

using ll = long long;
using ii = pair<int, int>;

const int MOD = 1e9 + 7;

ll fexp(int a, int n) {
  ll tmp = a, ans = 1;

  while (n > 0) {
    if (n & 1) ans = (ans * tmp) % MOD;
    tmp = (tmp * tmp) % MOD;
    n >>= 1;
  }

  return ans;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;

  cin >> n;

  ll ans = fexp(10, n);

  ans = (2 * MOD + ans - 2 * fexp(9, n)) % MOD;
  ans = (ans + fexp(8, n)) % MOD;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  vector<int> b(N);
  for(int i = 0; i < N; i++){
    cin >> b[i];
  }
  for(int k = 0; k < N; k++){
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if(b[k] == A[i][j]){
          A[i][j] = 0;
        }
      }
    }
  }
  if(A[0][0]==0 && A[0][1]==0 && A[0][2] == 0) 
    cout << "Yes" << endl;
  else if(A[1][0]==0 && A[1][1]==0 && A[1][2] == 0) 
    cout << "Yes" << endl;
  else if(A[2][0]==0 && A[2][1]==0 && A[2][2] == 0) 
    cout << "Yes" << endl;
  else if(A[0][0]==0 && A[1][0]==0 && A[2][0] == 0) 
    cout << "Yes" << endl;
  else if(A[0][1]==0 && A[1][1]==0 && A[2][1] == 0) 
    cout << "Yes" << endl;
  else if(A[0][2]==0 && A[1][2]==0 && A[2][2] == 0) 
    cout << "Yes" << endl;
  else if(A[0][0]==0 && A[1][1]==0 && A[2][2] == 0) 
    cout << "Yes" << endl;
  else if(A[2][0]==0 && A[1][1]==0 && A[0][2] == 0) 
    cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>


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

Measured memory_bytes: 3712
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
using namespace std;

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

const int maxn = 4e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
int a[maxn];
ll sum[maxn];
ll abs_(ll x)
{
    if(x<0) return -x;
    return x;
}
int main() {
    //freopen  (".in", "r", stdin);
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    ll ans=0x3f3f3f3f3f3f3f3f;
    for(int i=1;i<=n-1;i++)
    {
        ans=min(ans,abs_(sum[i]-(sum[n]-sum[i])));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 3840
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1010

enum Type{
	Jungle,
	Ocean,
	Ice,
};

int N;
int H,W;
int BIT[NUM][NUM][3];
char buf[NUM];

void add(int add_row,int add_col,int value,Type type){
	for(int row = add_row; row <= H; row += row & -row){
		for(int col = add_col; col <= W; col += col & -col){
			BIT[row][col][type] += value;
		}
	}
}

int getSum(int get_row,int get_col,Type type){
	int ret = 0;
	for(int row = get_row; row > 0; row -= row & -row){
		for(int col = get_col; col > 0; col -= col & -col){
			ret += BIT[row][col][type];
		}
	}
	return ret;
}

int getSum(int from_row,int from_col,int to_row,int to_col,Type type){
	return getSum(to_row,to_col,type)-getSum(from_row-1,to_col,type)-getSum(to_row,from_col-1,type)+getSum(from_row-1,from_col-1,type);
}

int main(){

	scanf("%d %d",&H,&W);

	int Q;
	scanf("%d",&Q);

	for(int row = 0; row <= H; row++){
		for(int col = 0; col <= W; col++){
			BIT[row][col][Jungle] = 0;
			BIT[row][col][Ocean] = 0;
			BIT[row][col][Ice] = 0;
		}
	}

	Type add_type;

	for(int row = 0; row < H; row++){
		scanf("%s",buf);
		for(int col = 0;col < W; col++){
			switch(buf[col]){
			case 'J':
				add_type = Jungle;
				break;
			case 'O':
				add_type = Ocean;
				break;
			case 'I':
				add_type = Ice;
				break;
			}
			add(row+1,col+1,1,add_type);
		}
	}


	int a,b,c,d,J_num,O_num,I_num;

	for(int loop = 0; loop < Q; loop++){
		scanf("%d %d %d %d",&a,&b,&c,&d);

		J_num = getSum(a,b,c,d,Jungle);
		O_num = getSum(a,b,c,d,Ocean);
		I_num = getSum(a,b,c,d,Ice);

		printf("%d %d %d\n",J_num,O_num,I_num);
	}

	return 0;
}



Measured memory_bytes: 14888
#include <iostream>

int main() {
  int A, B, C, K;
  std::cin >> A >> B >> C >> K;
  while (A >= B) {
    B *= 2;
    --K;
  }
  while (B >= C) {
    C *= 2;
    --K;
  }
  std::cout << ((K >= 0) ? "Yes" : "No") << std::endl;
  return 0;
}


Measured memory_bytes: 3616