akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

class RSQ {
public:
	RSQ(int n) {
		_n=1;
		while(_n<n) _n*=2;
		_dat.resize(2*_n-1);
		for(int i=0;i<2*_n-1;++i) _dat[i]=0;
	}
	int size() {
		return _n;
	}
	void update(int k,long long a) {
		k+=_n-1;
		_dat[k]+=a;
		while(k>0) {
			k=(k-1)/2;
			_dat[k]+=a;
		}
	}
	// return the sum of [a,b)
	// external call should be written like query(a,b,0,0,_n)
	ll query(int a,int b,int k=0,int l=0,int r=-1) {
		if(r==-1) r=_n;
		if(r<=a||b<=l) return 0;
		if(a<=l&&r<=b) return _dat[k];
		else {
			ll vl=query(a,b,k*2+1,l,(l+r)/2);
			ll vr=query(a,b,k*2+2,(l+r)/2,r);
			return vl+vr;
		}
	}
private:
	int _n;
	vector<ll> _dat;
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	ll sum=n*(n-1)/2+n;
	ll lb=0,ub=INF+10;
	while(ub-lb>1) {
		ll cnt=0;
		ll mid=(lb+ub)/2;
		vector<ll> b(n);
		vector<ll> c(n);
		REP(i,n) {
			if(a[i]<=mid) b[i]=1;
			else b[i]=-1;
		}
		ll buf=0;
		REP(i,n) buf+=b[i];
		RSQ rsq(2*n+1);
		ll tmp=0;
		rsq.update(n,1);
		for(ll i=n-1; i>0; i--) {
			tmp+=b[i];
			rsq.update(n+tmp,1);
			c[i]=n+tmp;
		}
		tmp=0;
		cnt+=rsq.query(0,n+buf);
		REP(i,n-1) {
			tmp+=b[i];
			rsq.update(c[i+1],-1);
			cnt+=rsq.query(0,n+(buf-tmp));
		}
		if(cnt<sum/2+1) lb=mid;
		else ub=mid;
	}
	cout<<ub<<endl;
}



Measured memory_bytes: 8676
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << a * b - c * b - a * d + c * d << endl;
} 

Measured memory_bytes: 256
import Control.Monad

solve :: Int -> [Int] -> Int
solve all grams = count + (remains `div` minGram)
  where count = length grams
        sumOfGrams = sum grams
        remains = all - sumOfGrams
        minGram = minimum grams

main :: IO ()
main = do
  [count, all] <- map read . words <$> getLine
  grams <- replicateM count readLn
  print $ solve all grams

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};


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

	string s,t;
	cin>>s>>t;
	ll n,m;
	n = s.size();
	m = t.size();
	ll match = INT_MAX;
	loop(i,0,n-m+1){
		ll cnt = 0;
		loop(j,0,m){
			if(s[i+j]!=t[j])
				cnt++;
		}	
		match = min(match,cnt);
		// cout<<match<<endl;
	}

	cout<<match;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define ggr getchar();getchar();return 0
