akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

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

    if(N==1){
        cout << 1 << endl
             << 0 << endl;
    }else if(N==2){
        cout << 2 << endl
             << 1 << endl
             << "00" << endl;
    }else{
        cout << N - 1 << endl;
        string a = "0", b = "0";
        cout << a + b << endl;
        rep(i,N-2){
            a += "1";
            cout << a + b << endl;
        }
    }
}


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

const double PI = acos(-1);

int main()
{
    int n,m; cin >> n >> m;
    vector<int> h(n); rep(i,n) cin >> h.at(i);
    vector<vector<int>> ab(m,vector<int>(2)); 
    rep(i, m) cin >> ab.at(i).at(0) >> ab.at(i).at(1);

    vector<int> tmp(n);

    rep(i, m) {
        int subA = ab.at(i).at(0), subB = ab.at(i).at(1);
        if(h.at(subA - 1) < h.at(subB - 1)) {
            tmp.at(subA - 1) = 1;
        } else if (h.at(subA - 1) > h.at(subB - 1)) {
            tmp.at(subB - 1) = 1;
        } else {
            tmp.at(subA - 1) = 1;
            tmp.at(subB - 1) = 1;
        }
    }

    int cnt = 0;
    rep(i, n) cnt += tmp.at(i);
    cout << n - cnt << endl;
}



Measured memory_bytes: 9596
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )
import Data.List ( sortBy )
import qualified Data.Vector.Unboxed as U


getParm :: IO [Int]
getParm = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  n <- readLn :: IO Int
  ass <- getParm
  print $ f n ass

sort' :: [Int] -> [Int]
sort' = sortBy (flip compare)

f :: Int -> [Int] -> Int
f n ass = h ass' n 0
  where
    h :: [Int] -> Int -> Int -> Int
    h _        0 acc = acc
    h (_:b:bs) n acc = h bs (n-1) (b+acc)

    ass' = sort' ass

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

using namespace std;
typedef long long ll;

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl;
#else
#define DEBUG(x)
#endif

#define ALL(obj) (obj).begin(), (obj).end()
#define BIT(n) (1LL << (n))

const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    // write code below
    string s;
    cin >> s;
    int res = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s.at(i) == 'R')
        {
            res++;
        }
    }
    cout << res - (s == "RSR") << endl;

    // write code above
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s; cin >> s;
	if(s.size() >= 4 && s.substr(0, 4) == "YAKI") cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;                                              
}
	


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	double row[10],v[2];
	for(;;){
		if (scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&row[0],&row[1],&row[2],&row[3],&row[4],&row[5],&row[6],&row[7],&row[8],&row[9],&v[0],&v[1]) == EOF){break;}
		int i;
		double t,dis = 0,d = 0;
		for(int i=0; i<10; i++){
			dis+=row[i];
		}
		for(i=0; i<10; i++){
			d+=row[i];
			t = d/v[0];
			if(dis <= t*(v[0]+v[1])){break;}
		}
		cout<<i+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
use std::io;

/// 一行を読み込んで、空白で区切ったベクタにして返す
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

/// n行を読み込んで、数字を空白で区切って二次元のベクタにして返す
#[allow(dead_code)]
fn read_table<T>(n: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut ret: Vec<Vec<T>> = Vec::new();
    for _ in 0..n {
        ret.push(read::<T>());
    }
    ret
}

/// n行を読み込んで、1文字ずつを二次元のベクタにして返す
#[allow(dead_code)]
fn read_char_table(n: usize) -> Vec<Vec<char>> {
    let mut ret: Vec<Vec<char>> = Vec::new();
    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let chr = buf.trim().chars().collect();
        ret.push(chr);
    }
    ret
}

/// n行を読み込んで、一次元のベクタにして返す
#[allow(dead_code)]
fn read_array<T>(n: usize) -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut array = Vec::new();

    for _ in 0..n {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        array.push(buf.trim().parse().unwrap());
    }
    array
}

pub fn sum_from_zero(n: i32) -> i32 {
    (0..n + 1).fold(0, |a, b| a + b)
}

fn main() {
    // 数値
    let (a, b) = {
        let i = read::<i32>();
        (i[0], i[1])
    };

    let diff = b - a;
    let bh = sum_from_zero(diff);

    let h = bh - b;
    println!("{}", h);
}


Measured memory_bytes: 4352
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] sum = new long[n + 1];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
            sum[i + 1] += a[i] + sum[i];
        }
        Map<Long, Integer> map = new HashMap<>();
        for (int i = 0; i < n + 1; i++) {
            if (map.containsKey(sum[i])) {
                map.put(sum[i], map.get(sum[i]) + 1);
            } else {
                map.put(sum[i], 1);
            }
        }
        long count = 0;
        for (Entry<Long, Integer> entry : map.entrySet()) {
                count += (long) entry.getValue() * (entry.getValue() - 1) / 2;
        }
        System.out.println(count);

    }

}

