akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

if k < 10 ** 6:#計算量的に間に合うので愚直に
    now = 1
    for i in range(k):
        now = d[now]

    print(now)

else:
    for i in range(len(route)):
        if route[i] == route[-1]:#routeには第二ループの始めがギリ入っている
            roop = route[i:-1]
            print(roop[(k - i) % len(roop)])#k-iは残り移動階数
            exit()

Measured memory_bytes: 49076
# coding: utf-8
d = {}
N = int(input())

for _ in range(N):
    ope, s = map(str, input().split())
    if ope == 'insert':
        d[s] = 0
    elif ope == 'find':
        if s in d.keys():
            print('yes')
        else:
            print('no')



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

int main() {
	int n = 0;
	cin >> n;
	switch (n){
	case 111:
		n = 999;
		break;
	case 119:
		n = 991;
		break;
	case 191:
		n = 919;
		break;
	case 199:
		n = 911;
		break;
	case 911:
		n = 199;
		break;
	case 919:
		n = 191;
		break;
	case 991:
		n = 119;
		break;
	case 999:
		n = 111;
		break;
	}
	cout << n << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
    long long int n1, n2, i, gcd, lcm;
    scanf("%lld %lld", &n1, &n2);
    for (i = 1; i <= n1 && i <= n2; ++i) {

        // check if i is a factor of both integers
        if (n1 % i == 0 && n2 % i == 0)
            gcd = i;
    }
    lcm = (n1 * n2) / gcd;
    printf("%lld\n", lcm);
    return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt();
		int[] d = new int[n];
		for ( int i = 0; i < n; i++ ) {
			d[i] = in.nextInt();
		}

		Arrays.sort(d);
		System.out.println(d[n / 2] - d[n / 2 -1]);
		in.close();
	}
}

Measured memory_bytes: 50192
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskC
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int H[] = CPUtils.readIntArray(N, in);

            long ans = 0;
            for (int i = 1; i < N; i++)
            {
                if (H[i - 1] > H[i])
                {
                    ans += H[i - 1] - H[i];
                    H[i] = H[i - 1];
                }
            }
            out.println(ans);
        }

    }

    static class CPUtils
    {
        public static int[] readIntArray(int size, Scanner in)
        {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
            {
                array[i] = in.nextInt();
            }
            return array;
        }

    }
}



Measured memory_bytes: 50432
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main(){
    int  i;
    i = 1;
while (1){
    int x;
    cin >> x;
    if (x == 0){
        break;
    }else{
        cout<< "Case " << i << ": " << x << endl;
        i++ ;
    }
}    return 0;
}


