akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define inf (1LL) << 30
using namespace std;
ll a[110][100010];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a,b;
	cin >> a >> b;
	a = "!" + a;
	b = "!" + b;
	ll c[a.size()][b.size()];
	for(ll i = 0;i < a.size();i++){
		for(ll j = 0;j < b.size();j++){
			if(i == 0 || j == 0){
				c[i][j] = 0;
			}
			else if(a[i] == b[j]){
				c[i][j] = c[i - 1][j - 1] + 1;
			}
			else{
				c[i][j] = max(c[i - 1][j],c[i][j - 1]);
			}
		}
	}
	//cout << c[a.size() - 1][b.size() - 1] << "\n";
	string lcs = "";
	ll i = a.size() - 1,j = b.size() - 1;
	while(i > 0 && j > 0){
		if(a[i] == b[j]){
			lcs += a[i];
			i--;
			j--;
		}
		else if(c[i - 1][j] > c[i][j - 1]) i--;
		else j--;
	}
	reverse(lcs.begin(),lcs.end());
	cout << lcs << "\n";
 	return 0;
}

Measured memory_bytes: 70656
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		int  page_num = sc.nextInt();
		if (page_num % 2 == 1) {
			System.out.println(page_num / 2 + 1);
		}else {
			System.out.println(page_num / 2);
		}
	}
}

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

using namespace std;
long long int n ,h[100003],f[100003];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i =1 ;i<= n ;i++)
    {
        cin>>h[i];
    }
    f[1] = 0;
    f[2] = abs(h[2] - h[1]);
    for(int i =3 ; i<= n ;i++)
    {
        f[i] = min(f[i-1] + abs(h[i] - h[i-1]) , f[i-2] +abs(h[i] - h[i-2]) );
    }
    cout<<f[n];
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;


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

int N;
cin >> N;
map<int, int> mp;
rep(i,N) {
    int a;
    cin >> a;
    mp[a]++;
}

int ans = 0;
for(auto x: mp) {
    int dist = x.second - x.first;
    if(dist >= 0) ans += dist;
    else ans += x.second;
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  string A = "Alice";
  string B = "Borys";
  if(abs(a-b)%2 == 0) cout << A << endl;
  else cout << B << endl;


  return 0;
}


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


def main():
    W, H, x, y = map(int,input().split())

    if x == W / 2 and y == H / 2:
        print((W * H) / 2, 1)
    else:
        print((W * H) / 2, 0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
x, n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()] if n != 0 else []
min_ = 100
cnt = 0
for i in range(100 + 2):
  if abs(i - x) < min_ and not i in a:
    min_ = abs(i - x)
    cnt = i
print(cnt)

Measured memory_bytes: 9152
#include <iostream>

int main()
{
	int A, B, T;
	double T05 = 0;
	std::cin >> A >> B >> T;
	int A_base = A;
	T05 = T + 0.5;

	int counter = 0;
	while ( A <= T05 )
	{
		counter += B;
		A += A_base;
	}

	std::cout << counter << std::endl;

	return ( 0 );
}


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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1000000000 + 7;
const int N = 1e6 + 5;

typedef long long ll;

ll n, a[N], d, ans;

inline void solve()
{
    cin >> n;
    d = n;
    n *= 3;
    for(int i = 1; i <= n; i ++)
        cin >> a[i];
    sort(a + 1, a + n + 1);
    for(int i = n - 1; d; i -= 2, d --)
        ans += a[i];
    cout << ans << endl;
}

int tests = 1;

int main()
{
//    scanf("%d", &tests);

    while(tests --)
        solve();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int W, H, N; cin >> W >> H >> N;
    vector<vector<int>> F(H, vector<int>(W,1));
    vector<int> L(110, 1);
    vector<int> R(110, 1);
    for (int i = 0; i < N; i++) {
        int x, y, a; cin >> x >> y >> a;
        if (a == 1) {
            for (int w = 0; w < x; w++) {
                R[w] = 0;
            }
        } else if (a == 2) {
            for (int w = x; w < W; w++) {
                R[w] = 0;
            }
        } else if (a == 3) {
            for (int h = 0; h < y; h++) {
                L[h] = 0;
            }
        } else if (a == 4) {
            for (int h = y; h < H; h++) {
                L[h] = 0;
            }
        }
    }

    int area = 0;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (R[w] && L[h]) area++;
        }
    }

    cout << area << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

