akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main () {
    int r;
    int D;
    int x;
    int i = 2001;

    scanf("%d", &r);
    scanf("%d", &D);
    scanf("%d", &x);
    for (; i <= 2010; i++) {
        x = r * x - D; // iの時の値がxに入ってる
        printf("%d\n", x);
    }

    return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
def main():
    _, A, B, C, D = map(int, input().split())
    S = input().rstrip("\r\n")
    ans = "Yes"
    for i in range(A-1,C-1):
        if S[i] == "#" and S[i+1] == "#":
            ans = "No"
            break
    for i in range(B-1,D-1):
        if S[i] == "#" and S[i+1] == "#":
            ans = "No"
            break
    if C < D or ans == "No":
        print(ans)
    else:
        ans = "No"
        for i in range(B-1, D):
            if S[i-1] == "." and S[i] == "." and S[i+1] == ".":
                ans = "Yes"
        print(ans)
if __name__ == "__main__":
    main()

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

int main () {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    if (d - a >= 0) {
      ans+= a;
      d -= a;
    }
    else ans+= d;
    if (d - b >= 0) {
      d -= b;
      cout << ans - d << endl;
    }
    else cout << ans << endl;
    
}

Measured memory_bytes: 3592
N = int(input())
inp = [input() for i in range(N)]

import numpy as np

s_list = []
p_list = []
for i in inp:
    s_list.append(i.split()[0])
    p_list.append(int(i.split()[1]))

sp_list = []
for i in range(N):
    sp_list.append([s_list[i],p_list[i]])

# 市を辞書順
sort_sp_list = sorted(sp_list)

# 市の種類
s_type = sorted(list(set(s_list)))
tmp_list = []
for type in s_type:
    tmp_list.append(sorted([s for s in sort_sp_list if s[0] == type],reverse=True))

rank_list = []
for tmp in tmp_list:
    for l in tmp:
        rank_list.append(l)

for rank in rank_list:
    print(sp_list.index(rank)+1)


Measured memory_bytes: 12504
//2018年  3月 22日 木曜日 16:13:27 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll H, W;

ll pre() {
	ll res = inf;
	rep(i, 1, W) {
		ll left = i * H;
		ll w = W - i;
		ll cen = (w + 1) / 2 * H;
		ll right = w / 2 * H;
		MIN(res, max(right, max(left, cen)) - min(right, min(left, cen)));
		ll up = (H + 1) / 2 * w;
		ll down = H / 2 * w;
		MIN(res, max(left, max(up, down)) - min(left, min(up, down)));
	}
	return res;
}

void solve() {
	cin >> H >> W;
	ll res = inf;
	MIN(res, pre());
	swap(H, W);
	MIN(res, pre());
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 998244353;
vector<ll> inv, FactorialInv, Factorial;
ll beki(ll a, ll b){
    ll ret = 1 % mod;
    a %= mod;
    while(b) {
        if(b & 1LL) ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}
void init_combination(ll MAX){
    Factorial.resize(MAX + 1);
    FactorialInv.resize(MAX + 1);
    inv.resize(MAX + 1);
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    if(b < 0) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}
ll ANS;
ll N, M, K;

void input() {
    cin >> N >> M >> K;
}

void solve() {
    ANS = 0;
    init_combination(1e6);
    for(ll k = 0; k <= K; k++) {
        ll tmp = M;
        tmp *= combination(N - 1, k);
        tmp %= mod;
        tmp *= beki(M - 1, N - 1 - k);
        tmp %= mod;
        ANS += tmp;
        ANS %= mod;
    }
    cout << ANS << endl;
}

int main() {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 26728
INF = 10 ** 18
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
dp = [INF for i in range(H + 1)]

dp[0] = 0

for i in range(N):
    for j in range(H):
        if j - ab[i][0] + 1 >= 0:
            dp[j + 1] = min(dp[j + 1], dp[j - ab[i][0] + 1] + ab[i][1])
        else:
            dp[j + 1] = min(dp[j + 1], dp[0] + ab[i][1])

print(dp[-1])

Measured memory_bytes: 43244
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		int H,W;
		Scanner sc = new Scanner(System.in);
		while(true){
			H = sc.nextInt();
			W = sc.nextInt();
			if(H == 0 || W == 0){
				break;
			}
			char [][] array = new char[H][W];
			sc.nextLine();
			for(int i = 0; i < H; i++){
				String line = sc.nextLine();
				for(int j = 0; j < W; j++){
					array[i][j] = line.charAt(j);
				}
			}
			int i = 0;
			int j = 0;
			boolean flag = true;
			boolean visit[][] = new boolean[H][W];
			here:while(flag){
				if(visit[i][j]){
					System.out.println("LOOP");
					break here;
				}
				visit[i][j] = true;
				switch(array[i][j]){
				case '>':
					j++;
					break;
				case '<':
					j--;
					break;
				case '^':
					i--;
					break;
				case 'v':
					i++;
					break;
				case '.':
					System.out.println(j+" "+i);
					break here;
				}
			}
		}
	}
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		for (int i = 1; i < 10; i++) {
			int tmp = i * 111;
			
			if (tmp >= n) {
				pr.println(tmp);
				break;
			}
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;


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

	string s;
	cin >> s;
	if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) dier("Bad");
	die("Good");

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}

int modinv(int a){ return power(a,mod-2);}

void solve()
{
	string s;
	cin>>s;
	vector<int> v(2019,0);
	v[0]=1;
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		int x=s[i]-'0';
		vector<int> nv(2019,0);
		for(int j=0;j<2019;j++)
		{
			if(v[j]==0)	continue;
			nv[(j*10+x)%2019]+=v[j];
		}
		ans+=nv[0];
		for(int j=0;j<2019;j++)
		{
			v[j]=nv[j];
			
			//if(v[j])
			//	cout<<j<<" "<<v[j]<<endl;
		}
		v[0]++;
		//cout<<endl;
	}
	cout<<ans<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	while(t--)	solve();
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int n, m;
	cin >> n >> m;
	int a = n - m;
	int b = m;
	int d = a * 100 + b * 1900;
	int ans;
	if (b == 1) {
		ans = 2 * d;
	}
	if (b == 2) {
		ans = 4 * d;
	}
	if (b == 3) {
		ans = 8 * d;
	}
	if (b == 4) {
		ans = 16 * d;
	}
	if (b == 5) {
		ans = 32 * d;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int cnt[100];
int main()
{
    int n,i,j,k,x,y,ans,curr,m;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++)
    {
        int byk;
        scanf("%d",&byk);
        for(j=1;j<=byk;j++)
        {
            scanf("%d",&curr);
            cnt[curr]++;
        }
    }
    ans = 0;
    for(i=1;i<=m;i++)
    {
        if(cnt[i] == n)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
import sys


n, m = map(int, input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]

for i in range(n - m + 1):
    for j in range(n - m + 1):
        valid = True
        for k in range(m):
            for l in range(m):
                if A[i + k][j + l] != B[k][l]:
                    valid = False
                    break
            if valid is False:
                break
        if valid:
            print("Yes")
            sys.exit()
print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
ll MOD;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
vector<vector<int>> G;
vector<ll> dp,dp2;
ll dfs1(int i,int p){
    ll res=1LL;
    for(auto e:G[i]){
        if(e==p)continue;
        res*=dfs1(e,i)+1LL;
        res%=MOD;
    }
    return dp[i]=res;
}
void dfs2(int i,ll s,int p){
    dp2[i]=dp[i]*s%MOD;
    vector<ll> v;
    for(auto e:G[i]){
        if(e==p)continue;
        v.push_back(dp[e]+1LL);
    }
    for(int i=v.size()-2;i>=0;i--){
        v[i]*=v[i+1];
        v[i]%=MOD;
    }
    ll k=s;
    int id=0;
    v.push_back(1);
    for(auto e:G[i]){
        if(e==p)continue;
        dfs2(e,(k*v[id+1]+1LL)%MOD,i);
        k*=(dp[e]+1LL);
        k%=MOD;
        id++;
    }
}
int main(){
    int n;cin>>n>>MOD;
    G.resize(n);
    dp.resize(n);
    dp2.resize(n);
    for(int i=0;i<n-1;i++){
        int u,v;cin>>u>>v;--u;--v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs1(0,-1);
    dfs2(0,1,-1);
    for(int i=0;i<n;i++){
        cout<<dp2[i]<<endl;
    }
}   


Measured memory_bytes: 19584
N,K = map(int,input().split())
A = list(map(int,input().split()))

Bit = 0
while(True):
    if((1<<(Bit+1))>K):  
        break
    else:
        Bit += 1
X = 0
for b in range(Bit,-1,-1):
    X_ = X+(1<<b)
    if(X_ > K):
        continue
    Sum = sum([X^a for a in A])
    Sum_ = sum([X_^a for a in A])
    if(Sum_ > Sum):
        X = X_
print(sum([X^a for a in A]))


Measured memory_bytes: 14208
#include<stdio.h>

int main(){
        int a, b, c; /*問題の色*/
        int count; /*種類の個数を数えるカウンタ*/
        char line[128]; /*キーボードから読みだした行*/

        /*入力*/
        fgets(line, 128, stdin);
        sscanf(line, "%d %d %d", &a, &b, &c);

        /*個数を数える*/
        count = 1;
        if(b != a) ++count;
        if((c != b) && (c != a)) ++count;

        /*出力*/
        printf("%d\n", count);

        return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		sc.close();
			
		System.out.println((a*c)<=b?c:(b/a));
	}

}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
long long f(long long x, long long y) {
	if (x == y) return x;
	long long a = min(x, y);
	long long b = max(x, y);
	long long n = (b-1) / a;
	return 2*n*a + f(a, b-n*a);
}
int main() {
	long long N, X;
	cin >> N >> X;
	cout << N + f(N-X, X) << endl;
}


Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.trim().toInt()
    val dice = List(n){
        val (d1, d2) = readLine()!!.trim().split(' ').map(String::toInt)
        d1 == d2
    }
    println(if ((2 until n).any{i -> dice[i - 2] && dice[i - 1] && dice[i]}) "Yes" else "No")
}

Measured memory_bytes: 38368
A, B, C = map(int, input().split()) # 横に2個

co = 0
checked = []
if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
    print(0)
else:
    while True:
        checked.append([A, B, C])
        a = (B + C)//2
        b = (C + A)//2
        c = (A + B)//2
        co += 1
        if a % 2 != 0 or b % 2 != 0 or c % 2 != 0:
            break
        if [a, b, c] in checked:
            co = -1
            break
        A = a
        B = b
        C = c

    print(co)

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

typedef long long ll;

#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()

ll stoneGame(vector<ll>& piles) {
	//cout << piles[0] << " ";
    ll n = piles.size();
    vector <vector<ll> > dp(n, vector <ll>(n,0));
    for (int i = 0;i < n;i++)
        dp[i][i] = piles[i];
    for (int d = 1; d < n; d++)
    {
        for (int i = 0;i < n-d;i++)
        {
            dp[i][i+d] = max(piles[i]-dp[i+1][i+d], piles[i+d] - dp[i][i+d-1]);
        }
    }
    return dp[0][n-1];
}


int main()
{
    int n;
    cin >> n;
    std::vector<ll> v(n);
    for (int i = 0; i < n; ++i)
    {
    	cin >> v[i];
    }
    cout << stoneGame(v) << "\n";

	return 0;
}


Measured memory_bytes: 70656
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let n = read::<usize>();
    let v = read_vec::<usize>();
    let mut vs: Vec<usize> = v.iter().cloned().collect();
    vs.sort();
    let m1 = vs[n/2-1];
    let m2 = vs[n/2];
    for x in v {
        if x <= m1 {
            println!("{}",m2);
        } else {
            println!("{}",m1);
        }
    }
}


Measured memory_bytes: 10928
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define mx *max_element
#define mi *min_element
#define fn for(long long int i =0 ;i <n;i++)
#define fn1 for(long long int i =1;i<=n;i++)
#define fm for(long long int j =0 ;j <m;j++)
#define fm1 for(long long int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6;
ll ar[N];
ll tree[2*N];
ll dp[N];
int main(){
	Fast;
	ll n , k ;
	cin >> n >> k ;
	fn{
	    cin >> ar[i];
	}
	memset(dp,N,sizeof(dp));
	dp[0]=0;
	fn{
	    for(int j =i+1;j<i+k+1;j++){
	        if(j<n){
	            dp[j]=min(dp[j],dp[i]+abs(ar[j]-ar[i]));
	        }
	    }
	}
	cout << dp[n-1];
	return 0;
}

Measured memory_bytes: 10496
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>

int main(void){
	double a, b, c, s, l, h;
	scanf("%lf%lf%lf", &a, &b, &c);
	c=c*M_PI/180;
	h=b*sin(c);
	l=a+b+sqrt(a*a+b*b-2*a*b*cos(c));
	s=a*h/2;
	printf("%f\n%f\n%f\n", s, l, h);
	return(0);
}


Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 200010;

template<int_fast64_t MOD> struct modint{
    using i64=int_fast64_t;
    i64 a;
    modint(const i64 a_=0): a(a_){
        if(a>MOD) a%=MOD;
        else if(a<0) (a%=MOD)+=MOD;
    }
    modint inv(){
        i64 t=1, n=MOD-2, x=a;
        while(n){
            if(n&1) (t*=x)%=MOD;
            (x*=x)%=MOD;
            n>>=1;
        }
        modint ret(t);
        return ret;
    }
    bool operator==(const modint x) const{return a==x.a;}
    bool operator!=(const modint x) const{return a!=x.a;}
    modint operator+(const modint x) const{
        return modint(*this)+=x;
    }
    modint operator-(const modint x) const{
        return modint(*this)-=x;
    }
    modint operator*(const modint x) const{
        return modint(*this)*=x;
    }
    modint operator/(const modint x) const{
        return modint(*this)/=x;
    }
    modint operator^(const modint x) const{
        return modint(*this)^=x;
    }
    modint &operator+=(const modint &x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint &operator-=(const modint &x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint &operator*=(const modint &x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint &operator/=(modint x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
    modint &operator^=(lint n){
        i64 ret=1;
        while(n){
            if(n&1) (ret*=a)%=MOD;
            (a*=a)%=MOD;
            n>>=1;
        }
        a=ret;
        return *this;
    }
    modint operator-() const{
        return modint(0)-*this;
    }
    modint &operator++(){
        return *this+=1;
    }
    modint &operator--(){
        return *this-=1;
    }
};

using mint=modint<998244353>;

map<string, mint> dp;

void str_and(string &s, string t){
        rep(i, (int)s.size()){
                if(s[i]=='1' && t[i]=='0') s[i]='0';
        }
}

mint dfs(string s){
        if(s.empty()) return 1;
        if(dp.find(s)!=dp.end()) return dp[s];

        mint ret=dfs(s.substr(1)) * (1+s[0]-'0');
        int n=s.size();
        For(len, 2, n+1){
               for(int p=1; p<=len/2; ++p)if(len%p==0){
                       string t=s.substr(0, p);
                       for(int j=p; j<len; j+=p) str_and(t, s.substr(j, p));
                       ret+=dfs(t) * dfs(s.substr(len));
               }
        }
        return dp[s]=ret;
}

int main(){
        string s;
        cin>>s;
        printf("%lld\n", dfs(s).a);
}

Measured memory_bytes: 7424
n = int(input())
a_list = [int(num) for num in list(input().split(" "))]

a_list.sort(reverse = True)

total_dif = 0
for a in range(0,n,2):
    if a+1 ==n:
        total_dif += a_list[a]
    else:
        total_dif += a_list[a]-a_list[a+1]
print(total_dif)


Measured memory_bytes: 2940
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n,i,j,k;
        cin>>n;
        ll a[n],b[n-1];
        for(i=0;i<n-1;i++)cin>>b[i];
        a[0]=b[0],a[n-1]=b[n-2];
        for(i=1;i<n-1;i++){
            a[i]=min(b[i],b[i-1]);
        }   

        ll sum=0;
        for(i=0;i<n;i++)sum+=a[i];
        cout<<sum;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INFV 10000000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int to,rev;
	ll cap;
	edge(){}
	edge(int tt,ll cc,int rr){
		to=tt;
		cap=cc;
		rev=rr;
	}
};

class dinic{
public:
	const ll INF=10000000000LL;
	vector<edge> G[105];
	int level[105];
	int iter[105];
	void add_edge(int from,int to,ll cap){
		G[from].push_back(edge(to,cap,G[to].size()));
		G[to].push_back(edge(from,0,G[from].size()-1));
	}

	void bfs(int s){
		memset(level,-1,sizeof(level));
		queue<int> que;
		level[s]=0;
		que.push(s);
		while(que.size()){
			int v=que.front();
			que.pop();
			for(int i=0;i<G[v].size();i++){
				edge &e=G[v][i];
				if(e.cap>0 && level[e.to]<0){
					level[e.to]=level[v]+1;
					que.push(e.to);
				}
			}
		}
	}

	ll dfs(int v,int t,ll f){
		if(v==t)return f;
		for(int &i=iter[v];i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[v]<level[e.to]){
				ll d=dfs(e.to,t,min(e.cap,f));
				if(d>0){
					e.cap-=d;
					G[e.to][e.rev].cap+=d;
					return d;
				}
			}
		}
		return 0;
	}

	ll max_flow(int s,int t){
		ll flow=0;
		while(1){
			bfs(s);
			if(level[t]<0)return flow;
			memset(iter,0,sizeof(iter));
			ll f;
			while((f=dfs(s,t,INF))>0){
				flow+=f;
			}
		}
	}
};

dinic di;

int n;
int a[101];
int main(void){
	scanf("%d",&n);
	int s=n,t=n+1;
	ll sum=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]>0){
			sum+=a[i];
			di.add_edge(i,t,a[i]);
			di.add_edge(s,i,0);
		}
		if(a[i]==0){
			di.add_edge(s,i,0);
			di.add_edge(i,t,0);
		}
		if(a[i]<0){
			di.add_edge(s,i,-a[i]);
			di.add_edge(i,t,0);
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=i*2;j<=n;j+=i){
			di.add_edge(i-1,j-1,INFV);
		}
	}
	printf("%lld\n",sum-di.max_flow(s,t));
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

# https://atcoder.jp/contests/abc116


def main():
    N = int(input())
    h = list(map(int, input().split()))

    H = max(h)

    mat = [None] * H
    for i in range(H):
        mat[i] = "".join(["1" if i < h[j] else "0" for j in range(N)])

    ans = 0
    for i in range(H):
        ans += sum([1 if len(s) > 0 else 0 for s in mat[i].split("0")])

    return ans


print(main())


Measured memory_bytes: 9200
# -*- coding: utf-8 -*-

n = int(input())
#tmp = input()
tmp = input().split()
#(lambda a:int(a))(tmp)
hoge = list(map(lambda a: int(a), tmp))
hoge.sort()
hoge.reverse()

sum_al=0
sum_bo=0
for i,j in enumerate(hoge):
	if (i%2 == 0):
		sum_al+=j
	else:
		sum_bo+=j
print(sum_al-sum_bo)

Measured memory_bytes: 3060
from heapq import heappop, heappush

n,m,s = map(int,input().split())
e = [[] for _ in range(n)]
for i in range(m):
  u,v,a,b = map(int,input().split())
  u -= 1
  v -= 1
  e[u].append((v,a,b))
  e[v].append((u,a,b))
c = []
d = []
for i in range(n):
  x,y = map(int,input().split())
  c.append(x)
  d.append(y)

INF = float('inf')
def dijkstra(s,n,g): # sからの最短距離 頂点数n g[v]=[(u1,w1),(u2,w2)....]:vからuへの有向辺があり、重みw
  que = []
  d = [INF for _ in range(n)]
  d[s] = 0
  heappush(que,(0,s))
  while len(que) > 0:
    p = heappop(que)
    v = p[1]
    if d[v] < p[0]:
      continue
    for u,w in g[v]:
      if d[u] > d[v]+w:
        d[u] = d[v]+w
        heappush(que,(d[u],u))
  return d

def newv(v,s):
  return v*2500+s

s = min(s,2499)
e2 = [[] for _ in range(n*2500)]
for u in range(n):
  for j in range(2500):
    #if j+c[u] < 2500:
    #  e2[newv(u,j)].append((newv(u,j+c[u]),d[u]))
    e2[newv(u,j)].append((newv(u,min(j+c[u],2499)),d[u]))
    for v,a,b in e[u]:
      if j >= a:
        e2[newv(u,j)].append((newv(v,j-a),b))

l = dijkstra(newv(0,s),n*2500,e2)
for i in range(1,n):
  ans = INF
  for j in range(2500):
    ans = min(l[newv(i,j)],ans)
  print(ans)


Measured memory_bytes: 115700
#include<iostream>

using namespace std;

int main()
{
 int a,b;
 char c;
 for(;;){
 cin >> a>>c>>b;
 if(c=='+')
 cout<<a+b<< endl;
else if (c=='-')
 cout<<a-b<<endl;
else if (c=='*')
 cout<<a*b<<endl;
else if (c=='/')
 cout<<a/b<<endl;
else
 break;
}
return 0;
}



Measured memory_bytes: 3096
a = input()
b = int(input())
br = []
count = 0
if b == 1:
    print(a[0])
else:
    if len(a) >= b:
        for i in range(b):
            if a[i] == "1":
                count += 1
        if count == b:
            print(1)
        else:
            for r in (list(a)):
                if r != "1":
                    print(r)
                    exit()
    else:
            for r in (list(a)):
                if r != "1":
                    print(r)
                    exit()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    vint a(n);
    rep(i,n) cin >> a[i];

    int res=INF;
    rep(i,n){
        int tmp=0;
        while(a[i]%2==0){
            a[i]/=2;
            tmp++;
        }
        chmin(res,tmp);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3640
nums = list(map(int, input().split()))
x1 = nums[0]
y1 = nums[1]
x2 = nums[2]
y2 = nums[3]
if x2 > x1:
    if y2 > y1:
        x3 = x2 - (y2 - y1)
        y3 = y2 + (x2 - x1)
        x4 = x1 - (y2 - y1)
        y4 = y1 + (x2 - x1)
    elif y2 < y1:
        x3 = x2 + (y1 - y2)
        y3 = y2 + (x2 - x1)
        x4 = x1 + (x3 - x2)
        y4 = y1 + (y3 - y2)
    else:
        x3 = x2
        y3 = y2 + (x2 - x1)
        x4 = x1
        y4 = y3
elif x2 < x1:
    if y2 > y1:
        x3 = x2 - (y2 - y1)
        y3 = y2 - (x1 - x2)
        x4 = x1 - (x2 - x3)
        y4 = y1 - (y2 - y3)
    elif y2 < y1:
        x3 = x2 + (y1 - y2)
        y3 = y2 - (x1 - x2)
        x4 = x1 + (x3 - x2)
        y4 = y1 - (y2 - y3)
    else:
        x3 = x2
        y3 = y2 - (x1 - x2)
        x4 = x1
        y4 = y3
else:
    if y2>y1:
        x3 = x2 - (y2 - y1)
        y3 = y2
        x4 = x3
        y4 = y1
    else:
        x3 = x2 + (y1 - y2)
        y3 = y2
        x4 = x3
        y4 = y1
print(x3,y3,x4,y4)

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

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

  string s;
  cin >> s;
  rep(i, 3)
  {
    cout << s.at(i);
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3592
n=int(input())

A=list(map(int, input().split()))

m = 0
while True:
  m = max(A)
  for i in range(n):
    if A[i] != 0:
      m = min(m,A[i])
  c = set(A) - set([0])
  if len(c) == 1:
    break
  
  for i in range(n):
    if A[i] == m:
      continue
    if A[i] == A[i]%m:
      continue
    else:
      A[i] = A[i]%m
print(m)
  

Measured memory_bytes: 16524
from collections import Counter
n, m = [int(item) for item in input().split()]
x = [int(item) for item in input().split()]

modm = [[] for _ in range(m)]
ans = 0
for item in x:
    modm[item % m].append(item)
for i in range(m//2+1):
    if i == 0:
        ans += len(modm[i]) // 2
    elif m % 2 == 0 and i == m // 2:
        ans += len(modm[i]) // 2
    else:
        a = modm[i]
        b = modm[m - i]
        if len(b) < len(a):
            a, b = b[:], a[:]
        ans += len(a)
        cnt = Counter(b)
        val = 0
        for key in cnt.keys():
            val += cnt[key] // 2
        ans += min(val, (len(b) - len(a)) // 2)
print(ans)

Measured memory_bytes: 19036
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();
        Set<Integer> set = new HashSet<>();
        set.add(A);
        set.add(B);
        set.add(C);
        System.out.println(set.size() == 2 ? "Yes" : "No");
    }
}



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

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

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

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

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

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

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

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

fn main() {
    input! {
        a: i32,
        b: i32,
    }
    
    for x in 0..100001 {
        if (x as f32 * 0.08) as i32 == a && (x as f32 * 0.1) as i32 == b {
            println!("{}", x);
            std::process::exit(0);
        }
    }

    println!("-1");
}


Measured memory_bytes: 4352
// AOJ 2243: Step Step Evolution
// 2017.11.11 bal4u@uu

#include <stdio.h>

#define LEFT  0
#define RIGHT 1
#define check(l,r)  ((tr[l])<=(tr[r]))

char a[100002];
int tr['9'+1];

int main()
{
	int i, s, cnt, ans;
	char *p, l, r;

	tr['1'] = tr['4'] = tr['7'] = 1;
	tr['2'] =           tr['8'] = 2;
	tr['3'] = tr['6'] = tr['9'] = 3;

	while (fgets(a, sizeof(a), stdin) && *a != '#') {
		if (a[1] < '0') { puts("0"); continue; }
		ans = 100000;
		for (i = 0; i < 2; i++) {
			cnt = 0, p = a;
			if (!i) l = *p++, r = *p++, s = LEFT;
			else    r = *p++, l = *p++, s = RIGHT;
			if (!check(l, r)) continue;

			while (*p >= '0') {
				if (s == LEFT) {
					if (check(*p, r)) l = *p, s = !s;
					else              r = *p, cnt++;
				} else {
					if (check(l, *p)) r = *p, s = !s;
					else              l = *p, cnt++;
				}
				p++;
			}
			if (ans > cnt) ans = cnt;
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1940
#include <iostream>
#include <cmath>

using namespace std;

long long count(long long keta, bool ot){
//    cerr << "KETA:" << keta << "OP" << ot << endl;
    long long ans = 1;
    while(keta > 0){
        ans *= 2;
        keta --;
    }
    ans--;
    if(ot){
        return ans + 1;
    }
    else{
        return 9*ans;
    }
}

string solve(long long N){
    int keta = 0;
    long long di = 2;
    long long mk = N;
    while(mk > 0){
        mk -= (di-1ll) * 81ll;
        keta++;
        di *= 2ll;
    }
//    cerr << keta << endl;
    di /= 2;
    mk += (di - 1ll) * 81ll;
    string ans;
    char x = '1';
    long long s = (di - 1ll) ;
    long long sx = s * 9;
    while(mk - sx > 0){
        x++;
        mk -= sx;
    }
    ans.push_back(x);
    char y = 0;
    while(keta > 0){
        if(y == 0){
            for (int j = 0; j < 10; ++j) {
                long long tt = count(keta-1, x != j + '0');
//                cerr << "j:" <<  j << ' ' << tt << '\n';
                if(mk - tt <= 0){
                    if(x == j + '0'){
                        ans.push_back(x);
                    }
                    else{
                        y = j + '0';
                        ans.push_back(y);
                    }
                    break;
                }
                else mk -= tt;
            }
        }
        else {
            long long tt = count(keta-1, true);
//            cerr << "co::: " << tt << '\n';
            if (mk - tt <= 0) {
                ans.push_back(x < y ? x : y);
            }
            else{
                ans.push_back(x < y ? y : x);
                mk -= tt;
            }
        }
        keta--;
    }
    return ans;
}

int main() {
    long long N;
    while(1) {
        cin >> N;
        if(N == 0) break;
        cout << solve(N) << '\n';
    }
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

// #define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll mod = (1000000007LL);
inline ll Mod(ll a, ll b){return (a%b);}
inline ll poww(ll a, ll b){ll res = 1;while (b > 0){if(b & 1) res = (res * a)%mod;a = (a * a)%mod;b >>= 1;}return res;}
ll gcd (ll a, ll b) { while (b) { a %= b,swap(a, b);}return a;}
void read(vector<int> &w, int n){w.resize(n);for(int i = 0; i < n; i++) cin>>w[i];}
void print(vector<int> &w){for(int i =0; i < sz(w); i++){if(i == sz(w) - 1) cout<<w[i]<<"\n";else cout<<w[i]<<" ";}}
int prodmod(vector<int> w);
int summod(vector<int> w);
///CUIDADO COM MAXN
#define N 300050

int n, m, q, k, v[N], ans;
pii w[N];
string s;

int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	cin>>n>>k;
	vector<int>v(n);
	read(v, n);
	sort(all(v));
	int sum=0;
	for(int i=0;i<k;i++)sum+=v[i];
	cout<<sum<<"\n";
}
/*
    CUIDADO COM MAXN, MOD, OVERFLOW 
    >Colocar (>DEFINE INT LONG LONG<) no inicio do template
    >mod = (1e9 + 7), por padrao (NAO ESQUECER DE ALTERAR)
    >NAO ESQUECER DEFINE INT LONG LONG
    > N = 1 ? 
*/
int summod(vector<int> w){int curr=0;for(int i=0;i<sz(w); i++){curr = (curr+w[i])%mod;if(curr<0)curr+=mod;}return curr;}
int prodmod(vector<int> w){int curr = 1;
for(int i = 0; i < sz(w); i++){if(w[i] >= mod) w[i] %= mod;curr = (curr * w[i]) % mod;if(curr < 0) curr += mod;}return curr;}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt() * 2;
		if (A <= B) {
			System.out.println(0);
		} else {
			System.out.println(A-B);
		}
	}

}

Measured memory_bytes: 35652
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int A, B, C;
	cin >> A >> B >> C;

	ll D = C - A - B;

	if (D <= 0) {
		co("No");
		return 0;
	}
	D = D * D;
	ll AB = 4ll * A * B;
	if (AB < D) {
		co("Yes");
	}
	else {
		co("No");
	}


	Would you please return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,a,b,x,d;
	cin>>a>>b>>n;
	x=min(b-1,n);
	d=(a*x)/b - a*(x/b);
	cout<<d;
}

Measured memory_bytes: 3648
n = int(input())
l = input().split()

for i in range(0,n):
	l[i] = int(l[i])

dict_i = {}
for i in range(-1,100001):
	dict_i[i] = 0
	
for j in range(n):
	dict_i[l[j]] += 1
	dict_i[l[j] + 1] += 1
	dict_i[l[j] - 1] += 1
print(max(dict_i.values()))

Measured memory_bytes: 19716
import java.util.NoSuchElementException

fun main(args: Array<String>) = FastScanner().run {
    val s = next()
    var ret = 1.shl(60)
    for (c in 'a'..'z') {
        var t = s
        while (t.count { it == c } != t.length) {
            val sb = java.lang.StringBuilder()
            for (i in 0 until t.length-1) {
                if (t[i] == c) sb.append(c)
                else sb.append(t[i+1])
            }
            t = sb.toString()
        }
        ret = Math.min(ret, s.length - t.length)
    }
    println(ret)
}

class FastScanner {
    private val printable = 33..126
    val `in` = System.`in`
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    fun hasNextByte(): Boolean {
        if (ptr < buflen) {
            return true
        } else {
            ptr = 0
            buflen = `in`.read(buffer)
            if (buflen <= 0) {
                return false
            }
        }
        return true
    }
    fun readByte(): Byte {
        return if (hasNextByte()) buffer[ptr++] else return -1
    }
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }
    fun next(): String {
        if (!hasNext()) throw NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }
    fun nextLong(): Long {
        if (!hasNext()) throw NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }
    fun nextInt(): Int {
        val nl = nextLong()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }
    fun nextDouble(): Double {
        return next().toDouble()
    }
}

Measured memory_bytes: 31988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-2, -1};
int dx[4] = {-1, -2};

int x, y;

const int MAX = 1000050;
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> x >> y;
	ll ret = 0;
	if((2*y - x) % 3 != 0 || (2*x - y) % 3 != 0) {
		cout << ret << endl;
		return 0;
	}
	int a = (2*y - x)/3;
	int b = (2*x - y)/3;
	if(a < 0 || b < 0) {
		cout << ret << endl;
		return 0;
	}
	COMinit();
	ret = COM(a+b, a);
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 23680
import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    long N = scan.nextLong();
    scan.close();

    long ans = N+1;
    long tmp = 0;
    double max= Math.sqrt(N);
    for(long i=2; i<=max; i++) {
      tmp = N/i;
      if(N%i == 0) {
        ans = tmp+i;
      }
    }

    System.out.println(ans-2);
  }
}