Measured memory_bytes: 3096
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 200111;
ll L;
int n;
ll a[maxn];
ll b[maxn];
ll suma[maxn], sumb[maxn];
ll geta(int l, int r) {return suma[r]-suma[l-1];}
ll getb(int l, int r) {return sumb[r]-sumb[l-1];}
ll solve()
{
	for (int i=1; i<=n; i++) b[i] = L-a[i];
	for (int i=1; i<=n; i++)
	{
		suma[i] = suma[i-1]+a[i];
		sumb[i] = sumb[i-1]+b[i];
	}
	ll ret = 0;
	for (int i=1; i<=n; i++)
	{
		int mn = min(i, n-i);
		ll cur;
		cur = geta(i-mn+1, i)+getb(i+1, i+mn);
		if (mn>0)
		{
			ret = max(ret, cur*2-a[i]);
			ret = max(ret, cur*2-b[i+1]);
		}
		if (i>mn)
		{
			cur = geta(i-mn, i)+getb(i+1, i+mn);
			ret = max(ret, cur*2-a[i]);
		}
		if (n-i+1>mn)
		{
			cur = geta(i-mn+1, i)+getb(i+1, i+mn+1);
			ret = max(ret, cur*2-b[i+1]);
		}
	}
	return ret;
}
int main()
{
	getii(L, n);
	for (int i=1; i<=n; i++) geti(a[i]);
	ll ans = solve();
	for (int i=1; i<=n; i++) a[i] = L-a[i];
	reverse(a+1, a+n+1);
	ans = max(ans, solve());
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a=0;
  int b=0;

  cin >> a;
  cin >> b;
  
  if(a<=b){
    for(int i=0; i<b; i++){
      cout << a;
    }
  }
  else{
    for(int i=0; i<a; i++){
      cout << b;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/* #defineと書くとマクロが定義できる
   rep(i,n) { //処理 }　と書くとn回ループが回せるようにしている*/
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
using ll = long long;

int main() {
  string n;
  cin >> n;

  if (n[2] == n[3] && n[4] == n[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  
  int a[20];
  int b[20];
  int s=0;
  int N;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  
  
    for(int i=0;i<N;i++){
      cin>>b[i];
  }
  
    for(int i=0;i<N;i++){
      if(a[i]>b[i]){
        s+=(a[i]-b[i]);
      }
    }
  cout<<s<<endl;
  }

Measured memory_bytes: 256
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    f, o = 0, 0
    for a in a_list:
        f += a % 4 == 0
        o += a % 2 != 0

    if f >= (N // 2) or f >= o:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14636
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {

r#"2
1 4"# => r#"5"#,

r#"7
14 14 2 13 56 2 37"# => r#"2354"#,
}

const INF:isize = 1 << 60;

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        n: usize,
        x: [isize; n],
    }
    let mut ans = INF;
    let mut memo = vec![vec![None; n]; 101];

    for i in 1..101 {
        let mut sum:isize = 0;
        for j in 0..n {
            if memo[i][j].is_none() {
                let t = x[j] - i as isize;
                memo[i][j] = Some(t * t);
            }
            let tt = memo[i][j].unwrap();
            sum = sum + tt;
        }
        ans = std::cmp::min(ans, sum);
    }

    ans.to_string()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct edge{
    int u, v, c;
    edge(int u, int v, int c) : u(u), v(v), c(c) {}
};

int main(){
    int A, B;
    cin >> A >> B;
    int d[A][B];
    rep(i, A){
        rep(j, B) cin >> d[i][j];
    }
    int N = 202, s = 1, t = 202;
    vector<edge> es;
    rep2(i, 1, 100){
        es.eb(i, i+1, -1), es.eb(202-i, 203-i, -2);
    }
    bool flag[A][B];
    memset(flag, false, sizeof flag);
    rep2(a, 0, 100){
        rep2(b, 0, 100){
            int M = -inf;
            rep(i, A){
                rep(j, B) chmax(M, d[i][j]-(a*(i+1)+b*(j+1)));
            }
            if(M >= 0){
                es.eb(a+1, 202-b, M);
                rep(i, A){
                    rep(j, B){
                        if(d[i][j]-(a*(i+1)+b*(j+1)) == M) flag[i][j] = true;
                    }
                }
            }
        }
    }
    rep(i, A){
        rep(j, B){
            if(!flag[i][j]) {cout << "Impossible" << endl; return 0;}
        }
    }
    cout << "Possible" << endl;
    cout << N << ' '<< sz(es) << endl;
    for(auto &e: es){
        cout << e.u << ' ' << e.v << ' ';
        if(e.c < 0){
            cout << (e.c == -1? "X" : "Y") << endl;
        }
        else cout << e.c << endl;
    }
    cout << s << ' ' << t << endl;
}

Measured memory_bytes: 3568
#include <iostream>

int main()
{
  int N;
  std::cin >> N;

  // ones place
  int a = N % 10;
  std::string out = "hon";
  switch (a) {
    case(0):
    case(1):
    case(6):
    case(8): {
      out = "pon";
      break;
    }
    case(3): {
      out = "bon";
      break;
    }
    default: {
      break;
    }
  }

  std::cout << out << std::endl;

  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h> 

int main(void)
{	
	int H, W, i, j;

	while(1)
	{
		scanf("%d %d",&H, &W);

		if(H != 0 && W != 0)
		{
			for(j=0; j<H; j++)
			{

				for(i=0; i<W; i++)
				{
					printf("#");
				}

				printf("\n");

			}
		}
		else
		{
			break;
		}

		printf("\n");
	}

	return 0;
}

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

signed main(){
  std::vector<int> v(5,0);
  for(int i=0;i<3;i++){
    int a,b;cin>>a>>b;
    v[a]++;v[b]++;
  }
  sort(v.begin(),v.end());
  if(v[4]==3)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d;
  string s;
  long long ans = 0;
  
  cin >> a >> b >> c >> d;

  if(a*b > c*d) ans = a*b;
  else ans = c*d;
  cout << ans << endl;

}

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

int main() {
    int n, k;
    double ans = 0.0, temp = 0.0, p;
    cin >> n >> k;
    vector<double> a(n);
    rep(i, n) {
        cin >> p;
        a.at(i) = (p + 1.0) / 2.0;
    }
    rep(i, k) temp += a.at(i);
    ans = temp;
    rep(i, n - k) {
        temp += a.at(i + k);
        temp -= a.at(i);
        ans = max(ans, temp);
    }
    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 1792
//In the Name of God
//Ya Ali

#include<bits/stdc++.h>

#define int long long

#define pb push_back
#define ld long double

#define err(A) cout<<#A<<" = "<<(A)<<endl

using namespace std;

const int maxn=131072;

int n;

vector<int> g[maxn];

int a[maxn];

int root;

int s;

int dfs(int v,int par=-1)
{
  int s=0;
  int c=0;
  int c1=0;
  int mx=0;
  for(int u:g[v])
    if(u!=par)
      {
	c++;
	int tmp=dfs(u,v);
	mx=max(mx,tmp);
	s+=tmp;
	if(tmp) c1++;
      }
  
  if(!c)
    return a[v];
  if(s<a[v] or a[v]*2<s)
    {
      cout<<"NO"<<endl;
      exit(0);
    }
  if(c==1)
    {
      if(a[v]!=s)
	{
	  cout<<"NO"<<endl;
	  exit(0);
	}
      else
	return s;
    }
  if(mx>a[v])
    {
      cout<<"NO"<<endl;
      exit(0);
    }
  return 2*a[v]-s;
}

int32_t main()
{
  ios::sync_with_stdio(0);cin.tie(0);
  
  cin>>n;

  for(int i=0;i<n;i++)
    cin>>a[i];
  
  for(int v,u,i=0;i<n-1;i++)
    {
      cin>>v>>u;
      v--,u--;
      g[v].pb(u);
      g[u].pb(v);
    }

  if(n==2)
    {
      if(a[0]==a[1])
	cout<<"YES"<<endl;
      else
	cout<<"NO"<<endl;
      return 0;
    }

  for(int i=0;i<n;i++)
    if(g[i].size()>1)
      root=i;

  if(!dfs(root))
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
    
  return 0;
}


Measured memory_bytes: 14336
N = int(input())
A = [int(i) for i in input().split()]

abs_A = [abs(i) for i in A]
sa = sum(abs_A)

nm = len([i for i in A if i<0])
if nm % 2 == 1:
    ma = min(abs_A)
    sa = sa - 2*ma

print(sa)


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

bool ok(string s){
	int n= s.length();
	bool maki = true;
	for(int i=0;i<n/2;i++){
		if(s[i] != s[n-i-1]) maki = false;
	}
	return maki;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();

    if(ok(s) && ok(s.substr(0, n / 2)) && ok(s.substr(n / 2 + 1, n / 2))){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n;
	cin >> n;
	ll a[5];
	ll m = INF;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		m = min(m, a[i]);
	}
	ll ans = (n - 1) / m + 5;
	dump(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
using namespace std;
int q,a,b,c,d,len,xa,xb,la,lb;
int is[2];
vector<P>w[2];
void get(vector<P>&w,int xa,int a){
	int g=0;
	for(int l=0,r=xa,mid;mid=l+r>>1,l<=r;)
		if((ll)mid*len+(xa-mid)<=a)g=mid,l=mid+1;else r=mid-1;
	if(g)w.push_back(P(g,len));
	a-=g*len;xa-=g;
	if(xa){
		w.push_back(P(1,a-(xa-1)));
		w.push_back(P(xa-1,1));	
	}
}
int sum2(vector<P>&w,int a){
	if(!a)return 0;
	int s=0;
	fo(i,0,w.size()-1){
		if(a<=w[i].fi){
			s+=a*w[i].se;
			break;
		}
		s+=w[i].fi*w[i].se;
		a-=w[i].fi;
	}
	return s;
}
int sum(int x){
	return sum2(w[0],x+is[0]>>1)+sum2(w[1],x+is[1]>>1);
}
P find(int x){
	int wz=0;
	for(int l=1,r=xa+xb,mid;mid=l+r>>1,l<=r;)
		if(sum(mid)<x)l=mid+1,wz=mid;else r=mid-1;
	return P(wz+1,x-sum(wz));
}
int get_len2(vector<P>&w,int x){
	fo(i,0,w.size()-1)
		if((x-=w[i].fi)<=0)return w[i].se;
}
int get_len(int x){
	return (x&1)==is[0]?get_len2(w[0],x+is[0]>>1):get_len2(w[1],x+is[1]>>1);
}
int main(){
	for(cin>>q;q--;){
		cin>>a>>b>>c>>d;
		len=0;
		for(int l=1,r=max(a,b),mid;mid=l+r>>1,l<=r;){
			int la=(a+mid-1)/mid,lb=(b+mid-1)/mid;
			if(a+1<lb||b+1<la)l=mid+1;else len=mid,r=mid-1;
		}
		la=(a+len-1)/len;lb=(b+len-1)/len;
		w[0].clear();w[1].clear();
		if(a+1==lb)xa=a,xb=lb;else 
		if(b+1==la)xa=la,xb=b;else{
			int k=0;
			for(int l=0,r=a/len,mid;mid=l+r>>1,l<=r;)
				if((ll)len*(a-mid*len-1+1)<b-mid)r=mid-1;else k=mid,l=mid+1;
			xa=xb=k+(b-k+len-1)/len;
		}
		if(xa>=xb)is[0]=1,is[1]=0;else is[0]=0,is[1]=1;
		if(len==1)w[0].push_back(P(a,1)),w[1].push_back(P(b,1));else{
			get(w[0],xa,a);
			get(w[1],xb,b);
			reverse(w[1].begin(),w[1].end());
		}
		P A=find(c);
		fo(i,c,d){
			putchar((A.fi&1)==is[0]?'A':'B');
			if(++A.se>get_len(A.fi))A=P(A.fi+1,1);
		}
		putchar('\n');
	}
}

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

int a[200005];
int cnt[200105]={0};
int k,n;
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{

    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        cnt[a[i]]++;
    }
    sort(cnt+1,cnt+200005,cmp);
    int ans=0;
    for(int i=k+1;i<=200000;i++)
    {
        if(cnt[i])ans+=cnt[i];
        else break;
    }
    cout<<ans;
    return 0;
}


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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<lli, lli> pii;

#define N 100010
vector<int> adj[N];
bitset<N>vis;
lli ans;
void bfs(int st)
{
    ans++;
    queue<int> qu;
    qu.push(st);
    vis[st] = 1;
    while(!qu.empty()){
        int u = qu.front();
        qu.pop();
        for(auto v: adj[u]){
            if(vis[v] == 0){
                vis[v] = 1;
                qu.push(v);
            }
        }
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    while(m--){
        int u, v, w;
        cin >> u >> v >> w;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1; i<=n; i++){
        if(vis[i] == 0){
            bfs(i);
        }
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 6520
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int a[20][20],c[20],cur[20];int n,m,k,ans=INF;
void dfs(int x,int sum){
	for(int i=1;i<=m;i++){
		cur[i]+=a[x][i];
	}
	int fg=1;
	for(int i=1;i<=m;i++){
		if(cur[i]<k) fg=0;
	}
	if(fg==1) {ans=min(ans,sum+c[x]);}
	for(int i=x+1;i<=n;i++){
		dfs(i,sum+c[x]);
		for(int j=1;j<=m;j++){
			cur[j]-=a[i][j];
		}
	}
}
int main(){
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		mem(cur,0);
		dfs(i,0);
	}
	if(ans!=INF) cout<<ans<<endl;
	else cout<<-1<<endl;
}
/*
3 3 10
50 2 3 9
60 2 2 4
70 8 7 9
*/

Measured memory_bytes: 3636
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[1010][1010];
signed main() {
    int N, K; cin >> N >> K;
    N -= K;
    dp[0][0] = 1;
    for(int i=1; i<=K; i++) {
        for(int j=0; j<=N; j++) {
            if(j >= i) (dp[i][j] += dp[i][j-i]) %= MOD;
            (dp[i][j] += dp[i-1][j]) %= MOD;
        }
    }
    if(N < 0) cout << 0 << endl;
    else cout << dp[K][N] << endl;
    return 0;
}



Measured memory_bytes: 7320
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	
        Scanner sc = new Scanner(System.in);
        int n, i, k = 0;
        int[] s;
        double sum, avg, a;
        double[] b = new double[100];
        
        while((n = sc.nextInt()) != 0) {
        	a = 0;
        	sum = 0;
        	s = new int[n];
        	for(i = 0; i < n; i++) {
        		s[i] = sc.nextInt();
        		sum += s[i];
        	}
        	avg = sum / n;
        	for(i = 0; i < n; i++) {
        		a += (avg - s[i]) * (avg - s[i]);
        	}
        	b[k] = a / n;
        	k++;
        }
        
        for(i = 0; i < k; i++) {
        	b[i] = Math.sqrt(b[i]);
        	System.out.print(b[i]);
        	//System.out.print(String.format("%.8f", b[i]));
        	if(i != k-1) System.out.println();
        }
    }
}


Measured memory_bytes: 32812
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int A,B,i,j=0;
string s;
cin>>A>>B>>s;
for(i=0;i<s.length();i++)
{
if(s[i]!='-')
{if(j==0)
A--;
else
B--;
}
else
j=1;
}
if(A==0&&B==0)
cout<<"Yes";
else
cout<<"No";
return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int sum;

int main()
{
	string st;
	cin>>st;
	for(int i=0;i<st.size();i++)
	{
		if(st[i]=='C')
		sum=1;
		if(st[i]=='F'&&sum==1)
		{
			sum=3;
			cout<<"Yes"<<endl;
		}
	}
	if(sum!=3)
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cstdlib>

using namespace std;
 
typedef long long ll;
  
ll expression();
ll term();
ll factor();
ll number();
  
int now;
string s;
ll P;
bool fg;
 
ll extgcd(ll a, ll b, ll& x, ll& y){
  ll d = a;
  if(b!=0){
    d=extgcd(b, a%b ,y,x);
    y-=(a/b)*x;
  }
  else{
    x=1; y=0;
  }
  return d;
}
 
ll mod_inverse(ll a,ll m){
  ll x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}
 
ll expression(){
  if(fg)return 0;
    ll res=term();
        while(true){
      if(s[now]=='+')now++,(res+=term())%=P;
      else if(s[now]=='-')now++,(res+=P-term())%=P;
      else break;
    }
    return res;
}
 
ll term(){
  ll res=factor();
  while(true){
    if(s[now]=='(')res+=factor();
    else if(s[now]=='*')now++,(res*=factor())%=P;
    else if(s[now]=='/'){
      now++;
      ll tmp=factor();
      if(tmp==0)fg=true;
      res=((res%P)*mod_inverse(tmp,P)%P)%P;
    }
    else break;
  }
  return res;
}
 
ll factor(){
    ll res=0;
    if(s[now]=='('){
        now++;
        res=expression()%P;
        now++;
    }
    else return number();
      
    return res%P;
}
  
ll number(){
    ll res=0;
    while('0'<=s[now] && s[now]<='9'){
        res*=10;
        res+=s[now++]-'0';
    }
    return res%P;
}

int main(){
  string tmp;
  while(getline(cin,tmp)){
    if(tmp[0] == '0')break;

    for(int i=0;i<tmp.size();i++){
      if(tmp[i]==':'){
	tmp[i]=' ';
	break;
      }
    }

    now = 0;
    s.clear();
    stringstream ss;
    ss << tmp;
    ss >> tmp;
    P = (atol)(tmp.c_str());
    while(!(ss >> tmp).fail()){
      s += tmp;
    }
 
    fg = false;
    ll ans = expression();
    if(fg) cout << "NG" << endl;
    else  cout << s << " = " << ans << " (mod " << P << ")" << endl;
 
  }
 
  return 0;
}

Measured memory_bytes: 1560
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++) ;
int main() {
ll X;
cin>>X;
for(ll i=-200; i<200; i++){
    for(ll j=-200; j<200; j++){
        if(i*i*i*i*i-j*j*j*j*j==X){
            cout<<i<<" "<<j<<endl;
            i+=500;
          j+=500;
        }
    }
}

}


Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
int main()
  {
//    int n,k,i=1,count=0,v;
    double l=0,n,k,i=1,count=0,v;
  cin>>n>>k;
 while(i<=n)
 {
 	 v=i;
    while(v<k)
    {
     v=v*2;
     count++;
    }
l+=(1/n)*pow(0.5,count);
    count=0;
    i++;
     }
    cout<<fixed<<setprecision(12)<<l;
    i++;
  }

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 2005;

int sum1[MAX_N][MAX_N], sum2[MAX_N][MAX_N], sum3[MAX_N][MAX_N];
int N, M, Q;
char S[MAX_N][MAX_N];

int main() {
  scanf("%d%d%d", &N, &M, &Q);
  for (int i = 1; i <= N; ++i)
    scanf("%s", S[i] + 1);

  int tot = 0, edge = 0;
  for (int i = 1; i <= N; ++i) 
    for (int j = 1; j <= M; ++j) {
      sum1[i][j] = sum1[i - 1][j] + sum1[i][j - 1] - sum1[i - 1][j - 1];
      if (S[i][j] == '1') sum1[i][j]++, tot++;
    }
  for (int i = 1; i <= N + 1; ++i)
    for (int j = 1; j <= M; ++j) {
      sum2[i][j] = sum2[i - 1][j] + sum2[i][j - 1] - sum2[i - 1][j - 1];
      if (S[i][j] == '1' && S[i - 1][j] == '1') sum2[i][j]++, edge++;
    }
  for (int i = 1; i <= N; ++i)
    for (int j = 1; j <= M + 1; ++j) {
      sum3[i][j] = sum3[i - 1][j] + sum3[i][j - 1] - sum3[i - 1][j - 1];
      if (S[i][j] == '1' && S[i][j - 1] == '1') sum3[i][j]++, edge++;
    }
      
  while (Q--) {
    int x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    int rest = sum1[x2][y2] - sum1[x1 - 1][y2] - sum1[x2][y1 - 1] + sum1[x1 - 1][y1 - 1];
    int redge = sum2[x2][y2] - sum2[x1][y2] - sum2[x2][y1 - 1] + sum2[x1][y1 - 1];
    redge += sum3[x2][y2] - sum3[x1 - 1][y2] - sum3[x2][y1] + sum3[x1 - 1][y1];
    printf("%d\n", rest - redge);
  }
  
  return 0;
}


Measured memory_bytes: 52736
#include<bits/stdc++.h>
using namespace std;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
   	#endif
    double a,b;
    cin>>a>>b;
    cout<<round((a+b)/2);
   	return 0;
}

Measured memory_bytes: 3808
a[1<<17];i;s;j;*c;main(b){for(;~scanf("%d",&b);i++?s+=abs(b-a[i-2]):i++)a[i]=b;for(;j++<*a;printf("%d\n",s+abs(b)-abs(*c-c[1])-abs(c[1]-c[2])+abs(*c-c[2])))c=a+j;}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    vector<char> ans;
    rep(i, S.size()) {
        int x = ((S[i] - 'A') + N) % 26;
        ans.push_back('A' + x);
    }
    rep(i, S.size()) {
        cout << ans[i];
    }
    cout << endl;
}

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


Measured memory_bytes: 384
let rec solve cur a b k =
  if a mod cur == 0 && b mod cur = 0 then 
    begin
      if k <= 1 then cur
      else solve (cur - 1) a b (k - 1)
    end
  else solve (cur - 1) a b k

let solve a b k = solve (min a b) a b k

let _ =
  let a, b, k = Scanf.scanf "%d %d %d" (fun a b k -> (a, b, k)) in
  solve a b k
  |> print_int

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

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

    int max_ = max(a, max(b, c));

    int ans = 0;
    ans += (max_ - a) / 2;
    ans += (max_ - b) / 2;
    ans += (max_ - c) / 2;

    int even = max_ % 2;
    int diffNumCount = 0;

    if (a % 2 != even) diffNumCount++;
    if (b % 2 != even) diffNumCount++;
    if (c % 2 != even) diffNumCount++;

    if (diffNumCount == 1) ans += 2;
    if (diffNumCount == 2) ans++;

    cout << ans << endl;

    return 0;
}


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

using namespace std;

const int N = 1e5 + 2;

long long n, x[N], v[N], pref[N], suff[N], a[N], b[N], c[N], d[N], C;
long long ans;

int main(){
      cin >> n >> C;

      for(int i = 1; i <= n; i ++){
            cin >> x[i] >> v[i];
            pref[i] = pref[i - 1] + v[i];
            c[i] = max(c[i - 1], pref[i] - x[i] - x[i]);
      }

      for(int i = n; i >= 1; i --){
            suff[i] = suff[i + 1] + v[i];
            a[i] = pref[i] - x[i];
            b[i] = suff[i] - (C - x[i]);
            d[i] = max(d[i + 1], suff[i] - (C - x[i]) - (C - x[i]));
            ans = max(ans, a[i] + d[i + 1]);
            ans = max(ans, b[i] + c[i - 1]);
            ans = max(ans, max(a[i], b[i]));
      }

      cout << ans << endl;
}


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

int main(int argc, char *argv[])
{
    std::string s, t;
    std::cin >> s >> t;
    int s_n, t_n;
    std::cin >> s_n >> t_n;
    std::string u;
    std::cin >> u;
    if(s == u) {
        --s_n;
    } else {
        --t_n;
    }
    std::cout << s_n << ' '<< t_n << std::endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

cnt = 0
for i in range(n):
    minj = i
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
    if i != minj:
        a[i], a[minj] = a[minj], a[i]
        cnt += 1

print(' '.join(map(str, a)))
print(cnt)



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
const long long INF = 1LL << 60;
//const int INF = 1e9+5;


int main(){
  int n,W;
  cin >> n >> W;
  vector<ll> w(n),v(n);
  rep(i,n) cin >> w[i] >> v[i];
  vector<vector<ll>> dp(n+5,vector<ll>(W+100,0));
  
  for(int i=0;i<n;i++){
    for(int j=0;j<=W;j++){
      
      if(j-w[i] >= 0){
        chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
      }
      
      chmax(dp[i+1][j],dp[i][j]);
      
    }
  }
  cout << dp[n][W] << endl;
} 

Measured memory_bytes: 83328
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
 
using namespace std;
 
double EPS = 1e-10;
 
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
 
  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }
 
  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }
 
  point operator * (double d){
    return point(x*d,y*d);
  }
 
  point operator / (double d){
    return point(x/d,y/d);
  }
};
 
struct segment{ point a,b; };
 
struct circle{ point p; double r; };
 
double dot(point a, point b) { return (a.x * b.x + a.y * b.y); }
 
double cross(point a, point b) { return (a.x * b.y - a.y * b.x); }
 
int ccw(point p0, point p1, point p2){
  point a = p1 - p0;
  point b = p2 - p0;
  if(cross(a,b)>EPS)return +1;
  if(cross(a,b)<EPS)return -1;
  if(dot(a,b)<-EPS)return +2;
  if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y)return -2;
  return 0;
}
 
double vec_abs(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}
 
double distance_ls_p(point a, point b, point c) {
  if ( dot(b-a, c-a) < EPS ) return vec_abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return vec_abs(c-b);
  return abs(cross(b-a, c-a)) / vec_abs(b-a);
}
 
double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
 
int crossCS(point a, point b, circle c){
  double res=distance_ls_p(a,b,c.p);
  double ac=dist(a,c.p);
  double bc=dist(b,c.p);
 
  if(res>c.r || (ac<c.r && bc<c.r))return 0;
  else if(c.r-res<EPS ||(ac<c.r && bc>=c.r)||(ac>=c.r && bc<c.r))return 1;
  else return 2;
}
 
 bool cmp_x(const point& p, const point& q){
  if(p.x != q.x)return p.x<q.x;
  return p.y < q.y;
}

vector<point>convex_hull(point* ps, int n){
  sort(ps,ps+n,cmp_x);
  int k=0;
  vector<point>qs(n*2);
 
  for(int i=0;i<n;i++){
    while(k>1&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0)k--;
    qs[k++]=ps[i];
  }
 
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&cross(qs[k-1]-qs[k-2],ps[i]-qs[k-1])<0)k--;
    qs[k++]=ps[i];
  }
  qs.resize(k-1);
  return qs;
}