char vi[1000001];
char can[1000001];
int vec[200000];

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

    for (int i = 0; i < n; i++) {
        scanf("%d", &vec[i]);
        if (!vi[vec[i]]) {
            vi[vec[i]] = 1;
            for (int j = vec[i]*2; j <= 1000000; j += vec[i])
                can[j] = 1;
        }
        else can[vec[i]] = 1;
    }

    int cnt = 0;
    for (int i = 0; i <n; i++) {
        cnt += !can[vec[i]];
    }

    printf("%d", cnt);
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    int c = a, cnt = 0;
    int d = 1;
    while(d < b) {
        d += a;
        --d;
        ++cnt;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <math.h>

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using PL = pair<ll, ll>;
using V = vector<int>;
using VL = vector<ll>;
using VD = vector<double>;

int main()
{
    int n;
    cin >> n;
    VD v(n, 0);
    REP(i, n)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    REP(i, n - 1)
    {
        v[i + 1] = (v[i] + v[i + 1]) * 0.5;
    }
    cout << v[n - 1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm.*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
// #define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define debug() cout << "Hi" << endl	// write debug(); in main()
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
/*		0. Go to main function first.
		1. Take all the inputs................................................
		2. Check Once whether the graph given is directed or undirected.......
		3. Tree can also be undirected.
		4. Whenever you do multiplication and division in the same line, beware.
*/
void solve(){
	//debug();
	// int main  or  int32_t main ...
	int a,b;
	cin >> a >> b;
	int m1 = (a*100)/8;
	int m2 = (b*10);
	int left = min(m1,m2);
	
	int n1 = ((a+1)*100)/8;
	int n2 = (b+1)*10;
	int right = max(n1,n2);
	
	bool pr = false;
	int ans = -1;
	for(int i=left;i <= right; ++i){
		int r1 = (i*8)/100;
		int r2 = i/10;
		if(r1==a && r2==b){
			pr = true;
			ans = i;
			break;
		}
	}
	if(pr)cout << ans << endl;
	else cout << -1 << endl;
}
/*	memset() can be used to set all values as 0 or -1 for integer data types.*/

int main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(12); std::cout << std::fixed;
	int t;
	// cin >> t;
	t = 1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

[A,B] = inpl()

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

ans_dq = deque([1])

c = gcd(A,B)
for i in range(2,int(c**0.5)//1+1):
    add_or_not = 0
    while c%i == 0:
        c = c//i
        add_or_not = 1
    if add_or_not: ans_dq.append(i)
if c != 1: ans_dq.append(c)

ans = len(ans_dq)
print(ans)

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

int A,B,C,X;

int main()
{       
        cin >> A;
        cin >> B;
        cin >> C;
        cin >> X;

        int ans = 0;
        
        for(int i=0;i<=A;i++){
                for(int j=0;j<=B;j++){
                        for(int k=0;k<=C;k++){
                                if(500*i+100*j+50*k == X){
                                        ans += 1;
                                }       
                        }       
                }       
        }       
        
        cout << ans << endl;
}       

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n, m, x;
  cin >> n >> m >> x;

  vector<ll> c(n);
  vector<vector<ll>> a(n, vector<ll>(m));
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  ll ans = INF;
  for (int i = 0; i < (1 << n); i++) {
    bitset<12> b(i);
    vector<ll> s(m, 0);
    ll sum = 0;
    for (int j = 0; j < 12; j++) {
      if (b[j]) {
        sum += c[j];
        for (int y = 0; y < m; y++) {
          s[y] += a[j][y];
        }
      }
    }

    bool ok = true;
    for (int j = 0; j < m; j++) {
      if (s[j] < x) {
        ok = false;
        break;
      }
    }

    if (ok && ans > sum) {
      ans = sum;
    }
  }

  if (ans == INF) {
    ans = -1;
  }

  cout << ans << ln;

  return 0;
}

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> g[10];
    for(int i = 0; i < n; i++){
        int c, x;
        cin >> c >> x;
        g[--x].push_back(c);
    }
    for(int i = 0; i < 10; i++){
        sort(g[i].rbegin(), g[i].rend());
    }
    for(int i = 0; i < 10; i++){
        for(int j = 1; j < g[i].size(); j++){
            g[i][j] += g[i][j-1];
        }
    }
    vector<int> dp(k+1, 0);
    for(int i = 0; i < 10; i++){
        vector<int> ndp = dp;
        for(int j = 0; j < min(k+1, (int)g[i].size()); j++){
            int val = g[i][j] + j*(j+1);
            for(int l = k; l-j-1 >= 0; l--){
                ndp[l] = max(ndp[l], dp[l-j-1] + val);
            }
        }
        dp = ndp;
    }
    cout << dp[k] << endl;
    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {
    int x; cin >> x;
    if (x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;    
   return 0;
}

Measured memory_bytes: 3616
import sys

input = sys.stdin.buffer.readline


class UnionFind:
    # あり本実装
    # rankとrootの配列を1つで賄う方法
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n

    # 根を求める
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 同じかどうかの判定
    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    # 集合の大きさ
    def size(self, x):
        return -self.find(x)

    # 　2つの集合の合体
    # 重みが大きい方に小さい方をつけるようにする
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False

        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
        return True


n, q = map(int, input().split())

UF = UnionFind(n)
for _ in range(q):
    t, u, v = map(int, input().split())
    if t:
        print(int(UF.is_same(u, v)))
    else:
        UF.unite(u, v)



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

// 210 5
// 31 41 59 26 53
const input: string[] = fs.readFileSync('/dev/stdin', 'utf8').split('\n');
const line1: string = input[0];
const line2: string = input[1];
let h: number = parseInt(line1.split(' ')[0], 10);
const n: number = parseInt(line1.split(' ')[1], 10);

const tech = line2.split(' ').map(n => parseInt(n, 10));
for (let i: number = 0; i < tech.length; i++) {
    h -= tech[i];
}

if (h <= 0) {
    console.log('Yes');
} else {
    console.log('No');
}



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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int W,H,T,P;
    cin>>W>>H>>T>>P;
    int x[50],y[50],t[50];rep(i,P)cin>>x[i]>>y[i]>>t[i];

    int s[50][50];
    rep(i,H)rep(j,W)cin>>s[i][j];
    int ans=0;
    rep(i,P){
        ans+=s[y[i]][x[i]];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3108
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            List<int> lstCs = new List<int>();
            bool Found = false;
            int aaa = A;
            while (true)
            {
                int Rest = aaa % B;
                if (Rest == C)
                {
                    Found = true;
                    break;
                }
                else
                {
                    if (lstCs.Contains(Rest))
                    {
                        Found = false;
                        break;
                    }
                    else
                    {
                        lstCs.Add(Rest);
                        aaa += A;
                    }
                }
            }

            if (Found)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <vector>
#include <cstdint>
#include <cstddef>
#include <string>

template<std::uint_fast64_t B = 9982433>
struct rolling_hash {
	using u32 = std::uint_fast32_t;
	using u64 = std::uint_fast64_t;
	using i128 = __int128_t;
	using size_type = std::size_t;

private :
	static constexpr u64 mod = (1UL << 61) - 1;
	static constexpr u64 base = B;

	std::vector<u64> hash, pow;

	u64 mul (const i128 &a, const i128 &b) const noexcept {
		i128 value = a * b;
		value = (value >> 61) + (value & mod);
		return (value < mod ? value : value - mod);
	}

	u32 xorshift (u32 value) const noexcept {
		value ^= value << 13;
		value ^= value >> 17;
		value ^= value << 5;
		return value;
	}

public :
	rolling_hash () = default;

	rolling_hash (const std::string &str) noexcept {
		build(str);
	}

	void build (const std::string &str) noexcept {
		const std::size_t n = str.length();
		hash.assign(n + 1, 0);
		pow.assign(n + 1, 1);
		for (std::size_t i = 0; i < n; i++) {
			hash[i + 1] = mul(hash[i], base) + xorshift(str[i] + 1);
			pow[i + 1] = mul(pow[i], base);
		}
	}

	u64 get(size_type first, size_type last) const noexcept {
		if (first > last) std::swap(first, last);
		u64 value = hash[last] + mod - mul(hash[first], pow[last - first]);
		return (value < mod ? value : value - mod);
	}

};



#include <bits/stdc++.h>

int main() {
	int n;
	std::string s;
	std::cin >> n >> s;
	
	rolling_hash rh(s);
	
	auto f = [&] (int x) -> bool {
		std::set<std::uint_fast64_t> set;
		for (int i = n - x; i >= 0; i--) {
			if (i + x + x <= n) set.emplace(rh.get(i + x, i + x + x));
			if (set.count(rh.get(i, i + x))) return true;
		}
		return false;
	};
	
	int ok = 0, ng = n;
	while (std::abs(ok - ng) > 1) {
		int mid = (ok + ng) >> 1;
		if (f(mid)) ok = mid;
		else ng = mid;
	}
	
	std::cout << ok << '\n';
	
	return 0;
}

Measured memory_bytes: 3912
#include<stdio.h>

main(){
	int n, x, count, i, j, k;
	
	while(1){
		scanf("%d%d",&n,&x);
		if(n==0&&x==0)break;
		
		count=0;
		
		for(i=1;i+2<=n;i++){
			for(j=i+1;j+1<=n;j++){
				for(k=j+1;k<=n;k++){
					if(i+j+k==x){
						if(i==j||i==k||j==k)count+=0;
						else count+=1;
					}
				}
			}
			
		}
		printf("%d\n",count);
		
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n, k;
	cin >> n >> k;
	vi a(n);
	rep(i, n) cin >> a[i];
	vi dp(k + 1);
	dp[0] = 0;
	rep1(i, k) {
		dp[i] = 0;
		rep(j, n) if(i - a[j] >= 0 && dp[i - a[j]] == 0) {
			dp[i] = 1;
			break;
		}
	}
	string ans;
	if(dp[k]) ans = "First";
	else ans = "Second";
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <string.h>
using namespace std;

int main(void) {

	string T, P;
	cin >> T;
	cin >> P;
	int array[P.size()];
	int pos = 0;
	bool flag = true;
	for (int i = 0; i < P.size(); i++)
		array[i] = 0;
#ifdef DEBUG
	for (int i = 0; i < P.size(); i++)
		cout << array[i] << endl;
#endif
	for (int i = 0; i < T.size(); i++) {
		if (P.size() < pos) {
			flag = false;
			break;
		}
		if (T[i] == P[pos]) {
			pos++;	
#ifdef DEBUG
	cout << pos-1 << endl;
	cout << P[pos-1] << endl;
#endif
		}					
		else if (pos) {
			if (T[i] == P[pos-1]) {
				array[pos-1]++;	
			}	
		}
	} 
#ifdef DEBUG
	cout << flag << endl;
#endif
	//?????????T.size < P.size ??¨???????????¨????????????
	//???????????¨????????????????????£?????´???
	//pos????????????P.size ??¨????????????
	if (flag && pos == P.size()) {
		bool f = true;
		for (int i = 0; i < P.size(); i++) {
#ifdef DEBUG
	cout << array[i] << endl;
#endif
			if (array[i] != 0)
				f = false;		
		}	
		if (f) {
			cout << "yes" << endl;
			return 0;
		}
	}
        cout << "no" << endl;
	return 0;
}

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

int main() {
  int N;
  std::string S;
  cin >> N >> S;

  int answer = 0;
  for (int i = 2; i < N + 1; i++) {
    std::string a = S.substr(0, i - 1);
    std::string b = S.substr(i - 1, N - i + 1);
    // cout << a << "," << b << endl;

    int counter = 0;
    std::unordered_set<char> cl;
    std::unordered_set<char> cr;
    for (auto c : a) { cl.insert(c); }
    for (auto c : b) {
      if (cl.find(c) != cl.end()) {
        cr.insert(c);
      }
    }
    for (auto c : cl) {
      if (cr.find(c) != cr.end()) {
        counter += 1;
      }
    }
    if (answer < counter) {
      answer = counter;
    }
  }
  cout << answer << endl;
  return 0;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
  vector<int> v(3);
  rep(i,3){
    cin >> v[i];
  }
  sort(v.begin(),v.end(),greater<int>());
  P(v[0]*10+v[1]+v[2]);
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n,m;

int main(){
    while(cin >> n >> m&&n){
        vector<ll> cnt(m,0);
        rep(i,n){
            ll d,v;
            cin >> d >> v;
            d--;
            cnt[d] = max(cnt[d],v);
        }
        ll ans = 0;
        rep(i,m)ans += cnt[i];
        cout << ans << endl;
    }
}


Measured memory_bytes: 3044
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

int dp[310][310],a[310][310],n;
ll pw[310];

int gauss() {
	int p=0;
	rep(i,0,n) {
		int fg=0;
		rep(j,p,n) if (a[j][i]) {
			rep(k,0,n) swap(a[p][k],a[j][k]); fg=1;
			break;
		}
		if (!fg) continue;
		rep(j,p+1,n) if (a[j][i]) {
			rep(k,0,n) a[j][k]^=a[p][k];
		}
		++p;
	}
	return p;
}
int main() {
	scanf("%d",&n); pw[0]=1;
	rep(i,1,n+1) pw[i]=pw[i-1]*2%mod;
	dp[0][0]=1;
	rep(j,0,n) rep(k,0,j+1) {
		dp[j+1][k+1]=(dp[j+1][k+1]+dp[j][k]*(pw[n]-pw[k]))%mod;
		dp[j+1][k]=(dp[j+1][k]+dp[j][k]*pw[k])%mod;
	}
	rep(i,0,n) rep(j,0,n) scanf("%d",&a[i][j]);
	int r=gauss(),ret=0;
	rep(i,r,n+1) ret=(ret+(ll)dp[n][i]*dp[i][r]%mod*powmod(2,n*n-i*n))%mod;
	ret=ret*powmod(dp[n][r],mod-2)%mod;
	if (ret<0) ret+=mod;
	printf("%lld\n",ret);
}


Measured memory_bytes: 896
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      int output = C - (A - B);
		if(output < 0){
          System.out.println(0);
        }else{
          System.out.println(output);
        }
	}
}

Measured memory_bytes: 21712
n = gets.to_i
ary = []

n.times do |i|
  xy = gets.chomp.split(" ").map(&:to_i)
  ary.push(xy)
end

#p ary,ary[2][1]

cmb = n*(n-1)/2
#p Math.sqrt(2) 
sum = 0

(n-1).times do |i|
  (n-i-1).times do |j|
    #p [i,j+i+1]
    x2 = (ary[i][0] - ary[j+i+1][0])**2
    y2 = (ary[i][1] - ary[j+i+1][1])**2
    xy2 = Math.sqrt(x2 + y2)
    #p [x2, y2, xy2]
    sum += xy2
  end
end

puts sum*(n-1)/cmb

Measured memory_bytes: 1788
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))

count = 0
L, R = "", ""

for i in range(Q):
  if Query[i][0] == "1": count += 1
  else:
    if Query[i][1] == "1":
      if count % 2 == 0: L = Query[i][2] + L
      else: R += Query[i][2]
    else:
      if count % 2 == 0: R += Query[i][2]
      else: L = Query[i][2] + L

if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1])

Measured memory_bytes: 43136
# Problem D - String Formation

from collections import deque

# input process
S = input().replace("\n", "")
S = deque(list(S))
Q = int(input()) # query number

# initialization
sento = 1

# process
for i in range(Q):
    query_num = input()
    # クエリが１の時
    if query_num[0]=="1":
        # 反転処理
        if sento==1:
            sento = 10
        elif sento==10:
            sento = 1
    elif query_num[0]=="2":
        n, f, c = query_num.split()
        f = int(f)
        if f==1: # 先頭追加処理
            # 先頭の位置によって変わる
            if sento==1:
                S.appendleft(c)
            elif sento==10:
                S.append(c)
        elif f==2: # 末尾追加処理
            if sento==1:
                S.append(c)
            elif sento==10:
                S.appendleft(c)

# output process
if sento==1:
    print("".join(S))
else:
    print("".join(list(S)[::-1]))


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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t); 

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

/*最小公倍数*/
ll lcm(ll a, ll b){
    return a*b/__gcd(a,b);
}

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}


