akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

n, w = map(int, input().split())
d = defaultdict(list)
for i in range(n):
    wi, vi = map(int, input().split())
    d[wi].append(vi)
for key in d.keys():
    di = d[key]
    di.sort(reverse=True)
    a = [0]
    for i in di:
        a.append(a[-1] + i)
    d[key] = a
keys = list(d.keys())
for i in range(4 - len(keys)):
    key = max(keys) + i + 1
    d[key] = [0]
    keys.append(key)
ans = 0
for i in range(min(w // keys[0] + 1, len(d[keys[0]]))):
    wi = w - keys[0] * i
    ai = d[keys[0]][i]
    for j in range(min(wi // keys[1] + 1, len(d[keys[1]]))):
        wj = wi - keys[1] * j
        aj = d[keys[1]][j]
        for k in range(min(wj // keys[2] + 1, len(d[keys[2]]))):
            wk = wj - keys[2] * k
            ak = d[keys[2]][k]
            idx = min(wk // keys[3], len(d[keys[3]]) - 1)
            ans = max(ans, ai + aj + ak + d[keys[3]][idx])
print(ans)


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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define rep(i,a,b) for (int i = a; i <= (int)b; ++i)
#define f first
#define s second

#define single_test

const int maxn = 3003;

int a[maxn];
int dp[maxn][maxn][2];
bool vis[maxn][maxn][2];

int go(int l, int r, bool turn) {
    if (l > r) return 0;
    int &ref = dp[l][r][turn];
    if (vis[l][r][turn]) {
        return ref;
    }
    vis[l][r][turn] = true;
    int ans;
    if (turn == false) {
        ans = a[l] + go(l + 1, r, 1);
        ans = max(ans, a[r] + go(l, r - 1, 1));
    }
    else {
        ans = -a[l] + go(l + 1, r, 0);
        ans = min(ans, -a[r] + go(l, r - 1, 0));
    }
    return ref = ans;
}

void solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    cout << go(0, n - 1, 0) << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 102352
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int MOD = 1e9 + 7;

int main() {
  int l, r, d;
  cin >> l >> r >> d;

  int ret = 0;
  for (int i = l; i <= r; ++i) {
    if (i % d == 0) ++ret;
  }

  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    rep(i, 3) cout << s[i];
    cout << endl;
    return 0;
}

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

int N;
double dp[310][310][310];

double rec(int i, int j, int k){
    if(dp[i][j][k] != -1) return dp[i][j][k];
    if(i == 0 && j == 0 && k == 0) return 0.0;
    double val = 0.0;
    if(i - 1 >= 0) val += rec(i-1, j, k) * i;
    if(j - 1 >= 0) val += rec(i+1, j-1, k) * j;
    if(k - 1 >= 0) val += rec(i, j + 1, k-1) * k;
    val += N;
    val /= (i+j+k);
    return dp[i][j][k] = val;
}

int main(void){
    // Your code here!
    cin >> N;
    int one = 0;
    int two = 0;
    int three = 0;
    int a = 0;
    for(int i = 0; i < N; i++){
        cin >> a;
        if(a==1) one++;
        else if(a==2) two++;
        else three++;
    }
    
    for(int i = 0; i < 310; i++) for(int  j= 0; j < 310; j++) for(int k = 0; k < 310; k++) dp[i][j][k] = -1;
    printf("%.10f\n", rec(one, two, three));
    
}


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

using namespace std;

long long dp[51][51][2501];

int main(){
    long long N, A;
    cin >> N >> A;
    vector<long long> x(N+1);
    for(int i = 0; i < N; i++){
        cin >> x[i+1];
    }
    
    
    // dp[j][k][s] := (x_1 ... x_j から k 枚選んで合計 s にするような選び方の総数)
    dp[0][0][0] = 1;
    for(long long j = 0; j < N+1; j++){
        for(long long k = 0; k < N+1; k++){
            for(long long s = 0; s < N*A+1; s++){
                if(j >= 1 && s < x[j]){ // j枚目を選ばないで 合計s
                    dp[j][k][s] = dp[j-1][k][s];
                }else if(j >= 1 && k >= 1 && s >= x[j]){ // j枚目を選ばないで合計s と j枚目を選んで合計s
                    dp[j][k][s] = dp[j-1][k][s] + dp[j-1][k-1][s-x[j]];
                }
            }
        }
    }

    long long ans = 0;
    for(int k = 1; k < N+1; k++){
        ans += dp[N][k][k*A];
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 50048
import * as fs from 'fs'

const input: string = fs.readFileSync('/dev/stdin', 'utf8');
const args: string[][] = input.split('\n').map(l => l.split(' '));

const n = parseInt(args[0][0]);

const sum = [...Array(n)]
  .map((_, i) => i + 1)
  .map(x => getFizzBuzz(x))
  .map(x => isNumber(x) ? x : 0)
  .reduce((x, y) => x + y);

console.log(sum);


function getFizzBuzz(n: number): string | number {
  const f = n % 3 === 0;
  const b = n % 5 === 0;
  if (f && b) {
    return 'FizzBuzz'
  } else if (f) {
    return 'Fizz'
  } else if (b) {
    return 'Buzz'
  } else {
    return n
  }
}

function isNumber(arg: any): arg is number {
  return typeof arg === 'number'
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)


int main(){
  int x,t;
  cin >> x >> t;
  cout << max(0,x-t) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 123, MOD = 1e9 + 7;
int n, l[2][N], r[2][N], dp[2][N], p[2][N];
ll c[2], s[N];

int get(int l, int r, int t) {
	if (l > r) return 0;
	return (p[t][r] - ((l > 0) ? p[t][l - 1] : 0) + MOD) % MOD;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> c[0] >> c[1];
	for (int i = 1; i <= n; i++) cin >> s[i];
	s[0] = -4e18, s[n + 1] = 4e18;
	for (int i = 1; i <= n + 1; i++) {
		for (int j = 0; j < 2; j++) {
			int & L = l[j][i], & R = r[j][i];
			L = l[j][i - 1], R = r[j][i - 1];
			if (s[i] - s[i - 1] < c[j]) L = i;
			while (R < i && s[i] - s[R] >= c[j]) R++;
		}
	}
	dp[0][0] = dp[1][0] = p[0][0] = p[1][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 2; j++) {
			dp[j][i] = get(l[j][i] - 1, min(i - 1, r[j ^ 1][i + 1] - 1), j ^ 1);
			p[j][i] = (p[j][i - 1] + dp[j][i]) % MOD;
		}
	}
	cout << (dp[0][n] + dp[1][n]) % MOD;
}


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

string way[6];
string instr;



int main(void)
{
	int N = 1;

	way[0] += "North";
	way[1] += "East";
	way[2] += "West";
	way[3] += "South";
	way[4] += "Right";
	way[5] += "Left";


	while(cin >> N, N > 0){
int dice[] = {1,3,6,4,2,5};
	int sum = 1;

	int t;
	for(int i = 0; i < N; i++){
		cin >> instr;

		if(instr == way[0]){
			t = dice[0];
			dice[0] = dice[4];	dice[4] = dice[2];	dice[2] = dice[5];	dice[5] = t;
		} 
		else if(instr == way[1]){
			t = dice[0];
			dice[0] = dice[3];	dice[3] = dice[2];	dice[2] = dice[1];	dice[1] = t;
		}
		else if(instr == way[2]){
			t = dice[0];
			dice[0] = dice[1];	dice[1] = dice[2];	dice[2] = dice[3];	dice[3] = t;
		}
		else if(instr == way[3]){
			t = dice[0];
			dice[0] = dice[5];	dice[5] = dice[2];	dice[2] = dice[4];	dice[4] = t;
		}


		else if(instr == way[5]){
			t = dice[5];
			dice[5] = dice[1];	dice[1] = dice[4];	dice[4] = dice[3];	dice[3] = t;
		}
		else if(instr == way[4]){
			t = dice[5];
			dice[5] = dice[3];	dice[3] = dice[4];	dice[4] = dice[1];	dice[1] = t;
		}

		sum += dice[0];


	}


		cout << sum << endl;
}
	return 0;
}

Measured memory_bytes: 1216
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main  {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.valueOf(sc.nextLine());
        int ans = 0;
        List<Integer> l = Arrays.asList(sc.nextLine().split(" ")).stream().map(numStr -> Integer.valueOf(numStr)).collect(Collectors.toList());
        Collections.sort(l);
        for(int i = 0; i < n; i++) {
            for(int j = i+1; j < n; j++) {
                for(int k = j+1; k < n; k++) {
                    if(l.get(i).equals(l.get(j)) || l.get(j).equals(l.get(k))) continue;
                    if(l.get(i) + l.get(j) > l.get(k)) ans++;
                    else break;
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 37264
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b) {
    if (c == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return;
  }
  rep(i, b) {
    int temp = a * (i + 1) % b;
    if (temp == c) {
      cout << "YES" << endl;
      return;
    }
  }
  cout << "NO" << endl;
}

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

Measured memory_bytes: 3608
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		ArrayList<String> arr = new ArrayList<>();
		String start = null;
		String end = null;
		String judge = "Yes";
		
		for(int i = 0; i < n ; i++) {
			String w = scan.next();
			if (arr.contains(w)) {
				judge = "No";
				break;
			}
			
			start = w.substring(0, 1);
			if(end != null && !start.equals(end)) {
				judge = "No";
				break;
			}
			arr.add(w);
			end = w.substring(w.length()-1);
		}
		System.out.println(judge);
		scan.close();
	}
}

Measured memory_bytes: 23892
K = gets.to_i
x, y = gets.split.map(&:to_i)

sx, sy = 1, 1
if x < 0 then sx = -1; x *= -1 end
if y < 0 then sy = -1; y *= -1 end
sz = false
if x < y
  sz = true
  x, y = y, x
end

ans = []

if K.even? && (x + y) % 2 == 1
  puts -1
  exit
end

cx, cy = 0, 0
while (x - cx + y - cy) > 2*K
  dy = [y - cy, K].min
  dx = [x - cx, K - dy].min
  cx += dx
  cy += dy
  ans << [cx, cy]
end

while cx != x || cy != y
  dx = x - cx
  dy = y - cy

  if dx + dy == K
    cx = x
    cy = y
    ans << [cx, cy]
  elsif (dx + dy) % 2 == 0
    a = (2*K - dx - dy) / 2
    b = K - a
    c = dx - K + a
    d = K - c
    cy -= a
    cx += b
    ans << [cx, cy]
    cx += c
    cy += d
    ans << [cx, cy]
  elsif dx + dy >= K
    a = [dy, K].min
    b = [dx, K - a].min
    cy += a
    cx += b
    ans << [cx, cy]
  else
    cx -= K
    ans << [cx, cy]
  end
end


puts ans.size
ans.each do |e|
  if sz
    e[0], e[1] = e[1], e[0]
  end
  puts "#{e[0]*sx} #{e[1]*sy}"
end


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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}

int main() {
    vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << vec[k-1];
}

Measured memory_bytes: 256
def examA():
    N = I()
    S = [""]*N; T = [""]*N
    for i in range(N):
        S[i],T[i] = LSI()
        T[i] = int(T[i])
    X = SI()
    ans = 0
    flag = False
    for i in range(N):
        if flag:
            ans +=T[i]
        if S[i]==X:
            flag = True
    print(ans)
    return

def examB():
    return

def examC():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, m;
    cin >> n >> m;
    int a[n];
    priority_queue<int> pq;
    rep(i, 0, n) {
        cin >> a[i];
        pq.push(a[i]);
    }
    while (m > 0) {
        int x = pq.top();
        pq.pop();
        x /= 2;
        m--;
        pq.push(x);
    }
    ll ans = 0;
    while (!pq.empty()) {
        int x = pq.top();
        pq.pop();
        ans += (ll)x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1148
#include<stdio.h>
int main(void)
{
  int n,a,b;
  
  scanf("%d %d %d",&n,&a,&b);
  if(n*a>b){
    printf("%d\n",b);
  }
  else if(n*a<b){
    printf("%d\n",n*a);
  }
  else if(n*a==b){
    printf("%d\n",n*a);
  }
  return 0;
}

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

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t;
	t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}

void solve() {
	int n, x;
	cin >> n >> x;
	int ans = 1;
	int co = 0;
	for (int i = 1; i <= n; i++) {
		int add;
		cin >> add;
		co += add;
		if (co <= x) ans += 1;
	}
	cout << ans;
}	
 	

Measured memory_bytes: 256
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    string s; cin >> s;
    if (s[0] != s[1] or s[1] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(ll i=0;i<(n);++i)
ll mod=7+1e9;
using vec = vector<ll>;
using matrix = vector<vec>;
matrix power(const matrix &a, ll n){
	ll sz = a.size();
	matrix res(sz,vec(sz));
	REP(i,sz)REP(j,sz){
		if(i==j) res[i][j] = 1;
		else res[i][j] = 0;
	}
	matrix r = a;
	while(n>0){
		if(n&1){
			matrix tmp(sz,vec(sz,0));
			REP(i,sz)REP(j,sz)REP(k,sz){
				tmp[i][j] += res[i][k]*r[k][j];
                tmp[i][j] %= mod;
			}
			res = tmp;
		}
		matrix tmp(sz,vec(sz,0));
		REP(i,sz)REP(j,sz)REP(k,sz){
			tmp[i][j] += r[i][k]*r[k][j];
            tmp[i][j] %= mod;
		}
		r = tmp;
		n >>= 1;
	}
	return res;
}
int main(){
    ll n, k;
	cin >> n >> k;
    matrix a(n, vec(n,0));
    for(ll i=0; i<n; ++i){
        for(ll j=0; j<n; ++j){
            cin >> a[i][j];
        }
    }
    a = power(a,k);
    ll cnt=0;
	for(ll i=0; i<n; ++i){
        for(ll j=0; j<n; ++j){
            cnt = (cnt+a[i][j])%mod;
        }
    }
	cout << cnt << endl;
}

Measured memory_bytes: 512
c = [list(map(int, input().split())) for _ in range(3)]
x = [0]*3
y = [0]*3
for i in range(3):
    y[i] = c[0][i] - x[0]
for i in range(3):
    x[i] = c[i][0] - y[0]
good = True
for i in range(3):
    for j in range(3):
        if c[i][j] != x[i] + y[j]:
            good = False
print("Yes" if good else "No")

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

using ll=long long;

vector<int> vec(9);

int Hantei(int x) {
  int ret_val=0;
  if      (x<400)  ret_val=1;
  else if (x<800)  ret_val=2;
  else if (x<1200) ret_val=3;
  else if (x<1600) ret_val=4;
  else if (x<2000) ret_val=5;
  else if (x<2400) ret_val=6;
  else if (x<2800) ret_val=7;
  else if (x<3200) ret_val=8;
  return ret_val;
}

void Shuukei(int x) {
  vec[x]++;
}

int main() {
  int N; cin >>N;
  int min_val=0,max_val=0;
  rep(i,0,N) {
    int a; cin >>a;
    Shuukei(Hantei(a));
  }
  rep(i,0,9) {
    if (vec[i]!=0) min_val++;
  }
  if (vec[0]==0) max_val=min_val;
  else if (min_val==1) max_val=vec[0];
  else {
    min_val--;
    max_val=min_val+vec[0];
  }
  cout <<min_val <<' ' <<max_val <<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
neig = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b, c = map(int, input().split())
    neig[a - 1].append((b - 1, c))
    neig[b - 1].append((a - 1, c))

Q, K = map(int, input().split())

S, D = [(K - 1, K - 1)], [0] * N
while len(S) > 0:
    p, pp = S.pop()
    for c, d in neig[p]:
        if not c == pp:
            D[c] = D[p] + d
            S.append((c, p))

for _ in range(Q):
    x, y = map(int, input().split())
    print(D[x - 1] + D[y - 1])


Measured memory_bytes: 82464
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
   int a,b,m;
   int ap[100005]={0},bp[100005]={0},m1,m2,m3,c[100005]={0},min1=9999999,min2=9999999;
   scanf("%d%d%d",&a,&b,&m);
   for(int i=0;i<a;i++){
   	scanf("%d",&ap[i]);
   	if(ap[i]<min1)
   	min1=ap[i];
   }
   
   for(int j=0;j<b;j++)
   {
   	scanf("%d",&bp[j]);
   	if(bp[j]<min2)
   	min2=bp[j];
   }
   
   for(int i=0;i<m;i++)  
   { 
   	scanf("%d%d%d",&m1,&m2,&m3);
   	c[i]=ap[m1-1]+bp[m2-1]-m3;  	 
   	}  
	sort(c,c+m); 
   int sum1=c[0];
   int sum2=min1+min2;
   
   if(sum1>sum2)
   printf("%d",sum2);
   else
   printf("%d",sum1);
   
    
   return 0;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();

    for (int i = n / 2 - 1; i > 0; i--) {
        if (s.substr(0, i) == s.substr(i, i)) {
            cout << 2 * i << endl;
            return 0;
        }
    }

    return 0;
}


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

class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        char lastc = s[0];
        int res = 0;
        foreach (var c in s)
        {
            if (c != lastc)
            {
                res++;
                lastc = c;
            }
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 11232
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] n = sc.next().toCharArray();
        boolean ans = false;
        for (int i = 0; i < n.length; i++) {
            if (n[i] == '7') {
                ans = true;
                break;
            }
        }
        System.out.println(ans ? "Yes" : "No");
    }
}

Measured memory_bytes: 26948
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>











int k;
string s, res;



void solve()
{
	cin >> k >> s;
	if(s.size() <= k)res = s;
	else
	{
		res = "";
		for(int i = 0; i < k; i++)res += s[i];
		res += "...";
	}
	cout << res << "\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 3656
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

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

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int a,b,k;
    cin>>a>>b>>k;
    rep(i,k){
        if(i%2==0){
            b+=a/2;
            a/=2;
        }
        else{
            a+=b/2;
            b/=2;
        }
    }
    cout<<a<<" "<<b<<endl;
}

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

int n;
vector<int> g[100005];
long long d[100005];
int rd[100005];
int sz[100005];
map<long long,int> mp;
queue<int> q;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> d[i];
		mp[d[i]] = i;
		sz[i] = 1;
	}
	for (int it = 1; it < n; ++it) {
		int u = mp.rbegin()->second;
		long long need = d[u] - (n - sz[u]) + sz[u];
		if (mp.find(need) == mp.end() || mp[need] == u) {
			return cout << -1 << '\n',0;
		} 
		int v = mp[need];
		g[u].push_back(v), g[v].push_back(u);		
		sz[v] += sz[u];
		mp.erase(mp.find(d[u]));
	}
	for (int i = 1; i <= n; ++i) rd[i] = -1;
	rd[1] = 0; q.push(1);
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int v : g[u]) if (rd[v] == -1) {
			rd[v] = rd[u] + 1; q.push(v);
		}
	}
	if (accumulate(rd + 1, rd + 1 + n, 0LL) != d[1]) {
		return cout << -1 << '\n',0;
	}
	for (int u = 1; u <= n; ++u) {
		for (int v : g[u]) if (u < v) {
			cout << u << ' ' << v << '\n';
		}
	} 
}


Measured memory_bytes: 11648
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr uint64_t INF = 1e18;

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

  int64_t a,b,c,d;
  cin >> a >> b >> c >> d;
  int64_t res = a * c;
  res = max(res, a*d);
  res = max(res, b*c);
  res = max(res, b*d);
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3684
#include<iostream>
#include<stdio.h>

using namespace std;

int main(void) {
	char week[7][4] = { "sat","sun","mon","tue","wed","thu","fri"};
	int x;
	cin >> x;
	int sa = (x - 9) % 7;
	if (sa >= 0)printf("%s\n", &week[sa]);
	else printf("%s\n", &week[7 + sa]);
	return 0;
}


Measured memory_bytes: 3100
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * プログラミングコンテスト<br>
 * 0147:Fukushimaken
 *
 * @author t690593
 *
 */
public class Main {

	/** 最大グループ数 */
	static final int MAX_GROUP_NUKMBER = 100;

	/** 客の到着間隔 */
	static final int TIME_INTERVAL = 5;

	/** 座席 */
	static int[] sheets = new int[17];

	/** 各グループの待ち時間 */
	static int[] waitTimes = new int[100];

	/** インプット */
	static List<Integer> inputs = new ArrayList<Integer>();

	/** インプットの最大グループ番号 */
	static int maxGroupNumber;

	/**
	 * メイン
	 *
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNextInt()) {
			int inputNum = scanner.nextInt();
			if (maxGroupNumber < inputNum) {
				maxGroupNumber = inputNum;
			}
			inputs.add(inputNum);
		}

		// 先頭のグループ番号
		int frontGroup = 0;
		// 最後尾のグループ番号
		int endGroup = 0;
		// 経過時間：分単位
		int time = 0;

		while (true) {
			// 5分間隔でお店に客がくる（最後尾は最大グループ数より大きくならない）
			if (time % TIME_INTERVAL == 0 && endGroup < MAX_GROUP_NUKMBER) {
				endGroup++;
			}

			for (int i = frontGroup; i < endGroup; i++) {
				int ninzu = i % 5 == 1 ? 5 : 2;
				int startPos = getOpendSheetsPosition(ninzu);
				if (startPos >= 0) {
					// 座れる場合
					secureSheets(startPos, calcMealtime(i), ninzu);
					waitTimes[i] = time - i * 5;
					frontGroup++;
				} else {
					// 座れない場合
					break;
				}

			}

			// 入力されたグループ番号の最大番号が席に座るか、全てのグループが席に座ったら終了
			if (frontGroup == MAX_GROUP_NUKMBER || frontGroup > maxGroupNumber) {
				break;
			}

			// 座席の食事時間を時間経過とともに減らす
			for (int i = 0; i < sheets.length; i++) {
				if (sheets[i] > 0) {
					sheets[i] = sheets[i] - 1;
				}
			}

			time++;
		}

		for (int input : inputs) {
			System.out.println(waitTimes[input]);
		}
	}

	/**
	 * 空いている席の最初の席番号を返却する<br>
	 * 席が空いていない場合、-1を返却する
	 *
	 * @param peopleNum
	 *            グループの人数
	 * @return 空いている席の最初の席番号
	 */
	private static int getOpendSheetsPosition(int peopleNum) {
		int startPos = -1;
		int openedSheetNum = 0;
		for (int i = 0; i < sheets.length; i++) {
			if (sheets[i] == 0) {
				if (startPos == -1) {
					startPos = i;
				}
				openedSheetNum++;
			} else {
				startPos = -1;
				openedSheetNum = 0;
			}

			if (openedSheetNum == peopleNum) {
				return startPos;
			}
		}
		return -1;
	}

	/**
	 * 対象グループの食事時間を計算する
	 *
	 * @param targetGroup
	 *            対象グループ番号
	 * @return 食事間
	 */
	private static int calcMealtime(int targetGroup) {
		return 17 * (targetGroup % 2) + 3 * (targetGroup % 3) + 19;
	}

	/**
	 * 座席を確保する
	 *
	 * @param startPos
	 *            席確保する最初の席番号
	 * @param mealtime
	 *            確保する時間（食事時間）
	 * @param peopleNum
	 *            グループ人数
	 */
	private static void secureSheets(int startPos, int mealtime, int peopleNum) {
		for (int i = 0; i < peopleNum; i++) {
			sheets[i + startPos] = mealtime;
		}
	}
}

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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

typedef long long ll;

#define MAX_N 10000

struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };
typedef pair<int, int> P;

int main()
{
    ll X, Y;
    cin >> X >> Y;
    int ans = 1;
    while (true) {
        X *= 2;
        if (X > Y)
            break;
        ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, A, B = map(int, raw_input().split())
t = [int(raw_input()) for i in xrange(N)]

ans = N
for ti in t:
    if A <= ti < B: ans -= 1
print ans


Measured memory_bytes: 4500
#include<iostream>
#include <bits/stdc++.h> 
 
using namespace std;
 
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> arr;
  for(int i=0; i<n; i++){
    int x;
    cin>>x;
    arr.push_back(x);
  }
  sort(arr.begin(),arr.end());
  int sum=0;
  for(int i=0; i<k; i++){
    sum += arr[i];
  }
  cout<<sum;
  return 0;
}

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

typedef long long ll;
ll solve(ll h[],ll n,ll i)
{
    if(n==0)
        return 0;
    if(i==n-1)
    {
        return 0;;
    }
    if(i==n-2)
        return abs(h[n-1]-h[n-2]);
    return min( (abs(h[i+1]-h[i])+solve(h,n,i+1)),(abs(h[i+2]-h[i])+solve(h,n,i+2)));
}
ll solve_dp(ll h[],ll n,ll k)
{

    ll ans[n]={INT_MAX};
    ans[0]=0;
    ll temp,i,j;
    ans[1]=abs(h[1]-h[0]);
    ans[2]=min(abs(h[2]-h[1])+ans[1],abs(h[2]-h[0]));
    for(i=3;i<min(k,n);i++)
    {
        temp=INT_MAX;
        for(j=i-1;j>=0;j--)
        {
            temp=min(temp,abs(h[i]-h[j])+ans[j]);

        }
        //temp=min(abs(h[i]-h[0]),abs(h[i]-h[i-2])+ans[i-2]);
        ans[i]=temp;
    }
    if(k<n){
           // cout<<"hello\n";
    for(i=k;i<n;i++)
    {
        temp=INT_MAX;
        for(j=i-1;j>=i-k;j--)
        {
            temp=min(temp,abs(h[i]-h[j])+ans[j]);
        }
        ans[i]=temp;
    }
    }
    return ans[n-1];

}

int main()
{
    ll n,i,k;;
    cin>>n>>k;
    ll h[n];
    for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    ll ans=solve_dp(h,n,k);
    cout<<ans<<endl;

}


Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
	int n, m, c[20];
	//input
	scanf(" %d %d", &n, &m);
	for(int i=0; i<m; ++i) scanf(" %d", &c[i]);	
	
	//solve
	
	//dp[i]:=i?????????????????????????????????????????????????°??????°
	int dp[50001] = {0};
	//???????????§????????°??§?????????
	for(int i=1; i<=50000; ++i) dp[i] = 100000;
	
	for(int i=0; i<=50000; ++i){
		for(int j=0; j<m; ++j){
			if(i+c[j]<=n){
				dp[i+c[j]] = min(dp[i+c[j]],dp[i]+1);	
			}
		}	
	}
	
	printf("%d\n", dp[n]);
}

Measured memory_bytes: 3388
#include<stdio.h>

int main(void){
  int a,b,n,sum;
  double x;

  while(~scanf("%d %d %d",&a,&b,&n)){

    a=a%b;
    for(sum=0;n;n--){
      sum+=(a*10)/b;
      a=(a*10)%b;
    }
    printf("%d\n",sum);
  }

  return 0;
}

Measured memory_bytes: 0
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
#include <map>
using namespace std;


int main() {
    int n;
  
    map<int, int> mp;    //  文字列 → 整数 の連想配列
   
  
   cin >> n;
   int a[n];
  
for(int i = 1;i<n+1;i++){
     
   cin >> a[i];
  
   mp[a[i]]=i;
  
}
   for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
     
      
     
       if(itr->first!=n){
          std::cout << itr->second << " ";    // 値を表示
     
       }else{
          std::cout << itr->second << "\n";
       }
    }
  
   
  return 0;
}

Measured memory_bytes: 5888
#include<iostream>
using namespace std;
int main()
{
   int A,B,X;
   cin>>A>>B>>X;
   int P;
   if(A>=2*B)
   {
       P = (X/500)*B;

       if(X%500!=0)
       {
           P += B;
       }
   }
   else
   {
       P = (X/1000)*A;

       if(X%1000!=0)
       {
        if(X%1000<=500 && A>B)
        {
            P += B;
        }
        else
        {
            P += A;
        }
        
       }
   }
   cout<<P<<endl;
   
}


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

int main(){
	int k,a,b;
	cin >> k >> a >> b;
	if(b>=a+k) cout << b-a-k << endl;
	else if(b+k<=a) cout << a-b-k << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll N, M, K;
    cin >> N >> M >> K;

    rep(a, N + 1) {
        rep(b, M + 1) {
            ll now = (N - a) * b + (M - b) * a;
            // cout << "(a, b) = (" << a << ", " << b << ") : " << now << endl;

            if (now == K) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  
  int count = 0;
  
  for ( int i=0 ; i+2<N ; i++ ){
    if ( ( S.at(i) == 'A' ) && ( S.at(i+1) == 'B' ) && ( S.at(i+2) == 'C' ) ) count++;
  }
  
  cout << count << endl;
  
}

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

int ToNodeIndex(int w, int h, int width)
{
    return width * h + w;
}

int solve(const std::vector<std::vector<int>> &connection, int start, int vertexCount)
{
    int maxDist = 0;
    const int NotChecked = -1;
    std::vector<int> distTable(vertexCount, NotChecked);
    std::queue<int> q;

    distTable[start] = 0;
    q.push(start);

    while (!q.empty())
    {
        int from = q.front();
        q.pop();

        for (auto& to :connection[from])
        {
            if (distTable[to] != NotChecked)
                continue;

            distTable[to] = distTable[from] + 1;
            q.push(to);

            if (maxDist < distTable[to])
                maxDist = distTable[to];
        }
    }

    return maxDist;
}

int main()
{
    int H, W;
    std::cin >> H >> W;
    std::vector<std::vector<int>> connection(H * W);

    char table[H][W];
    for (int i=0; i<H; ++i)
    {
        for (int j=0; j<W; ++j)
        {
            std::cin >> table[i][j];
        }
    }

    for (int i=0; i<H; ++i)
    {
        for (int j=0; j<W; ++j)
        {
            if (table[i][j] == '#')
                continue;

            int from = ToNodeIndex(j, i, W);
            // 右と接続
            if (j < W - 1 && table[i][j+1] != '#')
            {
                int to = from + 1;
                connection[from].emplace_back(to);
                connection[to].emplace_back(from);
            }
            // 下と接続
            if (i < H - 1 && table[i+1][j] != '#')
            {
                int to = from + W;
                connection[from].emplace_back(to);
                connection[to].emplace_back(from);
            }
        }
    }

    int max = 0;
    for (int i=0; i<H; ++i)
    {
        for (int j=0; j<W; ++j)
        {
            int dist = solve(connection, i * W + j, H * W);
            if (max < dist)
                max = dist;
        }
    }

    std::cout << max << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=0;i<VMAX;i++){
    C[i] = 0;
  }

  for(i = 1;i <= n;i++){
    scanf("%hd",&A[i]);
    C[A[i]]++;
  }

  for(i = 1;i < VMAX;i++){
    C[i] = C[i] + C[i - 1];
  }

  for(i=n;i > 0;i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
  for(i = 1;i <= n;i++){
    if(i != n)printf("%d ",B[i]);
    else printf("%d\n",B[i]);
  }
 return 0;
}




Measured memory_bytes: 9548
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){


	int A, B;	cin >> A >> B;
 	bool ans = false;
  	for(int i = 1 ; i <= 3 ; i++){
		if((A * B * i) % 2 == 1)
			ans = true;
    }
  
  	if(ans)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  
    return 0;
}

Measured memory_bytes: 256
//abc171_d.cpp
//Sun Jun 21 20:54:52 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll a[n];
	map<ll,ll> mp;
	ll sum = 0;
	for (int i=0;i<n;i++){
		ll a;
		cin >> a;
		sum += a;
		auto itr = mp.find(a);
		if (itr != mp.end()){
			mp[a]++;
		}else {
			mp[a] = 1;
		}
	}

	ll q;
	cin >> q;
	for (int i=0;i<q;i++){
		ll b,c;
		cin >> b >> c;
		auto itr = mp.find(b);
		if (itr != mp.end()){
			sum += (c-b)*mp[b];
			cout << sum << endl;
			auto itr2 = mp.find(c);
			if (itr2!=mp.end()){
				mp[c] += mp[b];
			}else {
				mp[c] = mp[b];
			}
			mp[b] = 0;
		}else {
			cout << sum << endl;
		}
	}

}

Measured memory_bytes: 8604
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int n = vs[0];
			int m = vs[1];
			int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int[] q = new int[n];
			for (int i = 0; i < n; i++) {
				int x = p[i] - 1;
				q[x] = i;
			}

			UnionFind union = new UnionFind(n);
			for (int i = 0; i < m; i++) {
				vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
				int x = vs[0] - 1;
				int y = vs[1] - 1;
				union.Unite(x, y);
			}

			int ans = 0;
			for (int x = 0; x < n; x++) {
				int i = q[x];
				if (union.Same(i, x)) {
					ans++;
				}
			}
			Console.WriteLine(ans);

		}
	}

	#region Union-Find木 UnionFind
	public class UnionFind
	{
		private readonly UnionFindNode[] _Parent;

		/// <summary>
		/// Union-Find木
		/// </summary>
		/// <param name="n">サイズ</param>
		public UnionFind(int n)
		{
			_Parent = new UnionFindNode[n];
			for (int i = 0; i < n; i++) {
				_Parent[i] = new UnionFindNode(i, 1);
			}
		}

		public int Find(int x)
		{
			if (_Parent[x].Parent == x) {
				return _Parent[x].Parent;
			}
			return _Parent[x].Parent = Find(_Parent[x].Parent);
		}

		public int Size(int x)
		{
			return _Parent[Find(x)].Size;
		}

		/// <summary>
		/// xとyの木を併合
		/// </summary>
		/// <param name="x"></param>
		/// <param name="y"></param>
		public void Unite(int x, int y)
		{
			int rx = Find(x);
			int ry = Find(y);
			if (rx != ry) {
				_Parent[ry].Parent = rx;
				_Parent[rx].Size += _Parent[ry].Size;
			}
		}

		/// <summary>
		/// x, yが同じ木に属している
		/// </summary>
		/// <param name="x"></param>
		/// <param name="y"></param>
		/// <returns></returns>
		public bool Same(int x, int y)
		{
			int rx = Find(x);
			int ry = Find(y);
			return rx == ry;
		}

		public override string ToString()
		{
			return string.Join(" ", _Parent.Select(p => $"({p.Parent},{p.Size})"));
		}
	}
	public class UnionFindNode
	{
		public int Parent;
		public int Size;
		public UnionFindNode(int parent, int size)
		{
			Parent = parent;
			Size = size;
		}
	}
	#endregion

}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  string s;
  cin >> s;


  if(s.length() == 26){

    int ind = -1;
    for(int i = 25; i > 0; i--){
      if(s[i] > s[i-1]){
        ind = i;
        break;
      }
    }
    if(ind==-1){
      cout << -1 << endl;
      return 0;
    }

    int num = 30;
    for(int i = ind; i < 26; i++){
      if(s[i] > s[ind-1]){
        chmin(num, int(s[i]-'a'));
      }
    }

    string ans;
    ans = s.substr(0, ind-1) + char(num+'a');

    cout << ans << endl;

  }else{

    // 出ていない文字を付け加える
    set<int> moji;

    rep(i, s.length()){
      moji.insert(int(s[i]-'a'));
    }

    rep(i, 26){
      if(moji.find(i) == moji.end()){
        s += char(i + 'a');
        break;
      }
    }

    cout << s << endl;
  }


  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	scanInit()

	n := nextInt()
	a := map[int]int{}

	mina := 9999999
	maxa := 0
	for i := 0; i < n; i++ {
		tmp := nextInt()
		a[tmp]++
		mina = min(mina, tmp)
		maxa = max(maxa, tmp)
	}

	maxc := 0
	for i := mina; i <= maxa; i++ {
		tmpc := a[i] + a[i+1] + a[i+2]
		maxc = max(maxc, tmpc)
	}

	fmt.Println(maxc)

}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 7944
n, y = map(int, input().split())
for i in range(n + 1):
  for ii in range(n - i + 1):
    if 10000 * i + 5000 * ii + 1000 * (n - i - ii) == y:
      print('{} {} {}'.format(i, ii, n - i - ii))
      exit()