int point_contain(point* ps, point p, int n){
  int cnt=ccw(ps[0],ps[1],p);
  ps[n++]=ps[0]; 

  for(int i=0;i<n-1;i++)
    if(cnt!=ccw(ps[i],ps[i+1],p))return 0;
   
  return 1;
}
 
int crossCP(point* ps, circle C, int sz){
 
  double ans=0;
 
  for(int i=0;i<sz;i++){
    double tmp=dist(ps[i],C.p);
    if(tmp>ans)ans=tmp;
  }
 
  if(C.r>=ans)return 2;
 
  vector<point>t=convex_hull(ps,sz);

  int tsz=t.size();
  int res1=point_contain(ps,C.p,tsz);
 
  double res2=100000000;
   t[t.size()]=t[0];
   tsz++;
  for(int i=0;i<tsz-1;i++)
    res2=min(res2,distance_ls_p(t[i],t[i+1],C.p));
 
  if(res1 && C.r<=res2)return 1;
  else if(!res1 && C.r<res2)return 4;
  else return 3;
}
 
int main(void){
  point p[3];
  vector<segment> t;
  circle C;
  string ans="zabcd";
 
  while(true){
    for(int i=0;i<3;i++){
      cin >> p[i].x >> p[i].y;
      if(p[i].x==0 && p[i].y==0)return 0;
    }
    cin >> C.p.x >> C.p.y >> C.r;
 
    int res=crossCP(p,C,3);
    cout << ans[res] << endl;
  }
  return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    int g[12] = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    if (g[x-1] == g[y-1]) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int n, a, b;

int main()
{
    scanf("%d %d %d", &n, &a, &b);

    if (a > b || (n == 1 && a != b)) { printf("0"); return 0; }

    printf("%lld", (b - a + 1) + 1LL * (b - a) * (n - 3));

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e5;
int n,a[55],b[55],c[55],sum;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<n;i++)
		cin>>c[i];
	sum=0;
	for(int i=1;i<=n;i++)
	{
		sum+=b[a[i]];
		if(a[i+1]==a[i]+1)
		sum+=c[a[i]];
	}
	cout<<sum<<endl;
	return 0;
}

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

