akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <limits.h>
#define MAX 20000000
#define NIL  INT_MIN

void maxHeepify( int , int );
void buildMaxHeep( int );
void swap(int , int );
void insert(int );
int extract(void);
void heepIncreasekey(int, int);
int H[MAX+1];
int n;


int main(){
int i;
int key;
int cnt=0;
char order[10];


while(1){

 
  
scanf("%s",order);
if(order[0]== 'i'){//挿入
scanf("%d",&key);
insert(key);
//cnt++;
//printf("111111\n");
}
 else  if(order[1]== 'x'){//取出し
   //cnt--;
   // printf("222222222\n");
 printf("%d\n",extract());
}

  if(order[2] == 'd')  break;//終了
}

for(i=1; i<=cnt; i++){
  //printf("%d",H[i]);
}
//printf("\n");
  
return 0;
}


void maxHeepify(int i, int n ){
int l,r;
int largest;
 
  l = i*2;
  r = i*2+1;
  //左の子、自分、右の子で値が最大のノードを選ぶ

  if( l <= n && H[l] > H[i] )
    largest = l;
  else
    largest = i;

  if( r <= n && H[r] > H[largest] )
    largest = r;

  if(largest != i){
    swap(i , largest );
    maxHeepify(largest,n);
  }


  

}
/*
void buildMaxHeep(int n){
  int i;

  for(i=n/2 ; i >= 1 ; i--){
    maxHeepify(i,n);
  }
  
}
*/
void swap(int a, int b){

  int tmp;
  tmp = H[a];
  H[a]= H[b];
  H[b]= tmp;

}

int extract(void ){
  int maxv;
  maxv = H[1];
H[1]=H[n];
n--;
maxHeepify(1,n);
 return maxv;
}

void insert(int key){
n++;
H[n] = NIL;
heepIncreasekey(n, key);
}

void heepIncreasekey(int i, int key ){

 if(key < H[i])return ;
 H[i]=key;
while(i >1 && H[i/2] < H[i] ){
swap(i,i/2);
i = i/2;
}

}



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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> xs(n), ys(n);
    for (int& x : xs) {
        cin >> x;
    }
    for (int& y : ys) {
        cin >> y;
    }
    set<pair<int, int>> missing;
    for (int i = 0; i < n; ++i) {
        if (xs[i] < ys[i]) {
            missing.insert(make_pair(ys[i], i));
        }
    }
    long long count = 0;
    while (!missing.empty()) {
        auto p = *missing.rbegin();
        missing.erase(p);
        int i = p.second;
        int diff = ys[i]-xs[i];
        int sides = ys[(i+n-1)%n] + ys[(i+1)%n];
        int steps = diff / sides;
        if (steps == 0) {
            cout << -1 << endl;
            return 0;
        }
        count += steps;
        ys[i] -= sides * steps;
        if (ys[i] > xs[i]) {
            missing.insert(make_pair(ys[i], i));
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
bool ch[82][82][13000];
int main() {
	ll h,w;
	cin>>h>>w;
	ll a[82][82],b[82][82];
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			cin>>b[i][j];
		}
	}
	ll c[82][82];
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			c[i][j]=abs(a[i][j]-b[i][j]);
	//		cout << c[i][j];
		}
//		cout <<endl;
	}
	ch[0][0][c[0][0]]=true;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			for(ll k=0;k<13000;k++){
				if(i!=0&&ch[i-1][j][k]==true){
					ll now=c[i][j];
					ch[i][j][k+now]=true;
					ch[i][j][abs(k-now)]=true;
				}
				if(j!=0&&ch[i][j-1][k]==true){
					ll now=c[i][j];
					ch[i][j][k+now]=true;
					ch[i][j][abs(k-now)]=true;
				}				
			}
		}
	}
	for(ll i=0;i<13000;i++){
		if(ch[h-1][w-1][i]){
			cout <<i<<endl;
			return 0;
		}
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 67776
<?php

$line = trim(fgets(STDIN));
$line = array_map(function($val){ return intval($val); }, preg_split("/\s/", $line));
$a = $line[0];
$b = $line[1];
$half = $line[2] * 2;
$x = $line[3];
$y = $line[4];
$needed = 0;
if($a > $b){
    if($b > $half){
        $needed = $half * max([$x, $y]);
    }
    elseif($a > $half){
        $needed = $x * $half + (($y - $x) > 0 ? $b * ($y - $x) :0);
    }
    elseif($a + $b > $half){
        $needed = $half * min([$x, $y]) + ($x - $y > 0 ? $a : $b) * abs($x - $y);
    }
    else{
        $needed = $a * $x + $b * $y;
    }
}
else{
    if($a > $half){
        $needed = $half * max([$x, $y]);
    }
    elseif($b > $half){
        $needed = $y * $half + (($x - $y) > 0 ? $a * ($x - $y) : 0);
    }
    elseif($a + $b > $half){
        $needed = $half * min([$x, $y]) + ($x - $y > 0 ? $a : $b) * abs($x - $y);
    }
    else{
        $needed = $a * $x + $b * $y;
    } 
}
echo $needed . PHP_EOL;

Measured memory_bytes: 3956
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))

