akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

const int V = 250;
const int E = 30000;
const int INF = 1e9;

namespace Graph {
#define travel(x, i) for (int i = fir[x]; i; i = e[i].nxt)
  static const int S = V - 1, T = V - 2;

  struct edge {
    int nxt, to, cap;
  } e[E];
  int fir[V], dis[V];

  inline void Init() {
    memset(fir, 0, sizeof fir);
  }
  
  inline void Add(int x, int y, int cto, int cback) {
    static int cnt = 1;
    e[++ cnt] = (edge){fir[x], y, cto};
    fir[x] = cnt;
    e[++ cnt] = (edge){fir[y], x, cback};
    fir[y] = cnt;
  }

  inline bool bfs() {
    queue <int> Q;
    memset(dis, -1, sizeof dis);
    dis[T] = 1;
    Q.push(T);
    int x;
    while (!Q.empty()) {
      x = Q.front();
      Q.pop();
      travel(x, i)
	if (e[i ^ 1].cap > 0 && dis[e[i].to] == -1) {
	  dis[e[i].to] = dis[x] + 1;
	  Q.push(e[i].to);
	}
    }
    return dis[S] != -1;
  }

  inline int dfs(int x, int flow) {
    if (!flow || x == T) return flow;
    int tmp, res = 0;
    travel(x, i)
      if (dis[e[i].to] == dis[x] - 1) {
	tmp = dfs(e[i].to, min(flow, e[i].cap));
	flow -= tmp;
	res += tmp;
	e[i].cap -= tmp;
	e[i ^ 1].cap += tmp;
	if (!flow) return res;
      }
    dis[x] = -1;
    return res;
  }
  
  inline int MaxFlow() {
    int ret = 0;
    while (bfs()) ret += dfs(S, INF);
    return ret;
  }
}
using namespace Graph;

char G[105][105];

int main() {
  int n, m, xs, ys, xt, yt;
  Graph::Init();
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i ++) scanf("%s", G[i] + 1);
  for (int i = 1; i <= n; i ++)
    for (int j = 1; j <= m; j ++) {
      if (G[i][j] == 'S') {
	xs = i; ys = j;
	Graph::Add(S, i, INF, 0);
	Graph::Add(S, j + 100, INF, 0);
      }
      else if (G[i][j] == 'T') {
	xt = i; yt = j;
	Graph::Add(i, T, INF, 0);
	Graph::Add(j + 100, T, INF, 0);
      }
      else if (G[i][j] == 'o') {
	Graph::Add(i, j + 100, 1, 1);
      }
    }
  if (xs == xt || ys == yt) puts("-1");
  else printf("%d\n", Graph::MaxFlow());
  return 0;
}


Measured memory_bytes: 512
import java.util.*;

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

        int d =0;
		int[]list  = new int[N];
		for(int i=0; i<N; i++){
			list[i] = sc.nextInt();
			if(list[i] % 2 == 0 && list[i] % 3 != 0 && list[i] % 5 != 0) {
             d++;   
			}			    
}
			if(d>0){
				System.out.println("DENIED");
			}else{
        		System.out.println("APPROVED");
}
}
}


Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

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

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}


int main(){
	int n, k;
	cin >> k >> n;
	vector<int> a(n);
	vector<int> dist(n,0);
	rep(i, n) cin >> a[i];
	rep(i, n - 1) dist[i] = abs(a[i+1] - a[i]);
	dist[n - 1] = abs(k - a[n-1] + a[0]);
	int m = *max_element(all(dist));
	cout << k - m << endl;
 
	return 0;
}

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

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

		for (int i = 0; i < 3 * n; i++) {
			a[i] = sc.nextInt();
		}

		Arrays.sort(a);

		long answer = 0;
		for (int i = 1; i < n + 1; i++) {
			answer += a[3 * n - 2 * i];
		}

		System.out.println(answer);

	}

}


Measured memory_bytes: 93016
import java.util.*;
import java.util.Map.Entry;
 
 
 
public class Main{
	
	public int num;
	public int vol;
 
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd(long a, long b) {
		if (b == 0) {
			return a;			
		}
		return gcd(b, a % b);
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}
 
 
 
	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}
 
 
	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}
 
 
	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}
 
 
	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 long[] A=new long[3];
	 for(int i=0;i<3;i++) {
		 A[i]=sc.nextLong();
	 }
	 
	 Arrays.sort(A);
	 
	 if(A[2]%2==0) {
		 System.out.println(0);
	 }else {
		 System.out.println(A[0]*A[1]);
	 }
	
    
}
}