#define ll long long
#define db double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ino freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

#define fr(i,n) for(i=0;i<n;i++)
#define frs(i,a,n) for(i=a;i<n;i++)
#define frv(i,n) for(i=n-1;i>=0;i--)

#define ne cout<<"\n";
#define cas(i) cout<<"Case #"<<i<<": "

#define vi vector <int>
#define vpi vector <pair <int,int> >
#define vpin(v,a,b) v.push_back(make_pair(a,b))
#define vsort(v) sort(v.begin(),v.end());
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))

#define todegree(rad) rad*(180.0/pi)
#define isnttriangle(a,b,c) (a+b<c||a+c<b||b+c<a)
#define pi acos(-1)
#define siz 1000


int main()
{
    ll n,i,j,k;
    ll x[siz];
    cin>>n;
    fr(i,n) cin>>x[i];

    ll mini=100000000;
    ll sum=0;
    frs(i,1,101)
    {
        sum=0;
        fr(j,n)
        {
            sum+=((x[j]-i)*(x[j]-i));
        }
        if(sum<mini) mini=sum;
    }

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




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

int N;
vector<vector<pair<int, int>>> xy;

bool JUDGE(int bit){
    for(int i = 0; i < N; i++){
        if(!(bit & (1 << i))) continue;
        for(pair<int, int> v : xy[i]){
            if(!(bit & (1 << v.first)) && v.second == 1) return false;
            else if(bit & (1 << v.first) && v.second == 0) return false;
        }
    }
    return true;
}

int main(){
    cin >> N;
    xy.resize(N);
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        xy[i].resize(A);
        for(int j = 0; j < A; j++){
            cin >> xy.at(i).at(j).first >> xy.at(i).at(j).second;
            xy[i][j].first--;
        }
    }

    int res = 0;
    for(int bit = 0; bit < (1 << N); bit++){
        if(JUDGE(bit)){
            int count = 0;
            for(int i = 0; i < N; i++){
                if(bit & (1 << i)) count++; 
            }
            res = max(res, count);
        }
    }
    cout << res << endl;
}

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

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


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def I():
    #1 line 1 int
     return int(sys.stdin.readline().rstrip())