ans=0
j=0
for i in range(n):
    ans+=1
    if i==0:
        j=a[i]
    if j==2:
        print(ans)
        exit()
    j=a[j-1]
print(-1)


Measured memory_bytes: 13044
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    ll r = 0, g = 0, b = 0;
    ll ans = 1;
    for (int i = 0; i < 3 * N; ++i) {
        if (S[i] == 'R') {
            if (g > 0 && b == 0) {
                if (g > r) ans = (ans * (g - r)) % MOD;
                r++;
            }
            else if (g == 0 && b > 0) {
                if (b > r) ans = (ans * (b - r)) % MOD;
                r++;
            }
            else if (g > 0 && b > 0) {
                ans = (ans * min(g, b)) % MOD;
                g--;
                b--;
            }
            else r++;
        }
        else if (S[i] == 'G') {
            if (r > 0 && b == 0) {
                if (r > g) ans = (ans * (r - g)) % MOD;
                g++;
            }
            else if (r == 0 && b > 0) {
                if (b > g) ans = (ans * (b - g)) % MOD;
                g++;
            }
            else if (r > 0 && b > 0) {
                ans = (ans * min(r, b)) % MOD;
                r--;
                b--;
            }
            else g++;
        }
        else {
            if (r > 0 && g == 0) {
                if (r > b) ans = (ans * (r - b)) % MOD;
                b++;
            }
            else if (r == 0 && g > 0) {
                if (g > b) ans = (ans * (g - b)) % MOD;
                b++;
            }
            else if (r > 0 && g > 0) {
                ans = (ans * min(r, g)) % MOD;
                r--;
                g--;
            }
            else b++;
        }
    }
    for (ll i = 1; i <= N; ++i) {
        ans = (ans * i) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	VI ans;
	while (true) {
		int a, b, x;
		char op;
		cin >> a >> op >> b;
		if (op == '?')break;
		switch (op){
		case '+':
			x = a + b;
			break;
		case '-':
			x = a - b;
			break;
		case '*':
			x = a * b;
			break;
		case '/':
			x = a / b;
			break;
		}
		ans.PB(x);
	}
	for (auto n : ans) {
		cout << n << endl;
	}
}


Measured memory_bytes: 3160
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn=200005;
int T,n,t[maxn];
long long total=0;
int main(){
    scanf("%d%d",&n,&T);
    for(int i=0;i<n;i++){
        scanf("%d",t+i);
    }
    for(int i=0;i<n-1;i++){
        total+=min(T,t[i+1]-t[i]);
    }
    total+=T;
    cout<<total<<endl;
    return 0;
}


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

int main()
{
    ll n, ans = 0;
    cin >> n;
    ll a[n + 1], b[n];
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n)
    {
        ans += min(b[i], a[i] + a[i + 1]);
        if (b[i] > a[i])
            a[i + 1] = max(a[i + 1] - (b[i] - a[i]), (ll)0);
        // rep(j, n + 1) cout << a[j];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5200
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP((i),0,(n))
#define ALL(v) (v).begin(),(v).end()

int main() {
string text;
  cin>>text;
  int count=0;
  rep(i,3){
    if(text.at(i)=='1')count++;
}
  cout<<count<<endl;
}

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

int main(){
    int i, j, flag = 0;
    string s, p, tmp;
    cin >> s >> p;
    tmp = p;
    for (j = 0; j < s.size(); j++){
        for (i = 0; i < p.size(); i++){
            tmp[i] = s[(i + j) % s.size()];
        }
        if (tmp == p){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5;
const ll M = 1e9 + 7;
vector<int> v[N];
ll dp[N][2];
void dfs(int s, int p){
    dp[s][0] = dp[s][1] = 1;
    for(auto i : v[s]){
        if(i != p){
            dfs(i, s);
            dp[s][0] = (dp[s][0] * dp[i][1]) % M;
            dp[s][1] = (dp[s][1] * ((dp[i][0] + dp[i][1]) % M)) % M;
        }
    }
}
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    for(int i = 1; i < n; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1, 1);
    cout << (dp[1][0] + dp[1][1]) % M;
return 0;
}

Measured memory_bytes: 19584
//by tzupengwang™
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

char s[ 100005 ] ;
int len ;

void init() {
  scanf( "%s" , s ) ;
  len = strlen( s ) ;
}

char st[ 5 ][ 20 ] = { "dream" , "dreamer" , "erase" , "eraser" } ;
int lel[ 5 ] = { 5 , 7 , 5 , 6 } ;

bool match( int ind , int nm ) {
  for ( int i = 0 ; i < lel[ nm ] ; i ++ ) {
    if ( s[ ind + i ] != st[ nm ][ i ] ) return false ;
  }
  return true ;
}

void process() {
  while ( len ) {
    bool ok = false ;
    for ( int i = 0 ; i < 4 ; i ++ ) {
      if ( len >= lel[ i ] && match( len - lel[ i ] , i ) ) {
        ok = true ;
        len -= lel[ i ] ;
        break ;
      }
    }
    if ( !ok ) break ;
  }
  if ( len == 0 ) puts( "YES" ) ;
  else puts( "NO" ) ;
}

int main() {
/*
#ifdef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
  int Cases;
  scanf( "%d" , &Cases ) ;
  for ( int cases = 1 ; cases <= Cases ; cases ++ ) {
*/
    init() ;
    process() ;
/*
  }
*/
  return 0 ;
}


Measured memory_bytes: 256
use std::io::Read;

struct CustomIn<'a> {
    sin: ::std::io::StdinLock<'a>,
}
impl<'a> CustomIn<'a> {
    pub fn new(sin: ::std::io::StdinLock<'a>) -> Self {
        CustomIn::<'a> { sin: sin }
    }

    pub fn _u32(&mut self) -> u32 {
        self.sin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0u32, |a, x| a * 10 + (x as u8 - b'0') as u32)
    }

    pub fn _u64(&mut self) -> u64 {
        self.sin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0u64, |a, x| a * 10 + (x as u8 - b'0') as u64)
    }

    pub fn _usize(&mut self) -> usize {
        self.sin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .fold(0usize, |a, x| a * 10 + (x as u8 - b'0') as usize)
    }
}

