akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static  ll INF = 1e9;
using namespace std;

signed main(){
	string s;
	cin>>s;
	rep(i,s.size()){
		if(s[i]==',')s[i]=' ';
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    
    static Scanner sc = new Scanner(System.in);
     
    public static void main(String[]args){
        while(true){
          String deck = sc.nextLine();  
            if (deck.equals("-")) {
                break;
            }
       
      

           String n = sc.nextLine();
           int numb = Integer.valueOf(n);
           String arr[] = new String [numb+1];
           arr[0] = deck;
            for (int i = 0; i < numb; i++) {
                  String a = sc.nextLine();
                  int index = Integer.valueOf(a);
                  String sub = arr[i].substring(0, index);
                  String remains = arr[i].substring(index,arr[i].length());
                  String newString = remains.concat(sub);
             
                  arr[i+1] = newString;
            }
            System.out.println(arr[numb]);
        }
        
    }
}


Measured memory_bytes: 26340
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 


int32_t main()
{
	IOS
	int n,w;cin>>n>>w;
	vector<int>V(n+1),W(n+1);
	for(int i=1;i<=n;i++)cin>>W[i]>>V[i];
	vector<int>dp(100010,1e15);
	dp[0]=0;//minimum waigth for making value 0 = 0;
	
	for(int i=1;i<=n;i++)
	{
		auto dp2=dp;
		for(int j=0; j + V[i] <= 100010; j++)
		{
			dp2[ j + V[i] ] = min( dp2[ j + V[i] ] , dp[ j ] + W[i] );
		}
		dp=dp2;
	}
	int maxvalue=0;
	for(int i=0;i<100010;i++)
	{
		if( dp[i] <= w )maxvalue=max(maxvalue,i);
	}
	cout<<maxvalue<<endl;
}
		


Measured memory_bytes: 1904
#include<cstring>
#include<iostream>
#include<cstdio>
#define int long long
#define maxn 100005
using namespace std;
typedef long long ll;
pair<int, char> a[maxn];
ll st[maxn];
ll p[maxn];
ll c[maxn], b[maxn];
signed main() {
	int n;
	cin >> n;
	char s[2];
	for(int i=1; i<=n; i++) {
		scanf("%d",&a[i].first);
		if(i < n) {
			scanf("%s",s);
			a[i].second = s[0];
		}
	}
	a[0] = make_pair(0,'&');
	int z=0;
	for(int i=1; i<=n; i++) {
		char op = a[i-1].second;
		if(op == '-') {
			a[i].first *= -1;
			st[++z] = a[i].first;
		}
		int pre = a[i-1].first;
		if(pre <= 0 && a[i].first > 0) {
			st[++z] = a[i].first;
		}
		if(pre > 0 && a[i].first > 0) {
			st[z] += a[i].first;
		}
	}
	c[z] = abs(st[z]);
	for(int i=z-1; i>=1; i--) c[i] = c[i+1] + abs(st[i]);
	for(int i=1; i<=z; i++) p[i] = p[i-1] + st[i];
	ll ans = p[z];
	for(int i=1; i<z; i++) {
		if(st[i+1] < 0) ans = max(ans,p[i+1]-st[i+2]+c[i+3]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int N,M;

vector<int> mat[100000];
vector<int> ans;
bool visited[100000];

void DFS(int v)
{
	visited[v] = 1;
	for(int i = 0; i < mat[v].size(); i++){
		int u = mat[v][i];
		if(visited[u]==0){
			ans.push_back(u+1);
			DFS(u);
			break;
		}
	}
}

int main()
{
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		mat[a].push_back(b);
		mat[b].push_back(a);
	}
	ans.push_back(1);
	DFS(0);
	reverse(ans.begin(), ans.end());
	DFS(0);
	cout << ans.size() << endl;
	for(int i=0;i<ans.size();i++){
		cout << ans[i];
		if(i!=ans.size()-1)
			cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 9720
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
ans = 0
min_diff = 100000
for i in range(N):
  temp = T - H[i]*0.006
  if abs(A-temp) < min_diff:
    ans = i+1
    min_diff = abs(A-temp)
print(ans)

Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    int[] x = new int[5];
    for (int i=0; i<5; i++) {
      x[i] = sc.nextInt();
      if (x[i] == 0) {
        System.out.println(i+1);
        return;
      }
    }
    
  }
}


Measured memory_bytes: 35564
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
#include <stdbool.h>


//using ll = long long;
int ASC( void *a,  void *b) {
	return strcmp(*(const char **)a, *(const char **)b);//降順
}
int GCD(int a, int b) {	//最大公約数
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int min(double a, double b ) {
	if (a < b) {
		return a;
	}
	else
		return b;
}
int max(int a, int b) {
	if (a < b)
		return b;
	else
		return a;
}
int main(void)
{
	int h, w, hh, ww, k;
	scanf("%d%d%d%d%d",&h,&w,&hh,&ww,&k);
	int min1 = h * 60 + w;
	int min2 = hh * 60 + ww;
	int ans = min2 - min1 - k;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1732
use std::collections::HashMap;
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let n = get!(usize);
    let v = get!([usize]);
    let mut map = HashMap::new();
    for i in 0..n {
        let counter = map.entry(v[i]).or_insert(0);
        *counter += 1;
    }
    //eprintln!("{:?}", v);
    //eprintln!("{:?}", map);
    let mut ans = 0;
    for (k, v) in map.iter() {
        if *k == *v {
            continue;
        } else if *k < *v {
            ans += *v - *k;
        } else {
            ans += *v;
        }
    }
    println!("{}", ans);
}


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

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

    vector<int> V(N), C(N);
    for (int i = 0; i < N; i++)
        cin >> V[i];
    for (int i = 0; i < N; i++)
        cin >> C[i];

    int res = 0;
    for (int i = 0; i < N; i++) {
        if (V[i] - C[i] > 0)
            res += V[i] - C[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int t, n;
	int h1, h2;
	int i, j;
	int min, max;
	
	scanf("%d", &t);
	for (i = 0; i < t; i++){
		min = 1000;
		max = -1000;
		
		scanf("%d", &n);
		scanf("%d", &h1);
		for (j = 1; j < n; j++){
			scanf("%d", &h2);
			if (max < (h2 - h1)){
				max = h2 - h1;
			}
			if (min > (h2 - h1)){
				min = h2 - h1;
			}
			h1 = h2;
		}
		if (max < 0){
			max = 0;
		}
		if (min > 0){
			min = 0;
		}
		printf("%d %d\n", max, -min);
	}
	return (0);
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int dp[100000][3],n;

int solve(vector<int> a[],int i,int j)
{
	if(i==n-1)
	{
		return a[i][j];
	}
	if(dp[i][j])
	return dp[i][j];
	int ans;
	ans=max(solve(a,(i+1),(j+1)%3),solve(a,i+1,(j+2)%3));
	dp[i][j]=ans+a[i][j];
	return dp[i][j];
}

int main()
{
	int x,ans;
	cin>>n;
	vector<int> a[n];
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>x;
			a[i].push_back(x);
		}
	}
	
	ans=max(max(solve(a,0,0),solve(a,0,1)),solve(a,0,2));
	cout<<ans;
}


Measured memory_bytes: 14720
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x3f3f3f3f      //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf，sscanf, getchar, fgets之类的一起使用了。
const int dr[]={0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]={-1, 1, 0, 0, -1, 1, -1, 1};
int read()//输入外挂
{
    int ret=0, flag=0;
    char ch;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        ret = ch - '0';
    while((ch=getchar())>='0'&&ch<='9')
        ret=ret*10+(ch-'0');
    return flag ? -ret : ret;
}
int a[205];
int main()
{
    //freopen("D:\\chnegxubianji\\inORout\\in.txt", "r", stdin);
    //freopen("D:\\chnegxubianji\\inORout\\out.txt", "w", stdout);
    int n;
    cin>>n;
    for(int i=0;i<n;++i)
        cin>>a[i];
    LL sum=LL_INF;
    for(int i=-100;i<=100;++i)
    {
        LL ans=0;
        for(int j=0;j<n;++j)
            ans+=(a[j]-i)*(a[j]-i);
        sum=min(sum,ans);
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int p1 = sc.nextInt(), p2 = sc.nextInt(), p3 = 0;
        int cnt = 0;
        
        for (int i = 1; i < n - 1; i++) {
            p3 = sc.nextInt();
            //System.out.println(p1 + ", " + p2 + ", " + p3);
            
            if ((p1 < p2 && p2 < p3) || (p3 < p2 && p2 < p1)) {
                cnt++;
            }
            p1 = p2;
            p2 = p3;
        }
        System.out.println(cnt);
    }
}


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

#define NS (100005)

using namespace std;

int n, dis[NS];

deque<int> que;

bool book[NS];

int main(int argc, char const* argv[])
{
    scanf("%d", &n), memset(dis, 127, sizeof(dis));
    que.push_back(1), dis[1] = 1;
    while (!que.empty())
    {
        int F = que.front(); que.pop_front();
        if (book[F]) continue;
        book[F] = 1;
        if (dis[F * 10 % n] > dis[F])
            dis[F * 10 % n] = dis[F], que.push_front(F * 10 % n);
        if (dis[(F + 1) % n] > dis[F] + 1)
            dis[(F + 1) % n] = dis[F] + 1, que.push_back((F + 1) % n);
    }
    printf("%d\n", dis[0]);
    return 0;
}


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

int main() {
    string s;
    cin >> s;
    if (s[(int)s.size()-1] == 's') {
        s += "es";
        cout << s << '\n';
        exit(0);
    }
    s += 's';
    cout << s << '\n';
    return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * WRITE STUFF DOWN
    * CHECK IF DEBUGGING OUTPUT BLOCKS ANSWER
*/



Measured memory_bytes: 3640
import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        outer:
        for(int k=0;;k++){
            int i = 0;
            String str = sc.next();
            int l = str.length();
            for(int j=0;j<l;j++){
                char a = str.charAt(j);
                int n = a - '0';
                if(l==1&&n==0) break outer;
                i+=n;
            }
            System.out.println(i); 
        }
    }
}


Measured memory_bytes: 26288
N = int(input())
S = [input() for _ in range(N)]

import string 
letters=string.ascii_lowercase
dic = {}
def alpha(N,dic):
  for i in letters:
    dic[i] = [0] * N
alpha(N,dic)

for i in range(N):
  for j in range(len(S[i])):
    dic[S[i][j]][i] += 1
#print(dic)
ans = []
for i in letters:
  ans.append(i * min(dic[i]))
print(*ans,sep="")

Measured memory_bytes: 3828
A,B,C,D=map(int,input().split())
x=0
y=0
for i in range(101):
    C=C-B
    if(C<=0):
        x=1
        break
    A=A-D
    if(A<=0):
        y=1
        break
if(x==1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61656
#include <cstdio>

int main() {
  int x, y;
  scanf("%d %d", &x, &y);

  int g[13] = {-1, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
  if (g[x] == g[y]) {
    puts("Yes");
  } else {
    puts("No");
  }
}

Measured memory_bytes: 128
N, Ma, Mb = map(int, input().split())
l = []
for i in range(N):
    l.append(list(map(int, input().split())))
ans = float('inf')

Mab = 10 * N + 1
dp = [[[float('inf')] * Mab for _ in range(Mab)] for _ in range(N + 1)]
dp[0][0][0] = 0
for n in range(N):
    for a in range(10 * N):
        for b in range(10 * N):
            if dp[n][a][b] == float('inf'):
                continue
            dp[n + 1][a][b] = min(dp[n + 1][a][b], dp[n][a][b])
            dp[n + 1][a + l[n][0]][b + l[n][1]] = min(dp[n + 1][a + l[n][0]][b + l[n][1]], dp[n][a][b] + l[n][2])
# np.set_printoptions(threshold=np.inf)
# print(dp)
for a in range(1, 10 * N):
    for b in range(1, 10 * N):
        if a * Mb == b * Ma:
            ans = min(ans, dp[n + 1][a][b])
if ans == float('inf'):
    print(-1)
else:
    print(int(ans))


Measured memory_bytes: 121948
/*#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC target("avx2")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>

//#define int long long

#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define endl '\n'


using namespace std;
typedef long long ll;
typedef long double ld;

mt19937 mrand(random_device{}());

const double PI = acos((double)-1);
const double eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;

void solve();
void scan();

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

void solve() {
	int n, k; cin >> n >> k;
	vector<bool> used(n);
	for (int i = 0; i < k; i++) {
		int d; cin >> d;
		while (d--) {
			int x; cin >> x; x--;
			used[x] = true;
		}
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (!used[i]) cnt++;
	}
	cout << cnt << endl;
	return;
}

Measured memory_bytes: 3664
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
long long a[3];
int main() {
    while (cin >> a[0] >> a[1] >> a[2]) {
        if(a[0]%2==0||a[1]%2==0||a[2]%2==0){
            cout<<"0"<<endl;
            continue;
        }
        sort(a,a+3);
        cout<<a[0]*a[1]<<endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

const int mod = 1e9+7;
#define ll long long int
const double epsilon = 1e-7;

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
int primes[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int counts[25];

int main(void){
    int n;
    scanf("%d", &n);
    for(int i = 0;i < 25;i++){
        int t = 1;
        for(int j = 1;j <= 6;j++){
            t *= primes[i];
            counts[i] += n/t;
        }
    }
    ll ans = 0;
    int c3 = 0, c5 = 0, c15 = 0, c25 = 0;
    int i = 0;
    while(counts[i] >= 2){
        if(counts[i] >= 2)c3++;
        if(counts[i] >= 4)c5++;
        if(counts[i] >= 14)c15++;
        if(counts[i] >= 24)c25++;
        i++;
    }
    //75
    if(counts[0] >= 74)ans++;
    //3*25
    ans += c25*(c3-1);
    //5*15
    ans += c15*(c5-1);
    //3*5*5
    ans += c5*(c5-1)*(c3-2)/2;
    printf("%lld\n", ans);
    //printf("c3 = %d, c5 = %d, c15 = %d, c25 = %d\n", c3, c5, c15, c25);
    //for(int i = 0;i < 8;i++)printf("%3d %3d %3d\n", counts[i*3], counts[i*3+1], counts[i*3+2]);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
 
typedef long long ll;
 
ll mod = 1000000007;
 
//nが素数かを判定する関数
bool prime(int n){
  bool x = true;
  for(int i=2;i*i<=n;i++)
    if(n%i==0) x = false;
  return x;
}
 
//a^pを求める関数
ll modpow(ll a,ll p){
  if(p==0) return 1;
  if(p%2==0){
    ll halfP = p/2;
    ll half = modpow(a,halfP);
    return half * half % mod;
  }
  else{
    return a * modpow(a,p - 1) % mod;
  }
}
 
//aCb mod 1000000007を求める
long comb(ll a,ll b){
  if(b>a-b) return comb(a,a-b);
  ll ansMul = 1;
  ll ansDiv = 1;
  for(int i=0;i<b;i++){
    ansMul *= (a-i);
    ansDiv *= (i+1);
    ansMul %= mod;
    ansDiv %= mod;
  }
  ll ans = ansMul * modpow(ansDiv,mod-2) % mod;
  return ans;
}
 
int main(){
  ll N,M,m;
  cin >> N >> M;
  ll i;
  ll count;
  ll ans = 1;
  for(i=2;i<=M;i++){
    if(M%i==0 && prime(i)){
      count = 0;
      while(M%i==0){
        M /= i;
        count++;
      }
      ans = ans * comb(count+N-1,count) % mod;
    }
  }
  cout << ans << endl;
}

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


int *PAR;	// 親の番号

typedef struct{
	int cost;
	int from;
	int to;
}SIDE_T;


int Ans_pivot(SIDE_T *box, int l, int r)
{
	int center;


	center = (l + r) / 2;

	if(box[l].cost < box[center].cost && box[center].cost < box[r].cost || box[r].cost < box[center].cost && box[center].cost < box[l].cost)
		return center;
	else if(box[center].cost < box[l].cost && box[l].cost < box[r].cost || box[r].cost < box[l].cost && box[l].cost < box[center].cost)
		return l;
	else
		return r;
}


int Partition(SIDE_T *box, int l, int r)
{
	int soeji, pivot;
	SIDE_T bk;
	int i = l - 1;
	int j = r;


	// 枢軸の決定
	soeji = Ans_pivot(box, l, r);
	bk = box[r];
	box[r] = box[soeji];
	box[soeji] = bk;
	pivot = box[r].cost;

	while(1){
		while(box[++i].cost < pivot);

		while(i < --j && pivot < box[j].cost);

		if(j <= i)
			break;

		bk = box[i];
		box[i] = box[j];
		box[j] = bk;
	}

	bk = box[i];
	box[i] = box[r];
	box[r] = bk;

	return i;
}


void Quick_sort(SIDE_T *box, int left, int right)
{
	int pivot;
	int i;


	if(right <= left)
		return;

	pivot = Partition(box, left, right);

	Quick_sort(box, left, pivot - 1);

	Quick_sort(box, pivot + 1, right);
}


// 配列の初期化
void Init(int n)
{
	int i;

	// 全ての要素は初めは自分自身が親
	for(i = 0; i < n; i++)
		PAR[i] = i;
}

// 親をみつける
int Find(int x)
{
	if(PAR[x] == x)
		return x;
	else{
		PAR[x] = Find(PAR[x]);	// 経路圧縮
		return PAR[x];
	}
}


// 親が同じか否か
int Same(int x, int y)
{
	if(Find(x) == Find(y))
		return 1;

	return 0;
}


// 違うグループ同士をくっつける
void Union(int x, int y)
{
	x = Find(x);
	y = Find(y);

	if(x == y)
		return;

	PAR[x] = y;
}


int Mark_check(int *box, int n)
{
	int i;


	for(i = 0; i < n; i++)
		if(box[i] == -1)
			return 0;

	return 1;
}


int main()
{
	int n;
	int in_data;
	int **graph, *_graph;
	int *mark;
	SIDE_T *side;
	int sum, count;
	int i, j;


	scanf("%d", &n);

	PAR = (int *)malloc(sizeof(int) * n);
	mark = (int *)malloc(sizeof(int) * n);
	for(i = 0; i < n; i++)
		mark[i] = -1;
	Init(n);

	side = (SIDE_T *)malloc(sizeof(SIDE_T) * n * n);

	_graph = (int *)malloc(sizeof(int) * n * n);
	graph = (int **)malloc(sizeof(int *) * n);
	for(i = 0; i < n; i++)
		graph[i] = _graph + (i * n);

	for(i = 0; i < n; i++)
		for(j = 0; j < n; j++)
			scanf("%d", &graph[i][j]);

	// 辺として取り出す
	count = 0;
	for(i = 0; i < n; i++){
		for(j = 0; j < n; j++){
			if(i <= j && graph[i][j] != -1){
				side[count].cost = graph[i][j];
				side[count].from = i;
				side[count++].to = j;
			}
		}
	}

	Quick_sort(side, 0, count - 1);
/*
	for(i = 0; i < count; i++)
		printf("from:%2d to%2d cost:%2d\n", side[i].from, side[i].to, side[i].cost);
*/

	sum = 0;
	for(i = 0; i < count; i++){
		if(Same(side[i].from, side[i].to) != 1){
			Union(side[i].from, side[i].to);
			sum += side[i].cost;
		}
		if(Mark_check(mark, n))
			break;
	}


	printf("%d\n", sum);

	return 0;
}


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

int main(){
    string s;
    cin >> s;
    vector<bool> alphabet(26,true);
    int num;

    for(int i=0; i<s.size(); i++){
        num=s.at(i)-'a';
        alphabet.at(num)=false;
    }
//    cout << num << endl;
    for(int i=0; i<27; i++){
        if(i<26){
            if(alphabet.at(i)){
            printf("%c\n", (char)(i + 'a'));
            break;
            }
        }
        else cout << "None" << endl;
    }
    
}

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

int main(void) {
    int N, M, X, count=0, A,left=0,right=0;
    cin >> N >>M >>X;
    vector<int> a(N+1);

    for(int i=0;i<M;i++){
      cin >> A;
      a[A] = 1;

    }

    for(int i=0;i<=N;i++){
        if(a[i]==1){
              if(i<=X){
                left++;
              }
              else{
                right++;
              }
        }
    }
    if(right>left){
      cout<< left << endl ;
    }
    else{
      cout<< right << endl ;
    }



    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val xyList = Array(n) { readLine()!!.split(" ").map(String::toInt).let { it[0] to it[1] } }

    fun calc(xi: Int, yi: Int, xj: Int, yj: Int): Double {
        return Math.sqrt(((xi - xj) * (xi - xj) + (yi - yj) * (yi - yj)).toDouble())
    }

    class Permutation<T> private constructor(
        private val baseIndex: Int,
        private var index: Int,
        val target: Array<T>?
    ) {
        private var subPermutation: Permutation<T>? = null

        constructor(objs: Array<T>) : this(0, 0, objs.clone())

        init {
            if (target == null || target.isEmpty()) {
                throw IllegalArgumentException("")
            }

            if (this.index < this.target.size - 1) {
                this.subPermutation = Permutation(this.baseIndex + 1, this.index + 1, this.target)
            }
        }

        operator fun next(): Boolean {
            if (this.subPermutation == null) {
                return false
            }
            val result = this.subPermutation!!.next()
            if (result) {
                return true
            }
            this.swap(this.baseIndex, this.index)
            ++this.index
            if (this.target!!.size <= this.index) {
                this.index = this.baseIndex
                return false
            }
            this.swap(this.index, this.baseIndex)
            return true
        }

        private fun swap(index1: Int, index2: Int) {
            val tmp = this.target!![index1]
            this.target[index1] = this.target[index2]
            this.target[index2] = tmp
        }
    }

    val permutation = Permutation((0 until n).toList().toTypedArray())
    var sum = 0.0
    do {

        val array = permutation.target!!
        for (i in 1 until n) {
            val pre = array[i - 1]
            val cur = array[i]

            val (xi, yi) = xyList[pre]
            val (xj, yj) = xyList[cur]

            sum += calc(xi, yi, xj, yj)
        }
    } while (permutation.next())


    //階乗
    fun factorial(i: Int): Long {
        return if (i == 1) {
            1
        } else {
            i * factorial(i - 1)
        }
    }

    println(sum / factorial(n))
}






Measured memory_bytes: 36952
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
using namespace std;

int main(){
  int n; cin >> n;
  if (n % 2 == 0) {
    cout << n << endl;
  } else {
    cout << n * 2 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a < b) swap(a, b);
	if (a%b != 0) return gcd(b, a%b);
	else return b;
}

int main() {
	ll a, b;
	cin >> a >> b;
	ll G = gcd(a, b);
	ll ans = 0;
	ll g = gcd(a,b);
	for (ll i = 2; i*i <= G; i++) {
		if (g%i == 0) {
			while (g%i == 0) g /= i;
			ans++;
		}
	}
	if (g != 1) ans++;
	cout << ans + 1 << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, m;
    cin >> n >> m;
    vl a(n);
    priority_queue<ll> pq;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        pq.push(a[i]);
    }
    for (int i = 0; i < m; ++i) {
        ll maxi = pq.top();
        pq.pop();
        pq.push(maxi / 2);
    }
    ll ret = 0;
    for (int i = 0; i < n; ++i) {
        ret += pq.top();
        pq.pop();
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>

int main(void){
    int n, i, f = 0;
    int a[3000];
    scanf("%d",&n);
    for(i = 0; i < n; i++){
        scanf("%d",&a[i]);
        f += a[i] - 1;        
    }
    printf("%d\n",f);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#pragma GCC optimize "-O3"
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned short us;
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll infll=(1ull<<63)-1;
const int inf=(1ull<<31)-1;
int a,b;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);cout.precision(18);
	cin>>a>>b;
	cout<<max(0,a-2*b);
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500*500)
n = int(input())
a = list(map(int, input().split()))
ans = 0

def dfs(i, p, sum):
    global ans
    if p == n:
        if sum % 2 == 0:
            ans += 1
    else:
        dfs(a[p], p+1, sum*a[p])
        dfs(a[p]+1, p+1, sum*(a[p]+1))
        dfs(a[p]-1, p+1, sum*(a[p]-1))

dfs(1, 0, 1)
print(ans)


Measured memory_bytes: 3064
//#include "bits/stdc++.h"
//using namespace std;
#include <stdio.h>
#include <assert.h>

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int main() {
  int N; scanf("%d", &N);
  int A[2][N + 1];
  for (int i{0}; i < 2; ++i) {
    for (int j{0}; j < N; ++j) {
      scanf("%d", &A[i][j]);
    }
  }

  int max{0};
  for (int i{0}; i < N; ++i) {
    int temp{0}, j{0};
    for (int j{0}; j <= i; ++j) temp += A[0][j];
    for (int j{i}; j < N; ++j) temp += A[1][j];
    if (max < temp) max = temp;
  }


  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <climits>
using namespace std;

unsigned long long to(string w , int base){
	unsigned long long ans = 0;
	for(int i = 0 ; i < w.size() ; i++) ans = ans * base + (w[i] >= 'A' ? w[i] - 'A' + 10 : w[i] - '0');
	return ans;
}

map<int,int> factor(int n){
	map<int,int> w;
	for(int i = 2 ; i*i<=n ; i++)
		while(n%i==0) w[i]++ , n /= i;
	if(n!=1) w[n]++;
	return w;
}
int main(){
	int n;
	string m;
	while(cin >> n >> m && n){
		unsigned long long v = to(m,n) , ans = -1;
		map<int,int> r = factor(n);
		for( map<int,int>::iterator it = r.begin() ; it != r.end() ; ++it){
			int a = it->first;
			int d = it->second;
			unsigned long long t = v;
			unsigned long long ok = 0;
			while(t){ ok += (t / a) ; t /= a;}
			ans = min(ok / d , ans);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MIN = -1e16;
int plm[] = {1, -1};

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<ll>> xyz(N, vector<ll>(3));
	for(int i=0;i<N;i++) {
		cin >> xyz[i][0] >> xyz[i][1] >> xyz[i][2];
	}
	
	vector<vector<vector<ll> > > dp(N+1, vector<vector<ll> >(M+1, vector<ll>(8, MIN)));
	for(int i=0;i<=N;i++)
		for(int j=0;j<8;j++)
			dp[i][0][j] = 0;

	for(int i=1;i<=N;i++) {
		for(int m=1;m<=M;m++) {
			int cnt = 0;
			for(int j=0;j<2;j++) {
				for(int k=0;k<2;k++) {
					for(int l=0;l<2;l++) {
						dp[i][m][cnt] = max(dp[i-1][m][cnt] ,dp[i-1][m-1][cnt] + plm[j] * xyz[i-1][0] + plm[k] * xyz[i-1][1] + plm[l] * xyz[i-1][2]);
						cnt++;
					}
				}
			}
		}
	}
	ll ans = LLONG_MIN;
	for(int i=0;i<8;i++) {
		ans = max(ans, dp[N][M][i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 102144
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const ll base = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    vector< ll> x, y;
    x.reserve(n);
    y.reserve(m);

    ll last;
    for (int i = 0; i < n; ++i) {
        ll a; cin >> a;
        if (i) {
            x.emplace_back(a - last);
        }
        last = a;
    }

    for (int i = 0; i < m; ++i) {
        ll a; cin >> a;
        if (i) {
            y.emplace_back(a - last);
        }
        last = a;
    }

    n--, m--;
    ll xsum = 0, ysum = 0;
    for(int i = 0; i < n; ++i) {
        ll now = x[i] * (n - i) % base * (i + 1) % base;
        (xsum += now) %= base;
    }

    for(int i = 0; i < m; ++i) {
        ll now = y[i] * (m - i) % base * (i + 1) % base;
        (ysum += now) %= base;
    }

    cout << (xsum * ysum) % base << endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0046
{
	class Program
	{
		static void Main(string[] args)
		{
			var height	= new List<float>();

			while( true ) {
				var	s = Console.ReadLine();
				if( s  == null ) {
					break;
				}
				height.Add( float.Parse( s ) );
			}
			
			var	max	= height.Max();
			var	min	= height.Min();
			Console.WriteLine( "{0:f3}", max - min );
		}
	}
}

Measured memory_bytes: 5960
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        String n = sc.next();
        char[]nn = n.toCharArray();

        for(int i=0; i<3; i++){               
            if(nn[i]=='1'){
                System.out.print('9'); 
            }else{
                System.out.print('1');                 
            }
 	    }
}
}

Measured memory_bytes: 21844
a = [int(input()) for i in range(5)]

time = 0
minMod = 10
for i in range(5):
    mod = a[i] % 10
    if(mod == 0):
        time += a[i]
    else:
        time += (1 + a[i] // 10) * 10
        if (mod < minMod):
            minMod = mod

print(time-10+minMod)






Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

string s, t;

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> s >> t;
    int res = 0;
    for (int i = 0; i < 3; i++) res += s[i] == t[i];
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
ll place[214514];
int main(){
	ll n,res=0;
	cin>>n;
	vector<ll> a;
	set<ll> used;
	for(ll i=1;i<=n;i++){
		ll x;
		cin>>x;
		a.pb(x);
		place[x]=i;
	}
	used.insert(0);
	used.insert(n+1);
	for(ll i=1;i<=n;i++){
		ll cur = place[i];
		set<ll>::iterator it =  used.upper_bound(cur);
		ll rig = *it;
		it--;
		ll lef = *it;
		res += i * (rig-cur) * (cur-lef);
		used.insert(cur);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 12784
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
const ll INF=1e18;
/*bool flag;
struct Mt{
	ll a[2][2];
	Mt(){
		memset(a,0,sizeof(a));
	}
}f,e;
ll mul(ll a,ll b){
	ll ans=a*b;
	if (ans<0) flag=1;
	if (ans>INF) flag=1;
	return ans;
}
Mt operator*(const Mt t1,const Mt t2){
	Mt ans;
	for (int i=0;i<2;++i){
		for (int j=0;j<2;++i){
			for (int k=0;k<2;++i){
				ans.a[i][j]+=mul(t1.a[i][k],t2.a[k][j]);
				if (ans.a[i][j]>INF) flag=1;
			}
		}
	}
}
Mt Pow(Mt a,ll k){
	Mt ans=e;
	for (Mt x=a;k;k>>=1,x=x*x) if (k&1) ans=ans*x;
	return ans;
}*/
int main(){
	/*flag=0;
	e.a[0][0]=1,e.a[0][1]=0,e.a[1][0]=0,e.a[1][1]=1;
	f.a[0][0]=0,f.a[0][1]=1,f.a[1][0]=2,f.a[1][1]=1;*/
	ll A=read(),B=read(),C=read(),k=read();
	if (k&1) cout<<B-A;
	else cout<<A-B;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

  int w,h,x,y,r,f;
  
  scanf("%d%d%d%d%d",&w,&h,&x,&y,&r);
  
  f=0;
  if(x+r>w)f=1;
  if(y+r>h)f=1;
  if(r>x)f=1;
  if(r>y)f=1;
  
  if(f==0)printf("Yes\n");
  else printf("No\n");
 
  
return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    int N = 100 / 0.01;
    rep(i, N) {
        int a = i*0.08;
        int b = i*0.1;
        if (a == A && b == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 764
N = int(input())
c = input()

R = c.count("R")
W = len(c) - R

if R == 0 or W == 0:
  print(0)
  exit()

L_W = 0
ans = R+W
for i in range(N+1):
  maxWR = max(L_W,R)
  if ans > maxWR:
    ans = maxWR
  if L_W == W:
    break
  if c[i] == "R":
    R -= 1
  else:
    L_W += 1

print(ans)

Measured memory_bytes: 9352
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> parse(string str) {
	vector<int> ret; int t = 0; str += ' ';
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == ' ') ret.push_back(t), t = 0;
		else t = t * 10 + str[i] - 48;
	}
	return ret;
}
int bitcount(int x) {
	int ret = 0;
	for (int i = 0; i < 31; i++) {
		if (x & (1 << i)) ret++;
	}
	return ret;
}
string s; double dp[4100][12];
int main() {
	while (s = "", getline(cin, s)) {
		vector<int> u = parse(s);
		vector<int> v(u.begin() + 1, u.end());
		int n = v.size();
		for (int i = 0; i < (1 << n); i++) {
			for (int j = 0; j < n; j++) dp[i][j] = 999999999.9;
		}
		for (int i = 0; i < n; i++) dp[1 << i][i] = v[i];
		for (int i = 1; i < (1 << n); i++) {
			if (bitcount(i) <= 1) continue;
			for (int j = 0; j < n; j++) {
				if (!(i & (1 << j))) continue;
				dp[i][j] = 999999999.9;
				for (int k = 0; k < n; k++) {
					if ((i & (1 << k)) && (j != k)) {
						double d1 = v[j] + v[k], d2 = abs(v[j] - v[k]);
						dp[i][j] = min(dp[i][j], dp[i - (1 << j)][k] + sqrt(d1 * d1 - d2 * d2));
					}
				}
			}
		}
		double ret = 999999999.9;
		for (int i = 0; i < n; i++) ret = min(ret, dp[(1 << n) - 1][i] + v[i]);
		cout << (ret <= u[0] + 1e-10 ? "OK" : "NA") << endl;
	}
}

Measured memory_bytes: 3492
x = input()
cs = 0
ct = 0
prev = ""
n = len(x)
cnt = 0
for i in range(n):
    if x[i] =="S":
        cs+=1
    elif x[i] =="T":
        if cs>0:
            ct+=1
    else:
        cs = 0
        ct = 0
    if cs>0 and ct>0:
        cnt+=1
        cs-=1
        ct-=1
print(n-cnt*2)


Measured memory_bytes: 3500
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
    minj = i
    for j in range(i, N):
        if A[j] < A[minj]:
            minj = j
    if i < minj:
        cnt += 1
        (A[i], A[minj]) = (A[minj], A[i])
print(" ".join(list(map(str, A))))
print(cnt)



Measured memory_bytes: 5604
n=int(input())
l=list(map(int,input().split()))
m=n//2
t=n%2+2
dp=[0]*t
for i in range(m):
    for j in range(t):
        dp[j]+=l[2*i+j]
    for j in range(1,t):
        dp[j]=max(dp[j],dp[j-1])
print(dp[-1])

Measured memory_bytes: 31648
#include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const vector<vector<int>> D = {
    {4, 0, 2, 3, 5, 1}, // N
    {2, 1, 5, 0, 4, 3}, // E
    {1, 5, 2, 3, 0, 4}, // S
    {3, 1, 0, 5, 4, 2}  // W
};

struct Dice {
  vector<int> face;

  Dice(vector<int> v) : face(v) {
  }

  void roll(char direction) {
    int dir;
    if (direction == 'N')
      dir = 0;
    if (direction == 'E')
      dir = 1;
    if (direction == 'S')
      dir = 2;
    if (direction == 'W')
      dir = 3;

    vector<int> tmp(6);
    rep(i, tmp.size()) tmp[D[dir][i]] = face[i];
    face = tmp;
  }

  int top() {
    return face.front();
  }
  int bottom() {
    return face.back();
  }
};

bool compare(Dice& d1, Dice d2) {
  bool identical = false;

  string direction1 = "NNNNENNNN";
  string direction2 = "EEEE";
  for (auto dir1 : direction1) {
    d2.roll(dir1);
    for (auto dir2 : direction2) {
      d2.roll(dir2);
      bool ok = true;
      rep(i, 6) if (d1.face[i] != d2.face[i]) ok = false;
      if (ok) {
        identical = true;
        break;
      }
    }
    if (identical)
      break;
  }
  return identical;
}

int main() {
  int n;
  cin >> n;
  vector<Dice> D;
  rep(i, n) {
    vector<int> v(6);
    rep(j, 6) cin >> v[j];
    D.emplace_back(v);
  }

  bool different = true;
  rep(i, n) for (int j = i + 1; j < n; j++) {
    if (compare(D[i], D[j]))
      different = false;
  }

  if (different)
    puts("Yes");
  else
    puts("No");
}


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

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; }
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;

//　定数, 変数 *********************************************
const ll MOD=1e9+7;
const ll INF=1ll<<60;

string S,T;

// *********************************************************
int main(){

    cin >>  S>> T  ;

    int ans = 1000;

    for(int i=0, len=S.length()-T.length(); i<=len; ++i){
        int k=0;
        for(int j=0, lenT=T.length(); j<lenT; ++j){
            if(S.at(i+j) != T.at(j)) ++k;
        }

        ans = min(ans,k);

    }

    cout << ans<<endl;

    return 0;
}

Measured memory_bytes: 3600
A = [list(map(int,input().split())) for _ in range(3)]
n = int(input())
bingo = False
def bingo_check(A,b):
	for i in range(3):
		for j in range(3):
			if A[i][j] == b:
				A[i][j] = -1
	return A

for i in range(n):
	s = int(input())
	A = bingo_check(A,s)

s,t = 0,0
for i in range(3):
	s += A[i][i]
	t += A[i][2-i]
if s == -3 or t == -3:
	bingo = True
if not bingo:
	for i in range(3):
		u,p = 0,0
		for j in range(3):
			u += A[i][j]
			p += A[j][i]
		if u == -3 or p == -3:
			bingo = True
if bingo:
	print('Yes')
else:
	print('No')


Measured memory_bytes: 3064
import scala.io.StdIn.{readInt,readLine}

object Main {
  def isSequence(h:Array[Long]) = {
    val diff = h(1)-h(0)
    def scan(i:Int):Boolean = {
      if(i==h.length) true
      else if(h(i)-h(i-1) != diff) false
      else scan(i+1)
    }
    scan(1)
  }

  def main(args:Array[String]):Unit = {
    println {
      Iterator.continually(readInt).takeWhile(_!=0).map { n=>
        val h = readLine.split(" ").map(_.toLong).toBuffer
        def scan(i:Int):Long= {
          val a = h.toBuffer
          a.remove(i)
          if(i==h.length) -1
          else if(isSequence(a.toArray)) h(i)
          else scan(i+1)
        }
        scan(0)
      }.mkString("\n")
    }
  }
}

Measured memory_bytes: 56512
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn main() {
    let input = read_stdin();
    let mut a = 0;
    let mut b = 1;
    for d in input.trim().bytes().rev().map(|b| (b - b'0') as isize) {
        let tmp_a = std::cmp::min(a + d, b + d + 1);
        let tmp_b = std::cmp::min(a + 10 - d, b + 9 - d);
        a = tmp_a;
        b = tmp_b;
    }
    println!("{}", std::cmp::min(a, b + 1));
}

Measured memory_bytes: 4352
K,A,B = map(int,input().split())
ans = 1

if (B-A) > 2:#交換すべき
    change = True
else:
    change = False

can = False
while(True):
    if change:
        if can:#交換可能
            multi = K//2
            K -= 2*multi
            ans += (B-A)*multi
            ans += K
            break
        else:
            if ans >= A:
                if (K-2) >= 0:
                    ans -= A
                    ans += B
                    K -= 2
                    can = True
                else:
                    ans += K
                    K -= K
                    break
            else:
                if ans + (K-2) >= A:
                    K -= (A-ans)
                    ans = B
                    K -= 2
                else:
                    ans += K
                    K -= K
                    break                
    else:
        ans += K
        K -= K
        break

print(ans)          

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

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

  while(1){
    cin>>n;
    if(!n)break;

    bool sch[30][51];
    set<int> max[51];

    for(int i=0;i<n;i++){
      for(int h=0;h<30;h++)
	sch[h][i]=false;
      max[i].insert(i+1);
    }

    for(int i=0;i<n;i++){
      cin>>s;
      for(int j=0;j<s;j++){
	cin>>t;
	sch[t-1][i]=true;
      }
    }

    set<int> maps;

    for(int i=0;i<30;i++){
      for(int j=0;j<n;j++){
	if(sch[i][j]){
	  maps.insert(max[j].begin(),max[j].end());
	  //for(int k=j;k<n;k++){
	  //if(sch[i][k]){
	  //cout<<i<<" "<<k<<endl;
	      //max[i].insert(max[k].begin(),max[k].end());
	      //max[k].insert(max[i].begin(),max[i].end());
	  //}
	  //}
	}
      }
      if(maps.size()==n){
	cout<<i+1<<endl;
	goto found;
      }

      for(int j=0;j<n;j++){
	if(sch[i][j])max[j].insert(maps.begin(),maps.end());
      }

      if(i==29)cout<<-1<<endl;
      maps.clear();
    }

  found:
    ;
  }
}

Measured memory_bytes: 972
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            int N = Integer.parseInt(s);

            int mx = 0;
            int x = 0;
            for (int i = 1; i <= N; i++) {
                int t = i;
                int c = 0;
                while (0 < t) {
                    if ((t & 1) == 1) break;
                    t = t >> 1;
                    c++;
                }
                if (mx <= c) {
                    mx = c;
                    x = i;
                }
            }

            System.out.println(x);
        }
    }
}


Measured memory_bytes: 21460
n = int(input())
_ = [list(map(int, input().split())) for _ in range(n)]
_.insert(0, [0, 0, 0])

dt = [_[i + 1][0] - _[i][0] for i in range(n)]
dx = [_[i + 1][1] - _[i][1] for i in range(n)]
dy = [_[i + 1][2] - _[i][2] for i in range(n)]

for i in range(n):
    man_d = abs(dx[i]) + abs(dy[i])
    if dt[i] >= man_d and (dt [i]- man_d) % 2 == 0:
        ans = "Yes"
    else:
        ans = "No"
        break

print(ans)

Measured memory_bytes: 31424
r,g,b,n = gets.chop.split.map(&:to_i)
ans = 0
(0..3000).each do |i|
  (0..3000).each do |j|
    if (i*r+j*g<=n) and ((n-i*r-j*g)%b==0)
      ans+=1
    end
  end
end
puts ans

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int INF=1e9+5;
const int N=2e5+5;
const int mod=1e9+7;

ll n;
vector<ll> v[N];
ll fac[N],finv[N],inv[N];
vector<ll> dp(N,-1);
ll sizee[N];
vector<ll> ans(N,-1);

void init(){
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(ll i=2;i<N;++i){
		fac[i]=fac[i-1]*i%mod;
		inv[i]=mod-inv[mod%i]*(mod/i)%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}

pair<ll,ll> solve(ll u,ll par){
	if(dp[u]!=-1) return pair<ll,ll>(dp[u],sizee[u]);
	ll res=1;
	vector<ll> sz;
	for(ll x:v[u]){
		if(x==par) continue;
		if(res==0) res=1;
		pair<ll,ll> p=solve(x,u);
		res=(res*p.first)%mod;
		sizee[u]+=p.second+1;
		sz.push_back(p.second+1);
	}
	res=(res*fac[sizee[u]])%mod;
	for(ll x:sz){
		// res/=fac[x]
		res=(res*finv[x])%mod;
	}
	dp[u]=res;
	return pair<ll,ll> (dp[u],sizee[u]);
}

ll poww(ll a,ll b){
	ll r=1;
	while(b){
		if(b&1) r=(r*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return r;
}

void dfs(ll u,ll par){
	ans[u]=dp[u];
	if(par!=-1){
		ans[u]=(ans[u]*(sizee[u]+1))%mod;
		ans[u]*=ans[par]*poww(dp[u],mod-2)%mod;
		ans[u]%=mod;
		ans[u]*=inv[n-1-sizee[u]];
		ans[u]%=mod;
	}
	for(ll x:v[u]){
		if(x!=par) dfs(x,u);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	init();
	cin>>n;
	for(ll i=0;i<n-1;++i){
		int x,y;
		cin>>x>>y;
		--x;
		--y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	solve(0,-1);
	dfs(0,-1);
	for(int i=0;i<n;++i) cout<<ans[i]<<" ";
	return 0;
}


Measured memory_bytes: 23680
<?php

class In {

	private $buf = [];
	private $count = 0;
	private $pointer = 0;

	public function nextLine() {
		$ret = '';
		if($this->hasNext()){
			while($this->hasNext()){
				$ret .= $this->next();
			}
		}else{
			$ret = trim(fgets(STDIN));
		}

		return $ret;
	}

	public function next() {
		if(!$this->hasNext()) {
			$str = trim(fgets(STDIN));
			$this->buf = explode(' ',$str);
			$this->count = count($this->buf);
			$this->pointer = 0;
		}

		return $this->buf[$this->pointer++];
	}

	public function hasNext() {
		return $this->pointer < $this->count;
	}

	public function nextInt() {
		return (int)$this->next();
	}

	public function nextDouble() {
		return (double)$this->next();
	}
}

class Out {
	public function println($str = '') {
		echo $str . PHP_EOL;
	}
}

$in = new In();
$out = new Out();

$a = $in->nextInt();
$b = $in->nextInt();
$c = $in->nextInt();

$ans = min(min($a+$b,$a+$c),$b+$c);

$out->println($ans);
?>


Measured memory_bytes: 4728
import re
pat = re.compile(r'(\-?\d+\.?\d*)\s(\-?\d+\.?\d*)\s([\+\-\*/])(?!\d)')

def revPolish(f):
    global pat
    f = pat.sub(lambda m: str(eval(m.group(1) + m.group(3) + m.group(2))),f)
    if f[-1] in '+-*/':
        return revPolish(f)
    else:
        return f

print(revPolish(input()))


Measured memory_bytes: 6592