akhauriyash/Code-Regression huggingface dataset:
A, B, C = map(int, input().split())
K = int(input())
for i in range(K):
    if A >= C:
        C = C * 2
        K -= 1
if K > 0:
    for i in range(K):
        if A >= B:
            B = B * 2
            K -= 1
        if B >= C:
            if K > 0:
                C = C * 2
            exit

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


Measured memory_bytes: 9208
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <utility>
#include <vector>

#define MAX_N (100000)

using namespace std;

int num_div_2(int n) {
  if (n % 4 == 0) {
    return 2;
  } else if (n % 2 == 0) {
    return 1;
  } else {
    return 0;
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // count how many times each element can be divided by 2 and sort by it
  vector<int> bs;
  for (int i = 0; i < N; i++) {
    bs.push_back(num_div_2(as[i]));
  }
  sort(bs.begin(), bs.end());

  // try the optimal placing strategy
  int b = 1, e = N, prev = bs[0], possible = 1;
  while (e - b > 0) {
    const int smallest = bs[b], largest = bs[e - 1];
    if (prev == 0) {  // the maximum remaining must be 2
      if (largest >= 2) {
        prev = largest;
        e--;
      } else {
        possible = 0;
        break;
      }
    } else if (prev == 1) {  // the maximum remaining must be 1
      if (largest >= 1) {
        prev = largest;
        e--;
      } else {
        possible = 0;
        break;
      }
    } else {  // choose the minimum remaining
      prev = smallest;
      b++;
    }
  }
  if (possible) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
const int N = (int) 1e5+5;

map<int,int> mp;
int n;
int a[N];
int main(){
    #ifdef NGKCP
        freopen("input.txt","r",stdin);
    #endif
    iostream::sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        mp[a[i]] ++;
    }
    if (n % 3){
        if (mp[0] != n)
            cout << "No";
        else
            cout << "Yes";
    }
    else{
        bool ok = 1;
        int xorr = 0;
        for(auto v: mp)
            ok &= (v.second % (n/3) == 0),
            xorr ^= ((v.second >= (n/3)) ?     v.first : 0),
            xorr ^= ((v.second >= ((n/3)*2)) ? v.first : 0),
            xorr ^= ((v.second >= ((n/3)*3)) ? v.first : 0);

        if (ok && xorr == 0)
            cout << "Yes";
        else
            cout << "No"; 
    }
}

Measured memory_bytes: 4224
s = input()
t = input()
def hamming_dist(str1,str2):
    ans = 0
    a,b = len(str1),len(str2)
    if a > b:
        ans = a - b
        length = b
    elif a < b:
        ans = b - a
        length = a
    else:
        length = a
    for i in range(length):
        if str1[i] != str2[i]:
            ans += 1
    return ans
print(hamming_dist(s,t))

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

void chmin(ll &a, const ll &b) { if (b < a) a = b; }
const ll INF = 1ll<<60;

int main(){
    ll n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i]; rep(i,n-1) a[i+1] += a[i];
    ll ans = INF;
    for(int i = 1; i <= n-3; i++){
        // left
        ll k = lower_bound(a.begin(),a.begin()+i+1,a[i]/2) - a.begin();
        if(k == i) k--;
        if(k != 0 && abs(a[k]*2-a[i]) > abs(a[k-1]*2-a[i])) k--;
        // right
        ll l = lower_bound(a.begin()+i+1,a.end(),(a[n-1]+a[i])/2) - a.begin();
        if(l == n-1) l--;
        if(l != i+1 && abs(a[n-1]-2*a[l]+a[i]) > abs(a[n-1]-2*a[l-1]+a[i])) l--;
        // change
        chmin(ans,max(max(a[k],a[i]-a[k]),max(a[n-1]-a[l],a[l]-a[i]))-min(min(a[k],a[i]-a[k]),min(a[n-1]-a[l],a[l]-a[i])));
    }
    cout << ans << endl;
}

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