fn main() {
    let mut sin = ::std::io::stdin();
    let mut cin = CustomIn::new(sin.lock());
    let (a, b) = (cin._usize(), cin._usize());
    println!("{}", (a - 1) * (b - 1));
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define MOD 100000
typedef long long ll;
typedef pair < int , int > Pii;
int dp[128][128][4];
int main(){
	int w,h;
	while(scanf("%d%d",&w,&h),h){
		memset(dp,0,sizeof(dp));
		dp[1][1][0] = 1;
		dp[1][1][1] = 1;
		reps(i,1,h+1){
			reps(j,1,w+1){
				rep(k,4)dp[i][j][k] %= MOD;
				if(i == 1 && j == 1){
					dp[i][j+1][0] += dp[i][j][2];
					dp[i][j+1][0] += dp[i][j][0];
					dp[i+1][j][1] += dp[i][j][3];
					dp[i+1][j][1] += dp[i][j][1];
				}
				else{
					dp[i][j+1][0] += dp[i][j][2];
					dp[i][j+1][0] += dp[i][j][0];
					dp[i+1][j][1] += dp[i][j][3];
					dp[i+1][j][1] += dp[i][j][1];
					dp[i][j+1][2] += dp[i][j][1];
					dp[i+1][j][3] += dp[i][j][0];
				}
			}
		}
		/*
		puts("###########################");
		reps(i,1,h+1){
			reps(j,1,w+1){
				printf("%2d",dp[i][j][0]);
			}
			printf("	");
			reps(j,1,w+1){
				printf("%2d",dp[i][j][1]);
			}
			printf("	");
			reps(j,1,w+1){
				printf("%2d",dp[i][j][2]);
			}
			puts("");
		}
		puts("###########################");
		*/
		printf("%d\n",(dp[h][w][0]+dp[h][w][1]+dp[h][w][2]+dp[h][w][3])%MOD);
	}
	return 0;
}

Measured memory_bytes: 1452
#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>;
const int MOD = 1000000007;

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

    int number = 1;
    rep(i, N) { // 小さい方を採択する
        int mulNumber = number * 2;
        int addNumber = number + K;
        number = min(mulNumber, addNumber);
    }

    cout << number << endl;

    return 0;
}

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

def isYakusuEight(a):
    if a % 2 == 0:
        return False
    cnt = 0
    for i in range(1, a+1):
        if a % i == 0:
            cnt += 1
    return cnt == 8

ans = 0
for i in range(1, N+1):
    if isYakusuEight(i):
        ans += 1
print(ans)

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: i64 = read();
    let p: i64 = read();
    let mut ans: i64 = 1;
    let mut i = 2;
    if n == 1 {
        println!("{}", p);
        return;
    }
    while i * i <= p {
        let mut po = p;
        let mut cnt = 0;
        while po % i == 0 {
            po /= i;
            cnt += 1;
        }
        if cnt >= n {
            ans = i;
        }
        i += 1;
    }
    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

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

