akhauriyash/Code-Regression huggingface dataset:
#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;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
int A[N];
int n , m;

void solve()
{
	int x, k ,d;
	cin >> x >> k >> d;

	// if(x == d)
	// {
	// 	if(k%2)cout << 0 ;
	// 	else cout << x;
	// 	return;
	// }
	int ok = 0;

	if(x < 0)
	{
		ok = 1;
		x = (-1)*x;
	}

	int rt = (x/d);

	if(rt >= k)
	{
		cout << x - k*(d);
	}
	else 
	{
		// cout << min(x-rt*d , abs(x - (rt+1)*d));
		if((k-rt)%2)cout << (rt+1)*d -x;
		else cout << x - rt*d;
	}

	// cout << ans;
}			
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i < int(n); ++i)
#define repx(i, x, n) for (int i = int(x); i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) ((a) <= (x) && (x) < (b))
#define OUT(a, x, b) ((x) < (a) || (x) < (b))
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const ll MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    int N = s.size();
    int g_cnt = 0, p_cnt = 0;

    rep(i, N)
    {
        char c = s[i];
        if (c == 'g')
            g_cnt++;
        else
            p_cnt++;
    }

    cout << int(N / 2) - p_cnt << endl;

    return 0;
}


Measured memory_bytes: 512
ABC = [int(i) for i in input().split()]

ABC.sort()
# print(ABC)

ans = 0

dif_AB = ABC[2] - ABC[0]
dif_AC = ABC[2] - ABC[1]

if dif_AB % 2 == 0:
    ABC[0] = ABC[2]
else:
    ABC[0] = ABC[2] - 1
ans += dif_AB // 2

if dif_AC % 2 == 0:
    ABC[1] = ABC[2]
else:
    ABC[1] = ABC[2] - 1
ans += dif_AC // 2

# print(ABC)
# print(ans)

dif_AB = ABC[2] - ABC[0]
dif_AC = ABC[2] - ABC[1]

if ABC[0] == ABC[1] and ABC[1] == ABC[2]:
    pass
elif dif_AB == 1 and dif_AC == 1:
    ans += 1
else:
    ans += 2
print(ans)


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