int main(){

    string s; cin >> s;

    if(s[s.size()-1] == 's'){
        cout << s << "es" << endl;
    }
    else{
        cout << s << "s" << endl;
    }


    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

typedef  long long ll;

#define rep(i,a,n) for(ll (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(ll (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007


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;
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}


void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}

ll divisors(ll n) {
    vector<ll> res;

    for(ll i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i-1);
        if(n/i == i) continue;
        res.push_back((n/i)-1);
    }

    ll ans = 0;

    rep(i,0,res.size()){
        if(res[i] != 0)
        if(n/res[i] == n%res[i]) ans += res[i];
    } 
    return ans;
}

void solve(void){
   int n,i;
   cin >> n >> i;
   if(n % i != 0)
   cout << 1 <<endl;
   else cout << 0 << endl;
}

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

Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int x=0;
  list<string> s;
  string t,b;
  while(getline(cin,t),t!="END_OF_TEXT")
    s.push_back(t);
  list<string>::iterator y=s.begin();
  char c;
  while(cin>>c,c!='-'){
    switch(c){
    case 'a':
      x=0;
      break;
    case 'e':
      x=(*y).length();
      break;
    case 'p':
      x=0;
      if(y!=s.begin())
	--y;
      break;
    case 'n':
      x=0;
      ++y;
      if(y==s.end())
	--y;
      break;
    case 'f':
      if(x==(int)(*y).length()){
	++y;
	if(y==s.end())
	  --y;
	else
	  x=0;
      }else{
	++x;
      }
      break;
    case 'b':
      if(x){
	--x;
      }else{
	if(y!=s.begin()){
	  --y;
	  x=(*y).length();
	}
      }
      break;
    case 'd':
      if(x==(int)(*y).length()){
	list<string>::iterator it=y;
	++it;
	if(it!=s.end()){
	  (*y)+=(*it);
	  s.erase(it);
	}
      }else{
	(*y).erase(x,1);
      }
      break;
    case 'k':
      if(x==(int)(*y).length()){
	list<string>::iterator it=y;
	++it;
	if(it!=s.end()){
	  (*y)+=(*it);
	  s.erase(it);
	  b="\n";
	}
      }else{
	b=(*y).substr(x);
	(*y).erase(x);
      }
      break;
    case 'y':
      if(0){
      }else if(b==""){
      }else if(b=="\n"){
	string u=(*y).substr(x);
	(*y).erase(x);
	++y;
	y=s.insert(y,u);
	x=0;
      }else{
	(*y).insert(x,b);
	x+=b.length();
      }
      break;
    }
  }
  for(y=s.begin();y!=s.end();++y)
    cout<<*y<<endl;
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