Measured memory_bytes: 94068
#include <iostream>

int main() {
  long long  n, a, b;
  long long q, r;
  long long sum = 0;
  std::cin >> n >> a >> b;
  q = (n / (a + b));
  r = (n % (a + b));
  sum = q * a;
  if (r >= a) sum += a;
  else sum += r;
  std::cout << sum << std::endl;
  
  return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int i = 0;
		int j = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		a:for(i = 0;; i++) {
			for(j = 0; j < n; j++) {
				if(a[j] % 2 == 0) {
					a[j] = a[j] / 2;
				} else {
					break a;
				}
			}
		}
		System.out.println(i);
	}
}

Measured memory_bytes: 22996
def ABC_67_A():
    A,B = map(int, input().split())
    
    if A%3 == 0:
        print('Possible')
    elif B%3 == 0:
        print('Possible')
    elif (A+B)%3 == 0:
        print('Possible')
    else:
        print('Impossible')

if __name__ == '__main__':

    ABC_67_A()

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,tmp,ans;
  cin >> a >> b >> c;
  if(a%2==0||b%2==0||c%2==0){
    cout <<"0\n";
  }else{
    ans=a*b*c;
    if(a%2!=0) ans = min(ans,b*c);
    if(b%2!=0) ans = min(ans,a*c);
    if(c%2!=0) ans = min(ans,b*a);
    cout << ans <<endl;
  }
}


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

int main(void) {
  int N, X;
  cin >> N >> X;

  int prev = 0;
  int64_t ans = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    int d = max((prev + a) - X, 0);
    ans += d;
    prev = (a - d);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <stack>
#include <queue>
#include <math.h>
using namespace std; 

int n,m,a[30][50001];
vector<int> c;

int solve(int i,int sum){
    if(sum>n){
        //cout<<i<<" "<<sum<<" "<<ans;
        return 50001;
    }
    if(a[i][sum]!=0)return a[i][sum];
    if(i==m&&sum==n)return 0;
    if(i==m)return 50001;
    else{
        a[i][sum]=min(solve(i+1,sum),solve(i+1,sum+c[i])+1);
        a[i][sum]=min(solve(i,sum+c[i])+1,a[i][sum]);
        return a[i][sum];
    }
}

int main(void){
    cin>>n>>m;
    c.resize(m,0);
    for(int i=0;i<m;i++){
        cin>>c[i];
    }
    cout<<solve(0,0)<<endl;
    return 0;
}

Measured memory_bytes: 10116
import java.util.Scanner;

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

        int min = 1000000000;
        int max = 0;
        for (int i = 0; i < N; i++) {
            int A = sc.nextInt();
            if (A < min) {
                min = A;
            }
            if(A > max) {
                max = A;
            }
        }
        System.out.println(max - min);

    }
}


Measured memory_bytes: 22228
from sys import stdin

def main():
    B = input()

    s1 = {'A', 'T'}
    s2 = {'C', 'G'}
    if B in s1:
        ans = {B} ^ s1
    else:
        ans = {B} ^ s2
    print(*ans)

input = lambda: stdin.readline().rstrip()
main()


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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define debug_interval ','
#define dump_interval endl
#define debug_toggle 0

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}

int city[51],a,b,p,q;

int main(){
    ios::sync_with_stdio(false);
    cin>>a>>b;
    for(int i=0;i<b;i++){
      cin>>p>>q;
      city[p]++;
      city[q]++;
    }
    for(int i=1;i<=a;i++){
      dump(city[i]);
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        long N = s.nextInt();
        long M = s.nextInt();

        if(N == 1 || M == 1){
            System.out.println(Math.abs(N + M - 3));
        } else if(N == 2 || M == 2){
            System.out.println(0);
        } else{
            System.out.println( (N - 2) * (M - 2));
        }
    }
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  long long H, a[N], b[N];
  long long max_a=0;
  cin >> H;
  for (int i = 0; i < N; i++){
    cin >> a[i] >> b[i];
    if (max_a < a[i]){
      max_a = a[i];
    }
  }

  sort(b, b+N);

  int ans = 0;
  for (int i = N-1; i >= 0; i--){
    if (max_a > b[i]) break;
    H -= b[i];
    ans++;
    if (H <= 0) break;
  }

  if (H > 0){
    long long n = H / max_a;
    if (H%max_a != 0){
      n += 1;
    }
    ans += n;
  }

  printf("%d\n", ans);
  
}


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


