akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

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

    ll ans = 1;
    for (int d1 = 1; d1 * d1 <= M; ++d1) {
        if (M % d1) continue;

        ll rest1 = M - N * d1;
        if (rest1 >= 0 && rest1 % d1 == 0 && d1 > ans) {
            ans = d1;
        }

        ll d2 = M / d1;
        ll rest2 = M - N * d2;
        if (rest2 >= 0 && rest2 % d2 == 0 && d2 > ans) {
            ans = d2;
        }
    }

    write(ans);
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int i, j;
	for (i = 1; i < 10; i++) {
		for (j = 1; j < 10; j++) {
			cout << i << "x" << j << "=" << i * j << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define PI (3.14159265358979323846)
#define INF (2147483647)
#define INF_LL (9223372036854775807)
#define DIV_NUM (1000000007)
typedef long long ll;

// 配列初期化テンプレ
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
	std::fill((T*)array, (T*)(array + N), val);
}

bool cmp(const int& data, const int& key) {
	return data < key;
}

int customSearch(const vector<int>& data, const size_t& N, const int& key) {

	int lo = 0;
	int hi = N; // data array size

	while (lo < hi) {							// (lo=hiの１点に収束するまで続ける)
		int mid = (lo + hi) / 2;				// loとhiの中間地点の値を確認
		if (cmp(data[mid], key)) lo = mid + 1;	// LISの値より入力が大きかったら、loを持ち上げる
		else               hi = mid;			// LISの値が入力より小さかったら、hiを下げる
	}
	// lo：input <= key となる最初のindex
	return lo;
}

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

	int q;
	cin >> q;

	for (int i = 0; i < q; i++) {
		int key;
		cin >> key; // 探したい数

		int index = customSearch(input, n, key);

		// lo：input <= key となる最初のindex
		if (index == n) {
			// 配列に見つからなかった場合
			cout << "0" << endl;
		}
		else if(input[index]==key){
			cout << "1" << endl;
		}
		else {
			cout << "0" << endl;
		}

	}

	return 0;

}



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

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

    vector<int> seq(n);
    for(int i=0; i<n; i++){
        cin >> seq[i];
    }
    for(int i=seq.size()-1; i>0; i--){
        cout << seq[i] << " ";
    }
    cout << seq[0] << endl;
    return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
};

/** Problem2585 : 1 Day Passport **/
const int MAX = 100;
struct edge {
	int from, to, cost, h, r;
	edge(int f, int t, int c, int _h, int _r):from(f), to(t), cost(c), h(_h), r(_r){}
	edge(){}
};



int main()
{
	int N, M, H, K;
	while (cin>>N>>M>>H>>K, N||M||H||K) {
		vector<edge> G;
		int pass[256];
		
		
		rep(i, M) {
			int a, b, c, h, r;
			cin>>a>>b>>c>>h>>r;
			a--, b--, r--;
			G.push_back(edge(a, b, c, h, r));
			G.push_back(edge(b, a, c, h, r));
		}
		
		int S, T;
		cin>>S>>T; S--, T--;
		
		int P; cin>>P;
		
		for (int i=0; i<256; i++) pass[i] = INF;
		pass[0] = 0;
		
		rep(i, P) {
			int l, d; cin>>l>>d;
			int k=0;
			rep(j, l) {
				int kk; cin>>kk;
				k |= 1<<(kk-1);
			}
			pass[k] = d;
		}
		
		while (true) {
			bool update = false;
			for (int i=0; i<1<<K; i++) {
				for (int j=0; j<1<<K; j++) {
					if (i!=j && pass[i|j] > pass[i]+pass[j]) {
						pass[i|j] = pass[i]+pass[j];
						update = true;
					}
				}
			}
			if (!update) break;
		}
		
		int ans = INF;
		for (int i=0; i<1<<K; i++) {
			vector<edge> G2 = G;
			for (int j=0; j<G2.size(); j++) {
				if ((i>>G2[j].r) & 1) G2[j].cost=0;
			}
			
			// Bellman-Ford
			int d[100][25];
			
			fill(d[0], d[0]+100*25, INF);
			rep(h, H+1) d[S][h]=0;
			
			while (true) {
				bool update=false;
				for (int j=0; j<G2.size(); j++) {
					edge e = G2[j];
					for (int h=0; h+e.h<H+1; h++) {
						if (d[e.to][h+e.h]>d[e.from][h]+e.cost) {
							d[e.to][h+e.h] = d[e.from][h] + e.cost;
							update = true;
						}
					}
				}
				if (!update) break;
			}
			
			for (int h=0; h<H+1; h++) {
				ans = min(ans, d[T][h]+pass[i]);
			}
		}
		
		cout << (ans==INF?-1:ans) << endl;
	}
}