int main()
{
    string s;
    int k;
    cin>>s>>k;
    int n=s.size();
    int c=0;
    string v;
    vector<string> ss(5*n,"zzzzzz");
    for(int i=0;i<n;i++){
        ss[c]=s[i];
        c++;
    }
    for(int i=0;i<n-1;i++){
        ss[c]=s[i];
        ss[c]+=s[i+1];
        c++;
    }
    for(int i=0;i<n-2;i++){
        ss[c]=s[i];
        ss[c]+=s[i+1];
        ss[c]+=s[i+2];
        c++;
    }
    for(int i=0;i<n-3;i++){
        ss[c]=s[i];
        ss[c]+=s[i+1];
        ss[c]+=s[i+2];
        ss[c]+=s[i+3];
        c++;
    }
    for(int i=0;i<n-4;i++){
        ss[c]=s[i];
        ss[c]+=s[i+1];
        ss[c]+=s[i+2];
        ss[c]+=s[i+3];
        ss[c]+=s[i+4];
        c++;
    }
    sort(all(ss));

    //for(int i=0;i<n*5;i++){
      //  cout<<ss[i]<<" ";
    //}

    int x=1;
    if(k==1){
        cout<<ss[0]<<endl;;
    }
    else{
    for(int i=1;i<c;i++){
        if(ss[i-1]==ss[i]){
            continue;
        }
        else{
            x++;
            if(x==k){
                cout<<ss[i]<<endl;
            }
        }
    }
    }
    
}


