akhauriyash/Code-Regression huggingface dataset:
/*..............................................*\
Author:Kishor Kumar Paroi
Dept:CSE-1703053
email.kishor.josephite@gmail.com
RUET,BANGLADESH
\*---------------------------*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vi vector<int>v
//const int N=100*1000;
//const int mod=1e9+7;

//# define int min3(int a,int b,int c){return min(a,min(b,c));}
//#define int max3(int a,int b,int c){return max(a,max(b,c));}
//#define int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
//#define int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    vi;
    int n;
    cin>>n;
    int flag=1;
    while(1)
    {
        if(n==1||n==2||n==4)
        {
            flag+=3;
            break;
        }
        else
        {
            if(n%2==0)
                n/=2;
            else
                n=3*n+1;
        }
        flag++;

    }
    cout<<flag<<endl;


}


Measured memory_bytes: 256
<?php

class In {

	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}
}

class Out {
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

$in = new In();
$out = new Out();

$N = $in->nextInt();
$P = $in->nextInt();

$A = [];
for ($i = 0;$i < $N;$i++) {
	$A[] = $in->nextInt();
}

$dp = [];
for ($i = 0;$i < $N+1;$i++) {
	$dp[] = [];
	for($j = 0;$j < $N+1;$j++) {
		$dp[][] = [];
		for($k = 0;$k < 2;$k++) {
			$dp[$i][$j][$k] = 0;
		}
	}
}

$dp[0][0][0] = 1;
for ($i = 0;$i < $N;$i++) {
	for($j = 0;$j < $N;$j++) {
		$dp[$i+1][$j][0] += $dp[$i][$j][0];
		$dp[$i+1][$j+1][$A[$i]%2] += $dp[$i][$j][0];
		$dp[$i+1][$j][1] += $dp[$i][$j][1];
		$dp[$i+1][$j+1][($A[$i]+1)%2] += $dp[$i][$j][1];
	}
}
$ans = 0;
for ($i = 0;$i <= $N;$i++) {
	$ans += $dp[$N][$i][$P];
}

$out->println($ans);

?>


Measured memory_bytes: 6776
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
int q,w;
char a[1000],b[1000],c[1000];
scanf("%s",a);
scanf("%s",b);
scanf("%s",c);
q=strlen(a);
w=strlen(b);
if(a[q-1]==b[0] && b[w-1]==c[0])
{printf("YES\n");}
else
{
printf("NO\n");}
return 0;
}

Measured memory_bytes: 128
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    bool mark[n + 2];
    memset(mark, 0, sizeof mark);
    int ac = 0, wa = 0;
    forn(i, m) {
        int v;
        string c;
        cin >> v >> c;
        if (mark[v])
            continue;
        else {
            if (c == "WA") {
                mp[v]++;
            } else {
                mark[v] = 1;
                wa += mp[v];
                ac++;
            }
        }
    }
    cout << ac << " " << wa << endl;
    return 0;
}

Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;


int main() {
	int N;
	LL ans = 0;
	cin >> N;
	for (int i = 1; i <= N; ++i) {
		if (i % 3 && i % 5) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main() {
	int n;
	long long k;
	cin >> n >> k;

	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		--a[i];
	}

	vector<vector<int> > to(n, vector<int> (64, -1));

	for(int i = 0; i < n; ++i) {
		to[i][0] = a[i];
	}

	for(int j = 0; j + 1 < 63; ++j) {
		for(int i = 0; i < n; ++i) {
			to[i][j + 1] = to[to[i][j]][j];
		}
	}

	int cur = 0;

	for(int j = 62; j >= 0; --j) {
		if(k & (1LL << j)) {
			cur = to[cur][j];
		}
	}

	cout << cur + 1 << '\n';

	return 0;
}

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

const ll mod=998244353;

ll a[N],dp[N][N];

int main(){
    int n,s;
    cin>>n>>s;
    for(int i=1;i<=n;i++) cin>>a[i];
    ll ans=0;
    for(int i=1;i<=n;i++){
        dp[i][0]++;
        for(int j=0;j<=3000;j++) dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod;
        for(int j=0;j<=3000;j++){
            if(j+a[i]>3000) continue;
            dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+dp[i][j])%mod;
        }

    }
    for(int i=1;i<=n+1;i++){
        ans+=dp[i][s]; ans%=mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

signed main(){

	char a;
	REP(i,0,3){
		cin>>a;
		if(a=='1')cout<<9;
		else cout<<1;
	}
	cout<<endl;

	return 0;
}

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

pa = [int(p) for p in input().split()]
pb = [int(p) for p in input().split()]

pc = []

for c in range(m):
  x, y, d = list(map(int, input().split()))
  pc.append(pa[x-1]+pb[y-1]-d)
  
min_c = min(pc)
if min_c<0:
  min_c=0
min_ab = min(pa)+min(pb)

if min_c < min_ab:
  print(min_c)
else:
  print(min_ab)

Measured memory_bytes: 18488
def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A

def solve(N, A):
    A = sorted(A)
    is_different = True
    for i in range(1, N):
        if A[i-1] == A[i]:
            is_different = False
    return 'YES' if is_different else 'NO'


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 25172
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

int n;
vector<int> x,y;
double ans = 0.0;

signed main() {
   cin >> n;
    vector<int> arr(n);
    rep(i,n) arr[i]=i;
    rep(i,n) {
        int xx,yy;
        cin >> xx>>yy;
        x.push_back(xx);
        y.push_back(yy);
    }
    do{
        double tmp = 0;
        //rep(i,n) cout << arr[i] << flush;
        //cout << "" << endl;
        rep(i,n-1) {
            tmp += sqrt(pow(x[arr[i]]-x[arr[i+1]],2)+pow(y[arr[i]]-y[arr[i+1]],2));
        }
        //cout << tmp << endl;
        ans += tmp;
    }while(next_permutation(arr.begin(),arr.end()));

    double bo=1.0;
    FOR(i,1,n+1) {
        bo*=i;
    }
    cout << setprecision(20)<<ans/bo << endl;

  return 0;
}


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())

//変数
ll X;
ll A;
ll B;

//解法
void solve() {

	X -= A;

	X = X%B;

	cout << X;

	return;
}

int main() {
	//入力
	cin >> X >> A >> B;
	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

const int N = 2e5 + 5;
const int V = 1e6 + 5;

int n;
int arr[N];
int fr[V];


int main()
{
  cin >> n;
  map<int, int> s;
  for(int i = 0; i < n; i++) {
    cin >> arr[i];
    s[arr[i]]++;
  }
  int ans = n;
  for(int i = 0; i < n; i++) {
    if(s[arr[i]] > 1 || arr[i] != 1 && s.count(1)) {
      ans--;
      continue;
    }
    bool good = false;
    for(int d = 2; d * d <= arr[i]; d++) {
      if(arr[i] % d == 0) {
        if(s.count(d) || s.count(arr[i] / d))
          good = true;
      }
    }
    if(good) ans--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>

using namespace std;

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B>C+D) cout << "Left" << endl;
  else if(A+B==C+D) cout << "Balanced" << endl;
  else if(A+B<C+D) cout << "Right" << endl;

  return 0;
}


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



int main(void){
    int d,n;
    cin >> d >> n;
    int ans = 0;
    int num = 1;
    rep(i,d){
        num *= 100;
    }
    for(int i=1;i<=n;i++){
        ans += num;
    }
  	if(n==100){
      	ans += num;
    }
  	cout << ans <<endl;
    
    return 0;
}





























































Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

int main(void) {
  int n, w, ans = 0, a, b, total_v = 0;
  cin >> n >> w;
  vector <int> v(n), weight(n);
  ffor(n) {
	cin >> weight[i] >> v[i];
    total_v += v[i];
  }
  
  vector <pair <bool, int>> dp(total_v + 1, {false, INF}); 
  // contains {reachable, min_weight}
  dp[0] = {true, 0};
  
  ffor(n) {
    for(int j = dp.size() - 1; j >= 0; j--) {
      if (dp[j].first == true && weight[i] + dp[j].second <= w) {
        dp[j + v[i]].first = true;
        dp[j + v[i]].second = min(dp[j + v[i]].second, weight[i] + dp[j].second);
      }
    }
  }
  for(int i = dp.size() - 1; i >= 0; i--) {
    if (dp[i].first == true) {
      cout << i << '\n';
      break;
    }
  }
}

Measured memory_bytes: 3964
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>

using namespace std;

unordered_set<int> vis;

int f(int x) {
	if (x&1)
		return x*3 + 1;
	else
		return x>>1;
}

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int v;
	cin >> v;
	vis.insert(v);
	for (int i = 2; i <= 1000000; ++i) {
		v = f(v);

		if (vis.count(v)) {
			cout << i << endl;
			break;
		}
		vis.insert(v);
	}

	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define LL long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)
#define YES "Yes"
#define NO "No"

using namespace std;

typedef pair<int, int> P;

class BBingo {
public:
    struct A {
        LL num;
        bool f = false;
    };

    void solve(std::istream &cin, std::ostream &cout) {
        A a[3][3];
        LL n;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                cin >> a[i][j].num;
                a[i][j].f = false;
            }
        }
        cin >> n;
        for (int i = 0; i < n; ++i) {
            LL b;
            cin >> b;
            for (int i = 0; i < 3; ++i) {
                for (int j = 0; j < 3; ++j) {
                    if (a[i][j].num == b) {
                        a[i][j].f = true;
                    }
                }
            }
        }

        for (int i = 0; i < 3; ++i) {
            if (a[i][0].f && a[i][1].f && a[i][2].f) {
                cout << YES;
                return;
            }
            if (a[0][i].f && a[1][i].f && a[2][i].f) {
                cout << YES;
                return;
            }
        }
        if (a[0][0].f && a[1][1].f && a[2][2].f) {
            cout << YES;
            return;
        }
        if (a[0][2].f && a[1][1].f && a[2][0].f) {
            cout << YES;
            return;
        }
        cout << NO;
    }
};

int main() {
	BBingo solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef struct{//辺
    int a;//始点終点
    int b;
    int color;//色
}Edge;
typedef struct{//節点
    int num;
    int color;
}Node;
int main(void){
    Edge e[1000000];
    int N; cin >> N;
    vector <vector<int> > map(N+1);//節点に接続している辺
    for(int i=1;i<N;i++){
        cin >> e[i].a >> e[i].b;
        map[e[i].a].push_back(i);
        map[e[i].b].push_back(i);
    }
    e[1].color = 1;
    queue<Node> q;//節点番号と初期色
    q.push((Node){e[1].a,1}), q.push((Node){e[1].b,1});
    int K = 0;
    while(!q.empty()){
        int x = q.front().num; int c = q.front().color; q.pop();
        if(K<map[x].size()) K = map[x].size();
        int clr = 1;
        for(int i=0;i<map[x].size();i++){
            if(e[map[x][i]].color == 0){//未到達なら
                if(c==clr) clr++;//初期色と同値
                e[map[x][i]].color = clr++;
                if(e[map[x][i]].a == x)//今来た節点の反対
                    q.push((Node){e[map[x][i]].b,clr-1});
                else
                    q.push((Node){e[map[x][i]].a,clr-1});
            }
        }
    }
    cout << K << endl;
    for(int i=1;i<N;i++) cout << e[i].color << endl;
    
}


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

int main(){
  int n,k; cin >> n >>k;
  int r = 0;
  REP(i,n){
    int h; cin >> h;
    if(h>=k) r++;
  }
  cout << r << '\n';
}
  

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Dynamic Arrays and List - Vector
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_1_A&lang=jp

"""
import sys


class Vector:
    def __init__(self):
        self.n = 0
        self.d = dict()

    def push(self, x):
        self.d[self.n] = x
        self.n += 1

    def access(self, p):
        return self.d[p]

    def pop(self):
        self.n -= 1


def main(args):
    v = Vector()
    q = int(input())
    for _ in range(q):
        op, x = (input() + ' 1').split()[:2]
        if op == '0':
            v.push(int(x))
        elif op == '1':
            print(v.access(int(x)))
        else:
            v.pop()


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 31952
ans = []
while True:
    n,x = [int(i) for i in input().split()]
    count = 0
    st = []
    if n == 0 and x == 0:
        break
    for i in range(1,n+1):
        for j in range(2,n+1):
                if j <= i:
                    continue
                k = x - (i + j)
                if j < k and k <= n:
                    count += 1
    ans.append(count)

for i in range(len(ans)):
    print(ans[i])



Measured memory_bytes: 5600
#include <iostream>

using namespace std;



int main() {
  int N, min_value, value, ans = -1000000000;
  cin >> N;

  cin >> min_value;
  for (int i = 0; i < N - 1; i ++) {
    cin >> value;
    if (value - min_value > ans) ans = value - min_value;
    if (value < min_value) min_value = value;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll a,b,c;
  cin>>a>>b>>c;
  ll sum=a+b+c;
  if(sum>=22){
    cout<<"bust"<<endl;
  }
else{
cout<<"win"<<endl;
}
}


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

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


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a, b;
	cin >> a >> b;
	if (a.size()>b.size()){ cout << "GREATER" << endl; }
	else if (a.size()<b.size()){ cout << "LESS" << endl; }
	else {
		REP(i, a.size()){
			if (a[i]>b[i]){ cout << "GREATER" << endl; return 0; }
			else if (a[i]<b[i]){ cout << "LESS" << endl; return 0;}
		}
		cout << "EQUAL" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mid ((l+r)/2)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define drep(i,a,b) for(int i=(a);i>=(b);--i)
#define file(a) freopen(#a".in","r",stdin),freopen(#a".out","w",stdout);
const int maxn=2e5+5,mod=1e9+7,inf=0x3f3f3f3f;
int n,m,Q,K,T;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}int a[maxn],b[maxn];
struct node{int l,r,len;}stk[maxn];
int l=1,r,fb[maxn],fa[maxn];
signed main(){
    //file(a);
    n=read();
    rep(i,1,n)a[i]=read(),fa[a[i]]++;
    drep(i,n,1)b[i]=read(),fb[b[i]]++;
    rep(i,1,n)if(fa[a[i]]+fb[a[i]]>n)puts("No"),exit(0);
    rep(i,1,n){
        if(a[i]!=b[i])continue;
        int j=i;
        while(a[j+1]==b[j+1]&&j+1<=n)++j;
        stk[++r]=(node){i,j,j-i+1};i=j;
    }
    while(l<=r){
        int now=0;
        drep(i,n,1){
            if(b[i]!=a[stk[l].l+now]&&b[stk[l].l+now]!=a[i])swap(b[i],b[stk[l].l+now]),++now;
            if(now>=stk[l].len)break;
        }++l;
    }puts("Yes");
    rep(i,1,n)printf("%d ",b[i]);puts("");
    return 0;
    // rep(i,l,r)cout<<stk[i].l<<" "<<stk[i].r<<endl;
    while(l+1<=r){
        node u=stk[l],v=stk[l+1];++l,++l;
        rep(i,0,min(u.len,v.len)-1)swap(b[i+u.l],b[i+v.l]);
        if(u.l+v.len<=u.r)stk[++r]=(node){u.l+v.len,u.r};
        if(v.l+u.len<=v.r)stk[++r]=(node){v.l+u.len,v.r};
    }
    if(l>r){
        puts("Yes");
        rep(i,1,n)printf("%d ",b[i]);puts("");
    }
    else{
        // rep(i,1,n)printf("%d ",b[i]);puts("");
        // cout<<stk[l].l<<" "<<stk[l].r<<endl;
        int now=0;
        drep(i,n,1){
            if(b[i]!=a[stk[l].l]&&b[stk[l].l]!=a[i])swap(b[i],b[stk[l].l+now]),++now;
            if(now>=stk[l].len)break;
        }puts("Yes");
        rep(i,1,n)printf("%d ",b[i]);puts("");
    }


    return 0;
}


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

long long dp[100001][3];

int find(int a[][3],int n)
{
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];


	for(int i=1;i<n;i++)
	{
		for(int j=0;j<3;j++)
			dp[i][j] = a[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
		
	
}

	return max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);


}

int main()
{
	int n;
	cin>>n;
	int a[n][3];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}

	int ans=find(a,n);

	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int x[200000];
signed main(){
	int a,sum=0,cnt=0,ans=INF;
	cin>>a;
	f(i,a){
		cin>>x[i];
		sum+=x[i];
	}
	f(i,a){
		cnt+=x[i];
		ans=min(ans,abs(cnt*2-sum));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

int ba[55];
int all[55];

int ans(int le, int x) {
	if (x <= 0) {
		return 0;
	}
	if (le == 0) {
		return 1;
	}
	if (1 + ba[le - 1] >= x) {
		return ans(le - 1, x - 1);
	}
	else {
		return 1 + all[le - 1] + ans(le - 1, x - 2 - ba[le - 1]);
	}
}

signed main() {
	int n, x;
	cin >> n >> x;
	ba[0] = 1;
	all[0] = 1;
	rep(i, n) {
		ba[i + 1] = ba[i] * 2 + 3;
		all[i + 1] = all[i] * 2 + 1;
	}
	cout << ans(n, x) << endl;

	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "algorithm"
#include "math.h"

using namespace std;

bool prime3(int m)
{
  double sqrt_m = sqrt(m);
  for (int i = 3; i <= sqrt_m; i += 2)
  {
    if (m % i == 0)
    {
      return false;
    }
  }
  return true;
}

int main()
{
  vector<int> a;
  a.push_back(2);
  int m = 3;
  while (a.size() < 55)
  {
    if (prime3(m))
    {
      a.push_back(m);
    }
    m += 10;
  }

  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    cout << a[i] << " ";
  }
  cout << "\n";
}

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

int N,L,A[100005],pt;
int main()
{
  cin >> N >> L;pt=-1;
  for(int i=0;i<N;i++)
    cin >> A[i];

  for(int i=0;i<N-1;i++)
    if(A[i]+A[i+1]>=L)
      {pt=i;break;}

  if(pt==-1)
    cout << "Impossible\n";
  else
    {
      cout << "Possible\n";
      for(int i=0;i!=pt;i++)
	cout << i+1 << '\n';
      for(int i=N-2;i!=pt;i--)
	cout << i+1 << '\n';
      cout << pt+1 << '\n';
    }
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
int main(){
    int n,m,k;
    cin>>n>>m>>k;
    int a[m];
    rep(i,m){
        cin>>a[i];
        --a[i];
    }
    map<int,int> mp;
    rep(i,m)mp[a[i]]=i;
    int v[n][k];
    rep(i,n){
        rep(j,k){
            cin>>v[i][j];
            --v[i][j];
        }
    }
 
    int all=1<<m;
    vector<int> dist(all,inf);
    dist[all-1]=0;
    queue<int> que;
    que.push(all-1);
    while(que.size()){
        int p=que.front();
        que.pop();
        vector<int> cur;
        rep(i,m){
            if(p&(1<<i))cur.push_back(a[i]);
        }
        rep(i,k){
            int nxt=0;
            for(auto e : cur){
                if(mp.count(v[e][i])){
                    nxt|=1<<mp[v[e][i]];
                }
            }
            if(dist[nxt]>dist[p]+1){
                dist[nxt]=dist[p]+1;
                que.push(nxt);
            }
        }
    }
    cout<<dist[0]<<endl;
    return 0;
}


Measured memory_bytes: 3456
L, R = map(int,input().split())
if R - L >= 2018:
    print(0)
else:
    a = L % 2019
    b = R % 2019
    if b < a:
        b += 2019
    ans = 2018
    for i in range(a,b+1,1):
        for j in range(i+1,b+1,1):
            if ans > (i*j) % 2019:
                ans = (i*j) % 2019
    print(ans)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define br break
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n ;
    cin >> n ;
    vl v ;
    v.pb(-1) ;
    forn(i , 1 , n ) {
       ll x;
       cin >> x;
       v.pb(x) ;
    }
    vl left ,  right ;
    ll ans = 1e18 ;
    forn(i , 1 , n){
        left.cl ;
        right.cl ;
       forn(k , 1 , i){
          left.pb(v[k]);
       }
       forn(k , i+1 ,n){
          right.pb(v[k]);
       }
       ll foo = acc(left) ;
       ll fiz = acc(right) ;
       ll res = abs(foo - fiz);
       ans = min(ans , res) ;
    }
    cout << ans << el ;
}































Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from collections import deque

def main():
    N = int(readline())
    path = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, c = map(int, readline().rstrip().split())
        path[a-1].append((b-1, c))
        path[b-1].append((a-1, c))
    Q, K = map(int, readline().rstrip().split())
    K -= 1

    dist = [-1] * N
    dist[K] = 0
    
    que = deque([K])
    while que:
        pre = que.popleft()
        for next, d in path[pre]:
            if dist[next] == -1:
                dist[next] = dist[pre] + d
                que.append(next)

    for _ in range(Q):
        x, y = map(int, readline().rstrip().split())
        print(dist[x-1] + dist[y-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 43800
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main() {
	vector<int>a, b, c;
	int n, i, x;
	vector<int>::iterator m, l;
	long long int count;
	
	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> x;
		a.push_back(x);
	}
	for (i = 0; i < n; i++) {
		cin >> x;
		b.push_back(x);
	}
	for (i = 0; i < n; i++) {
		cin >> x;
		c.push_back(x);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	count = 0;

	for (i = 0; i < n; i++) {
		m = lower_bound(a.begin(), a.end(), b[i]);
		l = upper_bound(c.begin(), c.end(), b[i]);
		
		count += (m - a.begin())*(n - (l - c.begin()));
	}

	cout << count;

	return 0;
}

Measured memory_bytes: 1784
import Control.Monad

battle [] score0 score1 = [score0, score1]
battle (d:ds) score0 score1 = if str0 > str1
  then battle ds (score0 + 3) score1
  else if str0 < str1
    then battle ds score0 (score1 + 3)
    else battle ds (score0 + 1) (score1 + 1)
  where
    str0 = d !! 0
    str1 = d !! 1

main = do
  n <- readLn
  d <- replicateM n $return . words =<< getLine
  putStrLn . unwords . map show $ battle d 0 0

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

using namespace std;

#define REPI(x) for(int i=0;i<x;i++)
#define REPJ(x) for(int j=0;j<x;j++)
#define SCANFD(x) scanf("%d",&x)

int main(){
    string a,b;
    int flag = -2;
    cin >> a >> b;

    if(a.size() < b.size())
        flag = -1;
    else if(a.size() > b.size())
        flag = 1;
    else {
        for(int i=0;i<a.size();i++){
            if(a[i]<b[i]){
                flag = -1;
                break;
            }else if(a[i]>b[i]){
                flag = 1;
                break;
            }
        }
        if(flag == -2)
            flag = 0;
    }

    if(flag == -1)
        printf("LESS\n");
    else if(flag == 0)
        printf("EQUAL\n");
    else
        printf("GREATER\n");
    return 0;
}


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

int main() {
  int n;
  while(cin >> n && n) {
    int a[n][n];
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin >> a[i][j];
    int b[n],c[n];
    for(int i=0;i<n;i++) {
      b[i]=1<<29;
      c[i]=0;
      for(int j=0;j<n;j++){
        b[i]=min(b[i],a[i][j]);
        c[i]=max(c[i],a[j][i]);
      }
    }
    int ans=0;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(b[i]==c[j])ans=b[i];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1156
import java.util.*;

public class Main{
  public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
    Long H=sc.nextLong();
    Long heaviness=1L;
    Long count=0L;
    
    while(H>1){
      H=H/2;
      count+=heaviness;
      heaviness*=2;
    }
    
    count+=heaviness;
    System.out.println(count);
  }
}

Measured memory_bytes: 23892
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;

bool vis[2005];
int d[2005],h[2005],tot;
int n,v[2005];
struct Edge{
	int x,next;
}e[10005];

void add_edge(int x,int y){
	e[++tot].x=y;
	e[tot].next=h[x],h[x]=tot;
}

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

void dfs(int x){
	vis[x]=true;
	for(int i=1;i<=n;i++){
		if(vis[i])continue;
		if(gcd(v[x],v[i])==1)continue;
		add_edge(x,i),d[i]++;
		dfs(i);
	}
}

void solve(){
	priority_queue<int> q;
	for(int i=1;i<=n;i++)
		if(d[i]==0)q.push(i),vis[i]=false;
	while(!q.empty()){
		int x=q.top();q.pop();
		for(int i=h[x];i;i=e[i].next){
			if(!vis[e[i].x])continue;
			d[e[i].x]--;
			if(d[e[i].x]==0){
				vis[e[i].x]=false;
				q.push(e[i].x);
			}
		}
		printf("%d ",v[x]);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",v+i);
	sort(v+1,v+n+1);
	for(int i=1;i<=n;i++)if(!vis[i])dfs(i);
	solve();
}

Measured memory_bytes: 512
S = input()
T = input()
S +=S
T +=T
for i in range(0,len(S)//2):
    flag = True
    for k in range(0,len(S)//2):
        if T[k+i] != S[k]:
            flag = False
    if flag == True:
        print("Yes")
        exit()
print("No")

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

int main() {
    int n, t, c, tt;
    cin >> n >> t;
    
    int ans = INT_MAX;
    for (int i = 0; i < n; i++) {
        cin >> c >> tt;
        if (tt <= t) {
            ans = min(ans, c);
        }
    }

    if (ans == INT_MAX)
        cout << "TLE" << endl;
    else
        cout << ans << endl;
}

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

int main(){
    int H,W;
    
    while(1){
        cin >> H >> W;
        if(H==0 && W==0){break;}
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i==0 || j==0 || j==W-1 || i==H-1){cout << "#";}
                else{cout << ".";}
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


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


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    k = input_int()
    t = 7
    for i in range(1000000):
        t %= k
        if t == 0:
            print(i + 1)
            return
        t = t * 10 + 7

    print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9136
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		long[][] cnt=new long[20][20];
		long ans=0;
		for (int i=0;i<N;++i) {
			double A=sc.nextDouble();
			int c5=-9,c2=-9;
			long a=(long)(A*1e9+.1);
			while (c5<9 && a%5==0) {
				++c5;
				a/=5;
			}
			while (c2<9 && a%2==0) {
				++c2;
				a/=2;
			}
			for (int u=-10;u<10;++u) {
				for (int v=-10;v<10;++v) {
					if (u+c2>=0&&v+c5>=0) ans+=cnt[u+9][v+9];
				}
			}
			cnt[c2+9][c5+9]++;
		}
		System.out.println(ans);
	}
}


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

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("../input.txt","r",stdin);

    string A,B;
    cin >> A >> B;

    bool isEqualSize = ((ll)A.size() == (ll)B.size());
    bool isAGreater = ((ll)A.size() > (ll)B.size());

    if(isAGreater){
        cout << "GREATER\n";
    }else if(isEqualSize){
        if(A == B){
            cout << "EQUAL\n";
        }else{
            for (ll i = 0; i < A.size(); ++i) {
                if((A[i]-'0') < (B[i]-'0')){
                    cout << "LESS\n";
                    return 0;
                }else if((A[i]-'0') > (B[i]-'0')){
                    cout << "GREATER\n";
                    return 0;
                }
            }
            cout << "EQUAL\n";
            return 0;
        }
    }else{
        cout << "LESS\n";
    }

}

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

bool triangle(ll a, ll b, ll c) {
    if (a > b and a > c) {
        return a < b + c;
    }
    else if (b > c and b > a) {
        return b < a + c;
    }
    else if (c > a and c > b) {
        return c < b + a;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    vector<ll> l(n);
    rep(i, n) cin >> l[i];
    int cnt = 0;
    rep(i, n) {
        for (int j = i+1; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                if (l[i] != l[j] and l[j] != l[k] and l[k] != l[i] and triangle(l[i], l[j], l[k])) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    
    vector<int> p(4);
    rep(i,4)cin>>p[i];

    sort(p.begin(),p.end());

    cout<<abs(p[3]-p[2]-p[1]+p[0])<<endl;
    return 0;

}
/*


*/



Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll a,b;
    cin>>a>>b;
    cout<<(a*b)/__gcd(a,b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

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

	atcoder::dsu d(n);
	while(q--) {
		int type, x, y; scanf("%d%d%d", &type, &x, &y);

		if(type) {
			printf("%d\n", d.same(x, y));
		} else {
			d.merge(x, y);
		}
	}
	return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
#define DEBUG_PRINT(var) std::cout << #var << " = " << var << "\n";

int main()
{
    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = s.size();
    if (n <= k) {
        cout << s << "\n";
    }
    else {
        cout << s.substr(0,k);
        cout << "...\n";
    }
    return 0;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

const ll LINF = 1001002003004005006ll;
int n;
int a[3010];
ll memo[3010][3010];
bool used[3010][3010];

ll rec(int s, int t) {
    if (s == t) return 0;
    if (used[s][t]) return memo[s][t];
    used[s][t] = true;
    ll ans = -LINF;
    chmax(ans, a[s] - rec(s+1, t));
    chmax(ans, a[t-1] - rec(s, t-1));
    return memo[s][t] = ans;
}

int main() {
    scanf("%d", &n);
    rep(i, n) scanf("%d", &a[i]);
    cout << rec(0, n) << endl;
    return 0;
}


Measured memory_bytes: 78464
import scala.io.StdIn._
object Main extends App {
  def gcd(l: Int, r: Int): Int = if (r == 0) l else gcd(r, (l % r))
  val Array(n, x) = readLine.split(" ").map{_.toInt}
  val xs = readLine.split(" ").map{xi => Math.abs(xi.toInt - x)}
  println(xs.reduce{gcd(_, _)})
}

Measured memory_bytes: 42344
#include<iostream>
#include<fstream>

using namespace std;

	ifstream fin;
	ofstream fout;

	//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1160&lang=jp

	int gomi = 0;

	int a[52][52] = {};
	int check(int, int);

	int main(){

		fin.open("input.txt");
		fout.open("output.txt");

		//		int w = 0, h = 0;
		int width = 0, height = 0;
		int count = 0;


		while (1){
			for (int i = 0; i < 50; i++)
				for (int j = 0; j < 50; j++)
					a[i + 1][j + 1] = 0;

			cin >> width >> height;
			if (width == 0 && height == 0)break;

			for (int i = 0; i < height; i++){
				for (int j = 0; j < width; j++){
					//初期化
					gomi = a[i + 1][j + 1] = 0;

					cin >> a[i + 1][j + 1];
				}
			}

			for (int i = 0; i < height; i++){
				for (int j = 0; j < width; j++){
					if (a[i + 1][j + 1] == 1){
						check(i + 1, j + 1);
//						a[i + 1][j + 1] = 1;
						count++;
					}
				}
			}
			cout << count << endl;
			fout << count << endl;

			//初期化
			count = 0;
			for (int i = 0; i < height; i++){
				for (int j = 0; j < width; j++){
					a[i + 1][j + 1] = 0;
				}
			}
		}
	}

	int check(int y, int x){
		for (int i = -1; i <= 1; i++){
			for (int j = -1; j <= 1; j++){
				if (i + j != 0 || i - j != 0){
					if (a[y + i][x + j] == 1){
						a[y + i][x + j] = 0;
						check(y + i, x + j);
					}
				}
			}
		}
		return 0;
	}

/*	int check(int y, int x){
		if (a[y + 1][x] == 1){
			a[y + 1][x] = 0;
			check(y + 1, x);
		}
		//-----------------------------
		if (a[y][x + 1] == 1){
			a[y][x + 1] = 0;
			check(y, x + 1);
		}
		//-----------------------------
		if (a[y - 1][x] == 1){
			a[y - 1][x] = 0;
			check(y - 1, x);
		}
		//-----------------------------
		if (a[y][x - 1] == 1){
			a[y][x - 1] = 0;
			check(y, x - 1);
		}
		//-----------------------------
		if (a[y + 1][x + 1] == 1){
			a[y + 1][x + 1] = 0;
			check(y + 1, x + 1);
		}
		//-----------------------------
		if (a[y + 1][x - 1] == 1){
			a[y + 1][x - 1] = 0;
			check(y + 1, x - 1);
		}
		//-----------------------------
		if (a[y - 1][x + 1] == 1){
			a[y - 1][x + 1] = 0;
			check(y - 1, x + 1);
		}
		//-----------------------------
		if (a[y - 1][x - 1] == 1){
			a[y - 1][x - 1] = 0;
			check(y - 1, x - 1);
		}
		//-----------------------------
		return 0;
	}*/

Measured memory_bytes: 1432
n,k=map(int,input().split())

a=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append([ai,bi])
    
a.sort()

sumb=0
for i in range(n):
    sumb=sumb+a[i][1]
    if sumb>=k:
        print(a[i][0])
        break
    


Measured memory_bytes: 20104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define N 1000000
int main()
{
   ll n;
   cin >> n;
   string s;
   map<string ,ll> m;
   ll ans = 0;
   for(ll i=0; i<n ; i++)
   {
        cin >> s;
        sort(s.begin() , s.end());
        ans += m[s];
        m[s]++;
   }
   cout << ans;
}     
     
     

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;

int main() {
	string s, t;
	cin >> s >> t;
	bool ans = true;
	for(int i = 0; i < (int)s.size(); i++) {
		if(s[i] != t[i]) {
			ans = false;
		}
	}
	if(t.size() != s.size() + 1) {
		ans = false;
	}
	if(ans) {
		cout << "Yes" <<endl;
	}else {
		cout << "No" << endl;
	}
}

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

int main () {
  int a, b, ans;
  cin >> a >> b;
  
  for (int i = 1; i <= 3; i++) {
    if (a==i) {
      ans += 4-i;
    }
    if (b==i) {
      ans += 4-i;
    }
  }
  if (a==1 && b==1) {
    ans += 4;
  }
  cout << ans * 100000 << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int c = 0;
	int cnt = 0;

	for(int i = 1; i <= n; i++) {
		if(i%2 == 0) continue;
		for(int j = 1; j <= i ; j++) {
		    if( i%j == 0 ) c++;
		    if(c > 8) break;
		}
		if(c == 8) {
			cnt++;
		}
		c = 0;

	}

	cout << cnt;

	return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  string s[n];
  
  for(int i = 0; i < n;i++){
    cin >> s[i];
  }
  
  sort(s,s+n);
  
  for(int i = 0; i < n;i++){
    cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    d = [0] * K
    A = [0] * K
    for i in range(K):
        d[i] = int(input())
        A[i] = list(map(int, input().split()))

    tmp = [0] * N
    for i in range(K):
        for a in A[i]:
            tmp[a-1] += 1

    ans = tmp.count(0)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192