def LI():
    #1 line n int
     return list(map(int,sys.stdin.readline().rstrip().split()))
def S():
    #1 line 1 string
     return sys.stdin.readline().rstrip()
def LS():
    #1 line n strings
     return list(sys.stdin.readline().rstrip().split())


xs=LI()

if xs[0] == xs[1]:
    print(xs[2])
elif xs[0] == xs[2]:
    print(xs[1])
else:
    print(xs[0])

Measured memory_bytes: 9812
#include <iostream>

using namespace std;

int main(){
    int s;
    cin >> s;
    
    int h,m;
    h = s/3600;
    s = s-h*3600;
    m = s/60;
    s = s-m*60;
    cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3088
#include <stdio.h>
int main(){
  int a,b,c,d,e,f;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  e=c-a;//|
  f=d-b;//-
  printf("%d %d %d %d",c-f,d+e,a-f,b+e);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;

typedef long long ll;

ll A_MAX = -1;
ll B[100000];

int N;
ll H;

int main()
{
    cin >> N;
    cin >> H;

    ll a,b;

    for(int i = 0;i < N;i++)
    {
        cin >> a >> b;
        A_MAX = max(A_MAX,a);
        B[i] = b;
    }

    sort(B,B + N);

    int result = 0;

    int cou = N - 1;
    while(A_MAX < B[cou] && 0 <= cou )
    {
        H -= B[cou];
        cou--;
        result++;
        if(H <= 0)
        {
            cout << result << endl;
            return 0;
        }
    }


    int temp = H / A_MAX;
    if(H % A_MAX != 0) temp++;
    result += temp;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 1024
from fractions import gcd


def main():
    n = int(input())
    A = list(map(int, input().split()))

    L = []
    R = []
    for i in range(n):
        if i == 0:
            L.append(A[0])
            R.append(A[-1])
            continue
        L.append(gcd(L[i-1],A[i]))
        R.append(gcd(R[i-1],A[-i-1]))
    R.reverse()

    for i in range(n):
        if i == 0:
            gcd_max = R[1]
        elif i != n-1:
            gcd_max = max(gcd_max, gcd(L[i-1], R[i+1]))
        else:
            gcd_max = max(gcd_max, L[-2])
    print(gcd_max)


if __name__ == '__main__':
    main()


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<int,int>pii;

const int maxn=1e5+55;
int a;
int main() {
	// freopen("Task.in","r",stdin);freopen("Task.out","w",stdout);
	int n;
	cin>>n;
	map<int,set<int> >mpp;
	for(int i=1 ; i<=n ; i++) {
		cin>>a;

		mpp[i].insert(a);
	}
	int cnt=0;
	for(map<int, set<int> >::iterator it=mpp.begin() ; it!=mpp.end() ; it++) {
		int u=it->ff;
		for(set<int>::iterator it2=it->ss.begin() ; it2!=it->ss.end() ; it2++) {
			int v=*it2;
			if(mpp[v].find(u)!=mpp[v].end()) {	
				++cnt;
				mpp[v].erase(u);
				mpp[u].erase(v);
			}
		} 
	}
	
	/*for (int i=1 ; i<=n ; i++) {
		if(a[a[i]]==i)
			cnt++;
	}*/
	// cnt/=2;
	cout<<cnt<<endl;
}

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

int main()
{
    int h, n;
    cin >> h >> n;
    int64_t a;
    int64_t s = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        s += a;
    }

    if (h > s)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>

int main(void) {
	// input
	int n, y;
	std::cin >> n >> y;

	// for
	for(int i_yukichi = 0; i_yukichi <= n; ++i_yukichi) {
		for(int i_higuchi = 0; i_higuchi <= n; ++i_higuchi) {
			int i_noguchi = (y - 10000*i_yukichi - 5000*i_higuchi) / 1000;
			if(i_noguchi >= 0 && y == i_yukichi * 10000 + i_higuchi * 5000 + i_noguchi * 1000 && n == i_yukichi + i_higuchi + i_noguchi) {
				std::cout << i_yukichi << " " << i_higuchi << " " << i_noguchi << std::endl;
				goto _end;
			}
		}
	}

	std::cout << "-1 -1 -1" << std::endl;
	
	_end:
	return 0;
}


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

namespace Calc
{
    class Program
    {

        static void Main(string[] args)
        {
            int[] i = Console.ReadLine().Split(' ')
                    .Select(e => int.Parse(e)).ToArray();
            
            int w = i[0];
            int h = i[1];
            int x = i[2];
            int y = i[3];
            int r = i[4];

            Console.WriteLine(x - r < 0 || x + r > w || y - r < 0 || y + r > h ? "No" : "Yes");
        }
    }
}

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

int main(){
    int n; cin >> n;
    int N[9];
    for(int i=0;i<9;i++){
        N[i] = (i + 1) * 111;
    }
    for(int i=0;i<9;i++){
        if(n <= N[i]){
            cout << N[i] << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	int dp[1<<12];
	void solve(){

			ini(n);
			ini(n1);
			FOR(i,0,1<<12){
				dp[i] = inf;
			}
			dp[0] = 0;
			FOR(i,0,n1){
				ini(x);
				ini(x1);
				int now = 0;
				FOR(i1,0,x1){
					ini(tmp);
					now|=(1<<(tmp-1));
				}
				FOR(i1,0,1<<12)
					dp[i1|now] = min(dp[i1|now],dp[i1]+x);
			}
			if(dp[(1<<n)-1] == inf)out(-1);
			else out(dp[(1<<n)-1]);
		



















	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int a[]={1,3,5,7,8,10,12};
int b[]={4,6,9,11};
int c[]={2};
int main()
{
    int x,y;
    cin>>x>>y;
    int flag1,flag2;
    for(int i=0;i<7;i++)
    {
        if(a[i]==x)
            flag1=1;
        if(a[i]==y)
            flag2=1;
    }
    for(int i=0;i<4;i++)
    {
        if(b[i]==x)
            flag1=2;
        if(b[i]==y)
            flag2=2;
    }
    for(int i=0;i<1;i++)
    {
        if(c[i]==x)
            flag1=3;
        if(c[i]==y)
            flag2=3;
    }
    if(flag1==flag2)
        cout << "Yes" <<endl;
    else
        cout << "No" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll Nagaemon1;
void swap(ll i,ll j){
  Nagaemon1=i;
  i=j;
  j=Nagaemon1;
}
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(void){
  ll q;
  rep(i,5){
    cin >> q;
    if(q==0)cout << i+1;
  }
}

Measured memory_bytes: 3592