akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

struct node {
	int key;
	struct node *right, *left, *parent;
};

typedef struct node Node;

Node *root;

void insert(int);
void print_i(Node *);
void print_p(Node *);
Node *find(int);
void delete (Node *);
Node *Minimum(Node *);
Node *getSuccessor(Node *);

int main() {
	int i;
	int n, k;
	char com[32];
	Node *u;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", com);

		if (com[0] == 'i') {
			scanf("%d", &k);
			insert(k);
		} else if (com[0] == 'p') {
			print_i(root);
			printf("\n");
			print_p(root);
			printf("\n");
		} else if (com[0] == 'd') {
			scanf("%d", &k);
			delete (find(k));
		} else {
			scanf("%d", &k);
			if (find(k) != NIL) {
				printf("yes\n");
			} else {
				printf("no\n");
			}
		}
	}
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	//場所決め
	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL) {
		root = z;
	} else {
		if (z->key < y->key) {
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void print_i(Node *s) {
	if (s == NIL) return;
	print_i(s->left);
	printf(" %d", s->key);
	print_i(s->right);
}
void print_p(Node *s) {
	if (s == NIL) return;
	printf(" %d", s->key);
	print_p(s->left);
	print_p(s->right);
}

Node *find(int k) {
	Node *s = root;
	while (s != NIL && k != s->key) {
		if (k < s->key) {
			s = s->left;
		} else {
			s = s->right;
		}
	}
	return s;
}

void delete (Node *z) {
	Node *y;  //削除対象
	Node *x;  // yの子

	//削除する節点を決める
	if (z->left == NIL || z->right == NIL) {
		y = z;
	} else {
		y = getSuccessor(z);
	}

	// yの子を決める
	if (y->left != NIL) {
		x = y->left;
	} else {
		x = y->right;
	}

	if (x != NIL) {
		x->parent = y->parent;
	}

	if (y->parent == NIL) {
		root = x;
	} else {
		if (y == y->parent->left) {
			y->parent->left = x;
		} else {
			y->parent->right = x;
		}
	}

	if (y != z) {
		z->key = y->key;
	}

	free(y);
}

Node *getSuccessor(Node *x) {
	if (x->right != NIL) {
		return Minimum(x->right);
	}
	Node *y = x->parent;
	while (y != NIL && x == y->right) {
		x = y;
		y = y->parent;
	}
	return y;
}

Node *Minimum(Node *s) {
	while (s->left != NIL) {
		s = s->left;
	}
	return s;
}


Measured memory_bytes: 20488
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

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

    for (int i = 0; i < N; i++)
    {
        double a, b, c, l;
        cin >> a >> b >> c;
        if (max({a, b, c}) == c)
        {
            if (a * a + b * b == c * c)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else if (max({a, b, c}) == b)
        {
            if (a * a + c * c == b * b)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else if (max({a, b, c}) == a)
        {
            if (c * c + b * b == a * a)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
        else
            cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3196
import java.util.*;

public class Main{
    int n;
    long[] a;

    Main(){
	Scanner sc = new Scanner(System.in);
	int cnt, q;

	while(sc.hasNext()){
	    cnt = 0;
	    n = sc.nextInt();
	    if(n == 0) break;
	    a = new long[n];

	    for(int i = 0; i < n; ++i) a[i] = sc.nextLong();
	    Arrays.sort(a);

	    q = sc.nextInt();
	    for(int i = 0; i < q; ++i) if(func(sc.nextLong())) ++cnt;
	    System.out.printf("%d\n", cnt);
	}
    }

    boolean func(long v){
	int p = 0, q = n-1, m;

	while(p <= q){
	    m = (p+q)/2;
	    if(a[m] == v) return true;
	    if(a[m] > v) q = m-1;
	    else p = m+1;
	}

	return false;
    }

    public static void main(String[] args){
	new Main();
    }
}

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


using namespace std;


const int MAXN = 100 * 1000 + 123;








int n, p[MAXN];

int main() {
    cin >> n;
    int cnt = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        if (p[i] != i)
            ans += (cnt + 1) / 2, cnt = 0;
        else
            cnt++;
    }
    ans += (cnt + 1) / 2;
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A,B,C;
  cin >> A >> B >> C;
  cout << min(B/A, C) << endl;
  return 0;
    

}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,k;
double a[200010];

LL f(double x,double y)
{
	if(y>=x) return 0;
	LL r=(LL)x/y;
	for(LL i=max(0LL,r-5);i<=r+5;i++)
	{
		double res=x/(i+1);
		//cout<<i<<' '<<res<<' '<<(LL)res<<endl;
		if(res<=y) return i; 
	} 
}

bool check(LL mid)
{
	LL lft=k;
	rep(i,n)
	{
		lft-=f(a[i],(double)mid);
		if(lft<0) return false;
	}
	//cout<<lft<<endl;
	return true;
}

int main()
{//freopen("in.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	rep(i,n) cin>>a[i];
	LL lb=1,ub=1e9,mid;
	while(lb<ub)
	{
		mid=(lb+ub)/2;//cout<<lb<<' '<<ub<<' '<<mid<<endl;
		if(check(mid)) ub=mid;
		else lb=mid+1;
	}
	cout<<lb<<endl;
	//check(0);
	//f(9,4);
	return 0;
}

Measured memory_bytes: 5264
import sys
readline = sys.stdin.readline

N = int(readline())
A = list(map(int,readline().split()))

dp = [[0] * (N + 1) for i in range(N + 1)]

# [i,j)
for l in range(1, N + 1):
  for i in range(N - l + 1):
    j = i + l
    
    if (N - l) % 2 == 0: # 先手
      dp[i][j] = max(dp[i + 1][j] + A[i], dp[i][j - 1] + A[j - 1])
    else:
      dp[i][j] = min(dp[i + 1][j] - A[i], dp[i][j - 1] - A[j - 1])
    
print(dp[0][N])

Measured memory_bytes: 139288
class Caesar
  class << self
    def shift(string, key)
      string.chars.map { |c| shift_letter(c, key) }.join
    end

    def shift_letter(char, key)
      # the input can only contain lowercase letters
      return char if char < 'a' || char > 'z'
      (((char.ord - 'a'.ord + key) % 26) + 'a'.ord).chr
    end
  end
end

class KeyGuessing
  KNOWN_WORDS = %w(the this that)

  class << self
    def guess_key(code)
      # This is sort of naive as I'm just trying out all of the possibilites,
      # but it's way simpler than trying calculate ord differences between
      # letters in words.
      (1..26).each do |key|
        decoded = Caesar.shift(code, key)
        words = decoded.split(' ')
        return key if words.any? { |w| KNOWN_WORDS.include?(w) }
      end
      nil
    end
  end
end

$stdin.each_line do |line|
  code = line.chop
  key = KeyGuessing.guess_key(code)
  if key
    puts Caesar.shift(code, key)
  else
    puts "Couldn't guess key for: #{code}"
  end
end

Measured memory_bytes: 8784
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod = 998244353;
 
int dx[]={-1, 0, 1, 0,1,-1,1,-1};
int dy[]={0, -1, 0, 1,1,-1,-1,1};




int32_t main()
{

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


string s; cin>>s; 
 if(s[0]=='7'||s[1]=='7'||s[2]=='7')
 {
     cout<<"Yes\n";
 }
 else cout<<"No\n";
  


}


Measured memory_bytes: 3648
N = gets.to_i
a_list = gets.split.map(&:to_i)
avg = a_list.reduce(&:+) / N

x = a_list.map { |a| (a - avg) ** 2 }.reduce(&:+)
y = a_list.map { |a| (a - (avg + 1)) ** 2 }.reduce(&:+)
ans = [x, y].min
puts ans


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

const int maxn = 200010;
int n, a[maxn], b[maxn];
long long sum[maxn];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        b[i] = b[i - 1] ^ a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    auto chk = [&](int l, int r) {
        return (sum[r] - sum[l - 1]) == (b[r] ^ b[l - 1]);
    };
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int l = 1, r = i, tmp;
        while (l <= r) {
            int mid = (l + r) >> 1;
            chk(mid, i) ? r = (tmp = mid) - 1 : l = mid + 1;
        }
        ans += i - tmp + 1;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<pair<int, int>> ab(n);
  vector<pair<ll, int>> sum(n);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    ab.at(i) = {a, b};
    sum.at(i) = {a+b, i};
  }
  sort(sum.rbegin(), sum.rend());
  ll ta = 0, ao = 0;
  rep(i, n){
    if(i % 2 == 0){
      ta += ab.at(sum.at(i).second).first;
    }else{
      ao += ab.at(sum.at(i).second).second;
    }
  }
  cout << ta-ao << endl;
  return 0;
}

Measured memory_bytes: 5596
#include<stdio.h>
#include<string.h>
#include<ctype.h>


int main(){

  char s[1000], c[10], r[1000];
  int q, i, j, a, b;

  scanf("%s", s);
  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%s", c);
    if(strcmp(c,"replace")==0){
      scanf("%d %d %s", &a, &b, r);
      for(j=a;j<=b;j++) s[j]=r[j-a];
    }else if(strcmp(c,"reverse")==0){
      scanf("%d %d", &a, &b);
      for(j=a;j<=b;j++) r[j-a]=s[j];
      for(j=0;j<b-a+1;j++) s[b-j]=r[j];
    }else if(strcmp(c, "print")==0){
      scanf("%d %d", &a, &b);
      for(j=a;j<=b;j++) printf("%c", s[j]);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 572
/*input
3 3 4

*/
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const ll mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c){cout<<"No"<<endl; return 0;}
    if(a==b || b==c || c==a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}		

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
int a[200010],f[200010],n;
bool check(int x){
    for(int i=1;i<=(n<<1)-1;i++)
        f[i]=(a[i]<x)?0:1;
    if(f[n]==f[n+1]||f[n-1]==f[n])
        return f[n];
    for(int i=n,j=n;i>=1;i--,j++)
        if(f[i]==f[i+1])return f[i];
        else 
        if(f[j]==f[j-1])return f[j];
    return f[n]^(n&1)^1;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=(n<<1)-1;i++)
        scanf("%d",&a[i]);
    int l=1,r=n<<1;
    while(r>l){
        int mid=(l+r)>>1;
        if(check(mid))
            l=mid+1;
        else r=mid;
    }
    printf("%d\n",r-1);
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>
#include <regex>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}


int main() {
	int N, T, ans=0, t, stop=0;
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		cin >> t;
		ans += t+T - max(stop, t);
		stop = max(stop, t + T);
	}
	print(ans);
}

Measured memory_bytes: 3620
#include<iostream>

using namespace std;

bool sosu(int n)
{
	for(int i=2;i*i<=n;i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}

int main(void)
{
	int n;
	bool flag[1000000];
	for(int i=1;i<=999999;i++){
		flag[i]=sosu(i);
	}
	while(cin>>n){
		int ans=0;
		for(int i=2;i<=n;i++){
			if(flag[i])
				ans++;
		}
		cout<<ans<<endl;
	}
}

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

using namespace std;

vector<int> ansh,answ;

int main(){
	while(1){
		int h,w;
		cin >> h >> w;
		if(h + w == 0) break;
		
		int dia = h*h + w*w;
		
		int ah,aw;
		int dmin = 1e9;
		
		bool f = false;
		
		for(int i = 1;i < 150;i++){
			for(int j = i + 1;j < 150;j++){
				int tdia = i*i + j*j;
				if(tdia >= dia){
					if(tdia == dia){
						if(i > h){ah = i;aw = j;f = true;break;}
					}else{
						if(dmin >= tdia){
							if(dmin == tdia){
								if(ah > i){
									ah = i;
									aw = j;
									dmin = tdia;
								}
							}else{
								ah = i;
								aw = j;
								dmin = tdia;
							}
						}
					}
				}
			}
			if(f) break;
		}
		
		ansh.push_back(ah);
		answ.push_back(aw);
	}
	
	for(int i = 0;i < ansh.size();i++) cout << ansh[i] << " " << answ[i] << endl;
	
	return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>

int x[5000];
int y[5000];
int i;
int tmp[5000];

int main(void){
	
	for(i=0;i<5000;i++){
		scanf("%d %d",&x[i],&y[i]);
		if(x[i]==0 && y[i]==0){
			break;
		}
	}
	for(i=0;i<5000;i++){
		if(x[i] > y[i]){
			tmp[i] = x[i];
			x[i] = y[i];
			y[i] = tmp[i];
		}
		printf("%d %d\n",x[i],y[i]);
			if(x[i+1]==0 && y[i+1]==0){
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private static void solveTC(int __) {
		
		/* For Google */
//		ans.append("Case #").append(__).append(": ");

//		code start

		int s=scn.nextInt(),w=scn.nextInt();
		if (w>=s){
			print("unsafe");
		}else {
			print("safe");
		}

//		code end

		ans.append("\n");
	}

	static void print(Object obj) {
		ans.append(obj.toString());
	}

	public static void main(String[] args) {
		
		scn = new Scanner();
//		int t = scn.nextInt();
		int t = 1;
		for (int i = 1; i <= t; i++) {
			ans = new StringBuilder();
			solveTC(i);
			System.out.print(ans);
		}
		
	}
	
	static Scanner scn;
	static StringBuilder ans;
	
	//Fast Scanner
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;
		
		public Scanner() {
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}
		
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
		
		int[] nextIntArray(int n) {
			int[] array = new int[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextInt();
			}
			return array;
		}
		
		Integer[] nextIntegerArray(int n) {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextInt();
			}
			return array;
		}
		
		long[] nextLongArray(int n) {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}
			return array;
		}
		
		String[] nextStringArray() {
			return nextLine().split(" ");
		}
		
		String[] nextStringArray(int n) {
			String[] array = new String[n];
			for (int i = 0; i < n; i++) {
				array[i] = next();
			}
			return array;
		}
	}
}

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

signed main(void)
{
	int x, dan;
	cin >> x;
	dan = 8;
	for (int i = 400; i < 2000; i += 200)
	{
		if (i <= x && x < i + 200)
		{
			cout << dan << endl;
			return 0;
		}	
		dan--;
	}
	return 0;
}


Measured memory_bytes: 3632
s = input()
k = int(input())
def counter(str):
    str_list = list(str)
    count = 0
    for i in range(1, len(str_list)):
        if str_list[i] == str_list[i-1]:
            str_list[i] = "&"
            count += 1
    return count
if k <= 3:
    print(counter(s*k))
else:
    moto = counter(s)
    cost1 = counter(s*2) - 2*moto
    cost2 = counter(s*3) - counter(s*2) - moto
    if k%2 == 0:
        print(moto*k + ((k-1)//2 + 1)*cost1 + ((k-1)//2)*cost2)
    else:
        print(moto*k + ((k-1)//2)*(cost1+cost2))


Measured memory_bytes: 38256
use proconio::input;
//use itertools::Itertools;

fn main() {
    input!(s: [String]);
    let mut n_ac = 0;
    let mut n_wa = 0;
    let mut n_tle = 0;
    let mut n_re = 0;
    s.into_iter()
     .for_each(|s| match &*s {
        "AC" => n_ac += 1,
        "WA" => n_wa += 1,
        "TLE" => n_tle += 1,
        "RE" => n_re += 1,
        _ => panic!("unreachable"),
    });
    println!("AC x {}\nWA x {}\nTLE x {}\nRE x {}",
             n_ac, n_wa, n_tle, n_re);
}

Measured memory_bytes: 7876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 
const ll INF = 1e18;

int main() {
    ll N; cin >> N;
    ll mul = 1;
    vector<ll> v(N); for (int i = 0; i < N; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    for (int i = 0; i < N; ++i) {
        ll a = v[i];
        if (a == 0) {
           cout << 0 << endl;
           return 0; 
        } 
        else if (mul <= INF / a) {
            mul *= a;
        }
        else {
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << mul << endl;
}

Measured memory_bytes: 4052
#include<stdio.h>

 int main()
{
  int n, a, i, j, y=0, l, m, k;
  scanf("%d", &n);
  int data[n];
  char c[12];

  for(i = 0; i < n; i++){
    scanf("%s %d", c, &a);

    if(c[0] == 'i'){
      data[i]=a;
    }

    else if(c[6] == 'F')
    {
      i -= 2;

      n -= 2;
    }

    else if(c[6] == 'L')
    {
      i--;

      n--;

      y++;
    }

    else
    {
      i--;
      n--;
      l=0;
      for(j = i; j >= 0; j--){

    if(l > 0) break;

    if(a == data[j]){
      k = 0;
      m = i-j;
      l++;
      while(m!=k++)
    data[j + k - 1]=data[j + 1 + k - 1];
      i--;
      n--;
    }
      }
    }
  }
  for(i = 0; i < n-y; i++){
    if(i == n-y-1)
      printf("%d\n",data[n-1-i]);
    else
      printf("%d ",data[n-1-i]);
  }
  return 0;
}

Measured memory_bytes: 5412
#include<stdio.h>

int main(){
	int n,i,sg=0,j;
	char s[101],t[101];
	scanf("%d%s%s",&n,s,t);
	for(i=n;i>=0;i--){
		int f=0;
		for(j=0;s[i+j]!=0;j++){
			if(s[i+j]!=t[j]){
				f=1;
				break;
			}
		}
		if(f!=1){
		sg=n-i;
	//		printf("%d\n",i);
	//		break;
		}
//		sg=n-i-1;
	}
	printf("%d\n",n*2-sg);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define INF int(1e-6)
#define MAX int(1e9)
typedef long long ll;
typedef long l;





int main (){
	ll n,m,x,y;
	cin >> n >> m;
	vector<pair<ll,ll> >v;
	for(ll i = 0; i<n; i++){
		cin >> x >> y;
		v.push_back(make_pair(x,y));
	}	
	
	sort(v.begin(),v.end());
	priority_queue<ll>pq;
	
	ll dia = 0; ll cnt = 0;
	
	for(ll i = 1; i<=m; i++){
		while(dia<n and v[dia].first == i){
			
			pq.push(v[dia].second);
			dia++;
		}
		
		if(!pq.empty()){
			cnt+= pq.top();
			pq.pop();
		}
	}
	

     
	
	cout << cnt << "\n";
	return 0;

}



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

using namespace std;

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

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

	cout << (H <= sum ? "Yes" : "No") << endl;
	return 0;
}


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

int main() {
  int N, A, B;
  cin >> N >> A >>B;
  int a, b;
  a = A * N ;
  b = B ;

  if (a <= b) {
    cout << a << endl;
  }
  else {
    cout << b << endl;
  }
}

Measured memory_bytes: 3548
#重み付きUnion-Find

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        px = find(par[x])
        wei[x] += wei[par[x]]
        par[x] = px
        return px

#xの根から距離
def weight(x):
    find(x)
    return wei[x]


#w[y]=w[x]+wとなるようにxとyを併合
def unite(x,y,w):
    w += wei[x]-wei[y]
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
            w = -w
        par[x] += par[y]
        par[y] = x
        wei[y] = w
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#x,yが同じ集合に属するときのwei[y]-wei[x]
def diff(x,y):
    return weight(y)-weight(x)
  
import sys
input = sys.stdin.readline  
n,m = [int(i) for i in input().split()]
par = [-1]*n
wei = [0]*n

for i in range(m):
  l,r,d = [int(i) for i in input().split()]
  if not same(l-1,r-1):
    unite(l-1,r-1,d)
  else:
    if diff(l-1,r-1) == d:
      continue
    else:
      print('No')
      exit()

print('Yes')

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

char S[ 5100 ];
char T[ 5100 ];
vector<string> A;

int main()
{
int i;
int j;
int K;
int iLen;
set<string> X;
char *p;

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

	cin >> S;
	cin >> K;

	i = 0;
	while( S[ i ] != '\0' )
	{
		A.push_back( S + i );
		i++;
	}

	iLen = i;
	sort( A.begin(), A.end() );
	for( i = 0; i < iLen; i++ )
	{
		p = (char*) A[ i ].c_str();

		j = 0;
		while( p[ j ] != '\0' )
		{
			j++;
			strcpy( T, p );
			T[ j ] = '\0';
			X.insert( T );
			if( X.size() == K )
			{
				cout << T << endl;

				return 0;
			}
		}
	}

	return 0;
}






Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    // read in integer 
    ll n, curr, ct;
    cin >> n;
    vector<int> a(n, 0);
    REP(i, n) cin >> a[i];

    curr = a[0];
    ct = 1;

    REP(j, n){
        if (curr == 2){
            cout << ct << endl;
            return 0;
        }
        curr = a[curr-1];
        ct++;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define m 1000000007
#define N 200005
#define modinv(a) power(a,m-2)
#define gcd(a,b) __gcd(a,b)
#define bits(x) __builtin_popcountll(x)
#define pb push_back
#define popb pop_back
#define all(v) v.begin(),v.end()
#define nl "\n"
typedef long long ll;
ll power(ll a,ll b)
{
    ll res;
    if(b==0)return 1;
    if(b==1)return a%m;
    if(b&1)
    {
        res=power(a,b-1)%m;
        res=((a%m)*(res%m))%m;
    }
    else
    {
        res=power(a,b/2)%m;
        res=((res%m)*(res%m))%m;
    }
    return res;
}
void solve()
{
    ll n,k=1000,ans;
    cin>>n;
    if(n%k==0)
    ans=0;
    else
    {
        ans=((n/k)+1)*k;
        ans-=n;
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3628
from collections import deque
h,w=map(int,input().split())
S=[input() for _ in range(h)]
inf=float("inf")
ans=0
for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            continue
        else:
            D=[[inf for _ in range(w)] for _ in range(h)]
            D[i][j]=0
            que=deque([(i,j)])
            while que:
                si,sj=que.popleft()
                for ni,nj in [(si+1,sj),(si-1,sj),(si,sj+1),(si,sj-1)]:
                    if 0<=ni<h and 0<=nj<w and S[ni][nj]!="#":
                        if D[ni][nj]>D[si][sj]+1:
                            D[ni][nj]=D[si][sj]+1
                            ans=max(ans,D[si][sj]+1)
                            que.append((ni,nj))
print(ans)
        

Measured memory_bytes: 48348
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  ll X; cin >> X;
  vector<pair<ll,ll>> p5s;
  for(ll B = -3800; B<=3800; B++){
    ll t = B*B*B*B*B;
    p5s.pb({t, B});
  }
  rep(i,sz(p5s)){
    rep(j,sz(p5s)){
      if(p5s[i].first-p5s[j].first==X){
        cout << p5s[i].second << " " << p5s[j].second<< endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <initializer_list>
#include <regex>
#include <cstdlib>
#include <ctime>
#include <random>
#include <set>
#include <cmath>
#include <iterator>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <forward_list>
#include <map>
#include <complex>
#include <exception>
#include <algorithm>
#include <numeric>
//#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
#define forup(i,a,b) for (auto i = a; i <= b; i++)
#define fordn(i, a, b) for(auto i = a; i < b; ++i)
#define print cout <<
#define input std::cin >>
#define readln(n) getline(std::cin, n);
#define forvec(i, v1) for(auto x: v1)
#define temp template<typename T>

double EPS = 1e-9;
int INF = 1000000005;
long long int modulu = 10e9 + 7;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);

using namespace std;

typedef long long int ll;
typedef long long unsigned llu;
typedef std::vector<std::string> vs;
typedef std::vector<char> vc;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::deque <ll> dqi;
typedef std::set<ll> seti;
typedef std::string str;

temp
void printans(T a) {
	for (auto x : a) std::cout << x << " ";
}

bool primetest(int x) {
	bool isprime = true;

	for (int i = 2; i <= sqrt(x); ++i) {

		if (x % i == 0) isprime = false;
	}

	return isprime;
}

int main() {

	ll num = 0;
	input num;

	for (num; ; num++) { if (primetest(num)) break; }

	print num;

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x)
{
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=2e5+10,mod=1e9+7;
char str[N];
int n;
int main() {
	rd(n);
	scanf("%s",str+1);
	int cnt=0,ans=1;
	int cur=0;
	for(int i=1;i<=2*n;++i) {
		int c=str[i]=='B';
		if(c!=cur) cnt++;
		else ans=ans*(ll)cnt%mod,cnt--;
		cur^=1;
	}
	if(cnt!=0) ans=0;
	for(int i=1;i<=n;++i) ans=ans*(ll)i%mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>
#include <queue>

#define PI 3.14159265358979323846

using namespace std;

typedef long long ll;
typedef long double ld;


int solve() {
    vector<string> w(7);
    w[0] = "MON";
    w[1] = "TUE";
    w[2] = "WED";
    w[3] = "THU";
    w[4] = "FRI";
    w[5] = "SAT";
    w[6] = "SUN";
    string now;
    cin >> now;
    ll cnt = 0;
    for(ll i = 0;i < 6; i++){
        if(w[i] == now){
            cnt = i + 1;
        }
    }
    cout << 7 - cnt << endl;

    return 0;
}


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


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.diverta2019
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            long n = ReadLong();

            long res = 0;
            for (long i = 1; i <= n / i; i++)
            {
                if (n % i > 0) continue;

                long m = n / i - 1;
                
                if (i<m) res += m;
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long int ll;

const ll MOD = 1000000007;
const ll inf = (ll) 1e18;

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

  string s;
  cin >> s;

  int n = s.length();

  ll ans = 0;
  ll count = 0;
  ll lastCount = 0;
  char last = '<';
  for (int i = 0; i < n; i++) {
    if (s[i] == last) {
      ans += count;
      count++;
    }
    else {
      if (s[i] == '<') {
        ans += max(count, lastCount);
        count = 1;
      }
      else {
        lastCount = count;
        count = 1;
      }
      last = s[i];
    }
  }
  if (last == '>') {
    ans += max(count, lastCount);
  }
  else {
    ans += count;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1172
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();

		String result = "Impossible";
		if (A % 3 == 0 || B % 3 == 0 || (A+B) % 3 == 0) {
			result = "Possible";
		}
		System.out.println(result);

	}

}

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

int main()
{
	int N;
	cin >> N;
	vector<long long> X( N );
	for( int i = 0; i < N; i++ ) {
		cin >> X[i];
	}

	vector<long long> x = X;
	sort( x.begin(), x.end() );
	for( int i = 0; i < N; i++ ) {
		long long n = X[i];
		int idx = lower_bound( x.begin(), x.end(), n ) - x.begin();
		int l = 0;
		int r = N - 1;
		if( idx < N / 2 ) l++;
		else r--;
		long long ans = x[(l  + r) / 2];
		cout << ans << endl;
	}
}


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

using namespace std;
 
int main(){
    long long n,a,i;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++){
        if(s[i]=='?'){
            if(i==0)
            s[i]='D';
            else if(i==n-1){
                s[i]='D';
            }else{
                if(s[i+1]=='D'&&s[i-1]=='D')
                s[i]='P';
                else if(s[i+1]=='?'&&s[i-1]=='D')
                s[i]='P';
                else
                s[i]='D';
            }
        }
    }cout<<s;

    return 0;
    }
 


Measured memory_bytes: 3756
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()



def main():
    N = iRaw()
    Ps = isRaw()
    ni =0
    curMin = N+1
    for i,p in enumerate(Ps):
        if p <= curMin:
            ni+=1
            curMin = p
    return ni


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 75644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
signed
main(){
        int n;
        while(cin >> n && n!=0)
        {
                vector<double> a(n);
                double ave = 0;
                for(int i=0;i<n;i++)
                {
                        cin >> a[i];
                        ave += a[i];
                }
                ave = ave /(double)n;
 
                int cnt = 0;
                for(int i=0;i<n;i++)
                {
                        if(a[i] <= ave){
                                cnt++;
                        }
                }
                cout << cnt << endl;
        }
}


Measured memory_bytes: 3296
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    for( int i=0; i<n; ++i ) {
        int y, m, d;
        cin >> y >> m >> d;

        const int by = y - 1;
        const int bigyn = by / 3;
        const int smlyn = bigyn * 2 + by % 3;

        const int fyds = ( bigyn * 20 * 10 ) + ( smlyn * ( 20 + 19 ) * 5 );

        const int bm = m - 1;        
        const int fmds = ( y % 3 == 0 )
                                ? bm * 20
                                : ( ( bm / 2 ) * ( 20 + 19 ) ) + ( ( bm % 2 ) * 20 )
                                ;

        cout << ( 196471 - ( fyds + fmds + d ) ) << endl;
    }
}

Measured memory_bytes: 1160
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const ll INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
const ll Maxn=1e5;
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll dp[100003][2];
int main()
{ //0是小于 1是等于
 string s;
 cin>>s;
 int a=s.size();dp[0][1]=1;
 for(int i=1;i<=a;i++)
    if(s[i-1]=='1')
 {
     dp[i][0]=dp[i-1][0]*3%mod+dp[i-1][1]%mod;
     dp[i][1]=dp[i-1][1]*2%mod;
 }
 else{

    dp[i][1]=dp[i-1][1];
    dp[i][0]=dp[i-1][0]*3%mod;
 }cout<<(dp[a][0]+dp[a][1])%mod;
}



Measured memory_bytes: 2048
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
static int v = int.Parse(input[0]);
static int e = int.Parse(input[1]);
static bool[] checkedVertex = new bool[v];//頂点が確認済みか？
static List<int> answers = new List<int>();
static List<int>[] nextList = new List<int>[v];
static List<int>[] nextListB = new List<int>[v];//逆頂点
static List<long>[] nextListBlength = new List<long>[v];
static int[] inDegree = new int[v];//入次数

	static void Main()
	{
    for(int i = 0; i < v; i++) 
    {
      nextList[i] = new List<int>();//リストの宣言が必要
      nextListB[i] = new List<int>();
      nextListBlength[i] = new List<long>();
    }

    for(int i = 0; i < e; i++)
    {
      string[] inputa = Console.ReadLine().Split(' ');
      int b = int.Parse(inputa[0]);
      int c = int.Parse(inputa[1]);
      long d = long.Parse(inputa[2]);
      nextList[b].Add(c);//隣接リストの作成
      nextListB[c].Add(b);
      nextListBlength[c].Add(d);
    }

    TopologicalSort();

    long answer = 0;
    long[] dp = new long[v+1];

    int[] vertexNums = new int[v];//各頂点が0,1,...番目
    for(int i = 0; i < v; i++)
    {
      vertexNums[answers[i]] = i+1;
    }

    for(int i = 2; i <= v; i++)
    {
      for(int j = 0; j < nextListB[answers[i-1]].Count; j++)
      {
        dp[i] = Math.Max(dp[i], 
          dp[vertexNums[nextListB[answers[i-1]][j]]] + nextListBlength[answers[i-1]][j]);
        
        answer = Math.Max(answer, dp[i]);
      }
    }

    Console.WriteLine(answer);
	}

  static void TopologicalSort()//トポロジカルソート
  {
    for(int i = 0; i < v; i++) inDegree[i] = 0;//初期化
    
    for(int i = 0; i < v; i++)
    {
      for(int j = 0; j < nextList[i].Count(); j++)
      {
        inDegree[nextList[i][j]]++;//入次数の計算
      }
    }

    for(int i = 0; i < v; i++)
    {
      if(inDegree[i] == 0 && !(checkedVertex[i])) BFS(i);
    }
  }

  static void BFS(int startVertex)//幅優先探索
  {
    Queue<int> que = new Queue<int>();
    que.Enqueue(startVertex);//追加
    checkedVertex[startVertex] = true;
    while(que.Count > 0)
    {
      int poppedMemo = que.Peek();//一番上を見る
      que.Dequeue();//取り出し
      answers.Add(poppedMemo);//追加
      for(int i = 0; i < nextList[poppedMemo].Count(); i++)
      {
        int aimVertex = nextList[poppedMemo][i];
        inDegree[aimVertex]--;
        if(inDegree[aimVertex] == 0 && !(checkedVertex[aimVertex]))
        {
          checkedVertex[aimVertex] = true;
          que.Enqueue(aimVertex);
        }
      }
    }
  }
  
}



Measured memory_bytes: 18728
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n, q;
	string s;
	cin >> n >> q >> s;
	vector<int> coun(n);
	vector<int> sum(n+1);
	vector<int> l(q);
	vector<int> r(q);
	for (int i = 0; i < q; i++){
		cin >> l[i] >> r[i];
	}
	for (int i = 1; i < s.length(); i++){
		if (s[i-1] == 'A' && s[i] == 'C'){
			coun[i] = 1;
		}
	}
	for (int i = 1; i <= n; i++){
		sum[i] = sum[i-1] + coun[i-1];
	}
	for (int i = 0; i < q; i++){
		cout << sum[r[i]] - sum[l[i]] << endl;
	}
 }

Measured memory_bytes: 2688
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
b = a[0]
c = []
while True:
  if b == 2:
    print(len(c)+1)
    exit()
  if len(c)> n:
    print(-1)
    exit()
  else:
    c.append(b)
    b = a[c[-1]-1]

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

int n, cntA, cntB, cntBA;
string s[10005];

signed main(){
  
  cin>>n;
  
  int ans = 0;
  
  for(int i=0;i<n;i++){
    
    cin>>s[i];
    
    if( s[i][0] == 'B' && s[i][s[i].size()-1] == 'A' ){
      cntBA++;
    }
    else if( s[i][0] == 'B' ) cntB++;
    else if( s[i][s[i].size()-1] == 'A' ) cntA++;
    
    for(int j=1;j<s[i].size();j++){
      if( s[i][j] == 'B' && s[i][j-1] == 'A' ) ans++;
    }
    
  }
  
  ans += max( 0LL, cntBA - 1 );
  
  if( cntA && cntBA ){
    ans++; 
    cntA--;
  }
  
  if( cntB && cntBA ){
    ans++;
    cntB--;
  }
  
  ans += min( cntA, cntB );
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll  long long int 
using namespace std;
int p[100020]={0},lim=100007;

int main()
{
	p[0]=p[1]=1;
	int i,j;
	for(i=2;i<=lim;i++)
	{
		if(p[i]==0)
		{
			for(j=i*2;j<=lim;j+=i)
				p[j]=1;
		}
	}
	int n;
	cin>>n;
	while(p[n]!=0)
		n++;
	cout<<n<<endl;
	
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
   string s;
   cin>>s;
   if(s[s.length()-1]=='s'){
       s=s+"es";
       cout<<s<<endl;
   }
   else{
       s=s+"s";
       cout<<s<<endl;
   }
   
   return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int A, B;
   cin >> A >> B;
   if (A == 1) A += 13;
   if (B == 1) B += 13;
   if (A > B) cout << "Alice" << endl;
   else if (A < B) cout << "Bob" << endl;
   else cout << "Draw" << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <climits>
#include <numeric>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
	#define debug printf
#else
	#define debug(...)
#endif
int main(int argc, char const *argv[])
{
	int a;
	cin>>a;
	string s;
	cin>>s;
	if(a >= 3200)
	{
		cout<<s<<endl;
	}
	else
	{
		printf("red\n");
	}
	return 0;
}

Measured memory_bytes: 256
INF = int(1e10)

N, K = list(map(int, input().split()))
H = list(map(int, input().split()))
H.insert(0, -1)

DP = [INF] * (2 * N)
DP[1] = 0

for i in range(1, N):
    for k in range(1, K + 1):
        if i + k <= N:
            DP[i + k] = min(DP[i + k], DP[i] + abs(H[i] - H[i + k]))

print(DP[N])

Measured memory_bytes: 52832
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 3e5;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;


int main(){

    FASTIO;
    PRECISION; 

    int n,k;
    cin>>n>>k;
    ld ans = 0;
    for(int i=1;i<=n;i++){
        int score = i;
        ld fact = 1;
        while(score<k){
            score*=2;
            fact/=2.0;
        }
        ans+=fact;
    }

    ans/=(n*1.0);
    cout<<ans<<"\n";
}


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

typedef long long ll;

int main(void){
    string s;cin >> s;
    string t = "";
    int i = 0;
    int n = s.size();
    while(i < n){
        if(s[i] == 'A')t += 'A',i++;
        else if(s[i] == 'B' and s[i+1] == 'C')t += 'B',i += 2;
        else t += 'C',i++;
    }
    
    long long cnt = 0,ans = 0;
    int m = t.size();
    for (int i = 0; i < m; ++i)
    {
        if(t[i] == 'A')cnt++;
        else if(t[i] == 'B')ans += cnt;
        else cnt = 0;
    }
    

    cout << ans << endl;
}


Measured memory_bytes: 776
/**
 * @author khokharnikunj8
 */

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

class ECrestedIbisVsMonster {
public:
    void solve(std::istream &in, std::ostream &out) {
        int h, n;
        in >> h >> n;
        vector<pair<int, int>> ar(n);
        for (int i = 0; i < n; i++) in >> ar[i].first >> ar[i].second;
        vector<int> dp(h + 1, INT32_MAX / 2);
        for (int i = 1; i <= h; i++) {
            for (int j = 0; j < n; j++) {
                int prev = i - ar[j].first;
                if (prev > 0) dp[i] = min(dp[i], dp[prev] + ar[j].second);
                else dp[i] = min(dp[i], ar[j].second);
            }
        }
        out << dp[h] << "\n";


    }
};


int main() {
    ECrestedIbisVsMonster solver;
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

ll N, mn = MOD, mn1 = 0, mx = 0, mx1 = MOD; 
vector<pair<ll,ll>> posi;

int main() {
	cin >> N;
	F0R(i,N) {
		pair<ll,ll> x; cin >> x.f >> x.s;
		if (x.f>x.s) swap(x.f,x.s);
		mn = min(mn,x.f);
		mn1 = max(mn1,x.f);
		mx = max(mx,x.s);
		mx1 = min(mx1,x.s);
		posi.pb(x);
	}
	ll ans = (mn1-mn)*(mx-mx1);
	sort(posi.begin(),posi.end());
	reverse(posi.begin(),posi.end());
	multiset<ll> coor;
	for (auto a: posi) coor.insert(a.s);
	for (auto a: posi) {
		coor.erase(coor.find(a.s));
		coor.insert(a.f);
		ans = min(ans,(mx-mn)*(*prev(coor.end())-*coor.begin()));
	}
	cout << ans;
}

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

using namespace std;

using ll = long long;

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

Measured memory_bytes: 3624
//ALDS1_12_cにて、AC
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main(){
  int n;
  cin>>n;
  vector<pair<int,int> > adj[10005]; //重み付き有向グラフの隣接リスト表現
  //隣接リストの作成
  int u,k;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      adj[u].emplace_back(v,c);
    }
  }

  //ここからダイクストラ
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
  vector<bool> fg(n+1000);
  vector<int> cost(n+1000);
  //初期化
  for(int i=0;i<n;i++){
    cost[i]=INF;
    fg[i]=false;
  }
  //出発地点はコスト0
  cost[0]=0;
  pq.emplace(0,0);
 
  //最短経路を検出
  while(!pq.empty()){
    auto now=pq.top(); pq.pop();
    int u=now.second;
    fg[u]=true;

    //最小値を取り出し、それが最短でなければ無視
    if(cost[u]<now.first) continue;
    
    //次の辺へ移動
    for(int j=0;j<adj[u].size();j++){
      int v=adj[u][j].first;
      if(fg[v]) continue;
      if(cost[v]>cost[u]+adj[u][j].second){
        cost[v]=cost[u]+adj[u][j].second;
        //priority_queueはデフォルトで大き値を優先するため、-1をかける。
        pq.emplace(cost[v],v);
      }
    }
  }

  for(int i=0;i<n;i++){
    cout<<i<<" "<<(cost[i]==INFINITY ? -1 : cost[i])<<'\n';
  }
  return(0);
}


Measured memory_bytes: 3368