using namespace std;
int n,k,w[100010],d[100010];
bool func(int m){
	int cnt=0;
	rep(i,n){
		if(m-w[i]>=0)cnt+=(m-w[i])/d[i]+1;
		if(cnt>=k)return false;
	}
	return true;
}
signed main(){
	cin>>n>>k;
	rep(i,n)cin>>w[i]>>d[i];
	int mi=0,ma=LLONG_MAX;
	while(ma-mi>1){
		int md=mi+(ma-mi)/2;
		if(!func(md))ma=md;
		else mi=md;
	}
	if(func(mi-1)&&!func(mi))cout<<mi<<endl;
	else if(func(mi)&&!func(ma))cout<<ma<<endl;
	else cout<<ma+1<<endl;
	ggr;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <iomanip>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
double pi = 3.141592653589793;
ll mod = 1000000007;

int main() {
    int N;
    cin >> N;
    double t[N], v[N];
    for (int i = 0; i < N; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    int slim[N + 1], elim[N + 1];
    slim[0] = 0;
    elim[N] = 0;
    for (int i = 0; i < N; i++) {
        slim[i + 1] = min(slim[i] + t[i], v[i]);
        elim[N - i - 1] = min(elim[N - i] + t[N - 1 - i], v[N - 1 - i]);
    }
    double ans = 0;
    for (int i = 0; i < N; i++) {
        int s = min(slim[i], elim[i]);
        int e = min(slim[i + 1], elim[i + 1]);
        double m = (t[i] - abs(s - e)) * 0.5 + max(s, e);
        if (m <= v[i]) {
            ans += 0.5 * (s + m) * (m - s) + 0.5 * (m + e) * (m - e);
        } else {
            ans += v[i] * t[i] * 1.0 - 0.5 * (v[i] - s) * (v[i] - s) - 0.5 * (v[i] - e) * (v[i] - e);
        }
    }
    cout << setprecision(8) << ans << endl;
}



Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound, __gcd, count, find, next_permutation
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   // setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cassert> // assert
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  // abs, sin, cos, tan
#include <ctime> // clock

// __builtin_popcountll

using namespace std;
using Graph = vector<vector<int>>;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  vll a(n), b(n), c(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  ll ans = 0;
  sort(all(a)), sort(all(b)), sort(all(c));
  for(ll i = 0;i < n;i++)
  {
    auto A = lower_bound(all(a), b[i]) - a.begin();
    auto C = c.end() - lower_bound(all(c), b[i] + 1);
    ans += A * C;
    //cout << A << " " << C << endl;
  }
  fin(ans);
  return;
}

//前処理
int main()
{
  int ti = clock();
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  //cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  //printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
  return 0;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
    
		int ans = 0;
        if (a == b) {
          ans = c;
        } else if (b == c) {
          ans = a;
        } else {
          ans = b;
        }
    
		// 出力
		System.out.println(ans);
	}
}


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

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define printFix(n,i) cout << fixed << setprecision(i) << n << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
#define bitrep(i,n) for (int i = 0; i < (1<<(n));i++)
#define isOne(bit,i) (bit & (1 << i))
using ll = long long;
using pii = pair<int, int>;
using si = set<int>;

const ll modSeed = pow(10,9) + 7;
const int INF = 100'000'000;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
ll X,K,D,ans;

int main(){
  cin >>X >> K >> D;
  X = abs(X);
  ll st = X / D;
  st = min(K,st);
  X -= D * st;
  K -=st;
  if(K%2==0){
    print(X);
  }else{
    print(abs(X-D));
  }
}


Measured memory_bytes: 3596
<?php
while ($line = fgets(STDIN)) {
   $array[] = trim($line);
}
$count = 0;
for($i=0; $i<=$array[0]; $i++){
  for($z=0; $z<=$array[1]; $z++){
    for($v=0; $v<=$array[2]; $v++){
      $x = 500*$i+100*$z+50*$v;
      if($x == $array[3]){
        $count++;
      }
    }
  }
}
echo $count;    
?>

Measured memory_bytes: 16260
"use strict"

const Main= (inpuut)=>{
  const number =inpuut.trim().split(" ").join("")-0
  const heihoukon=Math.pow(number,1/2)
  Number.isInteger(heihoukon)? console.log("Yes"):console.log("No")
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <stdio.h>

int main(void){

  int h,w;
  scanf("%d %d", &h, &w);
  char a[h][w+1];
  for (int i = 0; i < h; i++) {
    scanf("%s", a[i]);
  }
  int row[h],column[w];
  int flag;
  for (int i = 0; i < h; i++) {
    flag = 0;
    for (int j = 0; j < w; j++) {
      if (a[i][j] != '.') {
        flag = 1;
        break;
      }
    }
    row[i] = flag;
  }
  for (int i = 0; i < w; i++) {
    flag = 0;
    for (int j = 0; j < h; j++) {
      if (a[j][i] != '.') {
        flag = 1;
        break;
      }
    }
    column[i] = flag;
  }
  for (int i = 0; i < h; i++) {
    if (row[i] == 1) {
      for (int j = 0; j < w; j++) {
        if (column[j] == 1) {
          printf("%c", a[i][j]);
        }
      }
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    	public static void main(String[] args) {
    	    Scanner sc = new Scanner(System.in);
    	    for(;;){
    	       
    	    
    	    int x = sc.nextInt();
    	    int y = sc.nextInt();
    	    
    	    if(x == 0 && y == 0)break;
    	    if(x<y){
    	        System.out.println(x+" "+y);
    	    }else{
    	        System.out.println(y+" "+x);
    	    }
    	        
    	    }
    	}
}


Measured memory_bytes: 34404
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = 0
for i in range(N):
    ans += B[A[i]-1]
    if i < N-1 and A[i+1] - A[i] == 1:
        ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n, k := nextInt(), nextInt()

	res := k
	for i := 1; i < n; i++ {
		res *= k - 1
	}

	fmt.Println(res)
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int k = sc.nextInt();
	int[] h = new int[n];
	for (int i=0; i<n; i++) h[i] = sc.nextInt();
	Arrays.sort(h);
	long count = 0;
	if (n >= k) {
	    for (int i=0; i<n-k; i++) {
		count += h[i];
	    }
	}
	System.out.print(count);
    }
}


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

#define F first
#define S second
#define MP make_pair
#define PB emplace_back

using namespace std;

const int N = 1e4+100, mod = 1e9+7;

long double dp[N];

int main () {
    cout << setprecision(12) << fixed;
    dp[0]=1;
    long long int n;
    cin >> n;
    for(int i = 0 ; i < n ; i++ ) {
        long double x;
        cin >> x;
        for(int j = i + 1 ; j >= 0 ; j--) {
            dp[j]=dp[j]*(1-x);
            if(j!=0)dp[j]+=dp[j-1]*x;
        }
    }
    long long int sag = (n+1)/2;
    long double ans = 0;
    for(int i = sag ; i<= n ; i++ ) ans+=dp[i];
    cout << ans;
}


Measured memory_bytes: 256
a = []
a = input().split()
N = int(a[0])
K = int(a[1])
p = []
p = input().split()
p = [int(i) for i in p]

#print('N=', N, 'K=', K)
#print('p', p)

p.sort()
#print('sortp', p)

total = 0

for i in range(K):
  total = total + p[i]

print(total)






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

using namespace std;

int main(void){
    int N,M;
    cin>>N>>M;
    vector<long long> H(N);
    for(int i=0;i<N;i++){
        cin>>H[i];
    }
    vector<int> A(M),B(M);
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
        A[i]--;
        B[i]--;
    }
    vector<int> count(N,0);
    vector<int> judge(N,0);
    for(int i=0;i<M;i++){
        if(H[A[i]]<H[B[i]]){
            count[B[i]]++;
            count[A[i]]--;
        }
        if(H[A[i]]>H[B[i]]) {
            count[A[i]]++;
            count[B[i]]--;
        }
        if(H[A[i]]==H[B[i]]){
            count[A[i]]--;
            count[B[i]]--;
        }
        if(A[i]>=0&&B[i]>=0){
            judge[A[i]]++;
            judge[B[i]]++;
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(judge[i]==count[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}



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

int main() {
    int n, k, a, ans;
    cin >> n >> k;
    rep(i, n) cin >> a;
    n--;
    k--;
    ans = (n + k - 1) / k;
    cout << ans << endl;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a, b, c, d;

inline bool check() {
    while (1) {
        c -= b;
        if (c <= 0)return true;
        a -= d;
        if (a <= 0)return false;
    }
}

int main() {
    cin >> a >> b >> c >> d;

    cout << (check() ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        int a, b;
        cin >> a >> b;

        if (a == b) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

//計算量はO(log max(a,b))
ll gcd(ll x,ll y){
  ll mindata,maxdata;
  mindata=min(x,y);
  maxdata=max(x,y);
  while(maxdata%mindata!=0){
    ll temp;
    temp=maxdata%mindata;
    maxdata=mindata;
    mindata=temp;
  }
  return mindata;
}

int main(){
  bool flag=false;
  int N;
  ll K,A[110000],ans,a;
  cin>>N>>K>>A[0];
  ans=A[0];
  for(int i=1;i<N;i++){
    cin>>A[i];
    ans=gcd(ans,A[i]);
  }
  //cout<<ans<<endl;
  for(int i=0;i<N;i++){
    if(A[i]>=K && (A[i]-K)%ans==0) flag=true;
  }

  if(flag) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 1024
/*
Author : Hocky Yudhiono
6/27/2020 7:29:00 PM

1. You can sort the query if offline!
2. Don't bring the dp remaining state when dfsing on DP on Tree.
3. Try to reverse (Think from the back) if you stuck.
4. Be careful when submitting Div. 2 D-F, dont waste it on stupid WAs.
5. Try to reduce a problem
*/

#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef vector<int> vi;
typedef pair<LL,LL> PLL;
typedef pair<LL,int> PLI;
typedef pair<int,int> PII;
typedef pair<int,int> pii;
typedef vector<vector<LL>> VVL;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define popf pop_front
#define pf push_front
#define popb pop_back
#define mp make_pair
#define pb push_back
#define remove erase
#define fi first
#define se second

// If the time limit is strict, try not to use long double

// Remember to undefine if the problem is interactive
#define endl '\n'
#define DEBUG(X) cout << ">>> DEBUG(" << __LINE__ << ") " << #X << " = " << (X) << endl

const double EPS = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const LL LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const LL MOD = 1000000007;
const int dx[8] = {0,0,1,-1,1,-1,1,-1};
const int dy[8] = {1,-1,0,0,1,-1,-1,1};
// Do dir^1 to get reverse direction
const char dch[4] = {'R','L','D','U'};
// const string ds[8] = {"E","W","S","N","SE","NW","SW","NE"};
const double PI = 3.141592653589793;

inline void open(string a){
    freopen((a+".in").c_str(),"r",stdin);
    freopen((a+".out").c_str(),"w",stdout);
}

inline void fasterios(){
    // Do not use if interactive
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // cout << fixed << setprecision(10);
}

LL n,ans;

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        LL kiri = i;
        LL kanan = n-(n%i);
        LL curans = ((kiri+kanan)*(((kanan-kiri)/i)+1))/2;
        // cout << "compute " << kiri << " " << kanan << endl;
        // cout << i << " " << curans << endl;
        ans += curans;
    }
    cout << ans << endl;
    return 0;
}


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


int main() {
  int N, count;
  
  cin>>N;
  
  vector<int> x(N);
  vector<int> y(N);
  vector<int> route(N);
  
  rep(i,N) route[i] = i + 1;
  
  rep(i, N){
    cin>>x[i];
    cin>>y[i];
  }
  
  double distance, sum;
  double a;
  do{
    distance = 0;
    rep(i, N-1){
      distance += sqrt((x[route[i]-1] - x[route[i+1]-1]) * (x[route[i]-1] - x[route[i+1]-1]) + (y[route[i]-1] - y[route[i+1]-1])* (y[route[i]-1] - y[route[i+1]-1]));
      //distance += sqrt(a);
    }
    sum += distance;
    count += 1;
  }
  while(next_permutation(route.begin(), route.end()));
  
  
  cout<<setprecision(12)<<sum/count<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c;
  cin>>c>>a>>b;
  ll n;cin>>n;
  ll now=c;
  for(int i=0;i<n;i++){
    string s;cin>>s;
    if(s[0]=='n')now=max(0LL,a+now);
    else if(s[0]=='k')now=0;
    else now=max(0LL,now+b);
  }
  cout<<now<<endl;
  return 0;
}


Measured memory_bytes: 3240
#include<iostream>
#include<string>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;

int main(){

    int N;
    int64_t n = 0;
    int i;
    
    cin >> N;

    int a[N];

    for(i = 0;i<N;i++){
        cin >> a[i];
    }

    for(i = 1;i<N;i++){
        
        if(a[i-1] > a[i]){
            n = n + (a[i-1] - a[i]);
            a[i] = a[i] + (a[i-1] - a[i]);

        }


    }


    cout << n << endl ;   
 
 }

Measured memory_bytes: 4400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner scan = new Scanner(System.in);
		
		int m = scan.nextInt();
		int n = scan.nextInt();

		int[][] a = new int[m][n];
		int [] b = new int[n];
		
		for(int i = 0; i < m; i++){
			for(int j = 0; j < n; j++){
				a[i][j] = scan.nextInt();
			}
		}
	
		for(int k = 0; k < n; k++){
			b[k] = scan.nextInt();
		}
		
		for(int s = 0; s < m; s++){
			int total = 0;
			for(int t = 0; t < n; t++){
				total = total + a[s][t] * b[t];
			}
			System.out.println(total);
		}
	}
}

Measured memory_bytes: 41060
a = raw_input().split()
ans = {}
for i in a:
 if i not in ans:
   ans[i] = 1
 else:
   ans[i] += 1
tt,gg,q,w=0,0,"",""
for i in ans:
   if ans[i] > tt:
     tt = ans[i]
     w = i
   if len(i) > gg:
     gg = len(i)
     q = i
print w,q

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


int main(){
//A
string s;
cin>>s;
if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> x(n);
  for(int i=0; i<n; i++) cin >> x[i];
  sort(x.begin(), x.end());
  
  int a = x[0];
  int b = x[n-1];
  int ans = 1000000000;
  for(int i=a; i<=b; i++) {
    int sum = 0;
    for(int j=0; j<n; j++) sum += (i-x[j])*(i-x[j]);
    ans = min(ans, sum);
  }
  
  cout << ans << endl;
  return 0;
}

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

int main()
{
	long long ret = 0;
	int n;
	cin >> n;
	int max = 0;
	for (int i = 0; i < n; ++i) {
		int t;
		cin >> t;
		if (max < t) {
			max = t;
		}
		ret += t;
	}

	ret -= max / 2;

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
// Aizu Vol-1 0103: Baseball Simulation
// 2017.8.3

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

int main()
{
	int i, n;
	int p1, p2, p3, out, cnt;

	gets(buf), n = atoi(buf);
	for (i = 0; i < n; i++) {
		p1 = p2 = p3 = out = cnt = 0;
		while (1) {
			gets(p = buf);
			while (isspace(*p)) p++;
			if (*++p == 'I') {		// HIT
				if (p3) cnt++;
				p3 = p2, p2 = p1, p1 = 1;
			} else if (*p == 'U') {	// OUT
				if (++out == 3) break;
			} else {				// HOMERUN
				cnt += p1 + p2 + p3 + 1;
				p1 = p2 = p3 = 0;
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 524
#include<iostream>
int main(){
    int w, h, x, y, r;
    std::cin >> w >> h >> x >> y >> r;
    if(w < x + r){
        std::cout << "No" << std::endl;
    }
    else if(0 > x - r){
        std::cout << "No" << std::endl;
    }
    else if(h < y + r){
        std::cout << "No" << std::endl;
    }
    else if(0 > y - r){
        std::cout << "No" << std::endl;
    }
    else{
        std::cout << "Yes" << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using pi = pair<string, int>;

int main() {
  int n; cin >> n;
  vector<pi> pa(n);
  for(int i=0; i < n; i++){
    string s;
    int p;
    cin >> s >> p;
    pa[i] = make_pair(s, -p);
  }
  
  vector<pi> temp = pa;
  sort(pa.begin(), pa.end());
  for(int i = 0; i < n; i++){
    string s; int sf;
    tie(s, sf) = pa[i];
    for(int j =0; j < n; j++) {
      if(pa[i] == temp[j]) cout << j+1 << endl;
    }
  }
  
  return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

ll r, g, b, n;

ll ans;

int main(void) {
  // Here your code !
  scanf("%lld %lld %lld %lld", &r, &g, &b, &n);

  ans = 0;

  for (ll i = 0; i <= n; ++i) {
    for (ll j = 0; j <= n; ++j) {
      ll cur = r * i + g * j;
      if (cur > n) continue;
      if ((n - cur) % b == 0) {
        ans += 1;
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main ()
{
  int n, k, cont=1, cont1=1, total;
  scanf("%d%d", &n,&k);

  for(int i=0 ; i<n ; i++)
  {
    cont*= 2;
    cont1+= k;

    if (cont<=cont1){
      cont1=cont;
      total=cont;
    }else{
      total=cont1;
      cont=cont1;
    }
  }
  printf("%d\n", total);

  return 0;
}


Measured memory_bytes: 128
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int k,q;
	cin>>k>>q;
	vi v(k);
	rep(i,k){
		cin>>v[i];
	}	
	while(q--){
		ll n,x,m;
		ll sum,sum2;
		sum = sum2 = 0;
		cin>>n>>x>>m;
		vi d(k);
		rep(i,k){
			d[i] = v[i] % m;
		}
		ll q = ((n-1)/k);
		ll r = (n-1)%k;
		ll count = 0;
		rep(i,k){
			sum += d[i];
			if(d[i] == 0)count++;
		}
		count *= q;
		rep(i,r){
			if(d[i] == 0)count++;
			/*if(i != r-1)*/sum2 += d[i];
		}
		// sum2 -= v[r-1];
		// cout<<q<<" "<<sum<<"\n";
		ll f = x;
		f += q*sum;
		// cout<<count<<"\n";
		// cout<<f<<" ";
		f += sum2;
		// cout<<f<<" ";
		ll ans2 = f/m - x/m;
		ll ans = q*k + r - ans2 - count;
		cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
typedef long double ld;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int n;
ld x[maxn], y[maxn], d[maxn];
inline ld calc(int a,int b) {
	return std::max<ld>(0, sqrtl((x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b])) - d[a] - d[b]);
}
ld dis[maxn];
int vis[maxn];
inline void dij() {
	rep(i, 2, n) dis[i] = 1. / 0;
	for(int i = 1;i <= n;++i) {
		int id = -1; ld min = 1. / 0;
		for(int j = 1;j <= n;++j) if(!vis[j] && dis[j] < min)
			min = dis[j], id = j;
		vis[id] = 1;
		for(int j = 1;j <= n;++j) {
			dis[j] = std::min(dis[j], dis[id] + calc(id, j));
		}
	}
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> x[1] >> y[1];
	cin >> x[2] >> y[2];
	cin >> n, n += 2;
	rep(i, 3, n) {
		cin >> x[i] >> y[i] >> d[i];
	}
	dij();
	printf("%.100Lf\n", dis[2]);
}


Measured memory_bytes: 6400
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "]"; return os; }


// import here

int main(){
    LL n, c;
    cin >> n >> c;
    vector<pair<LL,LL>> sushi(n);
    for(LL i = 0; i < n; ++i){
        cin >> sushi[i].first >> sushi[i].second;
    }
    vector<LL> left_dist(n);
    for(LL i = 0; i < n; ++i){
        left_dist[i] = c - sushi[n-1-i].first;
    }
    vector<LL> left_total(n), right_total(n);
    LL left_sum = 0, right_sum = 0;
    for(LL i = 0; i < n; ++i){
        left_sum += sushi[n-1-i].second;
        left_total[i] = left_sum;
        right_sum += sushi[i].second;
        right_total[i] = right_sum;
    }
    LL ans = 0;
    vector<LL> left_best(n), right_best(n);
    LL best = 0;
    for(LL i = 0; i < n; ++i){
        left_best[i] = best;
        best = max(best, left_total[i] - left_dist[i] * 2);
    }
    best = 0;
    for(LL i = 0; i < n; ++i){
        right_best[i] = best;
        best = max(best, right_total[i] - sushi[i].first * 2);
    }
    for(LL i = 0; i < n; ++i){
        ans = max(ans, left_total[i] - left_dist[i] + right_best[n-1-i]);
        ans = max(ans, right_total[i] - sushi[i].first + left_best[n-1-i]);
    }
    cout << ans << endl;
    return 0;
}



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

int count2(ll a) {
  int cnt = 0;
  while (a % 2 == 0) {
    cnt++;
    a /= 2;
  }
  return cnt;
}

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

  vector<ll> a(N);
  rep(i, N) cin >> a.at(i);

  int num2 = count2(a.at(0));
  if (num2 == 0) {
    cout << "0" << endl;
    return 0;
  }

  rep(i, N) {
    int c = count2(a.at(i));
    if (c != num2) {
      cout << "0" << endl;
      return 0;
    }
  }

  ll lcm = pow(2, num2);
  rep(i, N) {
    int y = __gcd(lcm, a.at(i));
    lcm = lcm * a.at(i) / y;
  }
  cout << (M + lcm/2) / lcm << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	for(int i = 0; i < n1; i++) {L[i] = A[left + i];}
	for(int i = 0; i < n2; i++) {R[i] = A[mid + i];}
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for(int k = left; k < right; k++){
		cnt++;
		if(L[i] <= R[j]){
			A[k] = L[i++];
		}
		else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(int A[], int n, int left, int right){
	if(left + 1 < right){
		int mid = (left + right) / 2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

int main()
{
	int A[MAX], n, i;
	cnt = 0;
	
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d", &A[i]);
	}
	
	mergeSort(A, n, 0, n);
	
	for(i = 0; i < n; i++){
		if(i){
			printf(" ");
		}
		printf("%d", A[i]);
	}
	printf("\n");
	
	printf("%d\n", cnt);
	
	return 0;
}



Measured memory_bytes: 5636
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		long n = long.Parse(input[0]);
		long m = long.Parse(input[1]);
    long q = long.Parse(input[2]);
    long answer = 0;
    long[,] trains = new long[n+2,n+2];
    for(long i = 0; i < m; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る
      trains[nums[0],nums[1]]++;
    }

    for(int i = 0; i < n+2; i++)
    {
      for(int j = 1; j < n+2; j++)
      {
        trains[i,j] += trains[i,j-1];
      }
    }
    
    for(int i = 1; i < n+2; i++)
    {
      for(int j = 0; j < n+2; j++)
      {
        trains[i,j] += trains[i-1,j];
      }
    }
    
    for(long i = 0; i < q; i++)
    {
      long[] numsa = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る
      answer = trains[n+1,numsa[1]] - trains[numsa[0]-1,numsa[1]];
      Console.WriteLine(answer);
    }

	}
}

Measured memory_bytes: 19592
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int, int>
#define pll pair<long long,long long>
#define vl vector<long long>
#define vll vector<pll>
#define vi vector<int>
#define vii vector<pii>
#define sws ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define tcase int tt; cin>>tt; while(tt--)
#define tcase2 int tt; cin>>tt; for(int qq=1;qq<=tt;qq++)
using namespace std;
typedef long long int ll;
typedef  unsigned long long int ull;
typedef long double ld;
const int MAXN = 1000002;
const int MOD = 998244353;
const int MOD2 = 1000000007; 
const int INF = 1e8;
const ld EPS = 1e-7;
// Extra
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define forne(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define trav(a, x) for(auto& a : x)
#define fill(x,y) memset(x,y,sizeof(x))
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
ll fastpow(ll n,ll x)
{   
	if(x==0)
	return 1 ;
	if(x%2==0)
	return (fastpow(n*n%MOD2,x/2)%MOD2) ;
	return (x*fastpow(n*n%MOD2,(x-1)/2)%MOD2)%MOD2 ; 
}

int main(int argc, char** argv)
{   sws ;

   // tcase
    {
    	ll n ;
    	cin>>n ;
    	ll a[n] ;
    	forn(i,n)
    	cin>>a[i] ;
    	ll dp[n];
    	forn(i,n)
    	dp[i]=10000000000007 ;
    	dp[0]=0 ;
    	dp[1]=abs(a[1]-a[0]) ;
    	for(int i=2; i<n; i++)
    	{
    		dp[i]=min(dp[i],dp[i-1]+abs(a[i]-a[i-1])) ;
    		dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2])) ;
		}
		cout<<dp[n-1] ;
   
}

return 0 ;
}

Measured memory_bytes: 5104
class Dice(object):
    def __init__(self, nums):
        self.top, self.front, self.right, self.left, self.back, self.bottom = nums

    def roll(self, directions):
        if directions == 'E':
            self.top, self.right, self.left, self.bottom = self.left, self.top, self.bottom, self.right
            return

        if directions == 'N':
            self.top, self.front, self.back, self.bottom = self.front, self.bottom, self.top, self.back
            return

        if directions == 'S':
            self.top, self.front, self.back, self.bottom = self.back, self.top, self.bottom, self.front
            return

        if directions == 'W':
            self.top, self.right, self.left, self.bottom = self.right, self.bottom, self.top, self.left
            return

        self.roll(directions[0])
        self.roll(directions[1:])

if __name__ == '__main__':
    nums = [int(i) for i in input().split()]
    d = Dice(nums)
    q = int(input())
    for i in range(q):
        top, front = [int(x) for x in input().split()]

        if(front == d.top):
            d.roll('S')
        elif(front == d.right):
            d.roll('WS')
        elif(front == d.left):
            d.roll('ES')
        elif(front == d.back):
            d.roll('SS')
        elif(front == d.bottom):
            d.roll('N')

        if(top == d.right):
            d.roll('W')
        elif(top == d.left):
            d.roll('E')
        elif(top == d.bottom):
            d.roll('WW')

        print(d.right)

Measured memory_bytes: 6780
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

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

func main() {
	defer write.Flush()

	var n int
	fmt.Fscan(read, &n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(read, &a[i])
	}

	ar := make([]int, n)
	ar[n-1] = a[n-1]
	for i := n - 2; i >= 0; i-- {
		ar[i] = gcd(ar[i+1], a[i])
	}

	ans := ar[1]
	var al int
	for i := 0; i < n-2; i++ {
		if i == 0 {
			al = a[0]
		} else {
			al = gcd(al, a[i])
		}
		v := gcd(al, ar[i+2])
		if ans < v {
			ans = v
		}
	}
	al = gcd(al, a[n-2])
	if ans < al {
		ans = al
	}
	fmt.Fprintln(write, ans)
}


Measured memory_bytes: 3840
// ABC 161

//inputに入力データ全体が入る
function Main(input) {
  // BCA
  const A = parseInt(input.split(" ")[2],10);
  const B = parseInt(input.split(" ")[0],10);
  const C = parseInt(input.split(" ")[1],10);

  console.log(A + " " + B + " " + C)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
l=[]
for i in range(3):
    l += list(map(int,input().split()))

for i in [1,2,3,4]:
    cnt=0
    for j in l:
        if i==j:
            cnt+=1
    if cnt==0 or cnt>2:
        print('NO')
        break
else:
    print('YES')

Measured memory_bytes: 9172
#include <iostream>
#include <vector>
#include <numeric>
#include <functional>
#include <algorithm>

using namespace std;

long long maxflow(vector<vector<int>> E_, vector<vector<long long>> F_, int s, int t)
{
    int n = (int)E_.size();

    vector<vector<int>> E(n), R(n);
    vector<vector<long long>> F(n);
    for (int i=0; i<n; i++)
    for (int j=0; j<(int)E_[i].size(); j++)
    {
        int v = E_[i][j];
        R[i].push_back(int(E[v].size()));
        R[v].push_back(int(E[i].size()));
        E[i].push_back(v);
        E[v].push_back(i);
        F[i].push_back(F_[i][j]);
        F[v].push_back(0);
    }
    vector<bool> U(n);
    function<long long (int, long long)> dfs = [&](int p, long long f)
    {
        if (p==t)
            return f;
        U[p] = true;
        for (int i=0; i<(int)E[p].size(); i++)
        if (!U[E[p][i]] && F[p][i]>0)
        {
            long long t = dfs(E[p][i], min(f, F[p][i]));
            if (t>0)
            {
                F[p][i] -= t;
                F[E[p][i]][R[p][i]] += t;
                return t;
            }
        }
        return 0LL;
    };
    
    long long flow = 0;
    while (true)
    {
        for (int i=0; i<n; i++)
            U[i] = false;
        long long f = dfs(s, 1000000000000000LL);
        if (f==0)
            break;
        flow += f;
    }

    return flow;
}

int main()
{
    int N;
    cin>>N;
    vector<long long> a(N);
    for (long long &t: a)
        cin>>t;

    long long oo = 1000000000000LL;
    vector<vector<int>> E(N+2);
    vector<vector<long long>> C(N+2);
    for (int i=0; i<N; i++)
        if (a[i] > 0)
            E[N].push_back(i),
            C[N].push_back(a[i]);
        else
            E[i].push_back(N+1),
            C[i].push_back(-a[i]);
    for (int i=1; i<=N; i++)
        for (int j=i+i; j<=N; j+=i)
            E[j-1].push_back(i-1),
            C[j-1].push_back(oo);

    long long s = 0;
    for (long long t: a)
        if (t>0)
            s += t;
    cout<<s-maxflow(E, C, N, N+1)<<endl;
}


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

int main() {
	vector<char> C(6);
	for (int i = 0;i < 6;++i) {
		cin >> C[i];
	}
	for (int i = 0;i < 3;++i) {
		if (C[i] != C[5 - i]) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	string S,T;
	READ(S);
	READ(T);
	map<char,set<ll>> CP;
	ll N=S.length();
	ll M=T.length();
	FORI(i,0,N)
	{
		CP[S[i]].insert(i+1);
	}
	bool flag=true;
	FORI(i,0,M)
	{
		if(sz(CP[T[i]])==0)
		{
			flag=false;
		}
	}
	if(flag)
	{
		ll prev=0;
		ll rep=0;
		FORI(i,0,M)
		{
			ll mn=inf;
			auto it=CP[T[i]].end();
			it--;
			if(rep*N+*it>prev)
			{
				prev=*(CP[T[i]].upper_bound(prev-rep*N))+rep*N;
			}
			else
			{
				rep++;
				prev=*(CP[T[i]].upper_bound(prev-rep*N))+rep*N;
			}
		}
		cout<<prev<<endl;
	}
	else
	{
		cout<<-1<<endl;
	}
	


	return 0;
}

Measured memory_bytes: 5200
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,ans=0;
  cin >> n;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=1;i<n;i++){
    if(a[i-1]>a[i]){
      ans += a[i-1]-a[i];
      a[i] = a[i-1];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4776
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main(){
	string s, t;
	cin >> s >> t;
	int count(0);
	rep(i, 3) {
		if (s[i] == t[i]) {
			++count;
		}
	}
	cout << count;
	return 0;
	return 0;
}

Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]
X = [int(x) for x in input().split()]

X.sort()
gap = [X[i + 1] - X[i] for i in range(M - 1)]
gap.sort()

# gapのエントリのうち大きい方からN - 1個は使わない
# 使うのは (M - 1) - (N - 1) = M - N個
if M <= N:
    ans = 0
else:
    ans = sum(gap[0 : M - N])

print(ans)


Measured memory_bytes: 13840
#include <iostream>

using namespace std;

int main (void)
{
    string a, b, c;

    cin >> a >> b >> c;
    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256