int main(void) {
	int K, X;
	cin >> K >> X;

	for (int i = 0; i < 2*K-1; i++)
	{
		int a = X - K + 1;
		cout << a + i << " ";
	}
	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>

const long long MOD = 10e9 + 7;

using namespace std;

typedef long long ll;

long long f(long long i){
	long long n=i;
	int mul=1;
	while(i/10!=0){
		int i1 = i%10;
		int i2 = (i/10)%10;
		if(i1==i2){
			n=n-i1*mul;
		}	
		i=i/10;
		mul*=10;
	}	
	return n;
}

int main(){
	//int mi=1000000000; 
	//cout<<mi<<endl;
	int N,a,b,c;
	vector<int> va,vb,vc,aa,ab,ac;
	cin>>N;
	
	
	for(int i=0;i<N;i++){
		cin>>a>>b>>c;
		va.push_back(a);
		vc.push_back(c);
		vb.push_back(b);
	}
	aa.push_back(va[0]);
	ab.push_back(vb[0]);
	ac.push_back(vc[0]);
	for(int i=1;i<N;i++){
		aa.push_back( max(ab[i-1],ac[i-1]) + va[i]);
		ab.push_back(  max(aa[i-1],ac[i-1]) + vb[i]);
		ac.push_back(  max(ab[i-1],aa[i-1]) + vc[i]);
	}
	cout<<max(max(aa[N-1],ab[N-1]),ac[N-1])<<endl;
}

Measured memory_bytes: 2924
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1e5 + 5;
int dp[maxn][5] , a[maxn][4];
int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= 3;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(int i = 1;i <= 3;i++)dp[1][i] = a[1][i];
	for(int i = 2;i <= n;i++){
		dp[i][1] = max(dp[i - 1][2] + a[i][1], dp[i-1][3]+a[i][1]);
		dp[i][2] = max(dp[i - 1][1] + a[i][2], dp[i-1][3]+a[i][2]);
		dp[i][3] = max(dp[i - 1][2] + a[i][3],dp[i-1][1]+a[i][3]);
	}
	int ans = 0;
	for(int i = 1;i <= 3;i++)ans = max(dp[n][i],ans);
	printf("%d\n",ans);
}

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

#define ll long long

const int mxN=2e5;
int n, ft[mxN+2];
ll k, a[mxN+1], ans;
array<ll, 2> b[mxN+1];

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

	cin >> n >> k;
	for(int i=0; i<n; ++i) {
		cin >> a[i+1];
		a[i+1]+=a[i];
	}
	for(int i=0; i<=n; ++i)
		b[i]={a[i]-k*i, i};
	sort(b, b+n+1);
	for(int i=0; i<=n; ++i) {
		for(int j=b[i][1]; j; j-=j&-j)
			ans+=ft[j];
		for(int j=b[i][1]+1; j<=n+1; j+=j&-j)
			++ft[j];
	}
	cout << ans;
}

Measured memory_bytes: 5760
f a b n
    | n8 > a || n10 > b = -1
    | n8 == a && n10 == b = n
    | otherwise = f a b (n + 1)
  where n8 = n * 8 `div` 100
        n10 = n * 10 `div` 100

main = do
    [a, b] <- map read . words <$> getLine :: IO [Int]
    print $ f a b 1


Measured memory_bytes: 508
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
//#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }

int32_t main(){
	IOS;
	string s;
	cin >> s;
	int n = s.size();
	int cur = 0, ans = 0;
	string bef = "";
	while(cur < n){
		string t = "";
		int nxt = -1;
		for(int i=cur; i<n; i++){
			t += s[i];
			if(t.size() != bef.size() || t != bef){
				nxt = i + 1;
				break;
			}
		}
		if(nxt == -1){
			break;
		}
		bef = t;
		cur = nxt;
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int mi=n,mx=0;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mi=min(mi,a[i]);
        mx=max(mx,a[i]);
    }
    if(mx-mi>1) cout<<"No\n";
    else {
        if(mx==mi)
        {
            if(mx==n-1) cout<<"Yes\n";
            else{
                int num=n/2;
                if(mx<=num) cout<<"Yes\n";
                else cout<<"No\n";
            }
        }
        else{
            int cntmin=0,cntmx=0;
            for(int i=0;i<n;i++)
            {
                if(a[i]==mi) cntmin++;
                else cntmx++;
            }
            if(cntmx==1) cout<<"No\n";
            else{
                int kind=cntmin+cntmx/2;
                if(kind>=mx&&mx>=cntmin+1) cout<<"Yes\n";
                else cout<<"No\n";
            }
        }
    }
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<map>
#include<cmath>

using namespace std;

typedef long long ll;
#define INF 1000000007

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

    if(a == b && b == c && c == a) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

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

		boolean can = true;
		boolean before = false;
		int b = 0;
		for(int i =0;i < N;i++) {
			int H = scn.nextInt();
			if(b - H > 1) {
				can = false;
				break;
			}else if(b - H == 1){
				if(before) {
					can = false;
					break;
				}else {
					before = true;
				}
			}else {
				if(b - H == 0) {

				}else {
					before = false;
				}
			}
			b = H;
		}
		System.out.println(can?"Yes":"No");
	}

}

