akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(void)
{
    int N;
    string s, t;

    cin >> N >> s >> t;
    int matchLen = 0;
    for(int slide = 0; slide < N; slide++){
        int match = 0;
        for(int i = slide; i < N; i++){
            if(s[i] == t[i-slide]) match++;
        }
        if(match > matchLen) matchLen = match;
    }

    cout << 2*N - matchLen << endl;

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long lint;
lint n, i, x, sumx, sumx2, ans = 0x3f3f3f3f, now;

lint getsum(int i) {
    return sumx2 + n * i * i - 2 * i * sumx;
}

lint bs() {
    lint r = -20000, p = 1LL << 15;
    while(p > 0) {
        if(getsum(r + p) > getsum(r + p + 1)) {
            r += p;
        }
        p >>= 1;
    }
    return r + 1;
}

int main()
{
    //freopen("f.in", "r", stdin);
    //freopen("f.out", "w", stdout);
    cin >> n;
    for(i = 1; i <= n; i ++) {
        cin >> x;
        sumx += x;
        sumx2 += x * x;
    }
    /*for(i = -10000; i <= 10000; i ++) {
        now = sumx2 + n * i * i - 2 * i * sumx;
        if(now < ans) { ans = now; }
    }*/
    ans = bs();
    cout << getsum(ans) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
D dot(P a,P b) {return (conj(a)*b).X; }
D cross(P a,P b) {return(conj(a)*b).Y;}
int ccw(P a,P b,P c){
  b-=a;c-=a;
  if(cross(b,c) >EPS)return +1;
  if(cross(b,c)< -EPS)return -1;
  if(dot(b,c)< -EPS)return +2;
  if(norm(b)<norm(c))return -2;
  return 0;
}
bool isecSS(P a1, P a2, P b1, P b2) {
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
         ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}
bool isecSP(P a1,P a2,P b) {
  return abs(a1 - b) + abs(a2 - b) - abs(a2 - a1) < EPS;
}
P proj(P a1,P a2,P p){return a1+dot(a2-a1, p-a1)/norm(a2-a1)*(a2-a1);}
D distSP(P a1,P a2,P p) {
  P r=proj(a1,a2,p);
  if(isecSP(a1,a2,r))return abs(r-p);
  return min(abs(a1-p),abs(a2-p));
}
 
D distSS(P a1,P a2,P b1,P b2) {
  if (isecSS(a1,a2,b1,b2))return 0;
  return min(min(distSP(a1,a2,b1),distSP(a1,a2,b2)),min(distSP(b1,b2,a1),distSP(b1,b2,a2)));
}
int n,x,x1,y2;
double h,a[222][222];
vector<P>v[222];
main(){
  while(cin>>h>>n,h){
    r(i,222)r(j,222)a[i][j]=1e15;
    r(i,222)v[i].clear();
    v[n].push_back(P(0,0));
    v[n].push_back(P(0,1e9));
    v[n+1].push_back(P(h,0));
    v[n+1].push_back(P(h,1e9));
    r(i,n){
      cin>>x;
      while(x--){
        cin>>x1>>y2;
        v[i].push_back(P(x1,y2));
      }
    }
    r(i,n+2)r(j,n+2)r(k,v[i].size())r(l,v[j].size())
      a[i][j]=min(a[i][j],distSS(v[i][k],v[i][(k+1)%(int)v[i].size()],v[j][l],v[j][(l+1)%(int)v[j].size()]));
    r(k,n+2)r(i,n+2)r(j,n+2)a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
    printf("%.9f\n",a[n][n+1]);
  }
}

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

int main(){
  string s;
  cin >>s;
  string key = "keyence";
  if(s==key){
    cout << "YES" << endl;
    return 0;
  }
  int n = s.size();
  rep(i,n){
    for(int j = i; j<n; j++){
      string S = "";
      rep(k,n){
        if(i<=k && k<=j){
          continue;
        }
        else S.push_back(s[k]);
      }
      if(S==key){
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  
  return 0; 
}


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

int main() {
  int k;
  int a[1000001];
  cin >> k;
  
  a[0] = 7 % k;
  for (int i = 1; i <= k; i++) {
    a[i] = ((a[i-1] * 10) % k + 7) % k; 
  }
  for (int i = 1; i <= k; i++) {
    if (a[i-1] == 0) {
      cout << i;
      return 0;
    }
  }
  cout << "-1";
}

Measured memory_bytes: 7476
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
    int mod = 998244353;

    int N;

    cin >> N;

    vector<int> a(N);

    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }

    int sum = accumulate(a.begin(), a.end(), 0);

    vector<ll> S1(sum + 1);
    vector<ll> S2(sum + 1);

    S1.at(0) = 1;
    S2.at(0) = 1;

    for (int i = 0; i < N; i++)
    {
        for (int j = sum; j >= 0; j--)
        {
            if (j < a.at(i))
            {
                S1.at(j) = S1.at(j) * 2;
            } else
            {
                S1.at(j) = S1.at(j) * 2 + S1.at(j - a.at(i));
                S2.at(j) = S2.at(j) + S2.at(j - a.at(i));
            }

            if (S1.at(j) > 10 ^ 15 )
            {
                S1.at(j) %= mod;
                S2.at(j) %= mod;
            }
        }
    }


    ll count0 = 1;

    for (int i = 0; i < N; i++)
    {
        count0 = (count0 * 3) % mod;
    }
    


    ll count1 = 0;

    for (int i = (sum + 1) / 2; i <= sum; i++)
    {
        count1 = (count1 + S1.at(i)) % mod;
    }
    
    ll count2 = 0;
    if ( sum % 2 == 0)
    {
        count2 = S2.at(sum / 2);
    }
    
    ll temp = (count0 - 3 * count1 + 3 * count2) % mod;
    ll result = (temp + mod) % mod;

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


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

using namespace std;

int main(){
    int N, K, X, Y; cin >> N >> K >> X >> Y;
    int ans = 0;

    for(int i = 1; i <= N; i++){
        if(i <= K){
            ans += X;
        }else{
            ans += Y;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int n,m;
    while(scanf("%d%d",&n,&m),n,m){

        int a[10001]={0},b[10001]={0};
        int friends[1000]={0};
        int ans = 0;

        for(int i = 0;i < m; i++){
            scanf("%d%d",&a[i],&b[i]);
            if(b[i] == 1)swap(a[i],b[i]);
            if(a[i] == 1){
                friends[b[i]] = 1;
            }
        }
        friends[1] = 1;
        for(int i = 0;i < m; i++){
            if(friends[a[i]] == 1 && friends[b[i]] == 0){
                friends[b[i]] = 2;
            }
            else if(friends[a[i]] == 0 && friends[b[i]] == 1){
                friends[a[i]] = 2;
            }
        }
        friends[1] = 0;
        for(int i = 1;i <= n; i++)if(friends[i] == 2 || friends[i] == 1)ans++;
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1276
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B = IL()
print(max(A-2*B, 0))

Measured memory_bytes: 38480
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
using namespace std;



int main() {
	int n, a[200000], ans,sorteda[200000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sorteda[i] = a[i];
	}
	sort(sorteda, sorteda + n);
	for (int i = 0; i < n; i++) {
		ans = ((a[i] <= sorteda[n / 2 - 1]) ? sorteda[n / 2 ] : sorteda[n / 2-1]);
		cout << ans << endl;
	}
	return 0;
}




Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	void kaijou_set(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
};

int main(){
	
	int n;
	cin>>n;
	
	vector<int> a(n+1);
	set<int> S;
	int D;
	for(int i=0;i<n+1;i++){
		cin>>a[i];
		if(S.count(a[i])){
			D = a[i];
		}
		S.insert(a[i]);
	}
	
	combi C;
	C.kaijou_set(1000000);
	
	int k = 0;
	for(int i=0;i<n+1;i++){
		if(a[i]==D){
			k+=i;
			break;
		}
	}
	
	reverse(a.begin(),a.end());
	for(int i=0;i<n+1;i++){
		if(a[i]==D){
			k+=i;
			break;
		}
	}
	
	
	for(int i=1;i<=n+1;i++){
		int ans = C.combination(n+1,i);
		int x = C.combination(k,i-1);
		ans = mod(ans - x);
		cout<<ans<<endl;
	}
	
    return 0;
}



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

int main()
{
	string str1, str2;
	cin>>str1;
	cin>>str2;
	reverse(str2.begin(),str2.end());
	if(str1 == str2)
		cout<<"YES"<<endl;
	else
	{
		cout<<"NO"<<endl;
	}
	

	return 0;
}

Measured memory_bytes: 3620
from collections import deque

H, W = [int(i) for i in input().split()]
A = [list(input()) for _ in range(H)]

Q = deque([(i, j, 0) for i in range(H) for j in range(W) if A[i][j] == "#"])

ans = 0
while Q:
    i, j, dist = Q.popleft()
    ans = max(ans, dist)
    for di, dj in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W and A[ni][nj] == ".":
            A[ni][nj] = "#"
            Q.append((ni, nj, dist + 1))

print(ans)


Measured memory_bytes: 169360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,f,n) for(int i=f; i<(n); i++)
int main()
{
  ll ans = 0, n;
  string s;
  cin >> n;
  cin >> s;

  
  REP(i,0,10){
    int f1 = s.find_first_of(i+'0');
    if(f1 != -1){
      string s2 = s.substr(f1+1);
      REP(i2,0,10){
        int f2 = s2.find_first_of(i2+'0');
        if(f2 !=-1){
          string s3 = s2.substr(f2+1);
          REP(i3,0,10){
            int f3 = s3.find_first_of(i3+'0');
            if(f3 !=-1){
              ans++;
            }
          }
        }
      }
    }
  }
  cout << ans << endl;

  //--debug : end_stoper
  string end_stoper; cin >> end_stoper;

  return 0;
}

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

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    
    vector<int> d(n);
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int dist1 = j - i;
            int dist2 = labs(j - y) + labs(i - x) + 1;
            int dist = min(dist1, dist2);
            d[dist]++;
        }
    }

    for (int i = 1; i < n; i++) cout << d[i] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {
    
    int n; cin >> n;
    int t[n+1]; for (int i = 1; i <= n; ++i) cin >> t[i];
    int m; cin >> m;
    int p[m], x[m]; rep(i,m) cin >> p[i] >> x[i];

    int sum = 0;
    for (int i = 1; i <= n; ++i) sum += t[i];
    rep(i,m) {
        out(sum - t[p[i]] + x[i]);
    }


    
    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(void) {
  int a, b, t;
  cin >> a >> b >> t;
  cout << (t / a) * b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int N, K, h, ans;
int main() {
    scanf("%d %d", &N, &K);
    for(int i = 0; i < N; ++i) {
        scanf("%d", &h);
        if(h >= K) ++ans;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;

int main(){
	ll n, m, ans = 1;
	cin >> n >> m;
	if(n < m) swap(n, m);
	if(n - m < 2) {
		for(ll i = 1; i <= m; i++){
			ll k;
			if(10000 < i) k = (i * i) % MOD;
			else k = i * i;
			ans *= k;
			ans %= MOD;
		}	
		if(n - m) ans *= n;
		else ans *= 2;
		ans %= MOD;
	}
	else ans = 0;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;



int main()
{
	int L, R;
	cin >> L >> R;

	set <int> sti;

	ll ret = BIG;

	const ll mod = 2019;

	for (ll i = L; i <= R; ++i)
	{
		if (!sti.count(i%mod))
		{
			set <ll> stj;
			for (ll j = i + 1; j <= R; ++j)
			{
				if (!stj.count(j%mod))
				{
					amin(ret, ((i%mod) * (j%mod)) % mod);
				}
				else
				{
					break;
				}
				stj.insert(j%mod);

			}

			sti.insert(i%mod);
		}
		else
		{
			break;
		}
	}




	cout << ret << endl;

	return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

int N;
LL A[1<<20];
LL B[1<<20];

int main() {
  scanf("%d", &N);
  REP(i,N) scanf("%lld%lld", &A[i], &B[i]);
  LL result = 0;
  FORD(i,N,0) {
    LL tmp = A[i] + result;
    result += (B[i] - tmp % B[i]) % B[i];
  }
  printf("%lld\n", result);
}


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

int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  for(int i = 0; i < N; i++){cin >> x[i];}
  for(int i = 0; i < N; i++){cin >> y[i];}
  
  int ans = 0;
  for(int i = 0; i < N; i++){
    if(x[i] - y[i] > 0)ans += x[i] - y[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] homework = scanner.nextLine().split(" ");
        String[] days =scanner.nextLine().split(" ");
        int daySum = Arrays.stream(days).mapToInt(Integer::parseInt).sum();
        int d = Integer.parseInt(homework[0]) - daySum;
        if (d < 0) {
            System.out.println(-1);
        }else {
            System.out.println(d);
        }
    }
}

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

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

int main(){
    int h,w;
    cin >> h >> w;
    int num = h*w;
    vector<string> maze;
    vector<vector<int>> bfs(h,vector<int>(w,-1));
    rep(i,h){
        string s;
        cin >> s;
        maze.push_back(s);
        rep(i,s.size()){
            if(s[i]=='#') num--;
        }
    }

    queue<P> qu;
    P p(0,0);
    qu.push(p);
    bfs[0][0]=0;

    while(!qu.empty()){
        P p;
        p = qu.front();
        qu.pop();
        int temp = bfs[p.first][p.second];
        //cout << "now" << p.first << " " << p.second << " "<<temp<<endl;

        rep(i,4){
            int x,y;
            x = p.first; y = p.second;
            x+=dx[i]; y+=dy[i];
            if(x<0 || x>=h) continue;
            if(y<0 || y>=w) continue;
            if(maze[x][y]=='.'){
                if(bfs[x][y]==-1){
                    P p(x,y);
                    bfs[x][y]=temp+1;
                    qu.push(p);
                }
            }
        }
    }
    if(bfs[h-1][w-1]==-1){
        cout << "-1" << endl;
        return 0;
    }
    else{
        num -= (bfs[h-1][w-1]+1);
        cout << num << endl;
    }
}

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

int main()
{
    int n;
    cin >> n;
    vector<long long> P(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> P[i];
    }
    vector<int> prev(n, 0), next(n, n);
    stack<pint> st;
    st.push({0, -1});
    for (int i = 0; i < n; ++i)
    {
        while (st.size() > 0 && st.top().first >= P[i])
            st.pop();
        prev[i] = st.top().second + 1;
        st.push({P[i], i});
    }
    while (!st.empty())
        st.pop();
    st.push({0, n});
    for (int i = n - 1; i >= 0; --i)
    {
        while (st.size() > 0 && st.top().first >= P[i])
            st.pop();
        next[i] = st.top().second;
        st.push({P[i], i});
    }
    long long sum = 0;
    for (int i = 0; i < n; ++i)
    {
        sum += P[i] * (next[i] - i) * (i - prev[i] + 1);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cmath>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
int main( void ){
	int n;
	if (!scanf( "%d", &n )){
		return 1;
	}
	int sum = 0;
	int* array = new int[n];
	for(int i = 0; i < n; i++)
		if(!scanf("%d", array+i))
			return -1;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++)
			sum+=array[i] * array[j];
	}
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,f,n) for(int i=f;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;

signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    int a[] = {1,1,0,2,0,0,1,0,1,0};
    string s[] = {"hon", "pon", "bon"};

    cout << s[a[n % 10]] << '\n';

    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<string.h>
int main(void){
    int n;
    scanf("%d",&n);
    double a,sum=0.0;
    for(int i=0;n>i;++i){
        scanf("%lf",&a);
        sum+=(1.0/a);
    }
    printf("%f",1.0/sum);
    return 0;
}

Measured memory_bytes: 128
//handstand
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;

	vector<int> vec;

	int count = 0;
	int tmp = 0;
	char cur = s[0];
	while(1){
		if (s[count] == cur){
			tmp++;
		}else{
			vec.push_back(tmp);
			tmp = 1;
			if (cur == '1'){
				cur = '0';
			}else{
				cur = '1';
			}
		}
		count ++;
		if(count == n){
			vec.push_back(tmp);
			break;
		}
	}

	if(s[0] == '0'){
		vec.insert(vec.begin(),0);
	}
	if(s[n-1] == '0'){
		vec.push_back(0);
	}

	if(vec.size() < k*2+1){
		int sum = 0;
		for (int i = 0; i < vec.size(); ++i)
		{
			sum+=vec[i];
		}
		cout << sum << endl;
	}else{
		int times = vec.size()/2-k+1;
		int max = 0;
		for (int i = 0; i < times; i++)
		{
			int index = i*2;
			int t = 0;
			for (int j = index; j < index+k*2+1; ++j)
			{
				t += vec[j];
			}
			if(t>max){max = t;}
			// cout << t << endl;
		}
		cout << max << endl;
	}

	// for (int i = 0; i < vec.size(); ++i)
	// {
	// 	cout << vec[i];
	// }
	// cout<<endl;
	return 0;
}

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

int n;
vector<int> g[55];
int dep[55],fa[55];
int m,U[55],V[55];
bool fix[55];
int tot;
long long ans;

void dfs(int x,int p){
    for(int &y:g[x])if(y!=p){
        fa[y]=x;
        dep[y]=dep[x]+1;
        dfs(y,x);
    }
}

int main(){

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

    cin>>n;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        g[u].emplace_back(v);
        g[v].emplace_back(u);
    }
    dfs(1,-1);
    cin>>m;
    for(int i=0;i<m;i++)cin>>U[i]>>V[i];
    for(int s=0;s<1<<m;s++){
        memset(fix,0,sizeof(fix));
        tot=n-1;
        for(int i=0;i<m;i++)if(s>>i&1){
            int u=U[i],v=V[i];
            if(dep[u]<dep[v])swap(u,v);
            while(dep[u]>dep[v])fix[u]=1,u=fa[u];
            while(u!=v)fix[u]=1,fix[v]=1,u=fa[u],v=fa[v];
        }
        for(int i=2;i<=n;i++)tot-=fix[i];
        if(__builtin_popcount(s)&1)ans-=1ll<<tot;
        else ans+=1ll<<tot;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int x, num, i, j, v[10] = { 0,2,5,5,4,5,6,3,7,6 };
	cin >> x >> num;
	string ans = "";
	vector<int> d(num), dp(x + 1, -INF);
	rep(i, num)
		cin >> d[i];
	dp[0] = 0;
	rep(i, dp.size()) {
		if (dp[i] != -INF) {
			rep(j, num) {
				if(i + v[d[j]] <= x)
					chmax(dp[i + v[d[j]]], dp[i] + 1);
			}
		}
	}
	sort(d.begin(), d.end(), greater<int>());
	for (i = x; i > 0;) {
		rep(j, num) {
			if (v[d[j]] <= i && dp[i - v[d[j]]] == dp[i] - 1) {
				ans += '0' + d[j];
				i -= v[d[j]];
				break;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <stdio.h>
#include <vector>
#include<algorithm>
using namespace std;



int main()
{
	long long N, K,tmp = 0;

	cin >> N >> K;


	if (K == 1 || N % K == 0) {
		cout << "0";
		return 0;
	}

	if (N % 2 == 1 && K == 2) {
		cout << "1";
		return 0;
	}
	if(N % 2 == 0 && K == 2) {
		cout << "0";
		return 0;
	}


		N = N % K;
	while (1) {
		tmp = N;
			N = (N - K);
			N = abs(N);
			if (tmp < N) {

				cout << tmp;
				return 0;
			}




	}


}


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

  int m[100000];

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

  for(int i = 0; i < q; ++i){
    scanf("%d", &x);
    m[x-1] = m[x-1]+1;
  }

  for(int i = 0; i < n; ++i){
    if(m[i]+k-q > 0){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
  return 0;

}


Measured memory_bytes: 896
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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 main(){
    string s,t;
    cin >> s >> t;
    vector<char> v;
    v.assign(t.begin(),t.end()-1);
    v.push_back('\0');

    if(strcmp(&v[0],s.c_str())==0){
        if(t.length()==s.length()+1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef pair<set<string>,string>P;
set<string>::iterator it1,it2;
struct no{
  int id;
  int syurui;
  double p;
  int same;
  string s;
  set<string>st;
  no *left,*right;
  no(int ID){left=right=NULL;s="";st.clear();id=ID;p=0.0;}
};
int C=0;
typedef no* node;
node make_tree(int l,int r,const string &str){
  int cnt=0;
  node x=new no(C++);
  if(l==r)return x;
  for(int i=l+1;i<r;i++){
    if(str[i]=='(')cnt++;
    if(str[i]==')')cnt--;
    if(cnt==0&&str[i]==' '){
      if(l+1<=i-1)x->left=make_tree(l+1,i-1,str);
      if(i+1<=r-1)x->right=make_tree(i+1,r-1,str);
      break;
    }
  }
  return x;
}
void print_tree(node x){
  if(x->left==NULL && x->right==NULL){
    cout<<'x';
    return;
  }
  cout<<'(';
  if(x->left!=NULL)print_tree(x->left);
  cout<<' ';
  if(x->right!=NULL)print_tree(x->right);
  cout<<')';
}
void delete_tree(node x){
  if(x->left!=NULL)delete_tree(x->left);
  if(x->right!=NULL)delete_tree(x->right);
  delete(x);
}
P calc_tree(node x){
  int cnt=0;
  vector<string>v;
  set<string>sl,sr,st;
  string s1,s2,new_s;
  if(x->left==NULL && x->right==NULL){
    sl.insert("()");
    return P(sl,"()");
  }
  if(x->left!=NULL){
    P p=calc_tree(x->left);
    sl=p.first;
    s1=p.second;
    v.push_back(s1);
  }
  if(x->right!=NULL){
    P p=calc_tree(x->right);
    sr=p.first;
    s2=p.second;
    v.push_back(s2);
  }
  sort(v.begin(),v.end());
  for(it1=sl.begin();it1!=sl.end();it1++){
    st.insert((*it1));
    for(it2=sr.begin();it2!=sr.end();it2++){
      if((*it1)==(*it2))cnt++;
    }
  }
  for(it2=sr.begin();it2!=sr.end();it2++){
    st.insert((*it2));
  }
  for(int i=0;i<v.size();i++){
    new_s+=v[i];
  }
  x->syurui=st.size();
  x->same=cnt;
  x->p=(double)cnt/st.size();
  x->s="("+new_s+")";
  st.insert(x->s);
  x->st=st;
  return P(st,x->s);
}
//(((x ((x ((x x) x)) x)) (x x)) ((x x) x))
//(((x ((x ((x x) x)) x)) (x x)) ((x x) x))

int comp(node l,node r){
  double s1=l->p;
  double s2=r->p;
  if(abs(s1-s2)>1e-9) return s1<s2?1:-1;
  if(!l->left&&!r->left) return 0;
  node ll=l->left;
  node lr=l->right;
  node rl=r->left;
  node rr=r->right;
  if(comp(ll,lr)<0)swap(ll,lr);
  if(comp(rl,rr)<0)swap(rl,rr);
  int c=comp(ll,rl);
  if(!c)return comp(lr,rr);
  return c;
}

void swap_tree(int pre,node x){
  if(x->left==NULL)return;
  if((comp(x->left,x->right)<0)==!pre)swap(x->left,x->right);
  if(x->left!=NULL)swap_tree(0,x->left);
  if(x->right!=NULL)swap_tree(1,x->right);
}

string s;
signed main(){
  while(getline(cin,s),s!="0"){
    C=0;
    node root=make_tree(0,s.size()-1,s);
    calc_tree(root);
    swap_tree(0,root);
    print_tree(root);
    cout<<endl;
    delete_tree(root);
    s="";
  }
}


Measured memory_bytes: 3308
import sys
import itertools
import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

while 1:
    a, op, b = readline().decode('utf8').split()
    a=int(a)
    b=int(b)
    if op=='?':
        break
    else:
        if op=='+':
            print(a+b)
        elif op=='-':
            print(a-b)
        elif op=='*':
            print(a*b)
        else:
            print(a//b)



Measured memory_bytes: 5676
use std::io;

fn main() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n: i32 = n.trim().parse().unwrap();

    let mut point_a = 0;
    let mut point_b = 0;

    for _ in 0..n {
        let mut words = String::new();
        io::stdin().read_line(&mut words).unwrap();
        let mut iter = words.trim().split_whitespace();

        let s = iter.next().unwrap();
        let t = iter.next().unwrap();

        if s < t {
            point_b += 3;
        } else if s > t {
            point_a += 3;
        } else {
            point_a += 1;
            point_b += 1;
        }
    }

    println!("{} {}", point_a, point_b);
}



Measured memory_bytes: 5028
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};
	

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

	int n;
	cin >> n;

	string s;
	char prev;
	map<string,int> m;
	for(int i=0;i<n;i++){
		cin >> s;
		if(m[s] != 0){
			cout << "No\n";
			return 0;
		}
		m[s]++;
		if(i!=0 && prev != s[0]){
			cout << "No\n";
			return 0;
		}
		prev = *(s.end()-1);
	}
	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<pi,null_type,less<pi>,rb_tree_tag,tree_order_statistics_node_update> indexed_set_pair;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 102;
const int logN = 19;

const double pie = acos(-1);

int f[(int)1e6+5];
int a[N];
void solve() {
    int n;
    cin>>n;
    REP(i,1,n) {
        cin>>a[i];
        f[a[i]]++;
    }
    int fans = 0;
    REP(i,1,n) {
        f[a[i]]--;
        bool ans = true;
        int s = sqrt(a[i]);
        REP(j,1,s) {
            if(a[i]%j==0) {
                if(f[j]>0 || f[a[i]/j]>0) {
                    ans = false;
                    break;
                }
            }
        }
        if(ans) fans++;
        f[a[i]]++;
    }
    cout<<fans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 8232
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d;
  cin>>d;
  if(d==25) cout<<"Christmas"<<endl;
  else if(d==24) cout<<"Christmas Eve"<<endl;
  else if(d==23) cout<<"Christmas Eve Eve"<<endl;
  else if(d==22) cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 3628
A, B, H, M=map(int,input().split())
import numpy as np


if M==0 or M==60:
    m_deg = 0
else:
    m_deg = (M/60) *360

h_deg = (H/12)*360 +(M/60)*30

theta_deg = max(m_deg, h_deg) - min(m_deg, h_deg)
theta_rad = theta_deg*np.pi/180

cos_theta = np.cos(theta_rad)

C_2 = A**2 + B**2 - 2*B*A*cos_theta

print(C_2**0.5)

Measured memory_bytes: 27188
#include <iostream>
#include <algorithm>

using namespace std;

int main(){

	double n;
	while(cin>>n){
		if(n<=48)
			cout<<"light fly"<<endl;
		else if(n<=51)
			cout<<"fly"<<endl;
		else if(n<=54)
			cout<<"bantam"<<endl;
		else if(n<=57)
			cout<<"feather"<<endl;
		else if(n<=60)
			cout<<"light"<<endl;
		else if(n<=64)
			cout<<"light welter"<<endl;
		else if(n<=69)
			cout<<"welter"<<endl;
		else if(n<=75)
			cout<<"light middle"<<endl;
		else if(n<=81)
			cout<<"middle"<<endl;
		else if(n<=91)
			cout<<"light heavy"<<endl;
		else
			cout<<"heavy"<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
H, W, K = map(int, input().split())
C = [[1 if c == "#" else 0 for c in input()] for _ in range(H)]
ans = 0
for bith in range(1 << H):
    for bitw in range(1 << W):
        c = [x[:] for x in C]
        for h in range(H):
            if bith & (1 << h):
                c[h] = [0] * W
        for w in range(W):
            if bitw & (1 << w):
                for h in range(H):
                    c[h][w] = 0
        count = sum(sum(x) for x in c)
        if count == K:
            ans += 1
print(ans)

Measured memory_bytes: 9212
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    string s;
    cin >> s;
    int ans = 0;
    rep(i, 4) if (s[i] == '2') ans++;
    cout << ans << endl;
}


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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    vector<int> hg(n);
    for(int i=0;i<n;++i)
    {
        cin>>hg[i];
    }
    vector<vector<int>> vec(n);
    for(int i=0;i<m;++i)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }

    int ans=0;
    for(int i=0;i<n;++i)
    {
        int flag=0;
        for(int j=0;j<vec[i].size();++j)
        {
            if(hg[vec[i][j]]>=hg[i])
            {
                flag=1;
                break;
            }
        }
        if(flag==0)
            ans++;
    }
    cout<<ans<<"\n";

}  

Measured memory_bytes: 8740
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int num = 0;
        
        for(int i=0; i<=N; i++){
            
            if(N < Math.pow(K,i)){
                    System.out.println(i);    
                    break;
                }
                
        }
        
    }
}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C,D=0;
  str N;
  cin>>A>>B>>C;
  cout<<(A-B)%C<<endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sr = new Scanner(System.in);
    int X = sr.nextInt();
    int Y = sr.nextInt();
    int XX = X * 2;
    int Z = Y-XX;
    int z = Z/2;
    if (XX>Y)
      System.out.println("No");
    else if (XX==Y)
      System.out.println("Yes");
    else
      if (Z % 2 != 0)
        System.out.println("No");
      else
        if (z > X)
          System.out.println("No");
        else
           System.out.println("Yes");
    	
     
  }

}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;
//{{{ templates
#define TT_ template<typename T>inline
#define TTF_ template<typename T,typename F>inline
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TT_ typename T::iterator minel(T&v){return min_element(begin(v),end(v));}
TT_ typename T::iterator maxel(T&v){return max_element(begin(v),end(v));}

inline void fast_io(){ios_base::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple

struct Era {
  string name;
  int base;
  int western;
  Era(string name, int base, int western) :
    name(name), base(base), western(western) {}
  bool valid(int year){
    return (western - base < year && year <= western);
  }
  void show(int year){
    cout << name << " " << base + year - western << endl;
  }
};

int main()
{
  int N, Q;
  while (N = in(), Q = in(), N || Q){
    vector<Era> eras;
    for (int i = 0; i < N; i++){
      string name;
      int base, western;
      cin >> name >> base >> western;
      eras.emplace_back(name, base, western);
    }
    while (Q--){
      bool ok = false;
      int year = in();
      for (auto& era : eras){
        if (era.valid(year)){
          era.show(year);
          ok = true;
          break;
        }
      }
      if (!ok) puts("Unknown");
    }
  }
  return 0;
}

Measured memory_bytes: 1332
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S,T;
	int q;
	int a[100001],b[100001],c[100001],d[100001];
	int Ssum[100001]={},Tsum[100001]={};
	scan(S);scan(T);
	rep(i,S.size()){
		Ssum[i+1]=Ssum[i]+S[i]-'A'+1;
	}
	rep(i,T.size()){
		Tsum[i+1]=Tsum[i]+T[i]-'A'+1;
	}
	scan(q);
	rep(i,q){
		scan(a[i]);scan(b[i]);scan(c[i]);scan(d[i]);
		if((Ssum[b[i]]-Ssum[a[i]-1])%3==(Tsum[d[i]]-Tsum[c[i]-1])%3) prin("YES");
		else prin("NO");
	}
	return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
#include<vector>
#include <iomanip>
#include <cmath>
#include <string.h>
#include <stdio.h>

using namespace std;


int main(){

  int A,B,K;
  
  cin >> A >> B >> K;
  vector<int>n(110);
  
  int C = min(A, B);
  for(int i=1; i<=C; i++){
  	if(A%i==0 && B%i==0)
      n.at(i) =i;
  }
  
  sort(n.begin(), n.end(), greater<int>());
  
  cout << n.at(K-1) << endl;

  
  return 0;
  
}


Measured memory_bytes: 3156
def main():
    n = int(input())
    before = ''
    words = set()

    for i in range(n):
        w = input()
        if w not in words:
            words.add(w)
        else:
            print('No')
            return

        if before == '':
            before = w
            continue

        if before[-1] != w[0]:
            print('No')
            return
        before = w

    print('Yes')


main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

int iAbs( int x )
{
	return ( x > 0 ? x : -x );
}

int iMin( int x, int y )
{
	return ( x < y ? x : y );
}

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

	std::vector<int> v( N );
	for ( int i = 0; i < N; i++ )
	{
		std::cin >> v[i];
	}

	int mindiff = INT_MAX;
	for ( int i = 0; i <= N - K; i++ )
	{
		int l_to_r = iAbs( v[i] ) + iAbs( v[i + K - 1] - v[i] );
		int r_to_l = iAbs( v[i + K - 1] ) + iAbs( v[i + K - 1] - v[i] );
		int tmp = iMin( l_to_r, r_to_l );

		if ( tmp < mindiff )
		{
			mindiff = tmp;
		}
	}

	std::cout << mindiff << std::endl;

	return ( 0 );
}


Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ull i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vi a = {2, 4, 5, 7, 9}, b = {0, 1, 6, 8}, c = {3};
    int d = n% 10;
    if (find(a.begin(), a.end(), d) != a.end()) cout << "hon";
    else if (find(b.begin(), b.end(), d) != b.end()) cout << "pon";
    else cout << "bon";
    cout << endl;

    return 0;
}

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

using namespace std;

int main(){

	int n, a, alice = 0, bob = 0;
	cin >> n;
	int vetor[n];

	for(a = 0; a < n; a++)
	{
		cin >> vetor[a];
	}
	
	sort(vetor, vetor+n, greater<int>());
	
	for(a = 0; a < n; a++)
	{			
	
		if(a % 2 == 0)
		{
			alice = alice + vetor[a];
		} else{
			bob = bob + vetor[a];
		}
	}
	
	cout << alice-bob;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

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

	Int N;
	cin >> N;

	vector<Int> a(N);
	Int cnt = 0;
	Int sum = 0;
	for (Int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] < 0) {
			a[i] = -a[i];
			cnt++;
		}
		sum += a[i];
	}

	sort(a.begin(), a.end());
	if (cnt % 2) {
		cout << sum - 2 * a[0] << "\n";
	}
	else {
		cout << sum << "\n";
	}
}

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

void solve(long long N, std::vector<long long> X) {
    vector<pair<ll, ll>> indexvec;
    vector<pair<ll, ll>> ans;
    rep(i, N) { indexvec.push_back(pair<ll, ll>(X[i], i + 1)); }
    sort(indexvec.begin(), indexvec.end());
    ll m0 = indexvec[N / 2 - 1].first;
    ll m1 = indexvec[N / 2].first;
    rep(i, N) {
        if (i <= (N / 2 - 1)) {
            ans.push_back(pair<ll, ll>(indexvec[i].second, m1));
        } else if (i >= N / 2) {
            ans.push_back(pair<ll, ll>(indexvec[i].second, m0));
        }
    }
    sort(ans.begin(), ans.end());
    rep(i, N) { cout << ans[i].second << endl; }
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> X(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &X[i]);
    }
    solve(N, std::move(X));
    return 0;
}


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

int main(){
    ll N;
    cin >> N;
    if(N>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632