int main(){
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0; i<n; i++){
        cin>>arr[i];
    }
    ll ans = 0;
    for(ll i=0; i<n-1; i++){
        if(arr[i]>arr[i+1]){
            ans+=(arr[i] - arr[i+1]);
            arr[i+1] = arr[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}


int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

string s;
int dp[100010][2];

signed main() {
	cin >> s;
	dp[0][0] = 1;
	int n = (int)s.size();
	for (int i = 1; i <= n; i++) {
		if (s[i - 1] == '0') {
			dp[i][0] = dp[i - 1][0];
			dp[i][1] = dp[i - 1][1] * 3;
			dp[i][1] %= mod;
		}
		else {
			dp[i][0] = dp[i - 1][0] * 2;
			dp[i][1] = dp[i - 1][0] + dp[i - 1][1] * 3;
			dp[i][0] %= mod;
			dp[i][1] %= mod;
		}
	}
	cout << (dp[n][0] + dp[n][1]) % mod << endl;
}

Measured memory_bytes: 2048
<?php

fscanf(STDIN, "%d %d", $n, $k);
$h_arr = explode(' ', trim(fgets(STDIN)));

sort($h_arr);

$sum = 0;
for ($i = 0; $i < $n - $k; ++$i) {
    $sum += $h_arr[$i];
}

echo $sum;


Measured memory_bytes: 23200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<long long>A(N+1, 1);
  for(int i=0; i<M; i++){
    int a;
    cin >> a;
    A[a]=0;
  }
  for(int i=0; i<N-1; i++){
    if(A[i+2]==0) continue;
    A[i+2]=A[i]+A[i+1];
    A[i+2]%=1000000007;
  }
  cout << A[N] << endl;
}

Measured memory_bytes: 1024
n = input()
flag = True
if len(n) % 2 == 1:
    flag = False
for i in range(len(n)-1):
    if n[i] == 'h' and n[i+1] == 'i':
        continue
    elif n[i] == 'i' and n[i+1] == 'h':
        continue
    else:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
public class Main {
	static ArrayList<Integer> list = new ArrayList<Integer>();
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		makePrimeList();
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int sum = 0;
			for(int i = 0; i < n; i++) {
				int p = sc.nextInt();
				int m = sc.nextInt();
				if(m == 0) {
					if(!list.contains(p)) {
						sum -= 1;
					}
					continue;
				}
				else  {
				
				int min = Collections.binarySearch(list, p-m);
				if(min < 0) {
					
					min *= -1;
					min -= 1;
				}
				int max = Collections.binarySearch(list, p+m);
				if(max < 0) {
					
					max *= -1;
					max -= 2;
				}
				//if(max - min - 1 > 0)
				sum += max - min;
				//else if(max - min - 1 == 0) {
					//sum -= 1;
				//}
				}
			}
			
			System.out.println(sum);
			
		}
	}
	
	static void makePrimeList() {
		boolean[] isntPrime = new boolean[1000000];
		int i = 2;
		for(; i*i < isntPrime.length; i++) {
			if(!isntPrime[i]) {
				list.add(i);
				for(int j = i + i; j < isntPrime.length; j += i) {
					isntPrime[j] = true;
				}
			}	
		}
		
		for(; i < isntPrime.length; i++) {
			if(!isntPrime[i]) {
				list.add(i);
			}
		}
	}
		
}

Measured memory_bytes: 31132
integer(16) N,ans,i,j
read*,N
ans=huge(ans)
do i=1,N
  if(i*i>N)exit
  if(mod(N,i)==0)then
    do j=10,0,-1
      if(N/i>=10**j)then
        ans=min(ans,j+1)
        exit
      endif
    end do
  endif
end do
print"(I0)",ans
end

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	long f(long x, long y) {
		if (x > y) {
			long tmp = x;
			x = y;
			y = tmp;
		}
		if (x == 0) {
			return -y;
		}
		return 2 * x * (y / x) + f(y % x, x);
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		long x = sc.nextLong();

		System.out.println((n + f(n - x, x)));
	}

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


Measured memory_bytes: 20948
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;
int main() {
	string s;
	int K;
	cin >> s >> K;
	vector<string>V;
	for (int i = 0; i < s.size(); ++i) {
		for (int j = 1; i + j <= s.size(); ++j) {
			if (j <= 5) {
				V.push_back(s.substr(i, j));
			}
		}
	}
	sort(V.begin(), V.end());
	unique(V.begin(), V.end());
	cout << V[K - 1] << endl;
	return 0;
}


Measured memory_bytes: 1660
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N = lread();
    foreach (x; 1 .. 10)
        foreach (y; 1 .. 10)
            if (N == x * y)
            {
                writeln("Yes");
                return;
            }
    writeln("No");
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a = [0] + a + [0]

s = 0