Measured memory_bytes: 47032
#include <stdio.h>
int main(void)
{
	int i1, i2, i3, n, x, m;
	for (;;)
	{
		m=0;
		scanf("%d%d", &n, &x);
		if (n==0 && x==0)
		{
			break ;
		}

		for (i1=1;i1<=n;i1++)
		{
			for (i2=i1+1;i2<=n;i2++)
			{

				for (i3=i2+1;i3<=n;i3++)
				{
					if (i1+i2+i3==x)
					{
						//printf("%d%d%d\n", i1, i2, i3);
						m++;
					}
				}
			}
		}
		printf("%d\n", m);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <string.h>
int main(void) {
  while(1) {
	int n, p;
	scanf("%d%d", &n, &p);
	if (n == p && n == 0) break;
	int man[444] = {0};
	int glass = 0;
	int i = 0;
	glass = p;
	while (1) {
	  //  printf("i = %d  glass = %d  man[i] == %d\n",i,glass,man[i]);
	  if (glass != 0) {
		glass--; man[i]++;
	  }
	  else {
		glass = man[i];
		man[i] = 0;
	  }
	  int flag = 0;
	  for (int j = 0; j < n; j++) {
		if (j != i) {
		  if (man[j] != 0) {
			flag = 1;
			break;
		  }
		}
	  }
		
	  if (flag == 0 && glass == 0) break;
	  i = (1+i)%n;
	}
	printf("%d\n",i);
  }
  return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>
#include <vector>
 
int main(int argc, char* argv[])
{
    long n, m, q;
    scanf("%ld %ld %ld", &n, &m, &q);

    long x[501][501]={0};

    std::vector<long> a(2*m);
    std::vector<long> p(2*q);
    long i, j;
    for(i=0; i<m; i++) {
        scanf("%ld %ld", &(a[2*i]), &(a[2*i+1]));
        x[a[2*i]][a[2*i+1]] ++;
    }
    for(i=1; i<=500; i++) {
        for(j=2; j<=500; j++) {
            x[i][j] += x[i][j-1];
        }
    }

    for(i=0; i<q; i++) {
        scanf("%ld %ld", &(p[2*i]), &(p[2*i+1]));
    }

    for(i=0; i<q; i++) {
        long num = 0;
        long k;
        for(k=p[2*i]; k<=p[2*i+1]; k++) {
            num += (x[k][p[2*i+1]] - x[k][p[2*i]-1]);
        }
        printf("%d\n", num);
    }

    return 0;
}


Measured memory_bytes: 7552
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int a, b, t=0,ans;
  cin >> a >> b;
  vector<int> tou(499500, 0);

  rep(i, 999){
    t += i + 1;
    tou[t] = 1;
  }
  bool flag = true;
  for(int i = 1; i < 499500; i++){
    if(tou[i+a]==1 && tou[i+b]==1) {
      ans = i;
      for(int j = i+a+1; j < i+b; j++){
        if (tou[j] == 1) flag = false;
      }
      if(flag) break;
      flag = true;
    }
  }
  print(ans);

}


Measured memory_bytes: 2176
/** coder Mohammad Al-Hussein *_^ */
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod  1000000007
#define write freopen("output.txt","w",stdout)
#define read freopen("test (1).txt","r",stdin)
#define FIO std::ios_base::sync_with_stdio(false);
using namespace std;
int dp[16][16][2];
vector<int> v;

int dx[4] = {-2,-2,1,-1};
int dy[4] = {1,-1,-2,-2};
int solve(int x,int y,bool turn)
{
    if(x < 0 || y < 0 || x > 14 || y > 14)
    {
        if(!turn)  return 0;
        else return 1;
    }
    int &ret = dp[x][y][turn];

    if(ret != -1) return ret;

    if(turn)
    {
        bool x1 = 0,x2 = 0,x3 = 0,x4 = 0;
        x1 = solve(x+dx[0],y+dy[0],!turn);
        x2 = solve(x+dx[1],y+dy[1],!turn);
        x3 = solve(x+dx[2],y+dy[2],!turn);
        x4 = solve(x+dx[3],y+dy[3],!turn);

        return ret = x1 || x2 || x3 || x4;
    }
    else
    {
        bool x1 = 0,x2 = 0,x3 = 0,x4 = 0;
        x1 = solve(x+dx[0],y+dy[0],!turn);
        x2 = solve(x+dx[1],y+dy[1],!turn);
        x3 = solve(x+dx[2],y+dy[2],!turn);
        x4 = solve(x+dx[3],y+dy[3],!turn);
        return ret = x1 && x2 && x3 && x4;
    }
}
int main()
{
    int a[3];
    for(int i=0;i<3;i++)
        cin >> a[i];
    sort(a,a+3);
    if(a[0]+a[1] == a[2])
        cout << "Yes\n";
    else 
        cout << "No\n";






    return 0;
}















//
//    ll k;
//    scanf("%I64d",&k);
//    ll L = 1,R = 1e9,mid,ans;
//    while(L <= R)
//    {
//        mid = (L+R)/2;
//        if(1LL * mid*(mid-1)/2 >= k)
//        {
//            ans = mid;
//            R = mid-1;
//        }
//        else
//            L = mid+1;
//    }
//    if(ans * (ans-1) / 2 == k)
//    {
//        for(int i=ans; i>=1; i--)
//            printf("%d ",i);
//        return 0;
//    }
//    else
//    {
//        int m = ans-1;
//        int r = 1;
//        while(1)
//        {
//            if(k > m)
//            {
//                vis[r] = 1;
//                my.push_back(r++);
//                k -= m;
//                m--;
//            }
//            else
//            {
//                for(int i=ans; i>=1; i--)
//                    if(!vis[i])
//                        my.push_back(i);
//                int s1 = my[my.size()-1];
//                for(int i=my.size()-1; i>=2; i--)
//                {
//                    if(m-- > 0)
//                        swap(my[i],my[i-1]);
//                }
//            }
//        }
//    }
//    for(int i=my.size()-1; i >= 1; i--)
//        cout << my[i] << ' ';


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);

  if(x<0 || y<0) printf("No\n");
  else if(W>=x+r && H>=y+r && 0<=x+r && 0<=y+r) printf("Yes\n");
  else printf("No\n");
  
  
  return 0;
}