Measured memory_bytes: 1248
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <cmath>
#include <math.h>
#include <ctime>
#include <cstring>
#include <climits>
#include <sstream>
#include <array>
#include <tuple>
#include <set>
#include <iterator>
#include <cstdio>
#include <string>
#include <stack>
#include <valarray>
#include <utility>
#include <iomanip>
#include <list>
#include <numeric>
#include <regex>
#include <map>
#include <queue>
#include <deque>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll          long long
#define PI          3.1415926535
#define pb          push_back
#define ins         insert
#define INF         LLONG_MAX
#define mk          make_pair
#define lb(v,x)     lower_bound(all(v),x)
#define ub(v,x)     upper_bound(all(v),x)
#define ff          first
#define ss          second
#define rev         reverse
#define uset        unordered_set
#define umap        unordered_map
#define endl        "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a)       (ll)a.size()
#define double      long double
#define minpq       priority_queue <ll,vector<ll>,greater<ll> > 
#define fill(x,y)   memset(x,y,sizeof(x))
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define MOD         1000000007 //1e9+7
#define bp(n)       __builtin_popcountll(n)
#define mxt(a)      *(max_element(a.begin(),a.end()))
#define mnt(a)      *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i, a, b) for(ll i = (a); i<= (b); ++i)
#define trav(a, x) 	 for(auto &a : x)
#define re(i,n)      for(ll i = 0; i < n; ++i) 
const ll N = 2e5 + 7;
typedef pair<ll,ll>   pii;
typedef vector<pii>   vpii;
typedef vector<ll>    vll;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
template<typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template<typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0){ if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
ll sqr(ll x) { return x * x;}
// always use 1ll*ans to avoid signed integer overflow; 
void prec(){

}
ll dp[102][N],val[102];
ll wt[102];

ll f(ll i,ll v)
{			
	//cout<<i<<" " <<v<<endl; 
	if(v<=0) return 0;
	if(i==-1) return INT_MAX;
	ll &ans=dp[i][v];

	if(ans!=-1) return ans;
	ans=f(i-1,v);
	ans=min(ans,f(i-1,v-val[i])+wt[i]);
	return ans;
}
void solve(){
	int n,W;cin>>n>>W;
	rep(i,0,n-1) cin>>wt[i]>>val[i];
	fill(dp,-1);
	ll ans;
	for(ll i=0;i<=100000;i++) if(f(n-1,i)<=W) ans=i;
	cout<<ans<<endl;
}

int main()
{
    ios;
    int tc=1;
    //cin>>tc;
    prec();
    while(tc--)
    	solve();
    return 0; 
}


Measured memory_bytes: 159744
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		// 計算
		int result = 0;
		result = min(min(max(0, d-a), max(0, b-c)), min(max(0, b-a), max(0, d-c)));
		
		// 出力
		System.out.println(result);
	}
}




Measured memory_bytes: 23764
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
lis = list(input())
lis.sort()
for i in range(N-1):
    string = list(input())
    nx = []
    for l in lis:
        if l in string:
            nx.append(l)
            string.remove(l)
    lis = nx
lis.sort()
print(''.join(lis))

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