int main() {
  int w, h;
  cin >> w >> h;
  vector<int> a(w), b(h);
  int i, j;
  for (i = 0; i < w; i++) {
    cin >> a[i];
  }
  for (i = 0; i < h; i++) {
    cin >> b[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  for (i = 0; i < w; i++) {
    sort(b.begin(), b.end(), greater<int>());
    for (j = 0; j < b.size(); j++) {
    }
    for (j = 0; j < a[i]; j++) {
      if (b[j] == 0) {
        cout << 0 << endl;
        return 0;
      }
      b[j]--;
    }
  }
  for (i = 0; i < b.size(); i++) {
    if (b[i] != 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}



Measured memory_bytes: 3180
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let s = input::<String>();

    let c0 = s.chars().filter(|c| *c == '0').count();
    let c1 = s.len() - c0;
    let ans = 2 * std::cmp::min(c0, c1);
    println!("{}", ans);
}


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

namespace DPL2_A
{
    class Program
    {
        const int INF = 1 << 30;
        const int MAX = 15;
        static int n;
        static int[,] d = new int[MAX, MAX];
        static int[,] dp = new int[1 << MAX, MAX];
        static void solve()
        {
            for (int i = 0; i < 1 << n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    dp[i, j] = INF;
                }
            }
            dp[(1 << n) - 1, 0] = 0;

            for (int S = (1 << n) - 2; S >= 0; S--)
            {
                for (int v = 0; v < n; v++)
                {
                    for (int u = 0; u < n; u++)
                    {
                        if ((S >> u & 1) == 0 && d[v,u] != INF)
                        {
                            dp[S, v] = Math.Min(dp[S, v], dp[S | 1 << u, u] + d[v, u]);
                        }
                    }
                }
            }
            Console.WriteLine(dp[0,0] == INF ? -1 : dp[0,0]);
        }
        static void Main(string[] args)
        {
            var t = scan;
            n = t[0];
            int e = t[1];

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    d[i, j] = INF;
                }
            }
            for (int i = 0; i < e; i++)
            {
                var k = scan;
                d[k[0], k[1]] = k[2];
            }

            solve();
        }


        static int[] scan
        {
            get { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
        }
    }
}

Measured memory_bytes: 11644
#include <stdio.h>
int a[10000][10000];
int d[10000];
int p[10000];
int q[10000];
int main(){
    int n, i, j, t, u, v,c=0;
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++){
            a[i][j]=1000000000;
            if(i == j) a[i][j] = 0;
        }
    for(i = 0; i < n; i++) {
        scanf("%d", &j);
        scanf("%d", &c);
        for(j = 0; j < c; j++) {
            scanf("%d %d", &t, &u);
            a[i][t] = u;
        }
        d[i] = 1e9;
        q[i] = 0;
    }
    d[0] = 0;
    c = 0;
    while(c != n) {
        t = 0;
        j = 1000000001;
        for(i = 0; i < n;i++) {
            if(!q[i]&&d[i] < j) {
                t = i;
                j = d[i];
            }
        }
        q[t] = 1;c++;
        for(i = 0; i < n; i++) {
            if(a[t][i] != 1000000000) {
                if(d[i] > d[t] + a[t][i]) {
                    d[i] =  d[t] + a[t][i];
                }
            }
        }
    }
    for(i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
    return 0;
}



Measured memory_bytes: 3028
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

struct dat {
    int id;
    int z;

    dat () {}
    ~dat () {}

    dat (int a, int b): id(a), z(b) {}
    
    bool operator < (const dat& o) const {
        return z < o.z;
    }
};

int N, M;
int tx[5000], ty[5000];

dat arr_x[5000];
dat arr_y[5000];

int check[5000];

int solve(int x1, int y1, int x2, int y2) {
    fill(check, check + N, 0);

    for (dat* itx = lower_bound(arr_x, arr_x+N, dat(-1, x1));
            itx < arr_x+N && itx->z <= x2; ++itx) {
        ++ check[ itx->id ];
    }

    int ans = 0;
    for (dat* ity = lower_bound(arr_y, arr_y+N, dat(-1, y1));
            ity < arr_y+N && ity->z <= y2; ++ity) {
        ans += check[ ity->id ];
    }

    return ans;
}

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

    cin >> N >> M;
    for (int j = 0; j < N; ++j) {
        cin >> tx[j] >> ty[j];
    }

    // initialize
    for (int j = 0; j < N; ++j) {
        arr_x[j] = dat(j, tx[j]);
        arr_y[j] = dat(j, ty[j]);
    }
    sort(arr_x, arr_x + N);
    sort(arr_y, arr_y + N);

    for (int j = 0; j < M; ++j) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        cout << solve(x1, y1, x2, y2) << endl;
    }
    return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  int a[3], b[3];
  map<int, int> mp;
  REP(i, 3){
    cin >> a[i] >> b[i];
    mp[a[i]]++;
    mp[b[i]]++;
  }
  REP(i, mp.size()){
    if(mp[i] == 3){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll c = 1; c <= n; c++) {
    ll num = n/c;
    ans += c * (num)*(num+1)/2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
n = int(input())
     
f = [int(input().replace(" ", ""), 2) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
     
ans = float('-inf')
     
for i in range(1, 1024):
    price = 0
    for j in range(n):
        price += p[j][bin(i & f[j]).count('1')]
    ans = max(ans, price)
     
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

    int tmpH;
    cin >> tmpH;
    int result = 1;
    for(int i=1;i<N;i++){
        int tmp;
        cin >> tmp;
        if(tmp >= tmpH){
            tmpH = tmp;
            result++;
        }
    }

    cout << result << "\n";
	return 0;
}

Measured memory_bytes: 256
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    P = set(map(int, input().split()))
    if x not in P:
        print(x)
    else:
        ax = x
        while ax in P:
            ax += 1
        
        mx = x
        while mx in P:
            mx -= 1

        if abs(x-ax) < abs(x-mx):
            print(ax)
        else:
            print(mx)


Measured memory_bytes: 9196
while n = gets.to_i
menu1=Hash.new{|item,price|}
menu2=Hash.new{|item,price|}
	break if n==0
	n.times{
    	item,price= gets.chomp.split(" ")
		menu1[item]= price.to_i
	}
	m = gets.to_i
	m.times{
		recipt1 = gets.chomp.split(" ")
		recipt2 = recipt1.dup
		recipt2.shift
		recipt2.shift
		recipt2=recipt2.map{|i| menu1[i]}
		
		if menu1[recipt1[0]]>recipt2.inject{|sum,n| sum+n}
			menu1[recipt1[0]]=recipt2.inject{|sum,n| sum+n}
		end
	}
create=gets.chomp
puts menu1[create]

end

Measured memory_bytes: 8788
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<int> vec(128);
  for (int i = 0; i < s.size(); i++) vec[s[i]]++;
    for (int j = 97; j < 123; j++) {
      if (vec[j] == 0) {
        cout << char(j) << endl;
        return 0;
      }
    }
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(ll &f){
	f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
struct submission{
	ll id;
	string s;
};
submission a[DMAX];
ll n,m;
ll ans=0;
bool vst[DMAX];
ll prob[DMAX];
ll pen=0;
int main(){
	read(n),read(m);
	for(ll i=1;i<=m;i++){
		read(a[i].id);
		cin>>a[i].s;
	}
	for(ll i=1;i<=m;i++){
		if(vst[a[i].id]){
			continue;
		}
		else{
			if(a[i].s=="AC"){
				vst[a[i].id]=1;
				pen+=prob[a[i].id];
				ans++;
			}
			else{
				prob[a[i].id]++;
			}
		}
	}
	cout<<ans<<" "<<pen<<endl;
	return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>

int main(void) {

  int max1 = 0 , max2 = 0 , max3 = 0;

  int i;
  for(i = 1; i <= 10; i++){
    int num;
    scanf("%d", &num);
    if(num > max1){
      max3 = max2;
      max2 = max1;
      max1 = num;
    }
    else if(num >max2){
      max3 = max2;
      max2 = num;
    }
    else if(num > max3){
      max3 = num;
    }
  }

  printf("%d\n" , max1);
  printf("%d\n" , max2);
  printf("%d\n" , max3);


  return 0;
}


Measured memory_bytes: 2100
#include <stdio.h>

int main(void) {
    int a,b,c;
    
    scanf("%d %d %d",&a,&b,&c);
    
    if(a == b && b == c)
        printf("%d\n",1);
    else if(a==b||b==c||c==a)
        printf("%d\n",2);
    else
        printf("%d\n",3);
    
    return 0;
        
}

Measured memory_bytes: 128
N = gets.to_i
ABs= readlines.map{|l| l.split.map(&:to_i)}

G = Hash[(ABs + ABs.map{|a, b| [b, a]}).group_by(&:first).map{|k, v| [k, v.map(&:last)]}]
b, w, h = G[1], G[N], {1 => :b, N => :w}
until (b + w).empty?
  b = b.reject{|i| h.key?(i)}.each{|i| h[i] = :b}.flat_map{|i| G[i]}
  w = w.reject{|i| h.key?(i)}.each{|i| h[i] = :w}.flat_map{|i| G[i]}
end
puts h.values.count(:b) > N/2 ? 'Fennec' : 'Snuke'

Measured memory_bytes: 67932
from heapq import heapify, heappushpop
N, *A = map(int, open(0).read().split())
def f(L):
    q = L[:N]
    heapify(q)
    s = sum(q)
    yield s
    for e in L[N:2 * N]:
        s += e - heappushpop(q, e)
        yield s
print(max(map(sum, zip(f(A), list(f([-a for a in A[::-1]]))[::-1]))))

Measured memory_bytes: 36308
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)((n>>m)&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,s[500][500];
int main(){
	scanf("%lld",&n);
	ll sum=0,cnt=0;
	while((sum+cnt+1)<=n)sum+=++cnt;
	if(sum!=n){
		puts("No");
		return 0;
	}
	
	ll crr=0;
	rep(i,0,cnt)rep(j,0,i+1)s[i+1][j]=s[j][i]=++crr;	
	
	puts("Yes");
	printf("%lld\n",cnt+1);
	rep(i,0,cnt+1){
		printf("%lld ",cnt);
		rep(j,0,cnt)printf("%lld ",s[i][j]);
		puts("");
	}
}



Measured memory_bytes: 3072
n = int(input())

dp = [[0] * 3 for i in range(n)]


a = [list(map(int, input().split())) for i in range(n)]

for i in range(3):
    dp[0][i] = a[0][i]

for i in range(n - 1):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i + 1][j]= max(dp[i + 1][j], dp[i][k] + a[i + 1][j])
            else:
                continue
                
print(max(max(dp[n - 1][0], dp[n - 1][1]),dp[n - 1][2]))


Measured memory_bytes: 50200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a)>abs(x-b)){
        cout << "B" << endl;
    }else{
        cout << "A" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector> 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
#define pb push_back
#define popb pop_back
#define si size()
#define sof sizeof()
#define be begin()
#define en end()
#define all(v) v.be,v.en
#define le length()
#define mp make_pair 
#define mt make_tuple
#define F first
#define S second
#define ump unordered_map
#define forr(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define maxe *max_element
#define mine *min_element
#define hii ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
#define o(a) cout<<a<<" "
#define ol(a) cout<<a<<"\n"
#define o2(a,b) cout<<a<<" "<<b<<"\n"
#define o3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
#define mod 998244353
using namespace std;
int main() 
{ 
    lli n;
    cin>>n;
    lli a[n];
    forr(i,0,n)cin>>a[i];
    ump<lli,lli> m;
    set<lli> s;
    forr(i,0,n){
        m[a[i]]++;
        s.insert(a[i]);
    }
    lli ans=0;
    for(auto x: s){
        if(m[x]>1){
            ans+=(m[x]*(m[x]-1))/2;
        }
    }
    forr(i,0,n){
        //if(m[a[i]]>2){
            cout<<ans-(m[a[i]]-1)<<endl;
        //}
    }
    
    
    
    
    
    
    
} 


Measured memory_bytes: 15048
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define nt _int128
#define mod 1000000007
ll arr[100005],n,k;
ll dp[3][100005];
ll func(int chan,ll p)
{
    if(p==0)
        return 0;
    else if(dp[chan][p]!=-1)
        return dp[chan][p];
    bool flag=true;
    for(ll i=1;i<=n;i++)
    {
        if(arr[i]<=p)
        {
            flag=flag and func(1-chan,p-arr[i]);
        }
    }
    return dp[chan][p]=1-int(flag);
}
int main()
{
// #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    // cin >> t;
    t  = 1;
    while(t--)
    {
        
        cin>>n>>k;
        memset(dp,-1,sizeof(dp));
        for(ll i=1;i<=n;i++)
            cin>>arr[i];
        int x=func(true,k);
        if(x==1)
            cout<<"First";
        else
            cout<<"Second";
    }
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(long long i = a; i < (b); ++i)
typedef long long ll;
const int maxn = 234567;
int a[maxn], v[maxn];
int main(){
     int n; cin >> n;
    
     for(int i = 1; i <= n; i++) cin >> a[i];
     vector<int> good;
     for(int i = n; i >= 1; i--){
         int sum = 0;
         for(int j = i + i; j <= n; j += i) sum ^= v[j];
         v[i] = sum ^ a[i];
         if(v[i]) good.push_back(i);
     }
     cout << good.size() << endl;
     for(int v : good) cout << v << " ";
     cout << endl;
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int dp[10001];

int main(){
  int n,w;cin>>n>>w;
  rep(i, n){
    int cv, cw;cin>>cv>>cw;
    rep1(tw, w) if(tw-cw>=0)dp[tw] = max(dp[tw], dp[tw-cw] + cv);
  }
  
  cout<<dp[w]<<endl;

  return 0;
}



Measured memory_bytes: 3144
#include <stdio.h>

int main(void) {
	char S[1024];
	int count[26] = {0};
	int i;
	int asumikana = 0;
	if (scanf("%1023s", S) != 1) return 1;
	for (i = 0; S[i] != '\0'; i++) {
		int which = S[i] - 'a';
		if (0 <= which && which < 26) count[which]++;
	}
	for (i = 0; i < 26; i++) {
		if (count[i] % 2 != 0) asumikana++;
	}
	printf("%d\n", asumikana / 2);
	return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    while(true){
        int count=0;
        scanf("%d%d",&n, &x);
        if(n==0 && x==0)break;
        for(int i=1;i<=n;i++){
            for(int j=i;j<=n;j++){
                for(int k=j;k<=n;k++){
                    if((i!=j && j!=k && i!=k) && (i+j+k==x))count++; 
                }
            }    
        }
        cout << count << endl;
    }
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int n, k;
	cin >> n >> k;
	cout << !!(n % k) << "\n";
}

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


Measured memory_bytes: 256
import itertools
L = ['+', '-']
s = list(input())
for l in itertools.product(L, repeat=3):
  if 7 == eval(s[0]+l[0]+s[1]+l[1]+s[2]+l[2]+s[3]):
    print(s[0]+l[0]+s[1]+l[1]+s[2]+l[2]+s[3]+'=7')
    break

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

inline void read(int &x) {
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}


inline void read(long long  &x) {
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}

int const maxn=150000;
int a[maxn];
int num[maxn];
int n;
int main(){
    read(n);
    for (int i=1;i<=n;i++)
    {
        read(a[i]);
        num[ a[i] ]++;
    }
    int ans=0;
    for (int i=1;i<=100000;i++)
        ans=max(ans,num[i-1]+num[i]+num[i+1] );
    printf("%d\n",ans);;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

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

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int a,b;
  cin>>a>>b;
  string ans[100]; 
  for (int i(0);i<100;i++){
    if (i < 50){
      ans[i] = string(100,'.');
    }else{
      ans[i] = string(100,'#');
    }
  }
  for (int i(0);i<a-1;i++){
    int dan = 51 + i/25*2,retu = i%25*2;
    ans[dan][retu] = '.';
  }
  for (int i(0);i<b-1;i++){
    int dan = i/25*2,retu = i%25*2;
    ans[dan][retu] = '#';
  }
  cout << 100 << " " << 100 << endl;
  for (int i(0);i<100;i++){
    for (int j(0);j<100;j++){
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 256
def main():
    n, y = map(int, input().split())

    yukichi = 10000
    ichiyou = 5000
    hideyo  = 1000

    ans_x, ans_y, ans_z = -1, -1, -1
    for ix in range(0, n+1):
        for iy in range(0, n+1-ix):
            iz = n - ix - iy
            total = yukichi * ix + ichiyou * iy + hideyo * iz
            if total == y:
                ans_x, ans_y, ans_z = ix, iy, iz

    print(ans_x, ans_y, ans_z)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    static ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
    static long[] values;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		for (int i = 0; i < n; i++) {
		    graph.add(new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
		    int a = sc.nextInt() - 1;
		    int b = sc.nextInt() - 1;
		    graph.get(a).add(b);
		    graph.get(b).add(a);
		}
		values = new long[n];
		for (int i = 0; i < q; i++) {
		    values[sc.nextInt() - 1] += sc.nextInt();
		}
		update(0, 0, 0);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (i > 0) {
		        sb.append(" ");
		    }
		    sb.append(values[i]);
		}
		System.out.println(sb);
   }
   
   static void update(int idx, int from, long v) {
       values[idx] += v;
       for (int x : graph.get(idx)) {
           if (x == from) {
               continue;
           }
           update(x, idx, values[idx]);
       }
   }
}


Measured memory_bytes: 106636
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define tsort(v) sort((v).begin(), (v).end())
#define trev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define pop(v) (v).back(); (v).pop_back()
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_1
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

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

    lint n, a[3]={2,1,0};
    cin>>n;
    repi(i, 2, n+1){
        a[i%3] = a[(i+1)%3] + a[(i+2)%3];
    }
    co(a[n%3]);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const int N = 1001;
int comb[N] = { 0 };

int main(void){
    COUNT(i, N / 2){
        int cur = i;
        for(int j = i + 1; (cur += j) < N; j ++) comb[cur] ++;
    }

    for(int n; cin >> n, n; cout << comb[n] << endl);
 
    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {
  string s;
  cin>>s;
  int n=s.size();
  
  if(s=="zyxwvutsrqponmlkjihgfedcba") cout << -1 << endl;

  else{
    if(n!=26){
      vector<bool> p(26);
      rep(i,n){
        p[s[i]-'a']=true;
      }
      cout << s;
      rep(i,26){
        if(!p[i]){
          cout << (char)('a'+i) << endl;
          return 0;
        }
      }
    }
    else{
      int memo;
      char moji;
      for(int i=25;i>0;i--){
        if(s[i-1]<s[i]){
          memo=i-1;
          moji=s[i-1];
          break;
        }
      }
      rep(i,memo){
        cout << s[i];
      }
      string t=s.substr(memo,n-memo);
      sort(all(t));
      int m=t.size();
      rep(i,m){
        if((int)(t[i]-moji)>0){
          cout << t[i] << endl;
          return 0;
        }
      }
    }
  }

}


Measured memory_bytes: 256
/*
    AUTHOR : TANMAY SINHA
    INORMATION TECHNOLOGY
    BIT MESRA ,RANCHI
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define pb(x) push_back(x)
#define eb(x) emplace_back()
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define rep(j,L,R) for(j=L;j<R;j++)
#define per(i,L,R) for(i=L;i>= R;i--)
#define all(con) (con).begin(),(con).end()
#define fi first
#define se second
#define foreach(iter,con) for(auto iter=(con).begin(); iter!=(con).end(); iter++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
const ll INF = 1e18l+10,N = 1e5+10,MAX = 1e6+5;
#define sq(X) ((X)*(X))

int main()
{
    SPEED
    ll n,m;
    cin>>n>>m;
    cout<<6-n-m<<"\n";
}






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

int	main()
{
  int	r, g, b;
  
  cin >> r >> g >> b;
  if ((10 * g + b) % 4 == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return (0);
}


Measured memory_bytes: 3612
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct NODE{
  int p,left,right;
};
struct NODE Tree[MAX];
int n,Depth[MAX],Height[MAX];

void makedepth(int,int);
int makeheight(int);
int makesibling(int);
int main(){
  int i,j,v,l,r,deg,root=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    Tree[i].p=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r); 
    Tree[v].left=l;
    Tree[v].right=r;
    if(l!=NIL)Tree[l].p=v;
    if(r!=NIL)Tree[r].p=v;
  }
  for(i=0;i<n;i++){
    if(Tree[i].p==NIL)root=i;
  }
  makedepth(root,0);
  makeheight(root);
  for(i=0;i<n;i++){
    printf("node %d: ",i);
    printf("parent = %d, ",Tree[i].p);
    printf("sibling = %d, ",makesibling(i));
    deg=0;
    if(Tree[i].left!=NIL)deg++;
    if(Tree[i].right!=NIL)deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",Depth[i]);
    printf("height = %d, ",Height[i]);
    if(Tree[i].p==NIL)printf("root\n");
    else if(Tree[i].left==NIL&&Tree[i].right==NIL)printf("leaf\n");
    else printf("internal node\n");
  }
  return 0;
}
void makedepth(int i,int d){
  if(i==NIL)return;
  Depth[i]=d;
  makedepth(Tree[i].left,d+1);
  makedepth(Tree[i].right,d+1);
}
int makeheight(int i){
  int h1=0,h2=0;
  if(Tree[i].left!=NIL) h1=makeheight(Tree[i].left)+1;
  if(Tree[i].right!=NIL) h2=makeheight(Tree[i].right)+1;
  return Height[i] = (h1>h2?h1:h2);
}
  
int makesibling(int i){
  if(Tree[i].p==NIL)return NIL;
  if(Tree[Tree[i].p].left!=i && Tree[Tree[i].p].left!=NIL)return Tree[Tree[i].p].left;
  if(Tree[Tree[i].p].right!=i && Tree[Tree[i].p].right!=NIL)return Tree[Tree[i].p].right;
  return NIL;
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string,int> table;

int main() {
  string word,freq,longest;
  size_t N=0;
  while (cin >> word) {
    table[word] += 1;
    if (table[word]>N) {
      N = table[word];
      freq = word;
    }
    if (word.size()>longest.size())
      longest = word;
  }
  cout << freq << " " << longest << endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, x, y) for (int i = x; i <= (y); ++i)
#define repr(i, x, y) for (int i = x; i >= (y); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int N, C;
  cin >> N >> C;
  vector<vector<int>> D(C, vector<int>(C));
  rep(i, C) {
    rep(j, C) {
      cin >> D[i][j];
    }
  }
  int c;
  map<int, int> x, y, z;
  rep(i, N) {
    rep(j, N) {
      cin >> c;
      c--;
      switch ((i + j) % 3) {
        case 0:
          x[c]++;
          break;
        case 1:
          y[c]++;
          break;
        case 2:
          z[c]++;
          break;
      }
    }
  }

  int ans = INF;
  rep(xx, C) {
    rep(yy, C) {
      rep(zz, C) {
        if (xx == yy || yy == zz || zz == xx)
          continue;

        int temp = 0;
        for (auto iter = x.begin(); iter != x.end(); iter++) {
          int old_color = iter->fi;
          int num = iter->se;
          temp += D[old_color][xx] * num;
        }
        for (auto iter = y.begin(); iter != y.end(); iter++) {
          int old_color = iter->fi;
          int num = iter->se;
          temp += D[old_color][yy] * num;
        }
        for (auto iter = z.begin(); iter != z.end(); iter++) {
          int old_color = iter->fi;
          int num = iter->se;
          temp += D[old_color][zz] * num;
        }
        chmin(ans, temp);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x * (-1), a))
heapq.heapify(a)
while m != 0:
    price = heapq.heappop(a)
    price = price/2
    m -= 1
    heapq.heappush(a, price)

for i in range(len(a)):
    a[i] = int(a[i])
print(sum(a) * (-1))

Measured memory_bytes: 14180
# coding: utf-8
number = list(map(int,input().split()))
k = (number[0]+number[1])/2

if list(str(k))[-1] == "0":
    if number[0]<=k<=number[1] or number[1]<=k<=number[0]:
        print(int(k))
    else:
        print("IMPOSSIBLE")
else:
        print("IMPOSSIBLE")

Measured memory_bytes: 3060
N = int(input())
nijo = []
for k in range(2, int((2*N)**0.5) + 1):
  nijo.append(k**2)
nijo = [1] + nijo
count = [0 for _ in range(N)]
for k in range(2, len(nijo) +1):
  for j in range(2, len(nijo)+ 1):
    if nijo[k-1] + nijo[j-1] > 2*N:
      break
    for l in range(2, len(nijo)+1):
      if nijo[k-1] + nijo[j-1] + nijo[l-1] > 2*N:
        break
      elif (nijo[k-1] + nijo[j-1] + nijo[l-1]) %2 == 0:
        if k + l -j > 1 and -k+j+l > 1 and k + j -l >1:
          count[(nijo[k-1] + nijo[j-1] + nijo[l-1])//2-1] += 1

for _ in range(N):        
  print(count[_])

Measured memory_bytes: 69460
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

struct edge {
    int from;
    int to;
    int cost;
};

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    vector<edge> edges;
    vvll cost(n, vll(n, LINF));
    rep(i, m) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        if (c > l) continue;
        --a;
        --b;
        cost[a][b] = min(cost[a][b], c);
        cost[b][a] = min(cost[b][a], c);
    }

    rep(l, 3) rep(i, n) rep(j, n) rep(k, n) {
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
    }

    vvint ans(n, vint(n, INF));
    rep(i, n) rep(j, n) {
        if (cost[i][j] <= l) ans[i][j] = 1;
    }
    rep(l, 3) rep(i, n) rep(j, n) rep(k, n) {
        ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);
    }

    int q;
    cin >> q;
    vint s(q), t(q);
    rep(i, q) {
        cin >> s[i] >> t[i];
        --s[i];
        --t[i];
    }
    rep(i, q) {
        if (ans[s[i]][t[i]] == INF) puts("-1"); 
        else {
            cout << ans[s[i]][t[i]]-1 << endl;
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 2304
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		long N = stdIn.nextLong();
		long K = stdIn.nextLong();
		
		System.out.println(Math.min(N % K, K - (N % K)));
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
template <typename T>
struct SegTree{
  // 二項演算merge,単位元identify
  using F = function<T(T, T)>;
  T identity;
  F merge; 
  int size;
  vector<T> dat;
  
  // 二項演算fと単位元idを渡して宣言する
  SegTree(F f,T id):merge(f),identity(id){}

  // データの要素の数nを渡して初期化、sizeはnより大きい2の冪乗
  void init(int n){
    size = 1;
    while(size<=n) size *= 2;
    dat.resize(size*2-1,identity);
  }

  // 配列を渡して0(n)で初期化
  void build(vector<T> vec){
    rep(i,vec.size()) dat[size-1+i] = vec[i];
    dfs(0);
  }
  
  T dfs(int k){
    if(k>=size-1) return dat[k];
    else return dat[k] = merge(dfs(2*k+1),dfs(2*k+2));
  }

  // index kの要素をaに変更
  void update(int k,T a){
    k += size - 1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = merge(dat[2*k+1],dat[2*k+2]);
    }
  }

  // 区間[a,b)に対するクエリに答える。(k,l,r)=(0,0,size)
  T query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return identity;
    
    if(a<=l&&r<=b) return dat[k]; 
    else return merge(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
  }
  
  void show(){
    int index = 0;
    int num = 1;
    while(index<size){
      rep(i,num){
	if(dat[i+index]==identity) cout << "e ";
	else cout << dat[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;
    }
  }
  
};

// vector<int> compress(vector<int> a) {
//   int n = a.size();
//   vector<int> vals;
//   rep(i,n) vals.push_back(a[i]);

//   sort(vals.begin(), vals.end());
//   vals.erase(unique(vals.begin(), vals.end()), vals.end());

//   vector<int> res;
//   rep(i,n) {
//     int id = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin();
//     res.push_back(id);
//   }

//   return res;
// }

ll LIS(vector<int> h, vector<ll> a) {
  int n = h.size();
  
  auto f = [&](ll a, ll b) { return max(a, b); };
  ll id = 0;
  SegTree<ll> seg(f, id);
  seg.init(n);
  ll res = 0;
  rep(i,n) {
    ll x = seg.query(0, h[i], 0, 0, seg.size);
    seg.update(h[i], x+a[i]);
    chmax(res, x+a[i]);
  }
  return res;

}

int main()
{
  int n;cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  cout << LIS(h, a) << "\n";
  
  return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<queue>
#include<string>
#include<vector>
using namespace std;
bool f(int r,int c,vector<vector<bool> >&v,queue<pair<int,int> >& que){
    if(r<0||c<0||r>=v.size()||c>=v[0].size()||!v[r][c]) return false;
    v[r][c]=false;
    que.push(pair<int,int>(r,c));
    return true;
}
    
int main(){
    int row,col;
    cin>>row>>col;
    vector<vector<bool> > v(row,vector<bool>(col,true));
    string s;
    queue<pair<int,int> > que;
    for(int i=0;i<row;i++){
	cin>>s;
	for(int j=0;j<col;j++){
	    if(s[j]=='#'){
		v[i][j]=false;
		que.push(pair<int,int>(i,j));
	    }
	}
    }
    int ans=-1;
    int len=que.size();
    int next_len=0;
    int p,q;
    while(len){
	ans++;
	for(int i=0;i<len;i++){
	    p=que.front().first,q=que.front().second;
	    que.pop();
	    if(f(p,q-1,v,que))
		next_len++;
	    if(f(p,q+1,v,que)) next_len++;
	    if(f(p-1,q,v,que)) next_len++;
	    if(f(p+1,q,v,que)) next_len++;
	}
	len=next_len;
	next_len=0;
    }
    cout<<ans<<endl;
	
	
    return 0;
}


Measured memory_bytes: 8592
n = input()
l=len(n)
s1=str(n[0]*l)
s2=""
if n[0]=='9':
    s2="1"*(l+1)
else:
    s2=str(int(n[0])+1)*l

if n<=s1:
    print(s1)
else:
    print(s2)

Measured memory_bytes: 3060
#![allow(unused_imports)]
use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    k: usize,
    a: [usize; n]
    }
    for i in k..n {
        let ans = if a[i] > a[i - k] {
            "Yes"
        } else {
            "No"
        };
        println!("{}", ans);
    }
}


Measured memory_bytes: 5672
a, b, c, d = list(map(int, input().split()))

if abs(a - c) <= d:
    print("Yes")
else:
    if a <= b and b <= c:
        if abs(a - b) <= d and abs(b - c) <= d:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 3060
def main(x):
    a = x[0]
    b = x[1]
    c = x[2]
    if a < b and b < c:
        print('Yes')
    else:
        print('No')
        
    
if '__main__' == __name__:
    try:
        while True:
            main(list(map(int, input().strip().split(' '))))
    except EOFError:
        pass



Measured memory_bytes: 5604
import itertools
N = int(input())
k = int((2 * N) ** 0.5) + 1
if (k-1) * k == 2 * N:
    print('Yes')
    print(k)
    S = [[] for _ in range(k)]
    n = 1
    for i, j in itertools.combinations(range(k), 2):
        S[i].append(str(n))
        S[j].append(str(n))
        n += 1
    for s in S:
        print(len(s), ' '.join(s))
else:
    print('No')


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

int main(){
	long long n,k;
	cin >> n >> k;
	map<long long,long long> a;
	long long i,j;
	for(i=1;i<=n;i++){
		cin >> a[i];
	}
	
	map<long long, long long> find;
	long long next=1,begin,end;
  	if(n>=k){
      for(i=0;i<k;i++){
		next = a.at(next);
      }
    }else{
      for(i=0;i<n;i++){
		if(find.count(next)){
			begin = find.at(next);
			end = i;
			break;
		}else{
			find[next] = i;
			next = a.at(next);
			
		}
	}

	long long roop_after = (k-begin)%(end-begin);
	for(i=0;i<roop_after;i++){
		next = a.at(next);
	}
    }
	cout << next << endl;
	
	
}

Measured memory_bytes: 25960
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>



bool isprime(int x){
  int rootx=1;
  while ((rootx+1)*(rootx+1)<=x){
    rootx++;
  }
  
  bool answer=true;
  
  for (int i=2;i<=rootx;i++){
    if (x%i==0){
      answer=false;
    }
  }
  
  return answer;
}

int main(){

  int x;
  cin>>x;
  
  int answer=x;
  
  while (true){
    if (isprime(answer)){
      break;
    }
    else {
      answer++;
    }
  }
  
  cout<<answer<<endl;
  
    

  
    
  
  
  
  
}



Measured memory_bytes: 256
K,N = list(map(int,input().split()))
A = list(map(int,input().split()))
B = []
C = []
for i in range(N-1):
  B.append(A[i+1]-A[i])
B.append(A[0]+K-A[N-1])
B.remove(max(B))
print(sum(B))

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  string s;
  ll k;
  cin >> s >> k;
  for(int i = 0; i < k; ++i)
  {
    if (s[i] != '1')
    {
      cout << s[i];
      return;
    }
  }
  cout << s[k - 1];
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3648
n=int(input())
ans=False
for i in range(100//4+1):
  if 4*i>n:
    break
  for j in range(100//7+1):
    if 4*i+7*j>n:
      break
    elif 4*i+7*j==n:
      ans=True
      break
    
print(("No","Yes")[ans])

Measured memory_bytes: 2940
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m, c; rd(n, m, c);
  auto l=readln.split.to!(int[]);
  import std.typecons;
  alias Ball=Tuple!(int, "t", long, "v");
  auto bs=new Ball[](n);
  foreach(i; 0..n){
    rd(bs[i].t, bs[i].v);
    bs[i].t--;
  }

  sort!"a.v>b.v"(bs);
  long sum=0;
  foreach(b; bs)if(l[b.t]>0){
    sum+=b.v;
    l[b.t]--;
    if((--m)==0) break;
  }

  writeln(sum);
}


void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}



Measured memory_bytes: 7300
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt64(scanner)
	a := getNextInt64(scanner)
	b := getNextInt64(scanner)

	if n == 1 {
		if a == b {
			fmt.Println(1)
			return
		}
		fmt.Println(0)
		return
	}

	if a > b {
		fmt.Println(0)
		return
	}

	ans := (b - a) * (n - 2)
	fmt.Println(ans + 1)
	writer.Flush()
}


Measured memory_bytes: 640