Measured memory_bytes: 584
results = []

loop do

	locs = []

	n = gets.to_i
	break if n == 0
	n.times do
		s = gets.split ' '
		x = s.first.to_i
		y = s.last.to_i
		locs << [x, y]
	end

	m = gets.to_i
	m.times do
		s   = gets.split ' '
		dir = s.first
		dis = s.last.to_i
		dis.times do
			case dir
				when 'N'
					locs.map! { |l| [l[0], l[1] -= 1] }
				when 'S'
					locs.map! { |l| [l[0], l[1] += 1] }
				when 'E'
					locs.map! { |l| [l[0] -= 1, l[1]] }
				when 'W'
					locs.map! { |l| [l[0] += 1, l[1]] }
			end
			locs.reject! { |l| l[0] == 10 && l[1] == 10 }
		end
	end
	results << (locs.length == 0 ? 'Yes' : 'No')
end

results.each { |r| puts r }

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


typedef pair<ll,ll> pll;

ll n;
ll a[200005];
ll yo[200005];
int main()
{
        cin >> n;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
        }
        vector<ll> ans;
        for(ll i=n;i>=1;i--){
                ll pp = 0;
                for(ll j = i+i ; j <= n; j += i) pp = (pp + yo[j])%2;
                if(pp != a[i]) {
                        yo[i] = 1;
                        ans.pb(i);
                }
        }
        cout << ans.size() << endl;
        for(auto &i : ans) cout << i << " "; cout << endl;
        return 0;
}


Measured memory_bytes: 4852
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

#define PI 3.141592

using namespace std;

int main (void){
    int r;
    double ans=0;
    cin>>r;
    ans=((double)2*r*PI);
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  string s[3]; rep(i, 3) cin >> s[i];
  int idx[3] = {};
  int curr = 0;
  while(1) {
    curr = s[curr][idx[curr]++] - 'a';
    if(idx[curr] >= s[curr].size()) {
      cout << char('A' + curr) << endl;
      return 0;
    }
  }
  
  return 0;
}

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

const int N=300005;
const int mod=998244353;

int n,x,y,ans;
ll k,A,B;
int fac[N],inv[N];

int quickpow(int x,int y){
	int s=1;
	for (;y;y>>=1,x=1ll*x*x%mod)
		if (y&1) s=1ll*s*x%mod;
	return s;
}