Measured memory_bytes: 1664
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}

#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll maxn=2010;
const ll mod=1e9+7;
const ll maxm=1e5+500;

int s[maxn*2][maxn*2];
int  t[maxn*2][maxn*2];
ll fac[maxm];
ll rfac[maxm];

ll ent(ll n,ll k){
	if(k<0 || k>n)return 0;
	return  (fac[n]*((rfac[k]*rfac[n-k])%mod))%mod;
}

ll poww(ll a,ll b){
	ll ans=1;
	while(b){
		if(b&1){
			ans=(ans*a)%mod;
		}
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}
int main(){
	fac[0]=1;
	for(ll i=1;i<maxm;i++){
		fac[i]=(fac[i-1]*i)%mod;
	}
	for(ll i=0;i<maxm;i++){
		rfac[i]=poww(fac[i],mod-2);
	}
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=0;i<n;i++){
		ll a,b;
		cin>>a>>b;
		s[-a+maxn][-b+maxn]++;
		t[+a+maxn][+b+maxn]++;
		ans-=ent(2*(a+b),2*a);
	}
	ans%=mod;
	ans+=mod;
	ans%=mod;

	for(ll i=1;i<maxn*2;i++){
		for(ll j=1;j<maxn*2;j++){
			s[i][j]+=(s[i-1][j]+s[i][j-1])%mod;
			s[i][j]%=mod;
			ans+=((ll)s[i][j]*(ll)t[i][j])%mod;
			ans%=mod;
		}
	}
	cout<<(ans*poww(2,mod-2))%mod;
}




















