akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i<(n);i++)
#define fore(i,a) for(auto &i:a)
#define debug(a,b) cout << "debug : " << a << " , "<< b << endl
using ll=long long;
const ll INF=1LL<<60;
const ll mod=1E9+7;


int main(){
  int r;
  cin >> r;
  cout << r*r;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    if ((A * B) % 2 != 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

namespace ConsoleApplication3
{
    class Program
    {
        public static void Main()
        {
            int[] c = new int[26];
            while (true)
            {    string a = Console.ReadLine();
                if (a == null) break;
                for (int b = 0; b < a.Length; b++)
                {
                    for (int d = 65; d < 91; d++)
                    {
                        if (a[b] == (char)(d + 32) || a[b] == (char)d) { c[d - 65]++; break; }
                    }
                }
            }

            for(int e = 0; e < 26; e++)
            {
                Console.WriteLine("{0} : {1}",(char)(e+97),c[e]);
            }
        }
    }
}

Measured memory_bytes: 9092
#include <stdio.h>
 
main(){
  int a;
  int i;
  int b = 0;
  int c = 1;
  int n;
   
  scanf("%d",&n); 
  for(i = 0;i <= n;i++){ 
    a = b + c;
    b = c;
    c = a;
  }
  printf("%d\n",b);
   
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  vector<pair<int,int>> p(n);
  REP(i,n){
    int a,b;
    cin>>a>>b;
    p[i]=make_pair(a,b);
  }
  sort(ALL(p),greater<pair<int,int>>());
  cout<<p[0].first+p[0].second<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){

  int n, i, k, p;
  int co[1000];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    
    scanf("%d%d", &k, &p);
    
    if(k < p) co[i] = k;
    else if(k%p != 0) co[i] = k%p;
    else if(k%p == 0) co[i] = p;
  }
  for (i = 0; i < n; i++){
    printf("%d\n", co[i]);
  }
  return 0;
}

Measured memory_bytes: 600
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

int sum(int n)
{
    int c=0;
    while(n>=1)
    {
        c+=n%10;n/=10;
    }
    return c;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> N;
    int min_n=INF;
    for(int A=1; A<N; A++)
    {
        int B = N-A;
        int n = sum(A)+sum(B);
        min_n = min(min_n, n);
    }
    cout << min_n << endl;
  
    return 0;
}



Measured memory_bytes: 256
S = input()
s = list(S)
exp = ""
total = 0

for i in range(2**(len(S)-1)):
    a = list(bin(i)[2:])

    a = ["0"] * (len(s) - len(a)-1) + a
    for j in range(len(s)-1):
        if (a[j] == "1"):
            exp += s[j] + "+"
        else:
            exp += s[j]

    exp += s[-1]
    total += sum(map(int, exp.split("+")))
    exp = ""

print(total)


Measured memory_bytes: 3064
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();

            if (S.Length <= K)
            {
                Console.WriteLine(S);
            }
            else
            {
                S = S.Substring(0, K) + "...";
                Console.WriteLine(S);
            }
        }
    }
}