for i in range(n+1):
    s += abs(a[i]-a[i+1])

for i in range(n):
    print(s+abs(a[i]-a[i+2])-(abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])))

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

int main()
{
	int n;
	cin>>n;
	
	int c1[2] = {-1,-1};
	int c2[2] = {-1,-1};
	int c3[2] = {-1,-1};
	int c4[2] = {-1,-1}; 
	
	int l[n],r[n];
	for(int i=0;i<n;i++)
	{
		cin>>l[i]>>r[i];
		
		if(c1[0]==-1 || (l[i]+r[i]<c1[0]+c1[1]))
		{
			c1[0]=l[i];
			c1[1]=r[i];
		}
		
		if(c2[0]==-1 || (-l[i]+r[i]<-c2[0]+c2[1]))
		{
			c2[0]=l[i];
			c2[1]=r[i];
		}
		
		if(c3[0]==-1 || (l[i]-r[i]<c3[0]-c3[1]))
		{
			c3[0]=l[i];
			c3[1]=r[i];
		}
		
		if(c4[0]==-1 || (l[i]+r[i]>c4[0]+c4[1]))
		{
			c4[0]=l[i];
			c4[1]=r[i];
		}
	}
	
	int mx_dist=0;
	
	for(int i=0;i<n;i++)
	{
		mx_dist=max(mx_dist,abs(l[i]-c1[0]) + abs(r[i]-c1[1]));	
		mx_dist=max(mx_dist,abs(l[i]-c2[0]) + abs(r[i]-c2[1]));	
		mx_dist=max(mx_dist,abs(l[i]-c3[0]) + abs(r[i]-c3[1]));	
		mx_dist=max(mx_dist,abs(l[i]-c4[0]) + abs(r[i]-c4[1]));	
	}
	
	cout<<mx_dist<<endl;
	
	return 0;
}

Measured memory_bytes: 5112
# -*- coding: utf-8 -*-
import math
def main():
# 整数の入力
    x = int(input())
    n = 100.0
    counter = 0
    # 出力
    while True:
        counter += 1
        temp = n * 1.01
        n = int(temp)
        if n >= x:
            break
    print(counter)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9176
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            string[] line = Console.ReadLine().Split(' ');
            var L = int.Parse(line[0]);
            var R = int.Parse(line[1]);
            var d = int.Parse(line[2]);

            int cnt = 0;
            for (int i = L; i <= R; i++) if (i % d == 0) cnt++;
            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 26924
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N, R = map(int, input().split())
    if N >= 10:
        print(R)
    else:
        print(R + 100 * (10 - N))


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, m; cin >> n >> m;
  vector<vector<int>> a(n, vector<int>(m));
  for(int i=0;i<n;++i) {
    for(int j=0;j<m;++j) {
      cin >> a[i][j];
    }
  }
  map<int, bool> sel;
  vector<int> pos(n, 0);
  map<int, int> cnt;
  int ans = INF;
  for(int i=0;i<m;++i) {
    cnt.clear();
    for(int j=0;j<n;++j) {
      if(pos[j] < m) cnt[a[j][pos[j]]]++;
    }
    int ma = 0;
    int num = 0;
    for(int j=1;j<=m;++j) {
      if(cnt[j] > ma) {
        num = j;
        ma = cnt[j];
      }
    }
    ans = min(ans, ma);
    sel[num] = true;
    for(int j=0;j<n;++j) {
      while(pos[j] < m && sel[a[j][pos[j]]]) pos[j]++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int N,M; cin >> N >> M;
    vel a(N), b(N),c(M),d(M);
    rep(i,N) cin >> a[i] >> b[i];
    rep(i,M) cin >> c[i] >> d[i];

    rep(i,N) {
      ll dis = INF;
      ll poi;
        rep(j,M) {
            ll temp = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(dis > temp) poi = j+1;
            dis = min(dis, temp);
        }
      cout << poi << endl;
    }
    return 0;
}

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

int main()
{
  int n;
  cin>>n;
  string ans;
  int div=2;
  while(n!=0){
    if(n%2==0) ans+='0';
    else {
      ans+='1';
      n--;
    }
    n/=-2;
  }
  reverse(ans.begin(), ans.end());
  if(ans=="") ans+='0';
  cout<<ans;
}

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

using namespace std;

using int64 = long long;

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

  int n;
  cin >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) cin >> xs[i];

  vector<vector<int64>> dp = Make2DVector<int64>(n + 1, n + 1, INT64_MIN);
  function<int64(int, int)> solve = [&](int s, int t) -> int64 {
    if (dp[s][t] != INT64_MIN) return dp[s][t];

    if (s == t) return 0;
    int64 max = INT64_MIN;
    if (xs[s] - solve(s + 1, t) > max) {
      max = xs[s] - solve(s + 1, t);
    }
    if (xs[t - 1] - solve(s, t - 1) > max) {
      max = xs[t - 1] - solve(s, t - 1);
    }
    dp[s][t] = max;
    return max;
  };
  cout << solve(0, n) << endl;
}