int main() {
    int  a;
    cin >> a;
    if (a / 100 == a % 10) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    
 
    
    return 0;
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
typedef struct {
	int to;
	int cost;
} edge;

int main( void ){
	cin.tie( 0 );
	ios::sync_with_stdio( false );
	int N;
	cin >> N;
	vector <vector <edge> > G( N );
	vector <ll> cost( N, -1 );
	rep( i, 0, N - 1 ){		// グラフ定義, 0オリジン
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		G[ a ].push_back( edge{b, c} );
		G[ b ].push_back( edge{a, c} );
	}
	int Q, K; cin >> Q >> K;
	K--;
	cost[ K ] = 0;
	queue <int> que;
	que.push( K );
	while(!que.empty()){	// BFS
		int q = que.front(); que.pop();
		for(auto e:G[ q ]){	// つながってる部屋毎に
			if (cost[ e.to ] != -1)
				continue;
			cost[ e.to ] = cost[ q ] + e.cost;
			que.push( e.to );
		}
	}
	rep( i, 0, Q ){
		int a, b; cin >> a >> b;
		printf("%lld\n", cost[a-1]+cost[b-1]);
	}
}


Measured memory_bytes: 8820
N = int(input())
S = str(input())
ans = 0
if N == 3:
  if S == 'ABC':
    ans += 1
else:
  for i in range(N-2):
    if S[i] == 'A' and S[i+1] == 'B' and S[i+2] == 'C':
      ans += 1
print(ans)

Measured memory_bytes: 3060
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  var a = intShift();
  var b = intShift();
  
  var sum = 0;
  for(var i = a; i <= b; i++){
  	var j = ~~i.toString().split(NOSP).reverse().join(NOSP)
    if(i == j)sum++;
  }
  return sum;
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
31415 92653
`);

Measured memory_bytes: 17424
#include<bits/stdc++.h>
using namespace std;
int h,w,a[505][505],ans,opt1[250005],opt2[250005],opt3[250005],opt4[250005];
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			int nextx,nexty;
			if(i==h&&j==w) break;
			if(j==w) nextx=i+1,nexty=j;
			else nextx=i,nexty=j+1;
			if(a[i][j]%2)
			{
				opt1[ans]=i;
				opt2[ans]=j;
				opt3[ans]=nextx;
				opt4[ans++]=nexty;
				a[nextx][nexty]++;
			}
		}
	}
	printf("%d\n",ans);
	for(int i=0;i<ans;i++)
	{
		printf("%d %d %d %d\n",opt1[i],opt2[i],opt3[i],opt4[i]);
	}
	return 0;
}

Measured memory_bytes: 6016
/**
 * Я слил Atcoder Beginner Contest 172, решив всего две задачи!
 * Я не могу апнуть синего!
 * Я постоянно сливаю раунды, либо не решив тупую задачу, либо набрав штрафа!
 * Я постоянно уступаю всем своим друзьям и знакомым в контестах и нахожу этому оправдания!
 * Я постоянно придумываю сложные неверные решения к простым задачам!
 * -------------------------------------------------------------
 * -Решать сложные задачи
 * -Участвовать в контестах
 * -Делать виртуальные соревнования
 * -------------------------------------------------------------
 * Не уберу это, пока не начну нормально решать задачи, а не заниматься ерундой!!!
**/
  
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
 
typedef long long  ll;

#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define halt {cout<<"NO"; return 0;}

const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int N = 200010;
const int INF = 1e8;
const ll LL_INF=1e10;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

vector<int> adj[N];
vector<bool> used(N,0);
vector<ll> v;
vector<ll> otv(N);

ll ans=0;
void dfs(int s)
{
         if(used[s]) return;
         used[s]=true;
         if(s!=1) 
         {
                   ans+=v.back();
                  
         }
        otv[s]=v.back();
        v.pop_back();
        for(auto x: adj[s])
        {
                  dfs(x);
        }
         
}

int main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int questions=1;
 // cin>>questions;
 
 while(questions--)
 {
   int n;
   cin>>n;
   int z=n-1;
   while(z--)
   {
             int a,b;
             cin>>a>>b;
             adj[a].pb(b);
             adj[b].pb(a);
   }
   v.resize(n);
   forn cin>>v[i];
   
   sort(all(v));
 //  for(auto x: v) cout<<x<<" ";
   dfs(1);
   cout<<ans;
   kek;
   for(int i=1;i<=n;i++) cout<<otv[i]<<" ";
   
   
   
          
          
          
         
 }
 
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

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

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

  vector<pair<ll,int>> fs;
  for(ll i=2;i*i<=n;++i){
    int x=0;
    while(n%i==0){
      n/=i;
      ++x;
    }
    fs.emplace_back(i,x);
  }
  if(n!=1) fs.emplace_back(n,1);

  int ans=0;
  for(auto p:fs){
    int x = p.second;
    int b = 1;
    while(b <=x){
      x -=b;
      ++b;
      ++ans;
    }
  }
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 19764
#include <iostream>
#include <numeric>
#include <vector>
#include <tuple>

template <class Dist>
struct WeightedUnionFind {
    std::vector<int> par, sz;
    std::vector<Dist> dist;  // A[par[v]] - A[v] = dist[v]
    int gnum;

    explicit WeightedUnionFind(int n)
        : par(n), sz(n, 1), dist(n, 0), gnum(n) {
        std::iota(par.begin(), par.end(), 0);
    }

    int find(int v) {
        if (par[v] == v) {
            return v;
        } else {
            int p = find(par[v]);
            dist[v] += dist[par[v]];
            return par[v] = p;
        }
    }

    // A[u] - A[v] = d
    void unite(int u, int v, Dist d) {
        find(u), find(v);
        d += dist[u];
        d -= dist[v];
        u = par[u], v = par[v];
        if (u == v) return;

        if (sz[u] < sz[v]) {
            std::swap(u, v);
            d = -d;
        }

        sz[u] += sz[v];
        par[v] = u;
        dist[v] = d;
        --gnum;
    }

    // A[u] - A[v]
    Dist diff(int u, int v) {
        find(u), find(v);
        return dist[v] - dist[u];
    }

    bool same(int u, int v) { return find(u) == find(v); }
    bool ispar(int v) { return v == find(v); }
    int size(int v) { return sz[find(v)]; }
};

void solve() {
    int h, w, n;
    std::cin >> h >> w >> n;

    std::vector<std::vector<std::pair<int, int>>> gs(h);
    while (n--) {
        int x, y, v;
        std::cin >> x >> y >> v;
        --x, --y;
        gs[x].emplace_back(y, v);
    }

    WeightedUnionFind<int> wuf(w);
    for (const auto& g : gs) {
        int m = g.size();
        for (int i = 0; i + 1 < m; ++i) {
            int u = g[i].first, v = g[i + 1].first;
            int d = g[i].second - g[i + 1].second;

            if (wuf.same(u, v)) {
                if (wuf.diff(u, v) != d) {
                    std::cout << "No" << std::endl;
                    return;
                }
            } else {
                wuf.unite(u, v, d);
            }
        }
    }

    std::vector<int> minidx(w);
    std::iota(minidx.begin(), minidx.end(), 0);
    for (int v = 0; v < w; ++v) {
        int p = wuf.find(v);
        if (wuf.diff(v, p) < wuf.diff(minidx[p], p)) {
            minidx[p] = v;
        }
    }

    for (const auto& g : gs) {
        for (auto t : g) {
            int y, v;
            std::tie(y, v) = t;

            int p = wuf.find(y);
            v -= wuf.diff(y, minidx[p]);

            if (v < 0) {
                std::cout << "No" << std::endl;
                return;
            }
        }
    }

    std::cout << "Yes" << std::endl;
    return;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define all(v) v.begin(),v.end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

ll power(ll a, ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans*=a;
        a*=a;
        n>>=1;
    }
    return ans;
}

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

int main()
{
    IOS;
    ll n;
    cin>>n;
    ll a[n+1]={0};
    repf(i,0,n)
    {
        ll x;
        cin>>x;
        a[x]++;
    }
    vector<ll> v,c;
    repf(i,1,n+1) if(a[i]) v.pb(a[i]);
    sort(all(v));
    c.pb(v[0]);
    repf(i,1,v.size()) 
    {
        c.pb(c[c.size()-1]+v[i]);
        // cout<<i<<endl;
    }
    repf(i,1,n+1)
    {
        ll lo=0,hi=n/i,ans=0,mid;
        while(lo<=hi)
        {
            mid=(lo+hi)/2;
            // if(mid==0) cout<<lo<<" "<<hi<<" "<<mid<<endl;
            // if(i==n) cout<<lo<<" "<<hi<<" "<<mid<<endl;
            int x=lower_bound(all(v),mid)-v.begin();
            ll val=v.size()-x;
            // if(i==n) cout<<val<<endl;
            if(x!=0) val+=c[x-1]/mid;
            if(val>=i) 
            {
                ans=max(ans,mid);
                lo=mid+1;
            }
            else hi=mid-1;
        }
        cout<<ans<<endl;
    }
    return 0;  
}

Measured memory_bytes: 13036
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // long long64_t, long long*_t
#include <cstdio> // prlong longf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack 
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <list>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> x(m);
  vector<int> y(m);
  vector<int> a(n,1);//個数
  vector<int> b(n,0);//red++
  b[0]=1;
  for(int i=0; i<m; i++){
    cin >> x[i] >> y[i];
    if(b[x[i]-1]!=0){
      if(a[x[i]-1]==1){
        b[x[i]-1]=0;
        b[y[i]-1]=1;
      }
      else{
        b[y[i]-1]=1;
      }
    }
    a[y[i]-1]++;
    a[x[i]-1]--;
  }
  int sum=0;
  for(int i=0; i<n; i++){
    if(b[i]>0) sum++;
  }
  cout << sum << endl;
}


Measured memory_bytes: 1792
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  val ps = readLine.split(" ").map(_.toInt)
  
  def isSorted(a: Array[Int]): Boolean = a.sliding(2).forall(t => t(0) < t(1))
  
  val results = (for {
    i <- 0 until n - 1
    j <- i until n
  } yield {
    val l = ps(i)
    val r = ps(j)
    ps(i) = r
    ps(j) = l
    val result = isSorted(ps)
    ps(i) = l
    ps(j) = r
    result
  }) :+ isSorted(ps)
  
  println(if (results.exists(_ == true)) "YES" else "NO")
}

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

vector<bool> prime;
void sieve(int n){
    prime.resize(n+1,true);
    prime[0]=prime[1]=false;
    for(int i=2;i<=n;i++){
        if(prime[i]){
            for(int j=2;i*j<=n;j++) prime[i*j]=false;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    sieve(100004);
    vector<int> dp(100004);
    dp.at(0)=1;
    for(int i=1;i<100004;i++){
        dp.at(i)=dp.at(i-1);
        if(prime.at(i)&&prime.at((i+1)/2)) dp.at(i)++;
    }  
    int n;
    cin>>n;
    rep(i,n){
        int l,r;
        cin>>l>>r;
        cout<<dp[r]-dp[l-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[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 (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }


long long int value(long long int x, long long int A, long long int B) {
	return floor(A * x / B) - A * floor(x / B);
}

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

	string str1, str2;
	cin >> str1 >> str2;
	if (str1.size() != str2.size() - 1)No;
	rep(i, str1.size()) {
		if (str1.at(i) != str2.at(i))No;
	}
	Yes;

	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;


int main(){
    int N,T;
    cin >> N >> T;
    
    int ans=INF;
    for(int i=0; i<N; i++){
        int c,t;
        cin >> c >> t;
        
        if(t<=T){
            ans=min(ans,c);
        }
    }
    if(ans==INF){
        cout<<"TLE"<<endl;
    }else{
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int n, d, x;
    cin >> n >> d >> x;

    int a[105];
    REP(i, n){
        cin >> a[i];
    }

    int ans = x + n;

    REP(i, n){
        int num = 0;
        int y = 1;
        int j = 0;
        while(num <= d){
            num = y * a[i] + 1;
            ++y;
            ++j;
            if(num <= d) ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int INF=INT_MAX;
const ld PI=3.1415926535838797323;
const ld E=2.71828183;
const int MOD=1e9+7;

vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src-1]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c-1]){
            if(dst[nbr-1]==INF){
                q.push(nbr);
                dst[nbr-1]=dst[c-1]+1;
            }
        }
    }
    return dst;
}
int powMod(int base,int exp,int mod){
    //base^exp %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}

int binSearch(vi x,int g);
void solve();

int main() {
    //  int t;
      //cin >> t;
      //while(t--)
          solve();
}
void solve(){
    int n;
    cin >> n;
    int dig=n%10;
    if(dig==3)
        cout << "bon\n";
    else if(dig==0 || dig==1 || dig==6 || dig==8)
        cout << "pon\n";
    else
        cout<< "hon\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }
#define output(x) cout << x << endl;

int main() {
    long long int N, K;
    cin >> N >> K;
    long long int count = N / K;
    long long int even = (N + (K / 2)) / K;
    if(K % 2 == 1) cout << count * count * count << endl;
    else cout << (count * count * count) + (even * even * even) << endl;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  int n = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    if (a - 1 == n) {
      ++n;
    } else {
      ++cnt;
    }
  }
  if (cnt == N) {
    printf("-1\n");
  } else {
    printf("%d\n", cnt);
  }
}

Measured memory_bytes: 3220
import sys
n,m=map(int,input().split())
MOD = 10**9+7
ans=1
if m==1:
  print(1)
  sys.exit()
def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n, k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
pf={}
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
Max=max(list(pf.values()))
f_mod=[1]*(Max+n+1)
f_mod_inverse=[1]*(Max+n+1)
for i in range(1,Max+n+1):
  f_mod[i]=(f_mod[i-1]*i)%MOD
  f_mod_inverse[i]=(f_mod_inverse[i-1]*inv_mod(i)) % MOD  
for i in pf.values():
  ans*=comb_mod(i+n-1,n-1)
print(ans%MOD)


Measured memory_bytes: 71020
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  string S;
  cin>>S;
  
  if(S.size()==2) cout<<S;
  else cout<<S.at(2)<<S.at(1)<<S.at(0)<<endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<char>> a(N);
  vector<vector<char>> b(M);

  REP(i,N)REP(j,N){
    char c;
    cin >> c;
    a[i].push_back(c);
  }  
  REP(i,M)REP(j,M){
    char c;
    cin >> c;
    b[i].push_back(c);
  }  

  
  REP(i,N-M+1)REP(j,N-M+1){
    bool flag=true;
    REP(k,M)REP(l,M){
      if(a[i+k][j+l] != b[k][l]){
        flag=false;
        break;
      }
    }
    if(flag){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}



Measured memory_bytes: 256
def sieve(n=10**6):
  p=[1]*(n+1)
  for i in range(2,n+1):
    if p[i]:
      for j in range(2*i,n+1,i):p[j]=0
  p[0],p[1]=0,0
  return p
while True:
  try:print(sum(sieve(int(input()))))
  except:break


Measured memory_bytes: 14120
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e3 + 5, mod = 998244353;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    vector<int> v, v2;
    for(int i = 0; i < n; i++){
        int x, y;
        cin >> x >> y;
        v.push_back(x);
        v2.push_back(y);
    }
    sort(v.begin(), v.end());
    sort(v2.begin(), v2.end());
    if(n&1) return cout << v2[n / 2] - v[n / 2] + 1, 0;
    int idx = n / 2;
    cout << v2[idx] + v2[idx - 1] + 1 - v[idx] - v[idx - 1];


    return 0;

}


Measured memory_bytes: 5120
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int N, K;
int C[2005], G[2005];

vi books[11];

int dp[11][2005]; // dp[i][j] := i?¨?????????§???j????????£?????????????????????????????§???

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

    rep(i, N) {
        cin >> C[i] >> G[i];
        books[G[i]].PB(C[i]);
    }

    rep1(i, 10) {
        sort(all(books[i]), greater<int>());

        books[i].insert(begin(books[i]), 0);

        for (int j = 1; j < books[i].size(); ++j) {
            books[i][j] += books[i][j - 1];
            books[i][j] += (j - 1) * 2;
        }
    }

    for (int i = 1; i <= 10; ++i) {
        for (int j = 0; j <= K; ++j) {
            for (int k = 0; j + k <= K; ++k) {
                if (k >= books[i].size()) break;
                chmax(dp[i][j + k], dp[i - 1][j] + books[i][k]);
            }
        }
    }

    int ma = 0;

    for (int i = 0; i <= 10; ++i) for (int j = 0; j <= K; ++j) chmax(ma, dp[i][j]);

    cout << ma << endl;
}

Measured memory_bytes: 3128
#include<stdio.h>

int main(void)
{
    int i, j, a[100], N, min = 200, max = -200, ans = 1000000, total = 0;

    scanf("%d", &N);
    for(i = 0; i < N; i++) {
        scanf("%d", &a[i]);
        if(min > a[i])
            min = a[i];
        if(max < a[i])
            max = a[i];
    }

    for(i = min; i <= max; i++){
        total = 0;
        for(j=0;j<N;j++){
            total += (i - a[j]) * (i - a[j]);
        }
        if(ans > total)
            ans = total;
    }

    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
//long time no ac
#include <bits/stdc++.h>
using namespace std;

#define 	ll				long long
#define 	vii				vector<int>
#define		rep(i,n) 		for(i=0;i<n;i++)
#define		repe(i,I1,I2) 	for(i=I1;i<I2;i++)
#define		INF  			1e9 + 7
#define		pb  			push_back
#define		mp  			make_pair
#define		endl			'\n'
#define 	mod				1000000007


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k,t,c=0,i,m,ans;
	t=1;
	//cin>>t;
	
	while(t--)
	{
		cin>>n>>k>>c>>i;
		m=max(max(n,k),c);
		if (m==n)
		{
			ans=(pow(2,i)*m)+k+c;
			/* code */
		}
		else if (m==k)
		{
			ans=(pow(2,i)*m)+n+c;
			/* code */
		}
		else if (m==c)
		{
			ans=(pow(2,i)*m)+k+n;
			/* code */
		}
		cout<<ans;
		if(t!=0)
	   		cout<<"\n";
	}
	return 0;
}

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

void trace(vector<int> A, int N){
    for (int i = 0; i < N; i++){
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

int selectionSort(vector<int> A, int N){
    int sw = 0;
    for (int i = 0; i < N; i++){
        int minj = i;
        bool flag = false;
        for (int j = i; j < N; j++){
            if (A[j] < A[minj]){
                minj = j;
                flag = true;
            }
        }
        if (flag) sw++; 
        swap(A[i], A[minj]);
    }

    trace(A, N);
    cout << sw << endl;
}

int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    
    selectionSort(A, N);
}


Measured memory_bytes: 3156
S = input()

S = S[::-1]
T = ''
i = 0
while i < len(S):
    if S[i] == 'm':
        T += 'maerd'
        i += 5
    elif S[i] == 'e':
        T += 'esare'
        i += 5
    elif S[i:i + 3] == 'rem':
        T += 'remaerd'
        i += 7
    elif S[i:i + 3] == 'res':
        T += 'resare'
        i += 6
    else:
        break

if S == T:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3316
A, B, C, X, Y = map(int, input().split())

min_cost = A*X + B*Y
for i in range(1, 1+max(X,Y)):
  cost = i*C*2 + max(0,X-i)*A + max(0,Y-i)*B
  min_cost = min(min_cost, cost)

print(min_cost)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <sstream>

using namespace std;

class c_main
{
private:
    
public:
    c_main();
    void f_input();
};

c_main::c_main()
{

}

void c_main::f_input()
{
    double xp1,yp1,xp2,yp2;
    int q;
    int i;
    double x[1000];
    double y[1000];
    double a;
    double b;
    double x_a;
    double y_a;
    double a_a;
    double b_a;
    int pt1;

    cin >> xp1 >> yp1 >> xp2 >> yp2;
    
    if (xp1 == xp2){
        x_a = xp1;
        y_a = 0;
        pt1 = 0;
    }else if (yp1 == yp2){
        x_a = 0;
        y_a = yp1; 
        pt1 = 1;
    }else{
        //cout << "yp2 = " << yp2 << endl;
        //cout << "yp1 = " << yp1 << endl;
        //cout << "xp2 = " << xp2 << endl;
        //cout << "xp1 = " << xp1 << endl;
        a_a = (yp2-yp1)/(xp2-xp1);
        //cout << "a_a = " << a << endl;
        a = -1 * (1/a_a);
        //cout << "a = " << a << endl;
        b_a = -1 * a_a * xp1+ yp1;
        pt1 = 2;
    }
    
    //cout << x_a << endl;
    //cout << y_a << endl;
    //cout << a << endl;
    
    cin >> q;
    
    for ( i = 0; i < q; ++i){
        cin >> x[i] >> y[i];
        if (pt1 == 0){
            //cout << x_a << " " << y[i] << endl;
            printf("%10.10f %10.10f\n", x_a,y[i]);
        }else if(pt1 == 1){
            //cout << x[i] << " " << y_a << endl;
            printf("%10.10f %10.10f\n", x[i],y_a);
        }else if(pt1 == 2){
            b = -1 * a * x[i] + y[i];
            x_a = (b - b_a)/(a_a - a);
            y_a = a_a * x_a + b_a;
            //cout << x_a << " " << y_a << endl;
            printf("%10.10f %10.10f\n", x_a,y_a);
        }
    }
}

int main(){
    c_main main01;
    main01.f_input();
    
    return 0;
}

Measured memory_bytes: 3280
#include<stdio.h>
int main(void){
  int k,a,i,j,l,m;
  scanf("%d",&k);
  a=0;
  for(i=1;i<=k;i++){
    a=a+i;
  }
  for(i=1;i<=k-1;i++){
    for(j=i+1;j<=k;j++){
      for(l=i;l>=1;l--){
	if(i%l==0&&j%l==0){
	  a=a+6*l;
	  break;
	}
      }
    }
  }
  for(i=1;i<=k-2;i++){
    for(j=i+1;j<=k-1;j++){
      for(l=j+1;l<=k;l++){
	for(m=i;m>=1;m--){
	if(i%m==0&&j%m==0&&l%m==0){
          a=a+6*m;
          break;
	}
	}
      }
    }
  }
  printf("%d\n",a);
  return 0;
}



Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#ifndef ONLINE_JUDGE
#define tr(...) {__l(__LINE__);__f(#__VA_ARGS__, __VA_ARGS__);}
inline void __l(int line) { cerr << "#" << line << ": "; }template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define tr(...)
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}template<typename T>inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v){bool first = true;os << "[";for(auto i: v){if(!first)os << ", ";os << i;first = false;}return os << "]";}
const int N = 1000;
// make sure N size is correctttt!!!!!!!!!


int n, deg[N];
int32_t main(){_

   for (int i = 0; i < 3; ++i)
   {
      int a, b;
      cin>>a>>b;
      deg[a]++;
      deg[b]++;
   }

   int cnt[50] = {0};
   for (int i = 1; i <= 4; ++i)
   {
      cnt[deg[i]]++;
   }

   if(cnt[1] == 2 and cnt[2] == 2){
      cout<<"YES\n";
   }
   else{
      cout<<"NO\n";
   }

   //make sure N size is correct!!!!!!!!!
   return 0;
}

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

int main(){
  string S;
  cin >> S;
  int t;
  if (S.at(0)==S.at(1))
  {
    if(S.at(2)==S.at(3)){t=1;}
    else{t=0;}
  }else if(S.at(0)==S.at(2))
  {
    if(S.at(1)==S.at(3)){t=1;}
    else{t=0;}
  }else if(S.at(0)==S.at(3))
  {
    if(S.at(2)==S.at(1)){t=1;}
    else{t=0;}
  }
  if(S.at(0)==S.at(2)&&S.at(0)==S.at(1)){t=0;}
  if(t){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}



Measured memory_bytes: 256
X, K, D = map(int, input().split())

g = abs(X) % D

if K >= abs(X) // D:
    K -= abs(X) // D
    if K % 2 == 0:
        print(g)
    else:
        print(abs(g-D))
else:
    print(abs(X) - K * D)


Measured memory_bytes: 9164
#include <iostream>
#include <string>
#include <map>

using namespace std;

namespace {
map<string, int> m{{"SUN", 7}, {"MON", 6}, {"TUE", 5}, {"WED", 4}, {"THU", 3}, {"FRI", 2}, {"SAT", 1}}; 
}
int main() {
  string S;
  cin >> S;
  
  cout << m[S] << endl;
  
  return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
N,M = map(int,input().split())
S = input()
T = input()
 
flag = True
for n in range(N):
    if M*n%N==0:
        m = M*n//N
        flag = S[n]==T[m]
    if not flag:
        break
if not flag:
    print(-1)
else:
    print(N*M//gcd(N,M))

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static final long MOD = 1_000_000_007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		int count = 0;
		int before = -1;
		
		for (int i=0;i<n;i++) {
			a[i]=sc.nextInt();
		}
		for (int i=0;i<n;i++) {
			b[i]=sc.nextInt();
		}
		for (int i=0;i<n-1;i++) {
			c[i]=sc.nextInt();
		}
		
		for (int i=0;i<n;i++) {
			int k = a[i];
			count+=b[k-1];
			if(k==before+1) {
				count+=c[k-2];
			}
			before=k;
		}
		
		System.out.println(count);
		
		
		
		
	}



}

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

int binary_search(vector<int> &dp, int thr){
	int head = 0, tail = dp.size()-1;
	while(tail - head > 1){
		int mid = (head + tail) / 2;
		if(dp[mid] < thr) tail = mid;
		else head = mid;
	}
	if(dp[head] < thr) return head;
	if(dp[tail] < thr) return tail;
	return -1;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
    vector<int> dp;
    dp.push_back(a[0]);
    for(int i = 1; i < n; i++){
        int it = binary_search(dp, a[i]);
        if(it > -1) dp[it] = a[i];
        else dp.push_back(a[i]);
    }
    cout << dp.size() << endl;
	return 0;
}

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

using namespace std;

int main()
{
	string S;
	cin >> S;
	if (S.length() >= 4 && S.substr(0, 4) == "YAKI") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  long long n,k,q;
  scanf("%lli%lli%lli",&n,&k,&q);
  long long p[n];
  long long t[q];
  for (long long i=0;i<n;i++) {
    p[i] = 0;
  }
  for (long long i=0;i<q;i++) {
    scanf("%lli",&t[i]);
    p[t[i]-1] += 1;
  }
  for (long long i=0;i<n;i++) {
    if (k-q+p[i]>0) {
      printf("%s\n","Yes");
    } else {
      printf("%s\n","No");
    }
  }
  return 0;  
}

Measured memory_bytes: 3216
A,B,C,X,Y = map(int,input().split())
ABset = min(A+B,2*C)
Asgl = min(A,2*C)
Bsgl = min(B,2*C)
Z = min(X,Y)
Ans = ABset * Z
Ans += Asgl * (X - Z)
Ans += Bsgl * (Y - Z)
print(Ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

class cell{
public:
	int dir[4]; // up,right,down,left;
};

int main(){
	cell field[32][32];
	const int dx[] = { 0, 1, 0,-1};
	const int dy[] = {-1, 0, 1, 0};
	int check[32][32];
	int w,h,s;
	while(scanf("%d%d",&w,&h),w|h){
		rep(i,32)rep(j,32)check[i][j]=INT_MAX;
		rep(i,2*h-1){
			if( i%2==0 ){	 // tatesen
				rep(j,w-1){
					scanf("%d",&s);
					field[i/2][j].dir[1] = field[i/2][j+1].dir[3] = s;
				}
			}else{ // yokosen
				rep(j,w){
					scanf("%d",&s);
					field[i/2][j].dir[2] = field[i/2+1][j].dir[0] = s;
				}
			}
		}
		/*
		rep(i,h){
			rep(j,w){
				printf("(%d,%d) u:%d, r:%d, d:%d, l:%d\n",j,i,field[i][j].dir[0],field[i][j].dir[1],field[i][j].dir[2],field[i][j].dir[3]);
			}
		}
		*/
		
		
		queue<pair<int,int> > q;
		q.push(mp(0,0));
		check[0][0] = 0;
		bool goal = false;
		while(!q.empty()){
			int x = q.front().first;
			int y = q.front().second;
			int c = check[y][x];
			q.pop();
			rep(k,4){
				int tx = x + dx[k];
				int ty = y + dy[k];
				//printf("(%d,%d) c:%d\n",tx,ty,c);
				if( tx<0 || ty<0 || tx>=w || ty>=h || check[ty][tx]<=c+1 ) continue;
				if( field[y][x].dir[k]==1 ) continue;
				//printf("(%d,%d):%d --> dir:%d --> (%d,%d):%d\n",x,y,c,k,tx,ty,check[ty][tx]);
				check[ty][tx] = c+1;
				if( tx==w-1 && ty==h-1 ){
					goal = true; break;
				}
				q.push(mp(tx,ty));
			}
			if( goal ) break;
			//printf("size:%d\n",q.size());
		}
		printf("%d\n",check[h-1][w-1]==INT_MAX?0:check[h-1][w-1]+1);
	}
	return 0;
}

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

int main() {
  ll n,m,k;
  cin >> n >> m >> k;
  vector<ll> a(n+1), b(m+1);
  a[0] = 0; b[0]=0;
  ll total=0;
  for(int i=1;i<=n;i++){
    int tmp1;
    cin >> tmp1;
    total += tmp1;
    a[i] = total;
  }
  total = 0;
  for(int i=1;i<=m;i++){
    int tmp2;
    cin >> tmp2;
    total += tmp2;
    b[i] = total;
  }
  int ans=0;
  for(int i=0; i<=n; i++){
    int left = -1, right = b.size(), mid; 
    ll amari = k-a[i];
    if(amari<0) continue;
    while(right-left > 1){
      mid = left + (right-left)/2;
      if(b[mid] > amari) right = mid;
      else left = mid;
    }
    ans = max(ans, i+left);
  }
  cout << ans << endl;
}


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

int N;
string S;
int K;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>S>>K;

int n=S.size();

char c;
for(int i=0; i<n; i++){
  if(i==K-1){
    c=S[i];
  }
}

for(int i=0; i<n; i++){
  if(S[i]!=c){
    S[i]='*';
  }
}

cout<<S<<endl;

}



Measured memory_bytes: 256