Measured memory_bytes: 96896
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

long long fifth(long long A) {
    return A * A * A * A * A;
}


int main() {

    long long X;
    cin >> X;

    long long A = 1;
    map<long long, long long> m;
    m.insert(make_pair(0, 0));

    while (true) {
        m.insert(make_pair(fifth(A), A));
        decltype(m)::iterator it = m.find(fifth(A) - X);
        if (it != m.end()) {
            cout << A << " " << m[fifth(A) - X] << endl;
            return 0;
        }
        it = m.find(X - fifth(A));
        if (it != m.end()) {
            cout << A << " " << m[X - fifth(A)] * (-1) << endl;
            return 0;
        }
        A++;
    }
    
    return 0;
}

Measured memory_bytes: 3540
a, b, c, d, e, f = map(int, input().split())
s = set()
for i in range(30 // a + 1):
    for j in range(30 // b + 1):
        if 0 < (a * i + b * j) * 100 <= f:
            s = s | {a * i + b * j}
s2 = set()
for i in range(3000 // c + 1):
    for j in range(3000 // d + 1):
        if c * i + d * j <= f:
            s2 = s2 | {c * i + d * j}
ans = []
for i in s:
    for j in s2:
        if i * 100 + j <= f and j <= i * e:
            ans.append([j / i * -1, i * 100 + j, j])
ans.sort()
print(ans[0][1], ans[0][2])

Measured memory_bytes: 10404
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

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

    std::string S;
    std::cin >> S;

    int lr = 0;
    int rl = 0;
    int neg_lr = 0;
    int neg_rl = 0;

    for (int i = 0; i < N; ++i) {
        // l -> r
        if (S[i] == '(') {
            lr++;
        }
        else {
            if (lr == 0) {
                neg_lr++;
            }
            else {
                lr--;
            }
        }

        // l <-- r
        if (S[N-1 -i] == ')') {
            rl++;
        }
        else {
            if (rl == 0) {
                neg_rl++;
            }
            else {
                rl--;
            }
        }
    }

    std::cout << std::string(neg_lr, '(') << S << std::string(neg_rl, ')') << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int h,a,sum=0;
    cin>>h>>a;
    for (int i=0;i<a;i++)
    {
        int e;
        cin>>e;
        sum+=e;
    }
    if (sum>=h)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
degree = [ 0 ] * 4
for _ in range(3):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    degree[a] += 1
    degree[b] += 1
odd = len(list(filter(lambda x: x % 2 == 1, degree)))
print(['NO', 'YES'][odd <= 2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n;
long long W;
const long long INF = 1e16;

long long dp[110][100100];
int main() {
    cin >> n >> W;
    vector<long long> w(n, 0);
    vector<int> v(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> w.at(i) >> v.at(i);
    }

    int Vmax = n*1000;
    for(int i = 0; i <= n; ++i) {
        for(int j = 0; j <= Vmax; ++j) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= Vmax; ++j) {
            dp[i+1][j+v.at(i)] = min(dp[i+1][j+v.at(i)], dp[i][j]+w.at(i));
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }

    long long ans = 0;
    for(int j = 0; j <= Vmax; ++j) {
        if(dp[n][j] <= W) {
            ans = j;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 80128
def t(n):
  result = 1
  for i in range(2, int(-(-n**0.5//1))+1):
    if n%i == 0:
      result = i
  return result

def main():
  x = int(input())
  a = t(x)
  b = x // a
  result = a - 1 + b - 1
  return result
print(main())

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SC second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll cnt = 0;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}


int main()
{
  int n ;
  cin >> n ;
  vector<string> name(n) ;
  vector<ll> fi(5) ;
  ll ans = 0 ;
  
  REP(i,n){
    cin >> name.at(i) ;
    if(name.at(i).at(0)=='M'){
      fi.at(0)++ ;
    }
    else if(name.at(i).at(0)=='A'){
      fi.at(1)++ ;
    }
    else if(name.at(i).at(0)=='R'){
      fi.at(2)++ ;
    }
    else if(name.at(i).at(0)=='C'){
      fi.at(3)++ ;
    }
    else if(name.at(i).at(0)=='H'){
      fi.at(4)++ ;
    }
  }
  
  REP(i,3){
    FOR(j,i+1,4){
      FOR(k,j+1,5){
        ans += fi.at(i)*fi.at(j)*fi.at(k) ;
      }
    }
  }
  
  cout << ans <<endl ;

  return 0 ;
}



Measured memory_bytes: 6144
program main
	implicit none
	integer(8):: N,i,j,t,k
	character a*100, b*100,d*3
	read *, N
	read *, a
    d="..."
	if(len_trim(a)<=N)print'(a)',a
	
	if(len_trim(a)>N)then
	b(1:N)=a(1:N)
	b(N+1:N+3)=d(1:3)
	print'(a)',b(1:N+3)
	end if
	
end program main

Measured memory_bytes: 2908
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
const int Inf = 1e9 + 5;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0); 
    int n, x, y;
    cin >> n >> x >> y;
    vector<vector<int>> dis(n + 1, vector<int> (n + 1));
    vector<int> freq(n);
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            dis[i][j] = min({j - i, 1 + abs(x - i) + abs(y - j), 1 + abs(x - j) + abs(y - i)});
            freq[dis[i][j]]++;
        }
    }
    for (int i = 1; i < n; i++) {
        cout << freq[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 16000
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>

std::string query(size_t v) {
  printf("%zu\n", v+1);
  fflush(stdout);
  char buf[8];
  scanf("%s", buf);
  std::string reply = buf;
  return reply;
}

void game(size_t n) {
  if (n <= 10) {
    for (size_t i = 0; i < n; ++i) {
      if (query(i) == "Yes") return;
    }
    assert(false);
  }

  size_t res = 0;
  for (size_t i = 1; i < n; i <<= 1) {
    auto reply = query(i);
    if (reply == "Yes") return;
    if (reply == "Near") res |= i;
  }
  query(res);
  return;
}

int main() {
  size_t n, k;
  scanf("%zu %zu", &n, &k);

  std::vector<std::pair<size_t, size_t>> es;
  for (size_t i = 0; i < n; ++i)
    for (size_t j = 1; j < i; j <<= 1)
      if (i & j)
        es.emplace_back(i, j);

  printf("%zu\n", es.size());
  for (const auto& e: es)
    printf("%zu %zu\n", e.first+1, e.second+1);

  for (size_t i = 0; i < k; ++i)
    game(n);
} 



Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
int in[110],n,pre[110],anw=1e9;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>in[i];
    for(int i=1;i<=n;i++) pre[i]=pre[i-1]+in[i];
    for(int i=1;i<n;i++) anw=min(anw,abs(pre[i]-(pre[n]-pre[i])));
    cout<<anw;
}


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

namespace AtCoder
{
	public class Program
	{
		static void Main(string[] args)
		{
			int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
			int w = vs[0];
			int h = vs[1];
			int x = vs[2];
			int y = vs[3];

			double area = ((double)w) * ((double)h) / 2.0;
			int f = w % 2 == 0 && h % 2 == 0 && (w / 2) == x && (h / 2) == y ? 1 : 0;
			Console.WriteLine($"{area} {f}");
		}
	}
}


Measured memory_bytes: 13268
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let m: usize = sc.read();
    println!("{}", lcm(n, m));
}

fn lcm(a: usize, b: usize) -> usize {
    let g = gcd(a, b);
    a / g * b
}

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main() {
    int A, B, C, X, ans = 0;
    cin >> A >> B >> C >> X;
    for (int a = 0; a <= A; a++)
        for (int b = 0; b <= B; b++)
            for (int c = 0; c <= C; c++)
                if (500 * a + 100 * b + 50 * c == X) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
 int n;
 scanf("%d", &n);
 int a[n];
 int i, ans = 0;
 for(i = 0; i < n; i++)
  scanf("%d", &a[i]);
 for(i = 1; i < n - 1; i++)
  if((a[i - 1] >= a[i] && a[i] >= a[i + 1]) || (a[i - 1] <= a[i] && a[i] <= a[i + 1]))
   ans++;
 printf("%d\n", ans);
}

Measured memory_bytes: 128