int main() {
  int h, w;
  scanf("%d %d", &h, &w);
  vector<string> field(h, string(w, ' '));
  for (int y = 0; y < h; ++y)
    scanf(" %s", &field[y][0]);
  vector<vector<int>> mindist(h, vector<int>(w, INT_MAX));
  queue<pair<int, int>> q;
  for (int y = 0; y < h; ++y)
    for (int x = 0; x < w; ++x)
      if (field[y][x] == '#') {
        mindist[y][x] = 0;
        q.emplace(y, x);
      }
  while (!q.empty()) {
    pair<int, int> yx = q.front();
    q.pop();
    int y, x;
    tie(y, x) = yx;
    for (int d = 0; d < 4; ++d) {
      int y2 = y + dy[d], x2 = x + dx[d];
      if (0 <= y2 && y2 < h && 0 <= x2 && x2 < w &&
          mindist[y2][x2] > mindist[y][x] + 1) {
        mindist[y2][x2] = mindist[y][x] + 1;
        q.emplace(y2, x2);
      }
    }
  }
  int result = 0;
  for (int y = 0; y < h; ++y)
    result = max(result, *max_element(mindist[y].begin(), mindist[y].end()));
  printf("%d\n", result);

  return 0;
}


Measured memory_bytes: 13456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

int main() {
    ll argN, argQ;
    cin >> argN >> argQ;

    string base;
    cin >> base;

    vector<ll> argL(argQ);
    vector<ll> argR(argQ);
    for (ll i = 0; i < argQ; ++i) {
        cin >> argL.at(i) >> argR.at(i);
        argL.at(i)--;
        argR.at(i)--;
    }

    vector<ll> argP(base.size());
    ll ret = 0;
    for (ll i = 0; i < base.size() - 1; ++i) {
        if (base.at(i) == 'A' && base.at(i + 1) == 'C') {
                argP.at(i) = ret;
                ret++;
                i++;
        }
        argP.at(i) = ret;
    }

    if (base.at(base.size() - 1) != 'C' || base.at(base.size() - 2) != 'A') {
        argP.at(base.size() - 1) = argP.at(base.size() - 2);
    }

    for (ll i = 0; i < argQ; ++i) {
        cout << argP.at(argR.at(i)) - argP.at(argL.at(i)) << endl;
    }
}

Measured memory_bytes: 3456
A,B,C = [int(x) for x in input().split()]
K = int(input())

while(K > 0 and A >= B):
    K-=1
    B = B*2


while(K > 0 and B >= C):
    K-=1
    C = C*2

if( A < B and B < C):
    print("Yes")
else:
    print("No")


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