Measured memory_bytes: 21844
#include<stdio.h>
int main () {
	char n[4];
	scanf("%s", n);
	for(int i = 0; i < 3; ++i){
		if(n[i] == '1') n[i] = '9';
		else n[i] = '1';
	}
	puts(n);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;;
#define int long long 
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPR(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size()) 
#define MAX(x) *max_element(ALL(x)) 
#define MIN(x) *min_element(ALL(x)) 
#define INF 1000000000000 
#define MOD 10000007 
#define MAXR 100000 
#define PI 3.14159265358979323846
using namespace std;

signed main(){

    int k,a,b;
    cin >> k >> a>> b;

    for (int i = a; i <= b; i++) {
        if(i%k==0){
            cout << "OK" <<endl ;
            return 0;
        }
    }

    cout << "NG" <<endl ;
    

    

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
    ll i, j, k;
    ll N, x;
    cin >> N >> x;
    vll A(N);
    for(auto &e : A)
        cin >> e;
    ll ans = 0;
    if(A[0] > x) {
        ans += A[0] - x;
        A[0] = x;
    }
    for(i = 1; i < N; i++) {
        ll now = A[i - 1] + A[i];
        if(now > x) {
            ans += now - x;
            A[i] -= now - x;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import copy 
import numpy as np

N = int(input())

*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())


sum    = 0
temp_A = 0
for i in range(len(A)):

    if temp_A+1==A[i] and i!=0:
        sum = sum + C[temp_A-1]
    sum = sum + B[A[i]-1]
    temp_A = A[i]

print(sum)


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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  rep(i,4) {
    if(s.at(i) == '+') ans++;
    else ans--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

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

	int cnt = 0;
	for (int i = 2; i < n; i++) {
		int a, b, c;
		a = v[i - 2];
		b = v[i - 1];
		c = v[i];
		if ((a < b) && (b < c)) cnt++;
		else if ((a > b) && (b > c)) cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e18;

int32_t main(){
	IOS;
	int n,w;
	cin>>n>>w;
	pair<int,int> p[n];
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		p[i]={x,y};
	}
	sort(p,p+n);
	int dp[w+1]={0};
	for(int i=0;i<n;i++){
		for(int j=w;j>=p[i].ff;j--){
			dp[j]=max(dp[j],dp[j-p[i].ff]+p[i].ss);
		}
	}
	cout<<dp[w];
}

Measured memory_bytes: 1024
#include<cstdio>
int n,i,j,x;
int main(){
	for(scanf("%d%d",&n,&x),i=0;i<=n;++i)for(j=0;j+i<=n;++j)
	if((i)*10000+j*5000+(n-i-j)*1000==x){
		return 0*printf("%d %d %d\n",i,j,n-i-j);
	}
	puts("-1 -1 -1");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

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

	for(int i = 0; i < N-1; i++){
		if(A[i] < 0){
			A[i] *= -1;
			A[i+1] *= -1;
		}
	}

	ll res = 0;
	if(A[N-1] >= 0){
		res = accumulate(A.begin(), A.end(), 0LL);
	}else{
		A[N-1] *= -1;
		res = accumulate(A.begin(), A.end(), 0LL) - 2 * *min_element(A.begin(), A.end());
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A1 = Integer.parseInt(sc.next());
        int A2 = Integer.parseInt(sc.next());
        int A3 = Integer.parseInt(sc.next());
        if (A1+A2+A3>=22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
    }
}

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

typedef long long int lli;

int main() {
    lli b;

    while (cin >> b, b) {
	lli t = 0, n = 0;
	lli d = 1;

	while (2LL * b - d * d - d >= 0) {
	    if ((2LL * b - d * d - d) % (2LL * d) == 0) {
		t = d;
		n = (2LL * b - d * d - d) / (2LL * d);
	    }
	    d++;
	}

	cout << n + 1 << " " << t << endl;
    }

    return 0;
}



Measured memory_bytes: 3092
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll n, x; cin>>n>>x;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    vector<vector<ll>> amin(n+1, vector<ll>(n+1, INF));

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            chmin(amin[i+1][j+1], min(a[(i-j+n)%n], amin[i+1][j]));
        }
    }

    ll ans = INF;
    for(ll magic=0; magic<n; magic++){

        ll sum = 0;
        for(int i=0; i<n; i++){
            sum += amin[i+1][magic+1];
        }

        chmin(ans, sum + magic * x);
    }

    cout << ans << endl;
}

Measured memory_bytes: 31616
//
// Created on 2020/04/19.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
const long long MOD = 1e9+7;

int main() {
    ll ans = 0;
    ll n;
    ll k;
    cin>>n>>k;
    vector<ll>sum(n+1);
    sum[0] = 0;
    ll temp = 0;
    for (int l = 1; l <= n; ++l) {
        temp += l;
        sum[l] = temp;
    }

    for (int i = k; i <= n + 1 ; ++i) {
        ll max = n * i - sum[i -1];
        ll min = sum[i - 1];

        ll unique_cnt = max - min + 1;
        ans = (ans + unique_cnt) % MOD;
    }

    cout<<ans<<endl;
    return 0;
}


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

int main(){
    int n, m, k, a, ans = 0;
    cin >> n >> m;

    vector<int> v(m+1);
    for(int i = 0; i < n; i++){
        cin >> k;
        while(k--){
            cin >> a;
            v[a]++;
        }
    }
    for(int i : v) if(i == n) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;
int N, X[111], ans=0x3f3f3f3f;

int main(){
    int l=0x3f3f3f3f, r=0;
    cin >> N;
    for(int i=1; i<=N; i++){
        cin >> X[i];
        l=min(l, X[i]);
        r=max(r, X[i]);
    }
    for (int i=l; i<=r; i++){
        int res=0;
        for (int j=1; j<=N; j++){
            res+=(X[j]-i)*(X[j]-i);
        }
        ans=min(ans, res);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')

Measured memory_bytes: 39024
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    slen = len(s)

    ans = 0
    diff = 1
    for i in s[1:slen]:
        if i == 'p':
            if diff > 0:
                diff -= 1
            else:
                ans -= 1
                diff += 1
        else:
            if diff>0:
                diff -= 1
                ans += 1
            else:
                diff += 1

    
    print(ans)
        



solve()


Measured memory_bytes: 3316
a, b, c, d, e =[int(input())for i in range(5)]

if a < 0 and b < 0:
    ans = c*(b-a)
elif a > 0 and b > 0:
    ans = e*(b-a)
else:
    ans = c*(-a)+d+e*b
print(ans)
    


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


int main(){
    int a , b;
    cin >> a >> b ;
    rep(i,a+1){
        if(b == 2*i + 4*(a-i) ){
            cout << "Yes" << endl;
            return 0 ;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3632
// C - Colorful Leaderboard
#include <bits/stdc++.h>
using namespace std;

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

	set<int> colorTypes;
	int numberOfHighScorers = 0;
	while(N--){
		int a; cin>>a;
		int b = a/400;
		if(b<8) colorTypes.insert(b);
		else numberOfHighScorers++;
	}

	int minC = max(1, (int)colorTypes.size());
	int maxC = colorTypes.size() + numberOfHighScorers;
	printf("%d %d\n", minC, maxC);
}

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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: i64 = iterator.next().unwrap().parse().unwrap();
    let q: i64 = iterator.next().unwrap().parse().unwrap();

    let mut map: HashMap<usize, i64> = HashMap::new();
    for _i in 0..q {
        let a: usize = iterator.next().unwrap().parse().unwrap();
        *map.entry(a).or_insert(0) += 1;
    }

    let mut answer = Vec::with_capacity(n);
    for i in 1..(n + 1) {
        if k - q + *map.get(&i).unwrap_or(&0) > 0 {
            answer.push("Yes");
        } else {
            answer.push("No");
        }
    }

    return answer.connect("\n");
}

#[test]
fn test() {
    assert_eq!(
        solve(
            r"6 3 4
3
1
3
2"
        ),
        "No
No
Yes
No
No
No"
    );
    assert_eq!(
        solve(
            r"6 5 4
3
1
3
2"
        ),
        "Yes
Yes
Yes
Yes
Yes
Yes"
    );
    assert_eq!(
        solve(
            r"10 13 15
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9"
        ),
        "No
No
No
No
Yes
No
No
No
Yes
No"
    );
}


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

typedef long long ll;
typedef const void cv;
int downint(cv *a, cv *b) {
  return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0;
}

ll battle(ll hp){
  if(hp==1){
     return 1;
  }else{
    return battle(hp/2)*2+1;
  }
  

}
int main(void){
  ll h, result=0;
  scanf("%lld",&h);
  result=battle(h);
  printf("%lld",result);
  
  return 0;
}

Measured memory_bytes: 128
//wa time i don't believe in this at all
//suffix things are wack
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const int A = 26;
struct SA {
	vector<unordered_map<char,int> > eg;
	vi len,link;
	int los,sz;
	void add(char ch) {
		int r = len.size();
		sz++;
		len.push_back(sz);
		link.push_back(0);
		eg.emplace_back();
		int p = los;
		while(p >= 0 && !eg[p].count(ch)) {
			eg[p][ch] = r;
			p = link[p];
		}
		if(p >= 0) {
			int q = eg[p][ch];
			if(len[p]+1 == len[q]) {
				link[r] = q;
			} else {
				int nq = len.size();
				len.push_back(len[p]+1);
				link.push_back(link[q]);
				eg.push_back(eg[q]);
				while(p >= 0 && eg[p][ch] == q) {
					eg[p][ch] = nq;
					p = link[p];
				}
				link[r] = link[q] = nq;
			}
		}
		los = r;
	}
	void add(const string& s) {
		for(int i=0;i<s.size();i++) {
			add(s[i]);
		}
	}
	SA(const string& s) {
		len.push_back(0);
		link.push_back(-1);
		eg.emplace_back();
		los = sz = 0;
		add(s);
	}
};
bool bup(int u, int len, string& res, SA& sa) {
	if(len == 0) {return true;}
	for(int i=0;i<A;i++) {
		char ch = i+'a';
		if(sa.eg[u].count(ch)) {
			int v = sa.eg[u][ch];
			if(bup(v,len-1,res,sa)) {
				res.push_back(ch);
				return true;
			}
		}
	}
	return false;
}
int main() {
	ll n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	string rs = s;
	reverse(rs.begin(),rs.end());
	SA sa(s+rs);
	string ru;
	bup(0,n,ru,sa);
	reverse(ru.begin(),ru.end());
	ll nc = 0;
	for(;nc < n && ru[nc] == ru[0];nc++);
	int we = nc;
	while(nc < n && k > 1) {nc <<= 1;k--;}
	string res;
	for(int i=0;i<min(nc,n);i++) {
		res.push_back(ru[0]);
	}
	for(int i=we;i<n;i++) {
		res.push_back(ru[i]);
	}
	res = res.substr(0,n);
	cout << res << '\n';
}


Measured memory_bytes: 6668
#include <stdio.h>
int main(void){
    int tmp[8] = {0};
    int b=0,cnt=0,max=0,i,n;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(a[i]  >= 3200){
            b++;
        }else{
            tmp[a[i]/400]++;
        }
    }
    for(i=0;i<8;i++){
        if(tmp[i] > 0){
            cnt++;
        }
    }
    max = cnt + b;
    if(cnt == 0){
        cnt++;
    }
    printf("%d %d",cnt,max);
}

Measured memory_bytes: 128
def slove():
    import sys
    input = sys.stdin.readline
    h, w, a, b = list(map(int, input().rstrip('\n').split()))
    for i in range(h):
        if i < b:
            t = ["0"] * a
            s = ["1"] * (w - a)
            print("".join(t + s))
        else:
            t = ["1"] * a
            s = ["0"] * (w - a)
            print("".join(t + s))


if __name__ == '__main__':
    slove()


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

int main(){
	int n,m;
	cin>>n>>m;
	if (m == 1){
		cout<<n*(n-1)/2;
	}
	else{
		cout<< (n * (n-1)/2) + (m * (m-1)/2);
	}
}

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

#define INF (1<<30)

int main(){
	string s;	cin>>s;
	int n=s.length()+1;

	vector<int> L(n,0);
	vector<int> R(n,0);

	for(int i=0; i<s.length(); i++){
		if(s[i]=='<'){
			L[i+1]=L[i]+1;
		}
	}
	for(int i=s.length()-1; i>=0; i--){
		if(s[i]=='>'){
			R[i]=R[i+1]+1;
		}
	}

	long long ans=0;
	for(int i=0;i<n;i++){
		ans+=max(L[i],R[i]);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 4740
#include<stdio.h>
main(){
  int n,x;
  int i,j,k;
  int counter;
  while(1){
    scanf("%d%d",&n,&x);
    if(n==0 && x==0)
      break;
    for(i=1;i<=n;i++)
      for(j=i+1;j<=n;j++)
        for(k=j+1;k<=n;k++)
          if(i+j+k==x)
            counter++;
    printf("%d\n",counter);
    counter=0;
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  int ans = 0;
  int count = 1;
  while(count < B){
    count--;
    count += A;
    ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int cnt=0;

void insertionSort(vector<int> &A,int n,int g){
    rip(i,n,g){
        int v=A[i];
        int j=i-g;
        while(j>=0 && A[j]>v){
            A[j+g]=A[j];
            j-=g;
            cnt++;
        }
        A[j+g]=v;
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> da(n);
    rip(i,n,0){
        cin >> da[i];
    }
    int gi=1;
    int co=1;
    while(gi*2<n){
        gi*=2;
        co++;
    }
    vector<int> g(co);
    rip(i,co,0){
        g[i]=gi;
        gi/=2;
    }
    rip(i,co,0){
        insertionSort(da,n,g[i]);
    }
    printf("%d\n",co);
    rip(i,co,0){
        if(i==co-1){
            printf("%d\n",g[i]);
        }else{
            printf("%d ",g[i]);
        }
    }
    printf("%d\n",cnt);
    rip(i,n,0){
        printf("%d\n",da[i]);
    }
}


Measured memory_bytes: 6788
a = input()
lis = []
li = ["A","C","G","T"]
l = []
for i in range(len(a)):
    if a[i] in li:
        lis.append(a[i])
        if i == len(a)-1:
            l.append(lis)
    else:
        l.append(lis)
        lis = []
ans = 0
for n in l:
    if ans < len(n):
        ans = len(n)
print(ans)

Measured memory_bytes: 3064
import sys
N, M = list(map(int, input().split()))

T = [-1] * N
ans = -1

for m in range(M):
    s, c = list(map(int, input().split()))
    s -= 1
    if T[s] != -1 and T[s] != c:
        print(-1)
        sys.exit(0)
    T[s] = c


if N == 1 and T[0] == -1:
    print(0)
    sys.exit(0)
if N == 1 and T[0] == 0:
    print(0)
    sys.exit(0)


for i in range(10**(N-1), 10**N):
    A = list(str(i))
    for n in range(N):
        if T[n] == -1:
            continue
        elif T[n] == int(A[n]):
            continue
        break
    else:
        print(i)
        sys.exit(0)

print(-1)


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

using namespace std;

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

  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> xs(n), ys(m);
  for (int i = 0; i < n; ++i) {
    cin >> xs[i];
  }
  xs.push_back(x);
  sort(xs.begin(), xs.end());
  for (int i = 0; i < m; ++i) {
    cin >> ys[i];
  }
  ys.push_back(y);
  sort(ys.begin(), ys.end());
  if (xs[xs.size() - 1] < ys[0]) {
    cout << "No War\n";
  } else {
    cout << "War\n";
  }
}


Measured memory_bytes: 256
#include <iostream>
#include<set>
#include<map>
#define INF 1e8
using namespace std;
int main(void){
string s,t;
int a,b;

cin>>s>>t>>a>>b;
string d;
cin>>d;
if(d==s)
    a--;
else
    b--;
cout<<a<<" "<<b;

}



Measured memory_bytes: 3144
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i32 = read();
    let mut vec: Vec<Vec<i32>> = Vec::new();

    for i in 0..2 {
        let each_vec: Vec<i32> = (0..n).map(|_| read()).collect();
        vec.push(each_vec);
    }

    let mut max = 0;
    for i in 0..n {
        let mut each_count = 0;
        let mut j = 0;
        loop {
            each_count+=vec[0][j as usize];
            j+=1;
            if j>i {
                break;
            }
        }

        let mut k = i;
        loop {
            each_count+=vec[1][k as usize];
            k+=1;
            if k>=n {
                break;
            }
        }

        max = cmp::max(max, each_count);
    }

    println!("{}", max);
}

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

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 4352
//In the Name of God
#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

string s;

int main () {

cin >> s;

s[0] = '2';
s[1] = '0';
s[2] = '1';
s[3] = '8';

cout << s;

return 0;
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
s = input()
a_, b_ = 0, 0
for i in range(n):
    if s[i]=='a':
        if (a_ + b_) < a+b:
            a_ += 1
            print('Yes')
        else:
            print('No')
    elif s[i]=='b':
        if (a_ + b_ ) < a+b and b_ < b:
            b_ += 1
            print('Yes')
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 4016
import sys, math
input=sys.stdin.readline

N,D=map(int,input().split())
points=list(tuple(map(int,input().split())) for _ in range(N))
count=0

for i1 in range(N-1):
    for i2 in range(i1+1,N):
        sum_sq=sum((points[i1][j]-points[i2][j])**2 for j in range(D))
        if math.sqrt(sum_sq)==int(math.sqrt(sum_sq)):
            count+=1

print(count)

Measured memory_bytes: 3064
def main():
    n, k = map(int, input().split())
    inlis = list(map(int, input().split()))
    indic = dict()
    cnt = 0
    for i in range(n):
        num = inlis[i]
        if num in indic:
            indic[num] += 1
        else:
            indic[num] = 1
            cnt += 1
    if cnt <= k:
        print(0)
    else:
        indic_sort = sorted(indic.items(), key=lambda x:x[1])
        #print(indic_sort)
        sa = cnt - k
        tmp = 0
        ans = 0
        for j in range(n):
            tmp += 1
            ans += indic_sort[j][1]
            if tmp == sa:
                break
        print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 42764
#include <iostream>

using namespace std;


int main(){
	int n, x;
	cin >> n >> x;
	while(n != 0){
		int count = 0;
		for(int i = 1; i <= n - 2; i++){
			for(int j = i + 1; j <= n - 1; j++){
				for(int k = j + 1; k <= n; k++){
					if(i + j + k == x){
						count++;
					}
				}
			}
		}
		cout << count << endl;
		cin >> n >> x;
	}

	return 0;
}

Measured memory_bytes: 1160
(defun FizzBuzz-Sum (n)
    (let
        ((Sum 0))
        (progn
            (loop
                :for i :from 0 :to n
                :do (cond
                        ((= (mod i 3) 0)
                            ())
                        ((= (mod i 5) 0)
                            ())
                        (t
                            (incf Sum i))))
            Sum)))

(princ (FizzBuzz-Sum (read)))

Measured memory_bytes: 24328
#include<bits/stdc++.h>
#define mp make_pair
#define pr pair<ll,ll>
#define MAX 1000000
using namespace std;
typedef long long int ll;
#define mod 998244353
void sync(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}

int main(){
	sync();
	ll x,y,z;
	cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<endl;
	
}

Measured memory_bytes: 256
# include <stdio.h>

int main(void){
	int A, B, max;
	scanf("%d %d",&A, &B);
	max=A+B;
	if (A - B > max){
		max=A-B;
	}
	if (A * B > max){
		max=A*B  ;
	}
	printf("%d\n", max);
	return 0;
	
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

int x[100000];
int main() {
    int N, K;
    int i=0;
    scanf("%d %d", &N,&K);
    for(int i=0; i<N; i++){
        scanf("%d", &x[i]);
    }
    int min=1000000000;
    for(i =0; i+ K-1<N; i++){
        if(min > abs(x[i])+abs(x[i]-x[i+K-1])){
            min = abs(x[i])+abs(x[i]-x[i+K-1]);
        }
        if(min > abs(x[i+K-1])+abs(x[i]-x[i+K-1])){
            min = abs(x[i+K-1])+abs(x[i]-x[i+K-1]);
        }

    }

    printf("%d", min);
    return 0;

}

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

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut s: Vec<usize> = it.next().unwrap().chars().map(|c| c.to_digit(10).unwrap() as usize - 1).collect();
    let mut fact = vec![0usize; n + 1];
    for i in 1..(n + 1) {
        fact[i] = fact[i - 1];
        let mut k = i;
        while k % 2 == 0 {
            fact[i] += 1;
            k /= 2;
        }
    }
    let comb = |n: usize, k: usize| -> usize {
        if fact[n] - fact[n - k] - fact[k] > 0 {
            0
        } else {
            1
        }
    };
    if s.contains(&1) {
        for c in s.iter_mut() {
            if *c == 2 {
                *c = 0;
            }
        }
    }
    let mut v = 0;
    for (i, c) in s.iter().enumerate() {
        if *c != 0 {
            v ^= (comb(n - 1, i) & 1) * *c;
        }
    }
    println!("{}", v);
}

fn main() {
    run();
}


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

a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if x == i*500+j*100+k*50:
                ans += 1

print(ans)


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  ll B = nextLong();
  ll W = nextLong();
  ll A = nextLong();
  ll V = nextLong();
  ll T = nextLong();
  if ((W >= V) && T * (W-V) >= abs(A-B)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

using namespace std;

typedef string::iterator Iterator;

void cat(Iterator &it) {
    if(*it != 'm') return;
    ++it;
    if(*it == 'm') cat(it);
    if(*it != 'e') throw "Not Cat";
    ++it;
    if(*it == 'm') cat(it);
    if(*it != 'w') throw "Not Cat";
    ++it;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    string str;
    while(cin >> str) {
        Iterator it = str.begin();
        bool iscat = true;
        if(it != str.end()) {
            try {
                cat(it);
                if(it != str.end()) iscat = false;
            } catch(const char *msg) {
                iscat = false;
            }
        }
        cout << (iscat?"Cat":"Rabbit") << endl;
    }
    return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

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 N;
ll M;
ll a[110000];
ll d[110000];

ll calc(ll n) {
  return n * (n-1) / 2;
}

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

  rep(i, N) cin >> a[i];

  rep(i, N) {
    d[i] = a[i] + d[i-1];
    d[i] %= M;
  }

  map <ll, int> m;
  m[0] += 1;

  rep(i, N) {
    m[d[i]] += 1;
  }

  ll ans = 0;

  for (auto i = m.begin(); i != m.end(); ++i) {
    ans += calc(i->second);
  }

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

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int a[53][53];

int main()
{
    int n;
    while (cin >> n, n)
    {
        int r_sum[n] = {}, c_sum[n] = {}, sum = 0;
        rep(i, n)
        {
            rep(j, n)
            {
                cin >> a[i][j];
                r_sum[i] += a[i][j];
                c_sum[j] += a[i][j];
                sum += a[i][j];
            }
        }
        r_sum[n] = sum;

        rep(j, n) a[n][j] = c_sum[j];

        rep(i, n + 1)
        {
            rep(j, n)
            {
                cout << right << setw(5) << a[i][j];
            }
            cout << right << setw(5) << r_sum[i] << endl;
        }
    }
    return 0;
}


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

int n, a[200010], longest[200010];
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    memset(longest, 0, sizeof longest);
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) 
            longest[a[i]] = 1;
        else
            longest[a[i]] = longest[a[i] - 1] + 1;
    }
    int best = 0;
    for (int i = 1; i <= n; i++) best = max(best, longest[i]);
    cout << n - best;
}

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

int main() {

  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  if (A1 + A2 + A3 >= 22) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" << endl;
  }

}


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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void Yes(){
		cout << "Yes" << endl;
	}
	void No(){
		cout << "No" << endl;
	}
	void solve() {
		int n;
		cin >> n;
		vector<int> a(n, 0);
		for(int i=0; i<n; i++)cin >> a[i];
		sort(a.begin(), a.end());
		if(a[n-1] > a[0]+1)return No();
		if(a[0] == a[n-1]){
			if(a[0] == n-1)return Yes();
			if(a[0] <= n/2)return Yes();
			return No();
		}
		int small = 0;
		for(int i=0; i < n; i++)if(a[i] == a[0])small++;
		int big = n-small;
		int x = small + big/2;
		if(x != a[n-1] || big < 2)return No();
		return Yes();
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=100005;
int n,ans,num;
char ch;
bool vis[maxn]={0};
inline int get_num(){
	num=0;ch=getchar();
	while(ch<'0'||ch>'9'){ch=getchar();	}
	while(ch<='9'&&ch>='0'){num=(num<<3)+(num<<1)+ch-'0';ch=getchar();	}
	return num;
}
int main(){
	scanf("%d",&n);
	int a;
	ans=0;
	int chong=0;
	for(int i=0;i<n;i++){
		a=get_num();
		if(vis[a])chong++;
		else vis[a]=true;
	}
	
	ans=n-chong;

	if((chong&1)==0)cout<<ans;
	else cout<<ans-1;
	
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
bool used[50];
typedef pair<int,int>P;
int dx[]={-1,1};
int main(){
  int n;
  cin>>n;
  int a[n];
  r(i,n)cin>>a[i];
  int c=1e9;
  r(i,n){
    int cc=0;
    while(a[i]%2==0)a[i]/=2,cc++;
    c=min(c,cc);
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long int dp[2005];
long long int mod (long long int x)
{
    return (x%1000000007 + 1000000007)%1000000007;
}
int main()
{
    long long int s;
    cin>>s;
    
    for(int i=0;i<s+2;i++)
    {
        dp[i] =0LL;
    }
    dp[0] =1LL;
    dp[1]=0LL,dp[2]=0LL;
    dp[3]=1LL;
    dp[4]=1LL;
    dp[5]=1LL;
    for(long long int i=6;i<=s;i++)
    {
      for(long long int j =3;j<=i;j++)
      {
          if(i-j>=0 && i-j<=s && i>=0 && i<=s)
          dp[i] = mod(mod(dp[i]) + mod(dp[i-j]));
      }
    }
    cout<<mod(dp[s])<<endl;

    return 0;
}


Measured memory_bytes: 3624
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""
# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  import re
  #?tc????
  S = input().replace('?','.')
  T = input()
  #print(S)
  #.tc....
  #print(T)
  #coder
  # print(len(S) - len(T)) 7:5
  # 2
  for i in range(len(S) - len(T), -1,-1):
    # print(re.match(S[i:i+len(T)],T))
    # <_sre.SRE_Match object; span=(0, 5), match='coder'>
    # 後ろから、len(T)文まで見て、そこにTが入るかを検証
    # 入るなら Trueがかえる？
    if re.match(S[i:i+len(T)],T):
      #print(S) 
      S = S.replace('.','a')
      # すべてをaに置き換える(辞書順最初)
      print(S[:i] + T + S[i+len(T):])
      # i-1番目までSの部分、iからi+len(T)-1まではTを入れ（入れれることが確認できたから)
      # そして、i+len(T)番目から最後までSの部分を入れる
      exit()
  print('UNRESTORABLE')
if __name__ == '__main__':
  main()

Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(){
char s[2000],c;
int i,a[500],b,k,count=0;
for(i=0;i<450;i++){
a[i]=0;
}
while(fgets(s,1300,stdin)!=NULL){
k=strlen(s);
for(i=0;i<k;i++){
s[i]=tolower(s[i]);
if('a'<=s[i] && s[i]<='z'){
b=s[i]-'a';
a[b]++;
}
}
}
for(i=0;i<450;i++){
c=i+'a';
if('a'<=c && c<='z'){
printf("%c : %d\n",c,a[i]);
count++;
}
if(count==26){
break;
}
}
return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n;
	cin >> n;
	int* a = new int[n];
	rep(i, n) cin >> a[i];

	pii* ai = new pii[n];
	rep(i, n) {
		ai[i].first = a[i];
		ai[i].second = i + 1;
	}

	sort(ai, ai + n);

	rep(i, n) {
		cout << ai[i].second << " ";
	}

	cout << "\n";

	return 0;
}


Measured memory_bytes: 4752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String get = sc.nextLine();
		sc.close();
		String def = "CODEFESTIVAL2016";

		int wrongCount = 0;
		for(int i=0;i<def.length();i++){
			if(get.charAt(i)!=def.charAt(i)) wrongCount ++;
		}
		System.out.println(wrongCount);

	}

}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,mi=1000000000000001;
	cin>>n;
	for(int i=0;i<5;i++){
		cin>>a;
		mi=min(a,mi);
	}
	if(n%mi==0){
		cout<<std::fixed << std::setprecision(0)<<floor(n/mi)+4<<endl;
	}else{
		cout<<std::fixed << std::setprecision(0)<<floor(n/mi)+5<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int T[13] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

int main(){
	int x,y;
	cin >> x >> y;
	if(T[x] == T[y]) cout << "Yes" << endl;
	else cout << "No" << endl;

}

Measured memory_bytes: 256
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val (n, k) = readIntList()
    val p = readIntList()
    val sortedP = p.sorted()
    println(sortedP.subList(0, k).sum())
}

Measured memory_bytes: 40600
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] c = new int[M];
		for(int i=0;i<M;i++) c[i] = sc.nextInt();
		Arrays.sort(c);
		
		int[][] dp = new int[M+1][N+1];
		for(int i=0;i<=M;i++) for(int j=0;j<=N;++j) dp[i][j] = 1000000;
		dp[0][0] = 0;
		
		for(int i=0;i<M;i++){
			for(int j=0;j<=N;++j){
				dp[i+1][j] = dp[i][j];
				int k = j-c[i];
				if(k>=0){
					dp[i+1][j] = Math.min(dp[i+1][j], Math.min(dp[i][k]+1, dp[i+1][k]+1));
				}
			}
		}
		System.out.println(dp[M][N]);
		return;
	}
}


Measured memory_bytes: 31512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

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

int main()
{
	string s;
	vector<int>sp;
	cin>>s;
	string nxs="";
	for(int i=0;i<s.length();i++)
	{
		if(s[i]!='x')
		{
			nxs+=s[i];
			sp.push_back(i);
		}
	}

	for(int i=0;i<nxs.length();i++)
	{
		if(nxs[i]!=nxs[nxs.length()-1-i])
		{
			cout<<"-1"<<endl;
			return 0;
		}
	}
	int lp=0,rp=nxs.length()-1,lx=0,rx=s.length()-1;
	int cnt=0;
	for(;lp<=rp;)
	{
		int lc=sp[lp]-lx;
		int rc=rx-sp[rp];
		if(lc!=rc)
		{
			cnt+=abs(lc-rc);
		}
		lx=sp[lp];
		rx=sp[rp];
		lp++;
		rp--;
	}
	

	cout<<cnt<<endl;
}

Measured memory_bytes: 1148
use std::io::{BufRead, Write};
use std::io;
use std::usize;

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut st = String::new();
    input.read_line(&mut st).unwrap();
    let mut fin: usize = usize::MAX;
    let targets: Vec<char> = (0..26).map(|n| (n as u8 + 'a' as u8) as char).collect();
    for target in targets {
        let mut result: usize = 0;
        let mut s = st.trim().to_owned();
        while !s.chars().all(|x| x == s.chars().next().unwrap()) {
            s = (0..s.len() - 1)
                .map(|x| if s.chars().nth(x).unwrap() == target {
                    target
                } else {
                    s.chars().nth(x + 1).unwrap()
                })
                .collect();
            result += 1;
        }
        if result < fin {
            fin = result
        };
    }
    writeln!(output, "{}", fin).unwrap();
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v: Vec<u8> = Vec::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test("serval\n", "3\n");
    }
    #[test]
    fn case2() {
        test("jackal\n", "2\n");
    }
    #[test]
    fn case3() {
        test("zzz\n", "0\n");
    }
    #[test]
    fn case4() {
        test("whbrjpjyhsrywlqjxdbrbaomnw\n", "8\n");
    }
}


Measured memory_bytes: 4352