Measured memory_bytes: 23764
c=[list(map(int,input().split())) for _ in range(3)]
if c[0][0]-c[1][0]==c[0][1]-c[1][1]==c[0][2]-c[1][2]:
    if c[0][0]-c[2][0]==c[0][1]-c[2][1]==c[0][2]-c[2][2]:
        if c[0][0]-c[0][1]==c[1][0]-c[1][1]==c[2][0]-c[2][1]:
            if c[0][0]-c[0][2]==c[1][0]-c[1][2]==c[2][0]-c[2][2]:
                print('Yes')
                exit()
print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef struct _data {
	int x;
	int y;
} data;

int  main()
{
	string s;
	cin >> s;
	std::ifstream in("in10.txt");
	std::cin.rdbuf(in.rdbuf());
	ll ite = 0;
	ll ans = 0;
	for (long i = 0; i < s.size(); i++)
	{
		if (s[i] == 'W')
		{
			ans += i - ite;
			ite++;
		}
	}
	cout << ans << endl;
	return (0);
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {

    int a, b ,c;
    scanf("%d%d%d", &a, &b, &c);

    if (a==b && b==c) {
        printf("No\n");

    }else if (a!=b && b!=c && c!=a) {
        printf("No\n");

    }else {
        printf("Yes\n");

    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  if ((V - W) * T < abs(A - B))
    cout << "NO" << endl;
  else
    cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

ll N, u, v;
vector<vector<ll>> G;
vector<ll> du, dv;

int main(){
    cin >> N >> u >> v;
    G.resize(N+1);
    rep(i, 0, N-1){
        ll a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // u
    du.resize(N+1, -1);
    queue<ll> que;
    que.push(u);
    du[u] = 0;
    while(!que.empty()){
        auto t = que.front();
        que.pop();
        for(auto g : G[t]){
            if(du[g] != -1) continue;
            du[g] = du[t] + 1;
            que.push(g);
        }
    }

    // v
    dv.resize(N+1, -1);
    queue<ll> que2;
    que2.push(v);
    dv[v] = 0;
    while(!que2.empty()){
        auto t = que2.front();
        que2.pop();
        for(auto g : G[t]){
            if(dv[g] != -1) continue;
            dv[g] = dv[t] + 1;
            que2.push(g);
        }
    }

    ll mx = -1, li = 0;
    rep(i, 1, N+1){
        if(du[i] < dv[i] && mx < dv[i]){
            mx = dv[i];
            li = i;
        }
    }

    cout << dv[li]-1 << endl;
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+11;
int n,a[N],b[N],c[N];
int main(){
#ifdef flukehn
	freopen("g.in","r",stdin);
#endif
	cin>>n;
	int i,an=n,m=0;
	for(i=1;i<=n;++i){
		scanf("%d",a+i);
		if(i&1)++b[a[i]];
		else ++c[a[i]];
	}
	for(i=1;i<N;++i){
		an=min(an,n-b[i]-m);
		m=max(m,c[i]);
	}
	m=0;
	for(i=1;i<N;++i){
		an=min(an,n-c[i]-m);
		m=max(m,b[i]);
	}
	printf("%d\n",an);
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>

using namespace std;

class Dice{
private:
  int D1;
  int D2;
  int D3;
  int D4;
  int D5;
  int D6;

public:
  Dice(int d1,int d2,int d3,int d4,int d5,int d6){
  D1=d1;
  D2=d2;
  D2=d2;
  D3=d3;
  D4=d4;
  D5=d5;
  D6=d6;
  }

  void roll(char dire){
  int dd1=D1;
  int dd2=D2;
  int dd3=D3;
  int dd4=D4;
  int dd5=D5;
  int dd6=D6;
  
  if(dire=='E')
    {
    D1=dd4;
    D3=dd1;
    D4=dd6;
    D6=dd3;
    }
  if(dire=='N')
  {
    D1=dd2;
    D2=dd6;
    D5=dd1;
    D6=dd5;
  }
  if(dire=='S')
  {
    D1=dd5;
    D5=dd6;
    D6=dd2;
    D2=dd1;
  }
  if(dire=='W')
  {
    D1=dd3;
    D3=dd6;
    D6=dd4;
    D4=dd1;
  }
  
  }
  
  int ue(){
  return D1;
  }
  
  int light(int up,int mae){
    int i;
    int j;
    int k;
    int l;
      for(i=0;i<4;i++)
      {
      roll('E');
     for(j=0;j<4;j++)
     {
      roll('S');
     for(k=0;k<4;k++)
     {
        roll('E');
        for(l=0;l<4;l++)
        {
        roll('S');
          if(up==D1 && mae==D2)
          return D3;
        }
     }
     }
    }
  }
  
  
};

int main()
{
  int di[6]={};
  int i;
  int q;
  int up;
  int mae;
  
  for(i=0;i<6;i++)
    cin >> di[i];
    
  Dice dice1(di[0],di[1],di[2],di[3],di[4],di[5]);
  
  cin >> q;
  
  for(i=0;i<q;i++)
  {
    cin >> up >> mae;
    cout << dice1.light(up,mae) <<"\n";
  }
}

Measured memory_bytes: 1160