void init(int n){
	int i;
	fac[0]=inv[0]=1;
	for (i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=quickpow(fac[n],mod-2);
	for (i=n-1;i;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
}

int C(int x,int y){
	if (x<y) return 0;
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}

int main(){
	int i,j;
	scanf("%d%lld%lld%lld",&n,&A,&B,&k);
	init(n);
	for (i=0;i<=n&&1ll*i*A<=k;i++)
		if ((k-1ll*i*A)%B==0&&(k-1ll*i*A)/B<=1ll*n){
			j=(int)((k-1ll*i*A)/B);
			x=i; y=j;
			if (x>y) swap(x,y);
			(ans+=1ll*C(n,x)*C(n,y)%mod)%=mod;
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2560
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cnt,i,j;

input=input.split(" ");
for(cnt=0;cnt<3;cnt++){
for(i=0;i<3;i++){
    if(input[i]>input[i+1]){
        j=input[i]
        input[i]=input[i+1]
        input[i+1]=j
    }
}
}

console.log("%d %d %d",input[0],input[1],input[2]);



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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N, long long M, std::vector<long long> A){
    i64 sum = 0;
    rep(i, M) sum += A[i];
    if(sum <= N) cout << N - sum << endl;
    else cout << -1 << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

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


Measured memory_bytes: 3768
#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define ll long long
int main() {
	int n,i,x;
	string s;
	cin>>n>>s;
	
	for(i=0;i<s.length();i++){
	    x=(s[i]-'A'+n)%26;
	    s[i]=char(x+65);
	}
	cout<<s;
	 return 0;
}

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

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	int atop = 0;
	int	btop = 0;
	int	ctop = 0;
	char order = 'a';
	while (1) {
		if (order == 'a') {
			if (atop == a.size()) {
				cout << 'A' << endl;
				break;
			}
			order = a[atop];
			atop++;
		}
		if (order == 'b') {
			if (btop == b.size()) {
				cout << 'B' << endl;
				break;
			}
			order = b[btop];
			btop++;
		}
		if (order == 'c') {
			if (ctop == c.size()) {
				cout << 'C' << endl;
				break;
			}
			order = c[ctop];
			ctop++;
		}
	}
	return 0;
}

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

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

using namespace std;

int main() {
    int a, b, p;
    cin >> a >> b;
    p = a*b;
    if (p%2 == 1) cout << "Odd" << endl;
    else cout << "Even" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, i, j, k, ans, x, s;
	cin >> n;
	ans = 0;

	for (i = 1; i <= n; i++) {
		x = n / i;
		s = (1 + x) * x / 2;
		ans += i * s;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3196
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;

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

	string s;
	cin >> n >> s;
	vector<int> w(n+1);
	vector<int> e(n+1);

	rep(i, 0, n) {
		if (s[i] == 'W') {
			w[i + 1] = w[i] + 1;
		}
		else
		{
			w[i + 1] = w[i];
		}
	}

	rep(i, 0, n) {
		if (s[i] == 'E') {
			e[i + 1] = e[i] + 1;
		}
		else
		{
			e[i + 1] = e[i];
		}
	}
	int ans = n;

	rep(i, 0, n) {

		ans = min(ans, w[i] + e[n] - e[i + 1]);
	}

		
	cout << ans << endl;

	
	
}
	

Measured memory_bytes: 2964
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

string s;
int k;

int main(){
  cin>>s>>k;

  rep(i,s.size()){
    if(i==s.size()-1){
      int n = (int)s[i];
      n+=k;
      k=0;
      while(n>'z') n=n-'z'+'a'-1;
      s[i] = (char) n;
    }
    if(s[i]=='a') continue;
    else{
      if(s[i]+k>'z'){
        k-='z'-s[i]+1;
        s[i]='a';
      }
    }
  }

  cout<<s<<endl;

  return 0;
}

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

int main(){
  long long int N,a,b,count,best=11;
  cin >> N;
  for(long int i=1;i<sqrt(N)*2;i++){
    if(ceil((double)N/i)==floor((double)N/i)){
      count=0;
      a=i;
      b=N/i;
      while(a!=0 || b!=0){
        a/=10;
        b/=10;
        count++;
      }
      if(count<best)best=count;
    }
  }
  cout << best << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string s;
  cin >> n >> s;
  
  string t=s;
 
   string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i=0; i<s.size(); i++){
    for(int j=0; j<26; j++){
    if(s[i] == alpha[j]){
      t[i]=alpha[j+n];
    }
    }
  }
  
  cout << t << endl;
      
  
}


Measured memory_bytes: 256
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

ctn = 0
0.upto(a) do |coin_500|
  0.upto(b) do |coin_100|
    0.upto(c) do |coin_50|
      sum = coin_500 * 500 + coin_100 * 100 + coin_50 * 50
      if sum == x
        ctn += 1
      end
    end
  end
end

puts ctn

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[200005];
bool vis[200005];
int dfs(int x)
{
    int c= 1;
    vis[x]= 1;
    for(int i=0; i<adj[x].size(); i++)
    if(!vis[ adj[x][i] ])c+= dfs(adj[x][i]);
    return c;
}
int main()
{
    int n, m, x, y;
    scanf("%d %d", &n, &m);
    while(m--)
    {
        scanf("%d %d", &x, &y);
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int res= 0;
    for(int i=1; i<=n; i++)
    if(!vis[i])res= max(res, dfs(i));
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 24264
M=10**9+7
f=lambda:map(int,input().split())
n,k=f()
l=sorted(f())
c,a=1,l[k-1]-l[-k]
for i in range(k,n):
  c=c*i*pow(i-k+1,M-2,M)%M
  a+=c*(l[i]-l[~i])%M
print(a%M)

Measured memory_bytes: 14040
n = int(input())
s = input()

"""
ある点から西を全てEに、東を全てWにする際のコストを最小化したい

入力例1)
5
WEEWW

EAST: 21000             東から西にかけてEが何個あるか
WEST: 01112             西から東にかけてWが何個あるか
 SUM: 22112             この配列の最小値が答え
"""

east = [0]
for i in range(n-1):
    if s[n-1-i]=='E':
        east.append(east[-1]+1)
    else:
        east.append(east[-1])
east = east[::-1]

west = [0]
for i in range(n-1):
    if s[i]=='W':
        west.append(west[-1]+1)
    else:
        west.append(west[-1])

sum = []
for i in range(n):
    sum.append(east[i]+west[i])

print(min(sum))

Measured memory_bytes: 33272
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [a, b, c] <- map strToInt . words <$> getLine
    -- 出力
    putStrLn $ if (a - b) == (b - c) then "YES" else "NO"


Measured memory_bytes: 508
n=int(input())
A=[int(i) for i in input().split()]
if A==[100,0]:print(100,0)
else:
    Ai=max(A)
    Aj=0
    curdif=10000000000000000
    for a in A:
        if abs(Ai/2-a)<curdif:
            Aj=a
            curdif=abs(Ai/2-a)
    print(Ai,Aj)

Measured memory_bytes: 14060
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#define MOD 1000000007
using namespace std;

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

    int count = 0;
    

    vector<int> a(n);

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

    int next=a[0];

    for(int i=0;i<n;i++){
        count++;
        if(next == 2){
            cout << count << endl;
            return 0;
        }
        next = a[next-1];
    }

    cout << -1 << endl;

}

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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
#define check cout<<"?\n";
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();
    string s, t; cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < 3; ++i){
        if(s[i] == t[i]) ++ans;
    }
    cout << ans << '\n';
    return 0;
}


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

int amida[1001][101];

int main(int argc, const char * argv[]) {
    while(1){
        int n, m, a; cin >> n >> m >> a;
        if(!n && !m && !a) break;
        
        memset(amida, -1, sizeof(amida));
        for(int i = 0; i < m; i++){
            int h, p, q; cin >> h >> p >> q;
            amida[h][p] = q;
            amida[h][q] = p;
        }
        
        for(int i = 1000; i >= 0; i--){
            if(amida[i][a] != -1){
                a = amida[i][a];
            }
        }
        cout << a << endl;
    }
}

Measured memory_bytes: 1564
#include <bits/stdc++.h>
using namespace std;  
typedef long long ll;
int main() {
  ll N,K;
  cin >> N >> K;
  vector<ll> v(N),A(N);
  for (ll i=0;i<N;i++) {
    cin >> A.at(i);
    ll x = A.at(i);
    v.at(x-1)++;
  }
  
  ll count=0;
  for (ll i=0;i<N;i++) {
    if (v.at(i)>0) count++;
  }
  
  ll ans=0;
  if (count>K) {
    sort(v.begin(),v.end());
    for (ll i=0;i<N;i++) {
      if (v.at(i)==0) continue;
      ans += v.at(i);
      count--;
      if (count<=K) break;
    }
  }
  
  cout << ans;
}

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




int main() {
    int t=1;
    // cin>>t;
    while(t--){
        int n,x,t;
        cin>>n>>x>>t;
        if(n%x==0)
            cout<<(n/x)*t<<endl;
        else 
            cout<<(n/x+1)*t<<endl;
    }
    }

Measured memory_bytes: 3632
import scala.io.StdIn._

object Main {
  def factorial(n: Int): Long = {
    def loop(i: Int, j: Long = 0): Long = i match {
      case 1 => j
      case _ => loop(i - 1, i * j)
    }
    loop(n)
  }
  
  def main(args: Array[String]): Unit = {
    println((1 to readInt()).map(_.toLong).product)
  }
}

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

int main()
{
    int ans = 0;
    string in_str;
    while(getline(cin, in_str))
    {
        int len;
        int center_index;
        if(in_str.size() % 2 == 0)
        {
            len = in_str.size() / 2;
            center_index = len;
        }
        else
        {
            len = in_str.size() / 2 + 1;
            center_index = len - 1;
        }
        string str_left = in_str.substr(0, len);
        string str_right = in_str.substr(center_index, len);
        reverse(str_right.begin(), str_right.end());
        if(str_left == str_right)
        {
            ans++;
        }
        //cout << "left = " <<str_left << " right = "<< str_right << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3152
// プライオリティー・キューの使い方の勉強
// 参考にした: http://drken1215.hatenablog.com/entry/2019/04/07/001000
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;
using Data = pair<long long, vector<int> >;

int main()
{
    vector<long long> N(3);
    int K;
    for(int i = 0; i < 3; ++i) { cin >> N[i]; }
    cin >> K;
    vector<vector<long long> > v(3);
    for(int iter = 0; iter < 3; ++iter) {
        v[iter].resize(N[iter]);
        for (int i = 0; i < N[iter]; ++i) { cin >> v[iter][i]; }
        sort(v[iter].begin(), v[iter].end(), greater<long long>());
    }
    priority_queue<Data> que;
    set<Data> se;
    que.push(Data(v[0][0] + v[1][0] + v[2][0], vector<int>({0,0,0})));
    for (int k = 0; k < K; ++k) {
        auto c = que.top(); que.pop();
        cout << c.first << endl;

        // 次の3候補
        for(int iter = 0; iter < 3; ++iter) {
            if (c.second[iter] + 1 < N[iter]) {
                long long sum = c.first - v[iter][c.second[iter]] + v[iter][c.second[iter] + 1];
                auto num = c.second; num[iter]++;
                auto d = Data(sum, num);

                // すでにプッシュされたもの以外
                if (!se.count(d)) { se.insert(d); que.push(d); }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

const int INF = 100000; 

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

    vector<int> l(n+1, 0);
    vector<int> r(n+1, 0);
    for(int i = 1; i <= n; i++) cin >> l[i] >> r[i];

    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans += r[i] - l[i] + 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.Char

toggleCase :: Char -> Char
toggleCase c | 'A' <= c && c <= 'Z'  = chr(ord c - ord 'A' + ord 'a')
toggleCase c | 'a' <= c && c <= 'z'  = chr(ord c - ord 'a' + ord 'A')
toggleCase c = c

toggleString [] = []
toggleString (x:xs) = toggleCase x : toggleString xs


main = do
    s <-getLine
    putStrLn $ toggleString s
    

Measured memory_bytes: 3872
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>

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

using namespace std;

int n;
string S[55];
map<char, int> min_cnt;
map<char, bool> exist;

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> n;
    rep(i,n) cin >> S[i];

    rep(i,n) {
        map<char, int> temp_cnt;
        for (char c='a'; c<='z'; c++) exist[c] = false;
        rep(j,S[i].length()) {
            temp_cnt[S[i][j]]++;
            exist[S[i][j]] = true;
        }
        for (auto it=temp_cnt.begin(); it!=temp_cnt.end(); it++) {
            if (i == 0) {
                min_cnt[it->first] = it->second;
            } else {
                min_cnt[it->first] = min(min_cnt[it->first], it->second);
            }
        }
        for (char c='a'; c<='z'; c++) {
            if (!exist[c]) {
                min_cnt[c] = 0;
            }
        }
    }

    for (char c='a'; c<='z'; c++) {
        rep(i,min_cnt[c]) {
            cout << c;
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
// AOJ  0289: Infinite Express
// 2017.10.26 bal4u@uu

#include <stdio.h>

int calc(int s, int d)
{
	int ans = 0;
	if (s == d) return 0;
	if (s % 2 != 0) ans++, s++;
	if (d % 2 != 0) ans++, d--;
	return ans + calc(s >> 1, d >> 1);
}

int main()
{
	int n, s, d;

	scanf("%d", &n);
	while (n-- > 0) {
		scanf("%d%d", &s, &d);
		printf("%d\n", calc(s, d));
	}
	return 0;
}

Measured memory_bytes: 1808
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	cout << pow(n,3);
	return 0;
}
/* The judge is never wrong! Your code is buggy 
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  string s; 
  cin >> s;

  int ans = 0;
  REP(i, s.size()-1){
    if(s[i] == 'A' && s[i+1] == 'C') ans = 1;
  }

  ans? Yes: No;

  return 0;
}

Measured memory_bytes: 256