Measured memory_bytes: 71168
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

int main(void){
	int n=nextint();
	int z=nextint();
	int w=nextint();
	if(n==1){
	int a1=nextint();
	int ans=a1<w?w-a1:a1-w;
	printf("%d\n", ans);
	}else{
	for(int i=2; i<n; i++){
		nextint();
	}
	int a1=nextint();
	int a2=nextint();
	int b1=a2<w?w-a2:a2-w;
	int b2=a2<a1?a1-a2:a2-a1;
	int ans=b1>b2?b1:b2;
	printf("%d\n", ans);
	}
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
#define ll long long
ll gcd(ll a,ll b)
{
	return b==0?a:gcd(b,a%b);
}
int main()
{
	int n;
	cin>>n;
	ll t[110];
	ll sum;
	for(int i=0;i<n;i++)
	{
		cin>>t[i];
	}
	for(int i=0;i<n-1;i++)
	{
		sum=t[i]/gcd(t[i],t[i+1])*t[i+1];
		t[i+1]=sum;
	}
	cout<<t[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  string s,t;
  cin >> s >> t;

  map<char, vector<ll>> mp;
  rep(i, s.size()) {
    mp[s[i]].push_back(i);
  }

  for (auto i : t) {
    if (mp[i].size() == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }

  ll sum = 0, pre = -1;
  for (auto t_ch : t) {
    auto&& ch_vec = mp[t_ch];
    auto&& it = upper_bound(ch_vec.begin(), ch_vec.end(), pre);
    // cout << *it << endl;
    if (it == ch_vec.end() || *it <= pre) {
      sum += 1;
      pre = ch_vec.front();
    } else {
      pre = *it;
    }
  }

  cout << sum * s.size() + pre + 1 << endl;
}

Measured memory_bytes: 1728
#include"bits/stdc++.h"
#include"math.h"
using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int,int>;

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()

int main(){
  
  int n,x;cin >> n >> x;
  vector<int>a(n);rep(i,n)cin >> a[i];
  ll ans = 0;
  REP(i,1,n){
    if(a[i-1]+a[i]>x){
      int dif=a[i]+a[i-1]-x;
      if(dif>a[i]){
        a[i-1]-=dif-a[i];
        a[i]=0;
      }
      else{
        a[i]-=dif;
      }
      ans += dif;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    for (int i = 1; i <= 9; i++) {
        int b = x / i;
        if (b * i == x && b <= 9 && b >= 1) {
            cout << "Yes\n";
            rr;
        }
    }
    cout << "No\n";
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

int main(){
  int n,C;
  cin>>n>>C;
  vector<vector<long long int> > imos(C,vector<long long int>((1e5+1)*2,0));
  long long int s,t,c;
  for(long long int i=0;i<n;i++){
    cin>>s>>t>>c;
    c--;
    s*=2;
    s--;
    t*=2;
    imos[c][s]++;
    imos[c][t+1]--;
  }

  //for(int i=0;i<10;i++)cout<<imos[0][i]<<" ";

  vector<long long int> tmp(C,0);
  long long int ans=0;
  for(long long int i=0;i<(1e5)*2+1;i++){
    long long int anstmp=0;
    for(long long int j=0;j<C;j++){
      tmp[j]+=imos[j][i];
      if(tmp[j]!=0)anstmp++;
    }
    if(i%2==1)ans=max(ans,anstmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 48768
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var happiness = new Happiness[n];
            for (var i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(' ');
                happiness[i] = new Happiness(int.Parse(input[0]), int.Parse(input[1]));
            }
            var sorted = happiness.OrderByDescending(x => x.A + x.B).ToArray();
            var a = sorted.Where((x, i) => i % 2 == 0).Sum(x => (long)x.A);
            var b = sorted.Where((x, i) => i % 2 == 1).Sum(x => (long)x.B);
            Console.WriteLine(a - b);
        }
    }
    class Happiness
    {
        public int A;
        public int B;
        public Happiness(int a, int b)
        {
            A = a;
            B = b;
        }
    }
}


Measured memory_bytes: 26688
#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
int main()
{
    long long int h,w;
    cin>>h>>w;
    char g[h+1][w+1];
    int i,j;
    for(i=1;i<=h;i++)
    {
        for(j=1;j<=w;j++)
        {
            cin>>g[i][j];
        }
    }
    long long int dp[i][j];
    dp[1][1]=1;
    int flag = 0;
    for(j=2;j<=w;j++)
    {
        if(g[1][j]=='#')
            flag = 1;
        if(flag == 0)
            dp[1][j]=1;
        else
            dp[1][j]=0;
    }
    flag = 0;
    for(i=2;i<=h;i++)
    {
        if(g[i][1]=='#')
            flag = 1;
        if(flag==0)
            dp[i][1]=1;
        else
            dp[i][1]=0;
    }
    for(i=2;i<=h;i++)
    {
        for(j=2;j<=w;j++)
        {
            if(g[i][j]=='#')
                dp[i][j]=0;
            else
                dp[i][j]=dp[i-1][j]+dp[i][j-1];

            dp[i][j]%=MAX;
        }
    }
    cout<<dp[h][w];
    return 0;
}


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

typedef pair <string, int> si;

bool comp(si x, si y){
	return (x.second == y.second) ? (x.first < y.first) : (x.second > y.second);
}

int main(){
	map <string, int> mp;
	int n;	cin >> n;
	for (int i = 0; i < n; ++i){
		string x;	cin >> x;
		mp[x]++;
	}
	vector <si>	v;
	for(auto x : mp){
		v.push_back({x.first, x.second});
	}
	sort(v.begin(), v.end(), comp);
	int mx = v[0].second;
	for(si x : v){
		if(x.second == mx){
			cout << x.first << endl;
		}
		else break;
	}
 	return 0;
}

Measured memory_bytes: 29680
from queue import Queue

class Process:
	def __init__(self, name, time):
		self.name = name
		self.time = int(time)

	def set_time(self, time):
		self.time = time

n, q = map(int, input().split())
queue = Queue()
for i in range(n):
	name, time = map(str, input().split())
	queue.put(Process(name, time))

time_elapsed = 0
while queue.empty() != True:
	process = queue.get()
	time = process.time
	if time > q:
		process.set_time(time - q)
		time_elapsed += q
		queue.put(process)
	else:
		time_elapsed += time
		print(process.name + ' ' + str(time_elapsed))


Measured memory_bytes: 18624
ops = {"+": lambda a, b: b + a,
       "-": lambda a, b: b - a,
       "*": lambda a, b: b * a}
def f(stack, s):
    if s in ops:
        stack.append(ops[s](stack.pop(), stack.pop()))
    else:
        stack.append(int(s))
    return stack

print reduce(f, raw_input().split(), [])[-1]
    

Measured memory_bytes: 4308
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;

// 辺に重みをつける場合 
struct Edge{
    int to;
    int cost;
    Edge(int t,int c) : to(t), cost(c) { }
};

using Graph = vector<vector<Edge>>;


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

    int N, Q, K;
    cin >> N;
    Graph G(N);
    int a, b, c;
    rep(i,N-1){
        cin >> a >> b >> c;
        --a; --b;
        G[a].push_back(Edge(b, c));
        G[b].push_back(Edge(a, c));
    }
    cin >> Q >> K;
    --K;
    priority_queue<P, vector<P>, greater<P>> que;
    int dist[N];
    rep(i,N) dist[i] = INF;
    dist[K] = 0;
    que.push(P(0, K));
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int d = p.first;
        int x = p.second;
        if(d > dist[x]) continue;
        for(auto e : G[x]){
            int y = e.to;
            int c = e.cost;
            if(dist[y] > dist[x] + c){
                dist[y] = dist[x] + c;
                que.push(P(dist[y], y));
            }
        }
    }
    rep(i,Q){
        cin >> a >> b;
        --a; --b;
        cout << dist[a] + dist[b] << endl;
    }
}

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

int main() {

  int a, b, c, d;
  cin >> a >> b >> c >>d;
  
  if((c-a)*(c-a)<=d*d || ((b-a)*(b-a)<=d*d && (c-b)*(c-b)<=d*d)) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 3624
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=(N%100)%10;
		int b=0;
		int[][] c= {{2,4,5,7,9},{0,1,6,8},{3}};
		String[] d= {"hon","pon","bon"};
		while(true) {
			for(int i=0;i<3;i++)
				for(int j=0;j<c[i].length;j++)
					if(a==c[i][j])
						b=i;
						break;
		}
		System.out.print(d[b]);
	}

}


Measured memory_bytes: 35880
//テンプレ
#include <bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(),(v).end()

using namespace std;
constexpr int MOD = 1e9+7;
constexpr int INF = 1LL << 60;
template <class T = int> inline T in() { T x; cin >> x; return (x);}
template <class T = int> inline void out (const T& x){ cout << x << '\n' ;}
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  
//

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

    int N = in();
    vector<int> p(N);
    REP(i,N)cin >> p[i];   
    int discount = 0;
    REP(i,N) chmax(discount,p[i]);
    int ans = 0;
    REP(i,N) ans += p[i];
    ans -= discount/2 ;
    out(ans);

}

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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

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

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

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

    ll n;
    cin >> n;
    ll mod = 1e9 + 7;
    vector<ll> b(60);
    rep(i, 0, n) {
        ll a;
        cin >> a;
        rep(j, 0, 60) if (a & (1LL << j)) b[j]++;
    }
    ll ans = 0;
    rep(i, 0, 60) {
        ll ad = ((1LL << i) % mod) * b[i] % mod * (n - b[i]) % mod;
        ans = (ans + ad) % mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

x, y, a, b, c = get_nums_l()
ppp = get_nums_l()
qqq = get_nums_l()
rrr = get_nums_l()

ppp.sort(reverse=True)
qqq.sort(reverse=True)
rrr.sort(reverse=True)

xxx = ppp[:x] + qqq[:y]
xxx.sort()

ans = 0
for i in range(x+y):
    x = xxx[i]
    if i < len(rrr):
        x = max(x, rrr[i])
    ans += x

print(ans)


Measured memory_bytes: 107996
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef struct _data {
	int x;
	int y;
} data;

int  main()
{
	int a,b;
	cin >> a >> b;
	int i = max(a,b);
	i *= 10;
	while (i <= 1000)
	{
		if ((int)(i * 8 / 100 == a) && (int)(i * 10 / 100 == b))
		{
			cout << i; return 0;
		}
		i++;
	}
	cout << -1;
	// cout << (100 * 8 / 100);
	return (0);
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, a[2000];
bitset<2000 * 2000 + 1> bs;

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	bs.set(0);
	inc(i, n) { bs |= bs << a[i]; }
	
	int c = bs.count(), d = 0;
	inc(i, bs.size()) {
		if(bs[i]) { d++; }
		if(d == c / 2 + 1) { cout << i << endl; break; }
	}
	
	return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 998244353;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }


int main() {   
    ll x; cin >> x;
    ll a, b;
    for(int i=-500; i<500; i++){
        for(int j=-500; j<500; j++){
            ll num1 = pow(i,5);
            ll num2 = pow(j, 5);
            if(num1 - num2 == x){
                a = i; b = j; break;
            } 
        }
    }
    cout << a << " " << b << ln;
}

Measured memory_bytes: 3596
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    LL a, b;
    cin >> a >> b;
    cout << a / __gcd(a, b) * b << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a;
	cin>>n;
	a=n/10000000+n%10000000/1000000+n%1000000/100000+n%100000/10000+n%10000/1000+n%1000/100+n%100/10+n%10;
	if(n%a==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
fun main(arr: Array<String>) {
    val n = readLine()!!.toInt()
    val sp = (1..n).map { Pair(it, readLine()!!.split(" ").let { Pair(it[0], it[1].toInt()) }) }.sortedWith(Comparator { t, t2 -> if(t.second.first == t2.second.first) t.second.second.compareTo(t2.second.second) * -1 else t.second.first.compareTo(t2.second.first)})
    sp.forEach { println(it.first) }
}


Measured memory_bytes: 40752
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;


void main() {
  auto s = readln.split.map!(to!int);
  auto N = s[0];
  auto W = s[1];
  auto K = N.iota.map!(_ => readln.split.map!(to!int).array).array;
  K.sort!"a[1] < b[1]"();
  auto dp = new int[][](N, W+1);
  foreach (i; 0..W+1) dp[0][i] = (K[0][1] <= i) ? K[0][0] : 0;

  foreach (i; 1..N)
    foreach (w; 0..W+1) {
      if (w - K[i][1] >= 0)
        dp[i][w] = dp[i-1][w-K[i][1]] + K[i][0];
      dp[i][w] = max(dp[i-1][w], dp[i][w]);
    }

  dp[N-1][W].writeln;
}

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

bool compare_by_b(P a, P b) {
  if(a.second != b.second){
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> r(m);

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    P p(a, b);
    r[i] = p;
  }

  // 右端を昇順でSortする
  sort(r.begin(), r.end(), compare_by_b);

  int cnt = 0;
  int prev = -1;
  rep(i, m) {
    P p = r[i];

    // すでに切断済みならSkip
    // 切断済み → a が prev 以下の場合
    if(p.first <= prev) {
      continue;
    }

    // 右端の一つ前の箇所を切断する
    prev = p.second - 1;
    cnt++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 4016
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

int dp[101][4][3] = {};

/*----------------------------------------------------------------*/
signed main(){

    string n;
    int K;
    cin >> n >> K;

    dp[0][0][1] = 1;

    for(int i = 1;i <= n.size();i++){
        int N = n[i-1]-'0';
        
        dp[i][0][0] = dp[i-1][0][0];
        if(N != 0)dp[i][0][0] += dp[i-1][0][1];

        for(int j = 1;j <= K;j++){
            dp[i][j][0] = dp[i-1][j-1][0]*9 + dp[i-1][j][0];
            if(N != 0)dp[i][j][0] += dp[i-1][j-1][1]*max(N-1,0LL) + dp[i-1][j][1];
        }
        for(int j = 1;j <= K;j++){
            if(N == 0)dp[i][j][1] = dp[i-1][j][1];
            else dp[i][j][1] = dp[i-1][j-1][1];
        }
    }
    cout << dp[n.size()][K][0] + dp[n.size()][K][1] << endl; 


    
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc154.contest.atcoder.jp/tasks/abc154_b

Measured memory_bytes: 256
def exgcd(n1,n2): 
    x1,y1,m1 = (1,0,n1)
    x2,y2,m2 = (0,1,n2)
    while( n2 != 0):
        t = n1 // n2
        if (m1 >= m2):
            x1 -=  (x2 * t)
            y1 -=  (y2 * t)
            m1 -=  (m2 * t)
        else:
            x2 -= (x1 * t)
            y2 -= (y1 * t)
            m2 -= (m1 * t)
        i = n2
        n2 = n1 % n2
        n1 = i
    if (m1 == 1):return x1,y1
    return x2,y2

(m,n)  =  map(int,input().split())
(a1,b1) =  exgcd(m,n)
(a2,b2) =  exgcd(n,m)


if (abs(a1)+abs(b1) < abs(a2) + abs(b2)):
    print(a1,b1)
elif (abs(a1)+abs(b1) > abs(a2) + abs(b2)):
    print(b2,a2)
else:
    if (b1 >= a1):
        print(a1,b1)
    else:
        print(b2,a2)


Measured memory_bytes: 5608
const H,W=map(x->parse(Int,x),split(readline()))
const S=readlines()
const P=Pair{Int,Int}[]
const D=-ones(Int,H,W)
function init()
	for i=1:H,j=1:W
		if S[i][j]=='#'
			push!(P,i=>j)
			D[i,j]=0
		end
	end
end
function ev(x,y)
	for (dx,dy)=[0=>1,0=>-1,1=>0,-1=>0]
		tx=x+dx
		ty=y+dy
		if 1<=tx<=H&&1<=ty<=W&&D[tx,ty]==-1
			D[tx,ty]=D[x,y]+1
			push!(P,tx=>ty)
		end
	end
end
function main()
	init()
	while !isempty(P)
		(x,y)=shift!(P)
		ev(x,y)
	end
	println(maximum(D))
end
main()

Measured memory_bytes: 174328
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
  	cin >> s;
  	for (int i = 0; i < s.length() / 2; ++i)
      if (s[i] != s[s.length() - 1 - i])
      {
      	cout << "No";
        return 0;
      }
  cout << "Yes";
}

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

int main() {
  long long N;
  string S;
  cin >> N >> S;
  
  long long count_flag1 = 0;
  long long r = 0;
  long long g = 0;
  long long b = 0;
  for (long long i = 0; i < N; i++) {
    if (S[i] == 'R') {
      r++;
    } else if (S[i] == 'G') {
      g++;
    } else {
      b++;
    }
  }
  long long answer = r*g*b;
 
  for (long long w = 1; w <= N/2; w++) {
    for (long long i = 0; i+2*w < N; i++) {
      long long j = i+w;
      long long k = j+w;
      if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) {
        answer--;
      }
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;

class BoyerMoore {
public:
  std::string text;
  std::string pattern;
  int n;
  int m;
  std::map<char, int> lambda;
  BoyerMoore(std::string text_, std::string pattern_) : 
	text(text_), pattern(pattern_), n(text_.size()), m(pattern_.size()){
	compute_lambda();
  };
  void compute_lambda() {
	for(int j = 1; j <= m; j++) {
	  lambda[pattern.at(j - 1)] = j;
	}
  };
  int get_lambda(const char& c) {
	if (lambda.find(c) != lambda.end()) {
	  return lambda[c];
	} else {
	  return 0;
	}
  };
  bool match() {
	int s = 0;
	while(s <= n - m) {
	  int j = m;
	  while(j > 0 && pattern.at(j - 1) == text.at(s + j - 1)) {
		j--;
	  }
	  if(j == 0) {
		return true;
		s++;
	  } else {
		s += std::max(1, j - get_lambda(text.at(s + j - 1)));
	  }
	}
    return false;
  };
};


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

    int n;
    cin>>n;
    string s;
    cin>>s;
    string tmp;
    ll ans=0;
    for(int i=0;i<n-1;i++){
        tmp.push_back(s[i]);
        BoyerMoore bm(s.substr(i+1),tmp);
        // cout<<s.substr(i)<<" "<<tmp<<" "<<bm.match()<<endl;
        if(!bm.match()){
            tmp=tmp.substr(1);
        } else {
            ans=max((int)ans,(int)tmp.size());
        }
    }
    fin(ans);

//////////////////////////////////////////////////////
return 0;}



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

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> p(N + 1), pos(N + 1); rep(i, 1, N + 1) { cin >> p[i]; pos[p[i]] = i; }
	vector<int>a(N + 1), b(N + 1);
	rep(i, 1, N + 1) {
		a[i] = i*(N); b[i] = (N + 1 - i)*(N);
	}
	dump(a);
	dump(b);
	rep(i, 1, N + 1) {
		// -:i, +:N+1-i
		
		a[p[i]] += i - 1;
	}
	rep(i, 1, N + 1)cout << a[i] << (i == N ? '\n' : ' ');

	rep(i, 1, N + 1)cout << b[i] << (i == N ? '\n' : ' ');

	return 0;
}

Measured memory_bytes: 896
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def calot(i, g, N):
    return i * 10000 + g * 5000 + (N - i - g) * 1000


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, Y = il()
    for i in range(0, N+1):
        for g in range(0, N - i + 1):
            if calot(i, g, N) == Y:
                print(i, g, N - i - g)
                exit()
    else:
        print(-1, -1, -1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>

int main(){
	using namespace std;
	int a,b,i;
	cin >> a >> b;
	for (i = 0;;i++) {
		if (1 == b) break;
		if ((a * i)-(i - 1) >= b) {
			break;
		}
	}
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int mod=1e9+7;
void candies(int n,int a[],int k){
	long long int way[n][k+1];
	for(int i=0;i<=a[0];i++)
	way[0][i]=1;
	for(int i=a[0]+1;i<k+1;i++)
	way[0][i]=0;
	for(int i=1;i<n;i++){
		way[i][0]=1;
		for(int j=1;j<k+1;j++){
			if(j<=a[i])
			way[i][j]=(way[i-1][j]+way[i][j-1])%mod;
			else
			way[i][j]=(way[i][j-1]-way[i-1][j-a[i]-1]+way[i-1][j]+mod)%mod;
		}
	}
	cout<<way[n-1][k]<<endl;
}
int main(){
	int n,k;cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	candies(n,a,k);
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
vector<ll> t;
int main(){
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i += 2){
    cout << s[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 512