using namespace std;

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    if (a.back() == b.front() && b.back() == c.front())
        cout << "YES" << endl;
    else cout << "NO" << endl;

}

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

    solve();
    return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int IINF = INT_MAX;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    ll a, v; cin >> a >> v;
    ll b, w; cin >> b >> w;
    ll t; cin >> t;

    if(b < 0 && a < 0){
        if(abs(b) + w * t <= abs(a) + v * t) cout << "YES" << endl;
        else cout << "NO" << endl;
    }else if(b < 0){
        if(abs(b) + w * t <= v * t - a) cout << "YES" << endl;
        else cout << "NO" << endl;
    }else{
        if(b + w * t <= a + v * t) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3568
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
idx=1
idx_li=[]
ord_=[-1]*n
flag=False
for i in range(k):
    idx_li.append(idx)
    ord_[idx-1]=1
    idx=a[idx-1]
    if ord_[idx-1]==1:
        flag=True
        break
if flag:
    #non_loop=idx_li[:idx_li.index(idx)]
    loop = idx_li[idx_li.index(idx):]
    
    size=len(loop)
    print(loop[(k-(len(idx_li)-len(loop)))%size])
else:
    print(idx)

Measured memory_bytes: 32260
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最小公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最大公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a[200000];
    REP(i,n)cin >> a[i];
    ll x[200000]={0};
    REP(i,n)if(i%2)x[0] -= a[i];
    else x[0] += a[i];
    REP(i,n){
      x[i+1] = 2*a[i]-x[i];
      cout << x[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
import java.lang.reflect.*;

public class Main {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));   

    private static StringTokenizer st;

    public static void main ( String [] args ) throws IOException
    {
	    new Main().cal();
	
    }



    private void cal() throws IOException 
    {
     while(true){
     st= new StringTokenizer(br.readLine());
     int n = Integer.parseInt(st.nextToken());
     int a = Integer.parseInt(st.nextToken()); 
     int b = Integer.parseInt(st.nextToken());  
     if( n == 0 && a == 0 && b == 0) break;

	int out = 0;
	int temp;

	if( a > b ){ temp = a; a = b; b = temp;}

	if( a == b || b % a == 0){
		out = n/a;
		System.out.println(n-out);
		continue;
	}

	if( a > n ){
		System.out.println(n);
		continue;
	}

	out += n/a;
	int subs = n%a;
	int til;
	for( til = 1; til < a ; til++ ){
		if( (til*b) > n || (til*b)%a == 0 )	break;
	}
	for( int i=1; i < til ; i++ ){
		out += ((n-b*i)/a + 1);
	}

	System.out.println(n-out);

     }
    }

}

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

int main() {
  string s;
  string t;
  cin >> s >> t;
  int ans = t.size();
  for(int start = 0; start <= s.size()-t.size(); start++)
  {
    int diff=0;
    for(int i = 0; i < t.size(); i++){
      if(t.at(i) != s.at(start + i)){
      diff++;
      }
    }
    ans = min(ans, diff);
  }
  cout << ans;
}


Measured memory_bytes: 3596
//C
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
int main(){
    string s;
    cin >> s;
    int K;
    cin >> K;
    vector<pair<char,int>> a;
    for(int i=0; i<s.size(); i++){
        a.push_back(make_pair(s[i],i));
    }
    sort(a.begin(),a.end());
    /*for(int i=0; i<a.size(); i++){
        cout << a[i].first << a[i].second << endl;
    }*/

    set<string> l;
    for(int i=0; i<a.size(); i++){
        for(int j=1; a[i].second+j<=s.size() && j<=K; j++){
            l.insert(s.substr(a[i].second,j));
        }
        if(i == a.size()-1) break;
        if(l.size() >= K && a[i].first != a[i+1].first) break;
    }
    //cout << l.size() << endl;
    auto itr = l.begin();
    for(int i=1; i<K; i++){
        itr++;
    }
    cout << *itr << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,Q;
int S[200100],T[200100],X[200100];
int D[200100];
vector<int> zip;
struct event{
	int type; // 0 in 1 out
	int time;
	int val;
	event(){}
	event(int type,int time,int val):type(type),time(time),val(val){}
	bool operator < (const event& a) const{
		return time < a.time;
	}
};
vector<event> es;
int mini[600100];
int main(){
	cin >> N >> Q;
	for(int i=0;i<N;i++){
		cin >> S[i] >> T[i] >> X[i];
		zip.pb(S[i]-X[i]);
		zip.pb(T[i]-X[i]);
	}
	for(int i=0;i<Q;i++){
		cin >> D[i];
		zip.pb(D[i]);
	}
	sort(all(zip));
	zip.erase(unique(all(zip)),zip.end());
	for(int i=0;i<N;i++){
		int in = lower_bound(all(zip),S[i]-X[i])-zip.begin();
		int out = lower_bound(all(zip),T[i]-X[i])-zip.begin();
		es.pb(event(0,in,X[i]));
		es.pb(event(1,out,X[i]));
	}
	sort(all(es));
	int idx = 0;
	multiset<int> ms;
	ms.insert(INF);
	for(int t=0;t<zip.size();t++){
		while(idx<es.size()&&es[idx].time==t){
			if(es[idx].type==0){
				ms.insert(es[idx].val);
			}else{
				multiset<int>::iterator it = ms.find(es[idx].val);
				ms.erase(it);
			}
			idx++;
		}
		mini[t]=*ms.begin();
	}
	for(int i=0;i<Q;i++){
		int tid = lower_bound(all(zip),D[i])-zip.begin();
		if(mini[tid]==INF)cout << -1 << endl;
		else cout << mini[tid] << endl;
	}
	return 0;
}

Measured memory_bytes: 24168
#include<stdio.h>
int main(void){
   int n, i, p;
   scanf("%d", &n);
   while ( n ) {
       for ( i = 0; i < 9; i++ ) {
           scanf("%d", &p);
           n -= p;
       }
       printf("%d\n", n);
       scanf("%d", &n);
   }
   return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
    cin >> n;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i <= n-3; ++i) {
        if(s.substr(i, 3) == "ABC") cnt++;
    }
    cout << cnt << endl;
}

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

using namespace std;
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n;
int dp[20002][6];


int main () {
	SpeedForce;
	cin >> n;
	if (n == 3) {
		cout << "2 5 63\n";
		exit(0);
	}
	if (n == 4) {
		cout << "2 5 20 63\n";
		exit(0);
	}

	int a = n%3 ? n - 2 : n - 4;
	if (a > 15000) a = a % 2 ? 14999 : 15000;
	for(int i = 1; i <= a; i ++) cout << 2 * i << ' ';
	for (int i = 0; i < n-a; i ++) cout << 6 * i + 3 << ' ';

	return Accepted;
}

// B...a

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":	" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////

int main() {
  string s; cin>>s;
  sort(s.begin(),s.end());
  if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============prime_factor============================
vector<pll> prime_factor(ll N)
{
  vector<pll> res;
  for (ll i = 2; i * i <= N; ++i) {
    if (N % i == 0) {
      ll cnt = 0;
      while (N % i == 0) {
        N /= i;
        cnt += 1;
      }
      res.push_back({i, cnt});
    }
  }
  if (N != 1) {
    res.push_back({N, 1});
  }
  return res;
}
//=================================================


int main() {
  ll N;
  cin >> N;
  vector<ll> temp;
  temp.push_back(0);
  ll pw = pow(10, 6) * 3;
  for (ll i = 1; i <= pw; ++i) {
    temp.push_back((i + 1) * i / 2);
  }
  vector<pll> factor = prime_factor(N);
  ll ans = 0;
  for (ll i = 0; i < factor.size(); ++i) {
    ans += upper_bound(temp.begin(), temp.end(), factor.at(i).second) - temp.begin() - 1;
  }

  cout << ans << "\n";
}


Measured memory_bytes: 36284
inf = 10**15
mod = 10**9+7
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans=0
bc = [list(map(int, input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1])
for i in range(n):
    if bc and a[-1] >= bc[-1][1]:
        ans+=a.pop()
    else:
        if bc and bc[-1][0] != 0:
            bc[-1][0]-=1
            ans+=bc[-1][1]
        elif bc:
            bc.pop()
            if bc and a[-1] >= bc[-1][1]:
                ans += a.pop()
            elif bc:
                bc[-1][0]-=1
                ans+=bc[-1][1]
            else:
                ans+=a.pop()
        else:
            ans += a.pop()
print(ans)

Measured memory_bytes: 81432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
    ll n;   cin >> n;
    vector<ll> a(n);
    REP(i, n)   cin >> a[i];
    vector<ll> dp(n+1, 0);
    dp[0] = 3;
    ll res=1;
    REP(i, n){
        res *= dp[a[i]];
        dp[a[i]+1] += 1;
        dp[a[i]] -= 1;
        res %= MOD;
        if(dp[a[i]]<0) res=0;
        //cout << res << ' ';
    }
    cout << res << endl;
}

Measured memory_bytes: 4836
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;

struct UnionFind {
    vector<int> par; // 親を指すvector,-par[親]は木のサイズ
    UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
    int root(int x) { // 親をたどる&データの整理
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) { // データの結合
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);} // 所属判定
    int size(int x) {return -par[root(x)];} // 木のサイズ
} uf(400);

int main() {
    int n;
    cin >> n;
    vs s(n);
    rep(i, n) {
        cin >> s[i];
    }

    vvi dis(n, vi(n, INT_MAX/200));
    rep(i, n) {
        rep(j, n) {
            if(s[i][j] == '1') {
                uf.unite(2*i, 2*j+1);
                uf.unite(2*i+1, 2*j);
                dis[i][j] = 1;
                if(uf.same(2*i, 2*j)) {
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }

    

    rep(k, n) {
        rep(i, n) {
            rep(j, i) {
                dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
                dis[j][i] = dis[i][j];
            }
        }
    }

    int ans = 0;
    rep(i, n) {
        rep(j, i) {
            ans = max(ans, dis[i][j]);
        }
    }

    cout << ans+1 << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <set>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;


int main()
{
	int n;
	scanf("%d",&n);
	int a[50]={0};
	int b[50]={0};
	int c[50]={0};
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++)
	{
		scanf("%d",&b[i]);
		c[i]=a[i]-b[i];
	}
	int sum=0;
	for(int i=0;i<n;i++)
	{
		if(c[i]>0)
		{
			sum+=c[i];
		}
	}
	printf("%d\n",sum);
	return 0;
} 

Measured memory_bytes: 256
/*
    g++ -std=c++14 -O2 -Wall a.cpp -o a && a
    g++ -std=c++14 -O2 -Wall a.cpp -o a && a < in.txt > out.txt
*/
//  io
#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
#include <iostream>
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
//  util
#include <algorithm>
#include <cstring>
#include <string>
#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
//#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <queue>
#include <stack>
#include <vector>
//#include <set>
#include <map>
#include <tuple>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<int, int> vii;
typedef long long ll;
typedef long double ld;
constexpr int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//int modadd(int a, int b) { return ((a += b) < mod) ? a : (a - mod); }
//int modmult(int a, int b) { return (int)((a * b) % mod); }

int n;
ll a[16][16];
ll dp[1 << 16];
ll cost[1 << 16];

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

    memset(dp, 0, sizeof(dp));
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < (1 << n); i++)
    {
        for (int a1 = 0; a1 < n; a1++)
        {
            for (int a2 = a1 + 1; a2 < n; a2++)
            {
                if ((i & 1 << a1) && (i & 1 << a2))
                    cost[i] += a[a1][a2];
            }
        }
    }

    for (int i = 0; i < (1 << n); i++)
    {
        dp[i] = cost[i];
        for (int sub = i; sub > 0; sub = i & (sub - 1))
        {
            dp[i] = max(dp[i], dp[sub] + dp[i ^ sub]);
        }
    }
    cout << dp[(1 << n) - 1];
}

Measured memory_bytes: 4684
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int n,m,V;
int w[1100];
int v[1100];
int f[1010000];	//f[i]表示达到i价值的最优w 

int main()
{
	cin>>n>>m;
	for(int i=1; i<=n; i++)
	{
		cin>>w[i]>>v[i];
		V+=v[i];
	}
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	for(int i=1; i<=n; i++)
	{
		for(int j=V; j>=v[i]; j--)
		{
			f[j]=min(f[j],f[j-v[i]]+w[i]);
		}
	}
	for(int i=V;i>=1;i--)
	{
		if(f[i]&&f[i]<=m)
		{
			printf("%d",i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4224
/**
 *    author:  tourist
 *    created: 13.01.2020 23:48:43       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, d1, dx;
  cin >> n >> d1 >> dx;
  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    d[i] = 2 * d1 + (4 * i + 1) * dx;
  }
  vector<long long> x(n + 1);
  x[0] = 0;
  for (int i = 1; i <= n; i++) {
    x[i] = x[i - 1] + d[i - 1];
  }
  vector<long long> px(n + 2);
  for (int i = 0; i <= n; i++) {
    px[i + 1] = px[i] + x[i];
  }
  vector<double> coeff(n);
  for (int step = 0; step < n; step++) {
    double p = 0.5 / n;
    for (int mn = 0; mn <= step; mn++) {
      coeff[mn] += p / (mn + 1);
      p *= (step - mn) / (n - mn - 1.0);
      if (p < 1e-30) {
        break;
      }
    }
  }
  double ans = 0.0;
  for (int mn = 0; mn < n; mn++) {
    long long s = px[n + 1] - px[n - mn] - px[mn + 1];
    ans += coeff[mn] * (double) s;
  }
  cout << fixed << setprecision(17) << ans << '\n';
  return 0;
}


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

ll calc(ll n, ll r)
{
	if (n == 0) return 0;
	for (ll i = 0; i <= 9; i++){
		if ((n - r * i) % 10 == 0){
			return calc((n - r * i) / 10, -r) * 10 + i;
		}
	}
}

int main()
{
	ll n;
	while (scanf("%lld", &n), n){
		printf("%lld\n", calc(n, 1));
	}
}

Measured memory_bytes: 1188
//template---{{{
//Header file---{{{
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
//}}}
using namespace std;

//DEFINE---{{{
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b); i > (a); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
//end.DEFINE---}}}

//end.template ---}}}

int main() {
  int N, K;

  cin >> N >> K;

  if (N % K == 0) cout << "0" << endl;
  else cout << "1" << endl;

  return (0);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

    string s;
    cin >> s;

    bool north = false, south = false, east = false, west = false;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'N') north = true;
        if (s[i] == 'S') south = true;
        if (s[i] == 'E') east = true;
        if (s[i] == 'W') west = true;
    }
    cout << ((north == south && east == west)? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 760
#coding: utf-8
D, G = map(int, input().split())
l = []
P, C = [], []
for _ in range(D):
	p, c = map(int, input().split())
	P.append(p)
	C.append(c)
	#l.append([p, c, i+1])
ans = 10 ** 10
for mask in range(int(bin(1 << D), 0)):
	s = 0
	num = 0
	rest_max = -1
	for i in range(D):
		if mask >> i & 1:
			s += 100 * (i + 1) * P[i] + C[i]
			num += P[i]
		else:
			rest_max = i

	if s < G:
		s1 = 100 * (rest_max + 1)
		need = (G - s + s1 - 1) // s1
		if need >= P[rest_max]:
			continue
		num += need

	ans = min(ans, num)
print(ans)

Measured memory_bytes: 3064
while True:
    try:
        n = int(raw_input())
        ans = [i for i in range(n+1)]
        m = int(raw_input())
        for i in range(m):
            a, b = map(int, raw_input().strip().split(','))
            t = ans[a]
            ans[a] = ans[b]
            ans[b] = t
        ans = ans[1:]
        for x in ans:
            print x
    except EOFError:
        break

Measured memory_bytes: 6244
S = input()

As = []
Bs = []
count = 0
a = False
for i in range(len(S) - 1):
    count += 1
    if S[i] == S[i+1]:
        if a:
            As.append(count)
        else:
            Bs.append(count)
        a = not a
        count = 0
count += 1
if a:
    As.append(count)
else:
    Bs.append(count)

ans = sum(As) if sum(As) < sum(Bs) else sum(Bs)

print(ans)

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3588
import java.util.Scanner;
 
 
public class Main {    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int sx = sc.nextInt();
        int sy = sc.nextInt();
        int tx = sc.nextInt();
        int ty = sc.nextInt();
        int x = tx - sx;
        int y = ty - sy;
        String ans = "";
        StringBuffer sb = new StringBuffer(ans);
        for(int i=0;i<y;i++){
            sb.append("U");
        }
        for(int j=0;j<x;j++){
            sb.append("R");
        }
        for(int i=0;i<y;i++){
            sb.append("D");
        }
        for(int j=0;j<x;j++){
                sb.append("L");
        }
        sb.append("L");
        for(int i=0;i<y;i++){
            sb.append("U");
        }
        sb.append("UR");
        for(int j=0;j<x;j++){
            sb.append("R");
        }
        sb.append("DR");
        for(int i=0;i<y;i++){
            sb.append("D");
        }
        sb.append("DL");
        for(int j=0;j<x;j++){
            sb.append("L");
        }
        sb.append("U");
        System.out.println(sb.toString());
        sc.close();
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
template<class T>
using PAIR = pair<T,T>;
template<class T>
using vec = vector<T>;
template<class T>
using maps = map<string, T>;
template<class T>
using mapi = map<int, T>;
using ll = long long;
int main(){
    string S;
    cin >> S;
    vec<bool>f;
    vec<int>p;
    vec<int>ans(S.size(),0);
    for(int i=0,_i=S.size()-1;i<_i;i++){
        if(S[i] == 'R' && S[i+1] == 'L'){
            f.push_back(true);
            p.push_back(i);
        }
        else{
            f.push_back(false);
        }
    }
    f.push_back(false);
    int L,R;
    int cnt = 0;
    R = p[cnt];
    int ps = p.size()-1;
    for(int i=0,_i=S.size();i<_i;i++){
        if(f[i]){
            ans[i]++;
            L = p[cnt];
            if(cnt == ps){
                R = _i+1;
            }
            else{
                R = p[cnt+1];
            }
            cnt++;
        }
        else{
            if(S[i] == 'R'){
                if((R-i)%2 == 0){
                    ans[R]++;
                }
                else{
                    ans[R+1]++;
                }
            }
            else{
                if((i-L)%2 == 0){
                    ans[L]++;
                }
                else{
                    ans[L+1]++;
                }
            }
        }
        /*for(int j=0,_j=ans.size();j<_j;j++){
            cout << ans[j];
            if(j != _j-1){
                cout << " ";
            }
        }
        cout << "\n";*/
    }
    for(int i=0,_i=ans.size();i<_i;i++){
        cout << ans[i];
        if(i != _i-1){
            cout << " ";
        }
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 1280
import java.util.*;
import java.io.*;

class Main {

	static Node[] node = null;

	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		node = new Node[n];

		for (int i=0; i<n; i++) {
			node[i] = new Node();
		}

		for (int i=0; i<n; i++) {
			String line = br.readLine();
			String[] str = line.split(" ");
			int id = Integer.parseInt(str[0]);
			int left = Integer.parseInt(str[1]);
			int right = Integer.parseInt(str[2]);
			if (left != -1 && right != -1) {
				node[id].degree = 2;
				node[id].left = node[right].sibling = left;
				node[id].right = node[left].sibling = right;
				node[left].parent = node[right].parent = id;
				node[id].type = "internal node";
			}else if (left != -1) {
				node[id].degree = 1;
				node[id].left = left;
				node[id].right = node[left].sibling = -1;
				node[left].parent = id;
				node[id].type = "internal node";
			}else if (right != -1) {
				node[id].degree = 1;
				node[id].right = right;
				node[id].left = node[right].sibling = -1;
				node[right].parent = id;
				node[id].type = "internal node";
			}else {
				node[id].degree = 0;
				node[id].left = node[id].right = -1;
				node[id].type = "leaf";
			}
		}

		for (int i=0; i<n; i++) {
			if (node[i].parent == -1) {
				setDH(node[i],0);
				node[i].type = "root";
				node[i].sibling = -1;
				break;
			}
		}

		for (int i=0; i<n; i++) {
			StringBuilder sb = new StringBuilder();
			sb.append("node ").append(i).append(": parent = ").append(node[i].parent).append(", sibling = ");
			sb.append(node[i].sibling).append(", degree = ").append(node[i].degree).append(", depth = ");
			sb.append(node[i].depth).append(", height = ").append(node[i].height).append(", ").append(node[i].type);
			System.out.println(sb);
		}

		br.close();
	}

	static int setDH(Node nd,int depth){
		nd.depth = depth;
		if (nd.left != -1 && nd.right != -1) {
			int lh = setDH(node[nd.left],depth+1);
			int rh = setDH(node[nd.right],depth+1);
			nd.height = lh > rh ? lh : rh;
		}else if (nd.left != -1) {
			nd.height = setDH(node[nd.left],depth+1);
		}else if (nd.right != -1) {
			nd.height = setDH(node[nd.right],depth+1);
		}else {
			nd.height = 0;
		}
		return nd.height+1;
	}

	static class Node{
		int parent = -1;
		int sibling;
		int degree;
		int depth;
		int height;
		String type;
		int right;
		int left;
	}
}

Measured memory_bytes: 17060
import java.io.*;

public class Main{
	public static void main(String[] arsg) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		

		while(true){
			String str = br.readLine();
			if(str.equals("-")) break;
			int n = Integer.parseInt(br.readLine());
			for(int i = 0;i<n;i++){
				int h = Integer.parseInt(br.readLine());
				str = str.substring(h, str.length()) + str.substring(0,h);
			}
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 24260