Measured memory_bytes: 27488
#include<bits/stdc++.h>
using namespace  std;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int sum = 0;
    for(int i = 0; i < n; i++){
        int s = abs(2 * a[i]);
        int t = abs(2 * (k - a[i]));
    sum += min(s,t);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define ll long long
using namespace std;

int main()
{
	ll int n;
	ll int x, y;
	ll int i;
	priority_queue<ll int> q;


	cin >> n;

	x = (ll int)ceil(sqrt(n));
	i = 2;
	y = 1;

	while (i <= x) {
		if (n % i == 0) {
			q.push(-(i + n / i));
		}
		i++;
	}

	if (q.empty()) {
		cout << n - 1;
	} else {
		cout << -(q.top()) - 2;
	}

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
class Main{
    public static void main(String[] av){
	Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
	int b=sc.nextInt();
	int d=a/b;
	int r=a%b;
	double f=(double)a/b;
	System.out.print(d+" "+r+" ");
	System.out.printf("%.8f\n",f);

    
    
    }
}



Measured memory_bytes: 26444
a,b,k=map(int,list(input().split(" ")))
if b-a+1 <= k*2:
   for i in range(a,b+1):
      print(i)
else:
   for i in range(a,a+k):
      print(i)
   for i in range(b-k+1,b+1):
      print(i)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1000000007;

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

    vector<ll> A(N + 1);
    for(int i=0;i<N + 1;i++){
        cin >> A[i];
    }

    if(N == 0){
        if(A[0] == 1){
            cout << 1 << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }

    vector<ll> max_nodes(N + 1);
    max_nodes[0] = 1;
    for(int i=1;i<=N;i++){
        max_nodes[i] = min(ll(1LL << 61), max_nodes[i - 1] * 2);
    }

    vector<ll> l(N + 1), r(N + 1);
    if(A[N] > max_nodes[N]){
        cout << -1 << endl;
        return 0;
    }
    for(int i=N-1;i>=0;i--){
        l[i] = (l[i + 1] + A[i + 1] + 1) / 2;
        r[i] = min(max_nodes[i], (r[i + 1] + A[i + 1]));
        if(l[i] + A[i] > max_nodes[i] || l[i] > r[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    ll ans = 1;
    ll vs = 1;
    for(int i=1;i<=N;i++){
        vs = min(vs * 2 - A[i], r[i]);
        ans += vs + A[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6428
//author:luckYrat(twitter:@luckYrat_)

//#include <bits/stdc++.h>
//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
#define MOD 1000000007

#define pb push_back
#define fir first
#define scn second

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  int n;cin>>n;
  for(int i = 1; n >= i; i++){
    if(n == i*108/100){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl; 
}




Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000;

typedef long long ll;
typedef unsigned long long ull;

ll dp[1010][3][1010];

int main(void) {
  int x;
  cin >> x;
  int n = 2 * x;
  int pc[200100] = {};
  for (int i = 2; i <= n; i++) {
    if (pc[i] == 0) pc[i] = 1;
    for (int j = 2; i * j <= n; j++) pc[i*j] = -1;
  }
  for (int i = x; i <= n; i++) {
    if (pc[i] == 1) {
      cout << i << endl;
      return 0;
    }
  }
}


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

int main(int argc, const char * argv[]) {
    int antenaPos[5] = {0,0,0,0,0};
    for(int i = 0; i < 5; i++){
        cin >> antenaPos[i];
    }

    int k = 0;
    cin >> k;

    int max = 0;
    int min = 124;
    for(int i = 0; i < 5; i++){
        if(max < antenaPos[i]){
            max = antenaPos[i];
        }
        if(min > antenaPos[i]){
            min = antenaPos[i];
        }
    }

    if(max - min > k){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
const int COMMAX = 2000003;
const int MOD = 1000000007;
vector<long long> fac, finv, inv;
 
void InitializeCombination(void){
    fac.push_back(1LL);
    fac.push_back(1LL);
    finv.push_back(1LL);
    finv.push_back(1LL);
    inv.push_back(0LL); //Though 0^(-1) cannot be defined, there should be some number in inv[0]
    inv.push_back(1LL);
    for (int i = 2; i < COMMAX; i++){
        fac.push_back(fac[i-1] * (long long)i % (long long)MOD);
        inv.push_back((long long)MOD - inv[MOD%i] * (long long)(MOD/i) % (long long)MOD);
        finv.push_back(finv[i-1] * inv[i] % (long long)MOD);
    }
}
 
long long Combination(int n, int r){
    if (n < r) return 0LL;
    if (n < 0 || r < 0) return 0LL;
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
}

int main(void){

    int r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    InitializeCombination();
    long long res = (long long)MOD + Combination(r2+c2+2, r2+1)-Combination(r1+c2+1, r1);
    res %= MOD;
    res += MOD-Combination(r2+c1+1, c1);
    res %= MOD;
    res += Combination(r1+c1, r1);
    res %= MOD;
    cout << res << endl;
    return 0;
}

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

int main() {

	const int N = 30;
	bool food[N][N] = { false };
	int tate, yoko;
	int cnt, like, ans = 0;

	cin >> tate >> yoko;

	for (int i = 0; i < tate; i++) {
		cin >> cnt;
		for (int k = 0; k < cnt; k++) {
			cin >> like;
			food[i][like - 1] = true;
		}
	}

	/*//debug
	for (int i = 0; i < tate; i++) {
		for (int k = 0; k < yoko; k++) {
			food[i][k] ? cout << "T " : cout << "F ";
		}
		cout << endl;
	}
	*/

	for (int i = 0; i < yoko; i++) {
		int counter = 0;
		for (int k = 0; k < tate; k++) {
			if (food[k][i])counter++;
		}
		if (counter == tate)ans++;
	}

	cout << ans << endl;

	return 0;
	
}


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

using namespace std;

int main(){
    string n;
    cin >> n;
    string result = "bon";
    reverse(n.begin(), n.end());
    if(n[0] == '2' || n[0] == '4' || n[0] == '5' || n[0] == '7' || n[0] == '9'){
        result = "hon";
    }
    else if(n[0] == '0' || n[0] == '1' || n[0] == '6' || n[0] == '8'){
        result = "pon";
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	Integer steps[];
	BigInteger results[];

	public Main(int n, Integer a[]) {
		steps = new Integer[n];
		results = new BigInteger[n];
		for (int i = 0; i < steps.length; i++) {
			steps[i] = 1;
		}
		for (int e : a) {
			steps[e] = 0;
		}

	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int m = s.nextInt();
		Integer a[] = new Integer[m];
		for (int i = 0; i < m; i++) {
			a[i] = s.nextInt();
		}
		System.out.println(
				new Main(n, a).calc(0).mod(new BigInteger("1000000007")));
	}

	public BigInteger calc(int prefix) {
		BigInteger shortcut = results[prefix];
		BigInteger result;
		if (shortcut != null) {
			return shortcut;
		}
		if (prefix >= steps.length) {
			result = BigInteger.ZERO;
		} else if (prefix == steps.length - 1) {
			result = BigInteger.ONE;
		} else if (prefix == steps.length - 2) {
			result = BigInteger.ONE
					.add(((steps[prefix + 1] == 1) ? BigInteger.ONE
							: BigInteger.ZERO));
		} else {
			result = ((steps[prefix + 1] == 1) ? calc(prefix + 1)
					: BigInteger.ZERO)
							.add((steps[prefix + 2] == 1) ? calc(prefix + 2)
									: BigInteger.ZERO);
		}
		results[prefix] = result;
		return result;
	}
}

Measured memory_bytes: 654628
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int MOD = (int)(1e9) + 7;
const int INF = (1ll << 31) - 1;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct SegmentTree {
	int n;
	vector<int>d;
	SegmentTree(int m) {
		for (n = 1; n < m; n <<= 1);
		d.assign(2 * n, 0);
	}
	void add(int a, int b, int x = -1, int k = 1, int l = 0, int r = -1) {
		if (r == -1)r = n;
		if (r <= a || b <= l)return;
		if (a <= l&&r <= b) {
			if (x >= 0)d[k] += (r - l)*x;
			return;
		}
		else {
			if (d[k] != 0) {
				d[2 * k] += d[k] / 2;
				d[2 * k + 1] += d[k] / 2;
				d[k] = 0;
			}
			add(a, b, x, 2 * k, l, (l + r) / 2);
			add(a, b, x, 2 * k + 1, (l + r) / 2, r);
		}
	}
	int get(int i) {
		add(i, i + 1);
		return d[n + i];
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	SegmentTree seg(n);
	rep(i, 0, q) {
		int com; cin >> com;
		if (com) {
			int x; cin >> x;
			cout << seg.get(x - 1) << endl;
		}
		else {
			int s, t, x; cin >> s >> t >> x;
			seg.add(s - 1, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 4916
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n+1];
        for (int i=0; i < n; i++) a[i] = sc.nextInt();
        a[n] = k;

        Arrays.sort(a);

        int left = 0;
        int right = n;
        while (true) {
            int i = (left+right)/2;
            boolean[][] dp = new boolean[n+1][k+1];
            dp[0][0] = true;

            for (int j = 0; j < n; j++) {
                for (int l = 0; l <= k; l++) {
                    if (dp[j][l]) {
                        dp[j+1][l] = true;
                        if (i != j && l+a[j] <= k) {
                            dp[j+1][l+a[j]] = true;
                        }
                    }
                }
            }

            boolean f = false;
            for (int j = Math.max(k-a[i], 0); j < k; j++) {
                if (dp[n][j]) f = true;
            }

            if (right == left) {
                if (f) System.out.println(0);
                else System.out.println(1);
                break;
            } else if (right == left + 1) {
                if (f) System.out.println(i);
                else System.out.println(i+1);
                break;
            }

            if (f) right = i;
            else left = i;
        }
    }
}

Measured memory_bytes: 218696
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    for(int h; cin >> h, h; ){
        int ans = 0;
        vector<string>vec(h, "XXXXX");
        for(int y = h - 1; y >= 0; y--){
            for(int x = 0; x < 5; x++){
                cin >> vec[y][x];
            }
        }
        for(;;){
            int tmp = 0;
            vector<string>flg = vec;
            for(int y = 0; y < h; y++){
                for(int x = 0; x < 3; x++){
                    if(vec[y][x] == vec[y][x + 1] && vec[y][x + 1] == vec[y][x + 2]){
                        flg[y][x] = 'F';
                        flg[y][x + 1] = 'F';
                        flg[y][x + 2] = 'F';
                    }
                }
            }
            for(int x = 0; x < 5; x++){
                queue<char>Q;
                for(int y = 0; y < h; y++){
                    if(flg[y][x] == 'F'){
                        tmp += vec[y][x] - '0';
                    }
                    else{
                        Q.push(vec[y][x]);
                    }
                }
                for(int y = 0; y < h; y++){
                    vec[y][x] = '0';
                    if(!Q.empty()){
                        vec[y][x] = Q.front();
                        Q.pop();
                    }
                }
            }
            if(tmp)ans += tmp;
            else break;
        }
        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

	const int MOD = 1e9 + 7;

	ll ans = 1;
	rep(i, n)
	{
		ans *= (i + 1);
		ans %= MOD;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3632
n, y = map(int,input().split())
ans = 0
for a in range(0, n+1):
    for b in range(0, n+1):
        c = n - a - b
        if 10000*a + 5000*b + 1000*c == y and c >= 0 and ans ==0:
            print(a, b, c)
            ans = 1
if ans == 0:
    print(-1, -1, -1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll  long long int
#define mod 1000000007
using namespace std;
int main() {
    ll n;
    cin>>n;
    ll a[n+1];
    ll b[n+1];
    for(ll i=0;i<n+1;i++)cin>>a[i];
    for(ll i=0;i<n;i++)cin>>b[i];
    b[n]=0;
    ll s=0;
    if(a[0]>=b[0]){s=b[0],b[0]=0;}
    else
        s=a[0],b[0]=b[0]-a[0];
   
    for(ll i=1;i<n+1;i++){
        ll prev=b[i-1];
        if(a[i]>=prev+b[i]){
            s+=(prev+b[i]);
            b[i]=0;
           
        }
        else{
            ll d=a[i]-prev;
            if(d>0){b[i]-=d;}
            s+=(a[i]);
             
        }
        
    }
    cout<<s<<endl;
    }




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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

std::string insert_doll(std::string const& s) {
    string res;
    for(int i = 0; i < (int)s.size(); ++i) {
        res += "$";
        res += s[i];
    }
    res += "$";
    return res;
}

std::vector<int> manacher(std::string const& s) {
    int const n = s.size();
    std::vector<int> res(n);
    int i = 0, j = 0;
    while(i < n) {
        while(i - j >= 0 && i + j < n && s[i - j] == s[i + j]) ++j;
        res[i] = j;
        int k = 1;
        while(i - k >= 0 && i + k < n && k + res[i - k] < j) {
            res[i + k] = res[i - k];
            ++k;
        }
        i += k; j -= k;
    }
    return res;
}

class rolling_hash {
public:
    rolling_hash(std::string const& s)
        : n(s.size()), hs1(n + 1), hs2(n + 1), p1(n + 1, 1), p2(n + 1, 1)
    {
        for(int i = 0; i < n; ++i) {
            hs1[i + 1] = (hs1[i] * b1 + s[i]) % mod1;
            hs2[i + 1] = (hs2[i] * b2 + s[i]) % mod2;
            p1[i + 1] = p1[i] * b1 % mod1;
            p2[i + 1] = p2[i] * b2 % mod2;
        }
    }

    std::pair<ll, ll> query(int l, int r) const {
        return std::make_pair(((hs1[r] - hs1[l] * p1[r - l]) % mod1 + mod1) % mod1,
                              ((hs2[r] - hs2[l] * p2[r - l]) % mod2 + mod2) % mod2);
    }

private:
    const int n;
    std::vector<ll> hs1, hs2, p1, p2;
    static const ll b1 = 17LL;
    static const ll b2 = 19LL;
    static const ll mod1 = 999999937LL;
    static const ll mod2 = 1000000007LL;
};


map<pll, ll> calc(std::string s) {
    s = insert_doll(s);
    auto p = manacher(s);
    rolling_hash hs(s);
    map<pll, ll> cnt;
    int const n = s.size();
    vector<set<pll>> v(n);
    map<pll, pll> prev;
    for(int i = 0; i < n; ++i) {
        int l = i - p[i] + 2, r = i + p[i] - 1;
        if(l < r) {
            auto val = hs.query(l, r);
            v[r - l].insert(val);
            cnt[val]++;
            while(l + 2 < r - 2 && prev.count(val) == 0) {
                l += 2, r -= 2;
                auto val2 = hs.query(l, r);
                prev[val] = val2;
                val = val2;
                v[r - l].insert(val2);
            }
        }
    }
    for(int i = n - 1; i >= 2; --i) {
        for(auto& h : v[i]) {
            if(prev.count(h) == 1) {
                cnt[prev[h]] += cnt[h];
            }
        }
    }

    return cnt;
}

int main() {
    string s, t;
    cin >> s >> t;
    auto cnt1 = calc(s), cnt2 = calc(t);
    ll ans = 0;
    for(auto& p : cnt1) {
        if(cnt2.count(p.first) == 1) {
            ans += p.second * cnt2[p.first];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 24796
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int n;
string w[101];

int main(void)
{
    cin >> n;
    rep(i,n)
    {
        cin >> w[i];
    }

    rep(i,n)
    {
        rep(j,n)
        {
            if(i == j)
                continue;

            if(w[i] == w[j])
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    rep(i, n-1)
    {
        if(w[i][w[i].length()-1] != w[i+1][0])
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <cmath>
#include <iomanip>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>, int> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;

int n, m, p[100005], ds[100005], rnk[100005];

int find(int x){
    if(ds[x]==x) return x;
    return ds[x] = find(ds[x]);
}
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    for(int i = 1; i <= 100000; i++) ds[i] = i;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) cin >> p[i];
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        int u = find(a), v = find(b);
        ds[u] = v;
    }
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(find(ds[i]) == find(ds[p[i]])) ++cnt;
    }
    cout << cnt;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define dcout cout << fixed << setprecision(15)
#define rep(i, a) for(int i = 0; i < a; i++)
#define arep(i, x) for(auto i : x)
#define all(v) v.begin(), v.end()
#define int long long
#define F first
#define S second
#define VE vector<int>
#define MOD 1000000007
#define INF 10000000000
#define pb(x) push_back(x)
using namespace std;
signed main() {
    int x, y;
    cin >> x >> y;
    int ans = 1;
    int i = x;
    while(1) {
        if(i * 2 <= y) ans++;
        i *= 2;
        if(i > y) break;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
const int N = 2e5+100;
int nowl[N],nowr[N];
int num[N];
char s[N];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	for(int i=1;i<=n;i++) num[i]=1;
	for(int i=1;i<=n;i++){
		if(s[i]=='R'){
			nowr[i]=i;
		}
		else{
			nowr[i]=nowr[i-1];
		}
	}
	for(int i=n;i>=1;i--){
		if(s[i]=='L'){
			nowl[i]=i;
		}
		else nowl[i]=nowl[i+1];
	}
	for(int i=1;i<=n;i++){
		if(s[i]=='L'){
			if((i-nowr[i])&1){
				num[nowr[i]+1]++;
			}
			else num[nowr[i]]++;
			num[i]--;
		}
		else{
			if((nowl[i]-i)&1){
				num[nowl[i]-1]++;
			}
			else num[nowl[i]]++;
			num[i]--;			
		}
	}
	for(int i=1;i<=n;i++) cout<<num[i]<<' ';
	cout<<endl;
	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int data[2000];
int main(){
	int n,m,r,p;
	while(cin >> n >> m && (n||m) ){
		cin >> r;
		int comp[1000] = {0};
		vector<int> a[10000];
		vector<int> b[10000];
		rep(i,r){
			int t , id , name , q;
			cin >> t >> id >> name >> q;
			id--,name--;
			if(q){
				comp[id] = t;
			}else{
				a[name].push_back(comp[id]);
				b[name].push_back(t);
			}
		}
		cin >> p;
		rep(i,p){
			int s , t , name;
			cin >> s >> t >> name;
			name--;
			rep(j,2000) data[j] = 0;
			int cnt = 0;
			rep(j,a[name].size()){
				for(int k = max(s,a[name][j]) ; k < min(t,b[name][j]) ; k++){
					if(!data[k]){cnt++ , data[k] = true;}
				}
			}
			cout << cnt << endl;
		}
		

	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
    
    int n, f = 0, s = 0;
    string a, b;
    cin >> n;
    while (n--) {
        cin >> a >> b;
        if (a == b) f++, s++;
        else if (a > b) f += 3;
        else s += 3;
    }
    cout << f << " " << s << "\n";
    
    return 0;
}


Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node a, int b){
  if(a == NIL || b == a->key) return a;

  if(b < a->key)return treeSearch(a->left, b);
  else return treeSearch(a->right, b);

  return NIL;
}

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

  z = malloc(sizeof(struct 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 inorder(Node u){
  int i=0;
  if(u != NIL){
    inorder(u->left);

    printf(" %d",u->key);

    inorder(u->right);
  }
}

void preorder(Node u){
  int i=0;
 if(u != NIL){
   printf(" ");
   printf("%d",u->key);
   preorder(u->left);
   preorder(u->right);
  }
}



int main(){
  int m, i, x;
  char com[20];
  scanf("%d", &m);

  for ( i = 0; i < m; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
      } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 20468
#include<bits/stdc++.h>
#define lim 1001
using namespace std;
main()
{
    int q,m;
    cin>>m>>q;
    vector <int> A[lim];
    while(q--)
    {
        int n,t;
        cin>>n;
        if(n==0)
        {
            int x;
            cin>>t>>x;
            A[t].push_back(x);
        }
        else if(n==1)
        {
           cin>>t;
           if(A[t].size()==0)
                cout<<endl;
           else
           {
                for(int i=0;i<A[t].size();i++)
           {
               cout<<A[t][i];
               if(i<A[t].size()-1)
                cout<<" ";
           }
           cout<<endl;
           }

        }
        else
        {
            cin>>t;
                A[t].clear();
        }

    }

}




Measured memory_bytes: 5800
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    string s;
    cin >> s;

    ll gu_num = 0;
    ll pa_num = 0;

    ll score = 0;

    for(char c : s){
        if(c == 'p'){
            if(pa_num < gu_num){
                pa_num++;
            }else{
                gu_num++;
                score--;
            }
        }else{
            if(pa_num < gu_num){
                pa_num++;
                score++;
            }else{
                gu_num++;
            }
        }
    }

    p(score);
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

class UnionFind {
public:
    
    vl parent;  // 親ノード
    vl Siz;  // 集合の大きさ

    // コンストラクタ
    UnionFind(ll n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(ll n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    ll root(ll x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }
        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }
        Siz[x] += Siz[y];
        parent[y] = x;
    }
    
    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    ll size(ll x) {
        return Siz[root(x)];
    }
    
};

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

    vl a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;  b[i]--;
    }

    UnionFind Uni(n);
    Uni.init(n);

    // 操作を逆順に見る
    vl v(m+1);  // ans[i] : 橋iをつないだときの不便さ(i = mのときまだ1つもつないでいない)
    v[m] = n*(n-1)/2;
    for(ll i = m-1; i >= 0; i--) {
        if(Uni.same(a[i], b[i])) {
            v[i] = v[i+1];
        }
        else {
            v[i] = v[i+1] - Uni.size(a[i])*Uni.size(b[i]);
            Uni.unite(a[i], b[i]);
        }
    }

    exrep(i, 1, m) {
        out(v[i]);
    }
    
    re0;
}

Measured memory_bytes: 5248
#include<stdio.h>
int main(void){
	int N;
	scanf("%d",&N);
	if(N>64&&N<91)printf("1\n");
	if(N>96&&N<123)printf("2\n");
	if(N<65||N>122) printf("0\n");
	if(N>90&&N<97) printf("0\n");
	return 0;
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
		using namespace std;
		typedef long long ll;
		#define PI 3.14159265358979
		#define EPS 1e-8
		#define mod  998244353
		#define fi first
		#define se second
		#define mp make_pair
		#define pb push_back
		#define endl "\n"
			 
		const ll INF=1e15;	
		const int N=2e5+50;
		 

		 
		long long binpow(long long a, long long b, long long m) {
			a %= m;
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = res * a % m;
				a = a * a % m;
				b >>= 1;
			}
			return res;
		}
		
		ll modinverse(ll a,ll m)
		{
			return binpow(a,m-2,m);
		}
		
		map<ll,ll> bit;
		
		void update(ll idx,ll val)
		{
			while(idx<=1e9)
			{
				bit[idx]+=val;
				idx+=(idx & -idx);
			}
		}
		
		ll query(ll idx)
		{
			ll sum=0;
			
			while(idx>0)
			{
				sum+=bit[idx];
				idx-=(idx & -idx);
			}
			return sum;
		}
		
		int main()
		{
			ios_base::sync_with_stdio(false);
			cin.tie(NULL);cout.tie(0);
			
			ll n,d,a;
			cin>>n>>d>>a;
			
			vector<ll> x(n),h(n);
			
			vector<pair<ll,ll> > v(n);
			for(ll i=0;i<n;i++)
			{
				cin>>x[i]>>h[i];
				v[i]={x[i],h[i]};
			}
			
			ll ans=0;
			sort(v.begin(),v.end());
			
			for(auto i:v)
			{
				ll val=query(i.fi);
				if(val<i.se)
				{
					//cout<<i.fi<<" "<<val<<endl;
					ll mov=(i.se-val+a-1)/a;
					ans+=mov;
					val=mov*a;
					update(i.fi,val);
					update(i.fi+2*d+1,-val);
				}
				
			}
			cout<<ans;
			
			
			
			
		}
			
			
		


Measured memory_bytes: 165176
#include<bits/stdc++.h>
using namespace std;
int vis[101001];
vector <int> path1;
vector <int> path2;
vector <int> ve[101001];
void dfs(int i)
{
	vis[i]=1;
	path1.push_back(i);
	for(int j=0;j<ve[i].size();++j)
	{
		if(!vis[ve[i][j]])
		{
			dfs(ve[i][j]);
			return ;
		}
	}
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		ve[u].push_back(v);
		ve[v].push_back(u);
	}
	dfs(1);
	swap(path1,path2);
	dfs(1);
	printf("%d\n",path1.size()+path2.size()-1);
	for(int i=(int)path2.size()-1;i>=1;--i)
		printf("%d ",path2[i]);
	for(int i=0;i<path1.size();++i)
		printf("%d ",path1[i]);
	return 0; 
}


Measured memory_bytes: 9976
#include<math.h>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
//AtCoderC++.cpp

using namespace std;


int main() {
	int N; cin >> N;
	auto as = vector<int>(N);
	for (size_t i = 0; i < N; i++) {
		cin >> as[i];
	}
	sort(as.begin(), as.end());
	auto bar = vector<long long>();
	int count = 1;
	for (size_t i = 1; i < N; i++) {
		if (as[i] == as[i - 1])++count;
		else {
			if (count >= 4) {
				bar.push_back(as[i - 1]);
				bar.push_back(as[i - 1]);
			} else if (count >= 2) {
				bar.push_back(as[i - 1]);
			}
			count = 1;
		}
	}
	if (count >= 4) {
		bar.push_back(as[N - 1]);
		bar.push_back(as[N - 1]);
	} else if (count >= 2) {
		bar.push_back(as[N - 1]);
	}
	if (bar.size() < 2) {
		cout << 0 << endl;
	} else {
		cout << bar[bar.size() - 1] * bar[bar.size() - 2] << endl;
	}
}


Measured memory_bytes: 1276
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;
//union find木(グループわけができる)
int par[200005];
int unifind(int n) {
	for (int i = 1; i <= n; i++) {
		par[i] = i;
	}
	return 0;
}
//木の根を求める
int unifind_root(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = unifind_root(par[x]);
	}
}
//同じグループか判定
bool unifind_same(int x, int y) {
	return unifind_root(x) == unifind_root(y);
}
//グループ併合
int unifind_unite(int x, int y) {
	x = unifind_root(x);
	y = unifind_root(y);
	if (x == y) {
		return 0;
	}
	par[x] = y;
}

int main() {
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int n, m, u[200000], v[200000], w[200000], memo[200005] = {},res=0;
	long double x = 0;
	string str, str2;
	cin >> n>>m;
	unifind(2 * n);
	for (int i = 1; i <=m; i++) {
		cin >> u[i] >> v[i] >> w[i];
		if (w[i] % 2 == 0) {
			unifind_unite(u[i], v[i]);
			unifind_unite(u[i] + n, v[i] + n);
		}
		else {
			unifind_unite(u[i], v[i] + n);
			unifind_unite(u[i] + n, v[i]);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (memo[unifind_root(i)]==0&&memo[unifind_root(i+n)]==0) {
			res++;
			memo[unifind_root(i+n)]++;
			memo[unifind_root(i+n)]++;
		}
	}
	cout << res;
}


Measured memory_bytes: 7936
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});
/* 入力は 
5 14 80
*/
reader.on('close', () => {
    var l = lines[0].trim().split(' ').map(x=>parseInt(x));
    var a, b,c ;
    [a, b, c] = l;

    console.log(aux(a,b,c));
});

function aux(a,b,c)
{
    var count=0;
    for (var i=a; i<=b; i++){
	if (c % i===0) {
	    count++;
	}
    }
    return(count);
}


Measured memory_bytes: 16528
N=int(input())

lis=[]

temp=6
while temp<=N:
    lis.append(temp)
    temp*=6

temp=9
while temp<=N:
    lis.append(temp)
    temp*=9

lis.sort(reverse=True)

dp=[10**9]*(N+1)
dp[0]=0

#配列dp[N+1]にインデックスの数字を作るための最小手数をメモっていく
for item in lis:
    for i in range(N+1):
        if dp[i]!=10**9:
            if i+item<=N:
                dp[i+item]=min(dp[i]+1,dp[i+item])

ans=10**10
for index,item in enumerate(dp):
    ans=min(ans,item+N-index)
print(ans)

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

int n, w;                 // 個数nと残り重量w
int V[110], W[110];       // 価値vと重さwの配列
int dp[110][10010] = {};  // [個数][残り重量]のときの最大価値

int rec(int i, int w) {
  if (dp[i][w] > 0)  // 結果を知っているなら返す
    return dp[i][w];
  else if (i == n)  // 最後に到達した
    return 0;
  else if (w < W[i])  // 荷物が入らないならパス
    return rec(i + 1, w);
  else  // それ以外はメモして返す
    dp[i][w] = max(rec(i + 1, w), rec(i + 1, w - W[i]) + V[i]);
  return dp[i][w];
}

int main() {
  cin >> n >> w;
  for (int i = 0; i < n; i++) cin >> V[i] >> W[i];  // 一旦配列に突っ込む
  cout << rec(0, w) << endl;
}



Measured memory_bytes: 6804
import bisect
x = int(input())
n = 10**5
prime = [True]*(n+1)
prime[0] = False
prime[1] = False
P = []
for i in range(2,n+1):
  if not prime[i]:
    continue
  else:
    for j in range(2*i,n+1,i):
      prime[j] = False
for i in range(n+1):
  if prime[i]:
    P.append(i)
P.append((10**5)+3)
k = bisect.bisect_left(P,x)
print(P[k])

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

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

	int cnt = 0;
	while (a>=b) {
		b *= 2;
		cnt++;
	}
	while (b>=c) {
		c *= 2;
		cnt++;
	}

	if (cnt<=k) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3596
N, K = map(int, input().split())
mod = 998244353
move = []

for _ in range(K):
  L, R = map(int, input().split())
  move.append((L, R))

S = [0]*K
dp = [0]*(2*N)
dp[N] = 1

for i in range(N+1, 2*N):
  for k, (l, r) in enumerate(move):
    S[k] -= dp[i-r-1]
    S[k] += dp[i-l]
    dp[i] += S[k]
  dp[i] %= mod

print(dp[-1])

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

typedef struct{
	int front;
	int back;
}chair_t;

int main(){
	
	int n , m;
	chair_t pos[1010];
	
	while( cin >> n >> m ){
		if( !n && !m ) break ;
		
		
		for( int i=0 ; i<n ; i++ ){
			pos[i].front = i+1 ;
			pos[i].back  = i-1 ;
		}
		pos[0].back    = n-1 ;
		pos[n-1].front = 0   ;
		
		int npos = 0;
		while( npos != pos[npos].front ){
			for( int i=1 ; i<m ; i++ ){
				npos = pos[npos].front ;
			}
			pos[pos[npos].back].front = pos[npos].front ;
			pos[pos[npos].front].back = pos[npos].back;
			npos = pos[npos].front ;
		}
		
		cout << npos+1 << endl ;
	}
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s; cin >> s;
	bool ok = false;
	for (int i = 1; i < s.length(); i++) if (s[i - 1] == 'A' && s[i] == 'C') ok = true;
	if (ok) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

int main(){
int K,S;
  cin>>K>>S;
  
  int count=0;
  for(int x=0; x<=K; x++){
   for(int y=0; y<=K; y++){
     if(0<=S-x-y && S-x-y<=K){count++;}
    }
  }
  
  cout<<count;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H,P,L;
string S,T;
ll ans;
ll x[101010];
ll y[101010];
ll a[201010];
ll b[101010];
ll c[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
bool flag[100];
vector<ll> Prime{2,3,5,7,11,13,17,19,23,29,31};


int main() {
	cin>>A>>B>>C;
	cout<<min(C,B/A)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 305;
const int MAXLOG = 64;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
bool vis[MAXN];
int n, c, a[MAXN], f[MAXN], h[MAXN], bit[MAXN];
double ans, cnt, dp[MAXN][MAXN][MAXLOG];
void work(int pos) {
	if (pos == n + 1) {
		cnt += 1, memset(dp, 0, sizeof(dp));
		dp[0][a[1]][(bit[n] << 1) - 1] = 1;
		for (int i = 0; i <= c - 1; i++)
		for (int j = i; j <= c; j++)
		for (int s = 0; s <= (bit[n] << 1) - 1; s++) {
			int pos = h[i % n];
			if (j != i) dp[i + 1][j][s] += dp[i][j][s];
			if (bit[pos] & s) dp[i + 1][min(max(j, i + a[pos]), c)][s ^ bit[pos]] += dp[i][j][s] / (c / n);
		}
		ans += dp[c][c][0];
		return;
	}
	for (int i = 1; i <= n - 1; i++)
		if (!vis[i]) {
			f[pos] = i;
			h[i] = pos;
			vis[i] = true;
			work(pos + 1);
			vis[i] = false;
		}
}
int main() {
	read(n), read(c), c *= n;
	for (int i = 1; i <= n; i++)
		read(a[i]), a[i] *= n;
	for (int i = 2; i <= n; i++)
		bit[i] = 1 << (i - 2);
	sort(a + 1, a + n + 1, [&] (int x, int y) {return x > y; });
	work(2), printf("%.15lf\n", ans / cnt);
	return 0;
}

Measured memory_bytes: 46848
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
X, Y = map(int, input().split())

y = (Y - 2 * X) // 2
x = (4 * X - Y) // 2

if y < 0 or x < 0 or x + y != X or 2 * x + 4 * y != Y:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9700
#include<bits/stdc++.h>
using namespace std;
long long n,W,dp[103][100005],w[105],v[105];
int main(){
	cin>>n>>W;
	for(int i=0;i<n;i++)cin>>w[i]>>v[i];
	memset(dp,63,sizeof(dp));
	dp[0][0]=0;
	dp[0][v[0]]=w[0];
	for(int i=1;i<n;i++){
		for(int j=0;j<=100000;j++)
			dp[i][j]=dp[i-1][j];
		for(int j=v[i];j<=100000;j++)
			dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
	}
	for(int i=100000;i>=0;i--)
		if(dp[n-1][i]<=W)
		{
			cout<<i;
			return 0;
		}
}



Measured memory_bytes: 80768
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
	        String[] strs = input.nextLine().split(" ");
	        int plusindex = 0;
	        for(int i = 0 ; i < strs.length ; i++){
	        	if(strs[i].length() == 3 || strs[i].length() == 4){
	        		for(int j = 1 ; j <= 25 ; j++){
	        			StringBuilder sb = new StringBuilder();
	        			for(int k = 0 ; k < strs[i].length(); k++){
	        				int chai = strs[i].charAt(k)+j;
	        				if(chai > 122){
	        					sb.append((char)(chai-26));
	        				}else{
	        					sb.append((char)(chai));
	        				}
	        			}
	        			String sbt = sb.toString();
	        			if(sbt.equals("the") || sbt.equals("this") || sbt.equals("that")){
	        				plusindex = j;
	        				break;
	        			}
	        			if(plusindex != 0)break;
	        		}
	        	}
	        	if(plusindex != 0)break;
	        }
	        StringBuilder sb = new StringBuilder();
	        for(int i = 0 ; i < strs.length ; i++){
				for(int k = 0 ; k < strs[i].length(); k++){
					if(strs[i].charAt(k) == '.'){
						sb.append(".");
					}else{
						int chai = strs[i].charAt(k)+plusindex;
						if(chai > 122){
							sb.append((char)(chai-26));
						}else{
							sb.append((char)(chai));
						}
					}
				}
				if(i != strs.length-1)sb.append(" ");
	        }
	        System.out.println(sb);
	    }   
    }
}

Measured memory_bytes: 15340
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n];
    for(int i=0;i<n;i++)cin >> a[i] >> b[i] >> c[i];
    vector<vector<int> >dp(n+1,vector<int>(3,0));
    for(int i=0;i<n;i++){
        dp[i+1][0] = max(dp[i][1],dp[i][2]) + a[i];
        dp[i+1][1] = max(dp[i][0],dp[i][2]) + b[i];
        dp[i+1][2] = max(dp[i][0],dp[i][1]) + c[i];
    }
    cout << max(max(dp[n][0],dp[n][1]),dp[n][2]) << endl;
}


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


def f(AB):
    s = 0
    for a, b in sorted(AB, key=lambda x:x[1]):
        s += a

        if s > b:
            return 'No'

    return 'Yes'


def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for i in range(N)]
    print(f(AB))


if __name__ == '__main__':
    main()


Measured memory_bytes: 33460