print('-1 -1 -1')


Measured memory_bytes: 2940
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int pop_count(int bs) {
    int cnt = 0;
    for (int i = 0; i < 16; ++i) {
      cnt += (bs >> i) & 1;
    }
    return cnt;
  }

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

  void run() {
    for (; ; ) {
      int n = ni();
      int c = ni();

      if ((n | c) == 0) {
        break;
      }

      int[] a = new int[n + 1];
      for (int i = 0; i < n; ++i) {
        a[i] = 0;
        for (int j = 0; j < 16; ++j) {
          a[i] |= ni() << j;
        }
      }
      a[n] = 0;
      int[] b = new int[c];
      for (int i = 0; i < c; ++i) {
        b[i] = 0;
        for (int j = 0; j < 16; ++j) {
          b[i] |= ni() << j;
        }
      }

      int[][] dp = new int[n + 1][1 << 16];
      for (int i = 0; i <= n; ++i) {
        Arrays.fill(dp[i], -1);
      }
      dp[0][a[0]] = 0;
      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 1 << 16; ++j) {
          if (dp[i][j] == -1) {
            continue;
          }
          for (int k = 0; k < c; ++k) {
            int cnt = pop_count(b[k] & j);
            int nbs = (j ^ b[k]) & j | a[i + 1];

            dp[i + 1][nbs] = Math.max(dp[i + 1][nbs], dp[i][j] + cnt);
          }
        }
      }

      int ans = 0;
      for (int i = 0; i < 1 << 16; ++i) {
        ans = Math.max(ans, dp[n][i]);
      }

      System.out.println(ans);
    }
  }

  int ni() {
    return Integer.parseInt(sc.next());
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 73036
#include<bits/stdc++.h>
#define hh ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int main() {
	hh;
	int a[4];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]) {
		sort(a,a+4);
		if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9) {
			cout<<"YES"<<endl;
		} else {
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

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

int main() {
  int A,B,C;

  cin >> A >> B >> C;
  if (A == B  && B == C && C == A) {
    cout << "No" << endl;
  } 
  else if (A != B && B != C && A != C)
  {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int A,B,C;
	int MAX=0,SUM=0;
	cin>>A>>B>>C;
	MAX=A*10+B+C;
	SUM=A+B*10+C;
	if(MAX<SUM)MAX=SUM;
	SUM=A+B+C*10;
	if(MAX<SUM)MAX=SUM;
	cout<<MAX<<endl;
	return 0;
}

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

#define ll long long int

int main()
{
    ll A,B,N,ans;
    scanf("%lld%lld%lld",&A,&B,&N);
    if(N<B)
    {
        ans=((A*N)/B)-(A*(N/B));
    }
    else
    {
        N=B-1;
        ans=((A*N)/B)-(A*(N/B));
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
int main(){ 
  string S;cin>>S;
  sort(S.begin(),S.end());
  if(S.at(0)!=S.at(1)&&S.at(1)!=S.at(2))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main(){
  int N,M,highest = 0;
  cin >> N;
  vector<string> Nstring (N);
  for (int i = 0;i < N;i++)
    cin >> Nstring.at(i);
  cin >> M;
  vector<string> Mstring (M);
  for (int i = 0;i < M;i++)
    cin >> Mstring.at(i);
  string now;
  for (int i = 0;i < N;i++){
    int sum = 0;
    now = Nstring.at(i);
    for (int l = 0;l < N;l++)
      if (Nstring.at(l) == now) sum++;
    for (int l = 0;l < M;l++)
      if (Mstring.at(l) == now) sum--;
    if(sum > highest) highest = sum;
  }
  cout << highest << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

string sa;

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>a>>b>>c;
	for(i=0;i<c;i++){
		if(i%2==0)b+=a/2,a/=2;
		else a+=b/2,b/=2;
	}
	cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
n,w = map(int, input().split())
a = [[int(x) for x in input().split()] for i in range(n)]
dp = [-1 for i in range(w + 1)]
dp[0] = 0
for i in range(n):
    for j in range(w, -1, -1):
        if dp[j] != -1 and j + a[i][0] <= w:
            dp[j + a[i][0]] = max(dp[j + a[i][0]], dp[j] + a[i][1])
print(max(dp))

Measured memory_bytes: 44784