akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

struct th {
    int a, b, c;
    const bool operator<(const th& t) const {
        return a != t.a ? a < t.a : b != t.b ? b < t.b : c < t.c;
    }
};

int nxt(int x, int dig) {
    string s = to_string(x);
    while (s.length() < dig) s = '0' + s;
    sort(all(s));
    int a = stoi(s), b = stoi(string(s.rbegin(), s.rend()));
    return b - a;
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    while (true) {
        ll n, m; cin >> n >> m;
        if (!n && !m) break;

        vector<pair<int, int>> v(n);
        rep(i, 0, n) cin >> v[i].second >> v[i].first;
        sort(all(v)); reverse(all(v));

        ll ev = 0;
        rep(i, 0, n) {
            ll g = min(m, 1ll * v[i].second);
            v[i].second -= g; m -= g;
            ev += 1ll * v[i].first * v[i].second;
        }
        cout << ev << endl;
    }
}


Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>
#include <cassert>
using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n;
    cin >> n;
    vector<int>a(n),b(n-1);
    rep(i,n-1){
        cin >> b[i];
    }
    rep(i,n){
        if(i==0){
            a[i] = b[i];
        }else if(i==n-1){
            a[i] = b[i-1];
        }else{
            a[i] = min(b[i-1],b[i]);
        }
    }
    int sm = 0;
    rep(i,n){
        sm += a[i];
    }
    cout << sm << endl;
    return 0;
}

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

using namespace std;

int main() {
    int x = 0;
    cin >> x;

    int fifhand = 0;
    int fifth = 0;

    fifhand = (x / 500) * 1000;
    x = x % 500;
    fifth = (x / 5) * 5;

    cout << fifhand + fifth << endl;
    return 0;
}

Measured memory_bytes: 256
M = list(map(int, input().split()))

while M[0] > 0 or M[2] > 0:
  
    M[2] -= M[1]
    if M[2] <= 0:
      print('Yes')
      break
      
    M[0] -= M[3]
    if M[0] <= 0:
      print('No')
      break

Measured memory_bytes: 9072
#include<bits/stdc++.h>
using namespace std;
#define ALL(a) begin(a), end(a)
int main (void) {
    string s,t;
    cin>>s>>t;
    sort(ALL(s));
    sort(ALL(t),greater<char>());
    if (s<t) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = [input() for _ in range(int(input()))]
m = [input() for _ in range(int(input()))]
l = list(set(n))

y = [0]
for i in range(len(l)):
    x = n.count(l[i]) - m.count(l[i])
    y.append(x)

print(max(y))

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int N,M;
vector<vi> e;
vii d;

int main() {

    Scd2(N,M);
    d.resize(N);
    e.resize(N);
    Rep(i,N) Scd(d[i].first), d[i].second = i;

    vi col(N,-1);
    vi co(N);
    vii exs(M);
    map<pii,int> ans;

    int u,v;
    Rep(i,M){
        Scd2(u,v);
        u--,v--;
        e[u].push_back(v);
        e[v].push_back(u);
        exs[i] = pii(u,v);
        ans[pii(u,v)] = 1e9;
        ans[pii(v,u)] = 1e9;
    }

    bool ok = true;
    sort( d.begin(), d.end() );
    Rep(i,N) {
        co[d[i].second] = i;
    }
    // コストが小さい順に見ていく
    Rep(i,N){
        int dist = d[i].first;
        int from = d[i].second;
        if( col[from] != -1 ) continue;
        ok = false;
        for( int to : e[from] ){
            if( dist >= d[co[to]].first && ( col[to] == -1 || col[from] != col[to] ) ){
                // printf ("%d->%d\n", from, to );
                if( col[to] != -1 ) col[from] = col[to]^1;
                else col[from] = 0, col[to] = 1;
                ans[pii(from,to)] = dist;
                ans[pii(to,from)] = dist;
                ok = true;
                break;
            }
        }
        if( !ok ){
            printf ("%d\n", -1 );
            return 0;
        }
    }

    Rep(i,N){
        if( col[i] == -1 ){
            printf ("%d\n", -1 );
            return 0;
        }
    }
    Rep(i,N){
        printf ("%c", col[i]?'B':'W');
    }
    printf ("\n");
    Rep(i,M){
        printf("%d\n", ans[exs[i]] );
    }


    return 0;
}



Measured memory_bytes: 36608
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b,c;
    cin >> a;
    // スペース区切りの整数の入力
    if(a==1){
      cout << "Hello World";
    }
    else{
      cin >> b >> c;
      cout << b+c;
    }
}

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

int main(){
	string a,b;
	int len,sum=0;
	cin>>a>>b;
	len=a.size();
	for(int i=0;i<len;i++){
		if(a[i]!=b[i]) sum++;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    string s;
    cin >> s;

    bool ans=true;
    for (int i=0;i<=s.length()-1;i++)
    {
        if ((i%2==0)&&(s[i]=='L'))
        {
            ans=false;
        }
        else if ((i%2==1)&&(s[i]=='R'))
        {
            ans=false;
        }
    }

    if (ans)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3640
s = input()
k = int(input())

s1=0
sn1='0'
for i in range(len(s)):
    if(s[i] == '1'):
        s1+=1
    else:
        sn1=s[i]
        break
ans='0'
if(s1>=k):
    ans='1'
else:
    ans=sn1

print(ans)

Measured memory_bytes: 9124
import java.io.*;
import java.util.*;

public class Main
{

	
	
	
	public static void main(String[] Rohan)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

		String s = br.readLine();


		Stack<Integer> st = new Stack<Integer>();


		int num=0;

		for(int i=0;i<s.length();i++)
		{
			if(st.size()==0)
				st.push(s.charAt(i)-'0');
			else
			{
				if(st.peek()!=(s.charAt(i)-'0'))
				{
					st.pop();num+=2;
				}
				else
					st.push(s.charAt(i)-'0');;
			}
		}
		System.out.println(num);
			
		

	}
}

Measured memory_bytes: 24916
def main():
    n,m=map(int, input().split())
    k = [0]*n
    for i in range(m):
        a,b=map(int, input().split())
        k[a-1]+=1
        k[b-1]+=1
    for i in k:
        if i%2==1:
            print("NO")
            exit()
    print("YES")
if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
typedef long long ll;
typedef pair<int, int> P;

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

int main()
{

    int n, m;
    cin >> n >> m;
    printf("%s\n", n == m ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int ans = 0;
  int num;
  cin >> num;

  for (int i = 0; i < num; i++) {
    int v;
    cin >> v;
    ans += v - 1;
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <ios>
#include <vector>
#include <algorithm>
#include <map>
#include <utility>
#include <array>
using namespace std;
int main(void) {
    ios::sync_with_stdio(false);

    const int M = 256;
    while(true) {
        int N = 0;
        cin >> N;
        if(N == 0) {
            break;
        }
        vector<int> I;
        for(int i = 0; i < N; ++i) {
            int temp;
            cin >> temp;
            I.push_back(temp);
        }

        double min_H = -1;
        double min_S, min_A, min_C;
        for(int S = 0; S < 16; ++S) {
            for(int A = 0; A < 16; ++A) {
                for(int C = 0; C < 16; ++C) {
                    vector<int> R;
                    R.push_back(S);
                    for(int i = 0; i < N; ++i) {
                        R.push_back((A * R[i] + C) % M);
                    }
                    array<int, M> count;
                    fill(count.begin(), count.end(), 0);
                    for(int i = 0; i < N; ++i) {
                        count[(I[i] + R[i + 1]) % M] += 1;
                    }
                    double H = 0;
                    for(int c: count) {
                        if(c != 0) {
                            H -= c / static_cast<double>(N) * log(c / static_cast<double>(N));
                        }
                    }
                    if(min_H == -1) {
                        min_H = H;
                        min_S = S;
                        min_A = A;
                        min_C = C;
                    }
                    if(min_H > H + 1e-9) {
                        min_H = H;
                        min_S = S;
                        min_A = A;
                        min_C = C;
                    }
                }
            }
        }
        cout << min_S << " " << min_A << " " << min_C << endl;
    }

    return 0;
}

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

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


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

int main2() {
  string s, t;
  cin >> s >> t;

  t.pop_back();
  if (s == t) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

int main() {

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

Measured memory_bytes: 3628
def gcd(a, b)
  if a > b then
    a, b = b, a
  end
  
  while a % b != 0 do
    r = a % b
    a = b
    b = r
  end
  b
end

def main()
  a, b = gets.split.map{|x| x.to_i}
  puts gcd(a, b)
end

main



Measured memory_bytes: 6872
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll vis[100010];
queue<ll>q;
vector<ll>v[100010];
void bfs(ll x)
{
    vis[x]=1;
    q.push(x);
    while(!q.empty())
    {
        ll p=q.front();
        q.pop();
        for(ll i=0;i<v[p].size();i++)
        {
            ll y=v[p][i];
            if(vis[y]==0)
            {
                vis[y]=1;
                q.push(y);
            }
        }

    }

}

int main()
{
    ll t=1,i,j,k=0,q,p,x,y,z,n,m,a,b,r,c,d;
    //cin>>t;
    while(t--)
    {
       cin>>n>>m;
       for(i=0;i<m;i++)
       {
           cin>>x>>y;
           v[x].push_back(y);
           v[y].push_back(x);
       }
       memset(vis,0,sizeof(vis));
       ll cnt=0;
       for(i=1;i<=n;i++)
       {
           if(vis[i]==0)
           {
               cnt++;
               bfs(i);
           }
       }
cout<<cnt-1<<endl;

    }
    return 0;
}



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

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    bool pair1 = (a.back() == b.front());
    bool pair2 = (b.back() == c.front());

    cout << (pair1 && pair2 ? "YES" : "NO") << endl;
}

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

typedef long long ll;

ll x,k,d;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>x>>k>>d;
    x=abs(x);
    if((x+d-1)/d>=k){
        cout<<abs(x-k*d)<<endl;
    }else{
        k-=x/d;
        x%=d;
        k&=1;
        cout<<abs(x-k*d)<<endl;
    }

    return 0;
}

Measured memory_bytes: 3684
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, m, R;
vector<int> r;
ll d[200][200];
//ワーシャルフロイド

void warshall_floyd(int n) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m>>R;
    ll ans=INF;
    for (int i = 0; i < R; i++)
    {
        int tempr;
        cin >> tempr;
        r.push_back(tempr-1);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=INF;
            if(i==j){
                d[i][j]=0;
            }
        }
    }
    for(int i=0;i<m;i++){
        ll ai, bi, ci;
        cin>>ai>>bi>>ci;
        d[ai-1][bi-1]=ci;
        d[bi-1][ai-1]=ci;
    }
    warshall_floyd(n);
    vector<int> par(R);
    iota(ALL(par),0);
    do{
        ll sum=0;
        for(int i=0;i<R-1;i++){
        sum+=d[r[par[i+1]]][r[par[i]]];
        }
        ans=min(ans,sum);
    }while(next_permutation(ALL(par)));
    cout << ans << "\n";
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

#define REP(i,f,n) for(int i=(f); i < (n); ++i)
#define PER(i,f,n) for(int i=(n-1); i >= f; --i)

//----------------------------------
//----------------------------------
//
int digit(int n)
{
	int count = 0;
	while(n > 0)
	{
		n /= 10;
		count++;
	}
	return count;
}

signed main()
{
    ios::sync_with_stdio(false);
	int a, b;
	while(cin >> a)
	{
		cin >> b;
		cout << digit(a+b) << endl;
	}

}

Measured memory_bytes: 3152
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int[] input = new int[5];
		for(int i = 0; i < input.length ; i++) {
			input[i] = sc.nextInt();
		}


		int[] input2 = new int[5];
		for(int i = 0; i < input.length ; i++) {
			input2[i] = input[i] % 10;
		}

		int minNo = -1;
		int min = 10;
		for(int i = 0; i < input.length ; i++) {
			if(input2[i] < min && input2[i] != 0) {
				min = input2[i];
				minNo = i;
			}
		}

		int answer = 0;
		for(int i = 0; i < input.length ; i++) {
			if(i != minNo && input2[i] != 0) {
				input[i] = ((int)(input[i]/10) + 1)*10;
			}
			answer += input[i];
		}

		System.out.println(answer);
	}

}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
inline bool isprime(ll num)
{if(num==2||num==3)return true;
if(num%6!=1&&num%6!=5)return false;
for(int i=5;1ll*i*i<=num;i+=6){if(num%i==0||num%(i+2)==0)return false;}
return true;}
const int mod = 1e9+7;
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll g = exgcd(b,a%b,y,x);y-=a/b*x;return g;}
inline ll quick_pow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res=mul(res,a,mod);a=mul(a,a,mod);b>>=1;}return res;}
inline ll quick_pow(ll a,ll b){ll res=1;while(b){if(b&1)res=mul(res,a,mod);a=mul(a,a,mod);b>>=1;}return res;}
inline ll inv(ll x){return quick_pow(x,mod-2);}
inline ll inv(ll x,ll mod){return quick_pow(x,mod-2,mod);}
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dp[11][10];
int sum[11];
const int N = 3e5+10;
ll tr[11][N];
int cnt[N];
ll res[N];
ll ans[N];
int main(){
	for(int i=1;i<=9;i++)dp[1][i]=1;
	for(int i=2;i<11;i++){
		for(int j=0;j<=9;j++){
			if(j==0)dp[i][j]=dp[i-1][j]+dp[i-1][j+1];
			else dp[i][j]=dp[i-1][j-1]+dp[i-1][j]+dp[i-1][j+1];
		}
	}
	int ct=0;
	for(int i=1;i<=9;i++)tr[1][++cnt[1]]=i,ans[++ct]=i;
	for(int i=2;i<11;i++){
		for(int j=1;j<=cnt[i-1];j++){
			if(tr[i-1][j]%10==0){
				tr[i][++cnt[i]]=tr[i-1][j]*10+tr[i-1][j]%10;
				ans[++ct]=tr[i][cnt[i]];
				tr[i][++cnt[i]]=tr[i-1][j]*10+tr[i-1][j]%10+1;
				ans[++ct]=tr[i][cnt[i]];
			}
			else if(tr[i-1][j]%10!=9)
			{
				tr[i][++cnt[i]]=tr[i-1][j]*10+tr[i-1][j]%10-1;
				ans[++ct]=tr[i][cnt[i]];
				tr[i][++cnt[i]]=tr[i-1][j]*10+tr[i-1][j]%10;
				ans[++ct]=tr[i][cnt[i]];
				tr[i][++cnt[i]]=tr[i-1][j]*10+tr[i-1][j]%10+1;
				ans[++ct]=tr[i][cnt[i]];
			}
			else{
				tr[i][++cnt[i]]=tr[i-1][j]*10+tr[i-1][j]%10-1;
				ans[++ct]=tr[i][cnt[i]];
				tr[i][++cnt[i]]=tr[i-1][j]*10+tr[i-1][j]%10;
				ans[++ct]=tr[i][cnt[i]];
			}
			if(ct>=2e5+10)break;
		}
	}
	int k;
	scanf("%d",&k);
	printf("%lld\n",ans[k]);
}

Measured memory_bytes: 24320
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

///////////////////////////////////////////////////////////////////////////

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

	vector<ll> H (N);
	rep (i, N) {
		cin >> H[i];
	}

	ll maxn = H[0];

	for (ll i = 1; i < N; ++i) {
		if (H[i] - maxn <= -2) {
			cout << "No" << endl;
			return 0;
		}

		maxn = max (maxn, H[i]);
	}

	cout << "Yes" << endl;
}



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

using namespace std;

long long dp[105][100005], a[100005], b[100005], t, kq, n, w, ans;

int main() {
    cin >> n >> w;
    for (int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i <= w; i++)
        dp[0][i] = 0;
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 0; j < a[i]; j++)
            dp[i][j] = dp[i - 1][j];
        for (int j = a[i]; j <= w; j++)
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a[i]] + b[i]);
    }
    cout << dp[n][w];
}

Measured memory_bytes: 80640
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

        int n = sc.nextInt();
        Map<String, Integer> map = new HashMap<>();
        map.put("AC", 0);
        map.put("WA", 0);
        map.put("TLE", 0);
        map.put("RE", 0);

        for(int i=0; i<n; i++){
            String s = sc.next();
            map.put(s, map.get(s) + 1);
        }

        System.out.println("AC x " + map.get("AC") + "\nWA x " + map.get("WA") +"\nTLE x " + map.get("TLE") + "\nRE x " + map.get("RE"));
    }
}

Measured memory_bytes: 58424
#include<cstdio>
#include<cstring>
#define R register
using namespace std;
char str[233];
int main()
{
	scanf("%s",str+1); int len = strlen(str+1);
	for(R int i = 1; i <= len; i++){
		if((i & 1) && (str[i] == 'L')) return !puts("No");
		if(!(i & 1) && (str[i] == 'R')) return !puts("No");
	} puts("Yes");
}

Measured memory_bytes: 128
#include<stdio.h>
 int main() 
{
 int W,H,x,y,r;
 scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
 if (W>=x+r && H>=y+r && r<=x && r<=y && x>=0 && y>=0)
{ printf("Yes\n");} else { printf("No\n");} return 0; } 




 



 



Measured memory_bytes: 2104
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int main(){
	ll a,b,n;
	scanf("%lld%lld%lld",&n,&a,&b);
	ll mn=(n-1)*a+b;
	ll mx=(n-1)*b+a;
	printf("%lld\n",max(mx-mn+1,0LL));
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int i, j, k, n;
  scanf("%d", &n);

  int M[n][2];
  for(i=0; i<n; i++)
    {
      scanf("%d", &M[i][0]);
      scanf("%d", &M[i][1]);
    }

  int x[n][n];

  for(i=1; i<n; i++)
    {
      for(j=0; j<n; j++)
	{
	  x[i][j]=999999;
	}
    }

  for(j=0; j<n; j++)
    {
      x[0][j]=0;
    }
  for(j=0; j<n-1; j++)
    {
      x[1][j]=M[j][0]*M[j][1]*M[j+1][1];
    }

    for(i=2; i<n; i++)
    {
      for(j=0; j<n-i; j++)
	{
	  for(k=0; k<i; k++)
	    {
	      if(x[i][j]>x[k][j]+x[i-k-1][j+k+1]+M[j][0]*M[i+j][1]*M[j+k][1])
		{
		  x[i][j]=x[k][j]+x[i-k-1][j+k+1]+M[j][0]*M[i+j][1]*M[j+k][1];
		}
	    }
	}
    } 

  printf("%d\n", x[n-1][0]);

  return 0;
}

Measured memory_bytes: 632
(defmacro read-to-let* ((&rest args) &body body)
  `(let* ,(mapcar #'(lambda (arg)
		     (if (listp arg)
			 arg
			 `(,arg (read))))
		 args)
     ,@body))

       


(read-to-let* (a b h)
  (princ (/ (* (+ a b) h) 2)))

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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

ll get(ll x, ll y) {
  return (x / y);
}

int main() {
  int n, k; read(n, k);
  map <int, int> cnt;
  for(int i = 0; i < n; i++) {
    int x; cin >> x;
    cnt[x]++;
  }
  vector <int> p;
  for(auto x : cnt) p.push_back(x.second);
  if(p.size() <= k) {
    cout << 0 << '\n';
    return 0;
  }
  sort(p.begin(), p.end());
  int ans = 0;
  for(int i = 0; i < p.size() - k; i++) ans += p[i];
  cout << ans << '\n';
}

Measured memory_bytes: 10748
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, K = in.nextInt
  val As = Array.fill(N)(in.nextInt)

  (0 until N - K).foreach{i =>
    println(if (As(i + K) > As(i)) "Yes" else "No")
  }
}

Measured memory_bytes: 60468
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b + 1) / 2 << endl;
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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=1e15;

int main()
{
    ll x;
    cin >> x;
    ll k=x/11;
    ll r=x-k*11;
    if(r==0) cout << 2*k << endl;
    else if(1<=r && r<=6) cout << 2*k+1 << endl;
    else cout << 2*k+2 << endl;
    return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

//模範解答
public class Main{
	public static void main(String args[]){
      Scanner scan = new Scanner(System.in);
      int K = scan.nextInt();
      int a[] = new int[1000001];
      a[1] = 7 % K;
      for(int i = 2;i <= K;i++)
        a[i] = (a[i-1] * 10+7) % K;

      for(int i = 1;i <= K;i++){
        if(a[i] == 0){
          System.out.println(i);
          return;
        }
      }
      System.out.println(-1);
    }
}

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

using namespace std;

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

  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k) {
    cout << s;
  } else {
    cout << s.substr(0, k) + "...";
  }

  return 0;
}


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

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

        public static void Solve()
        {
            var AB = Console.ReadLine();
            var (A, B) = (AB[0], AB[2]);
            Console.WriteLine(A == B ? "H" : "D");
        }
    }
}


Measured memory_bytes: 25832
#include <bits/stdc++.h>
#define SIZE 200005
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int to[SIZE];
int L[SIZE],R[SIZE];
int main()
{
	int n;
	scanf("%d",&n);
	vector <int> vx;
	for(int i=0;i<n;i++)
	{
		int x,l;
		scanf("%d %d",&x,&l);
		int s=x-l,t=x+l;
		L[i]=s,R[i]=t;
		vx.push_back(s);
		vx.push_back(t);
	}
	sort(vx.begin(),vx.end());
	vx.erase(unique(vx.begin(),vx.end()),vx.end());
	for(int i=0;i<vx.size();i++) to[i]=vx.size();
	for(int i=0;i<n;i++)
	{
		L[i]=lower_bound(vx.begin(),vx.end(),L[i])-vx.begin();
		R[i]=lower_bound(vx.begin(),vx.end(),R[i])-vx.begin();
		to[L[i]]=min(to[L[i]],R[i]);
	}
	for(int i=((int) vx.size())-2;i>=0;i--) to[i]=min(to[i],to[i+1]);
	int cnt=0,now=0;
	while(now<vx.size())
	{
		cnt++;
		now=to[now];
	}
	printf("%d\n",cnt-1);
	return 0;
}

Measured memory_bytes: 2676
# # for i in range(m):
# s = input()
# t = input()
# n = len(s)
# m = len(t)
# # print(s,t,n,m)
# if n+1==m:
# 	for i in range(n):
# 		# print(s[i], t[i])
# 		if s[i]!=t[i]:
# 			print("No")
# 			break
# 	else:
# 		print("Yes")
# else:
# 	print("No")
	# l, r = [int(j)-1 for j in input().split()]
	################
def fun(a,b,c,k):
	ans =0 
	if k<=a:
		return k
	else:
		ans = a
		k-=a
	if k<=b:
		return ans
	else:
		k-=b
	# if k<=c:
	# print(ans, c)
	return ans-min(c,k)
a,b,c,k = [int(j) for j in input().split()]
# l = [a,b,c]
# j = 0
print(fun(a,b,c,k))


# while(k>0):
# 	a = min(k, l[j])
# 	k-=a


Measured memory_bytes: 61760
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{

    ll n,m,i,j,k,p,q,o,l,s,t;
    string a;
   cin>>n>>a;
   k=0;
  for(i=0;a[i];i++)
  {
      if(a[i]=='A' && a[i+1]=='B' && a[i+2]=='C')
      {
          k++;
      }
  }
  cout<<k<<endl;
}


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

int main(void) {
    long int N,c = 0,i,j,k;
    string S;
    cin >> N;
     cin >> S;
     long int r=0,g=0,b=0;
  
    
 
    for (i=0;i<N;++i){
        if(S[i] == 'R'){
            r++;
        }
        if(S[i] == 'G'){
            g++;
        }
        if(S[i] == 'B'){
            b++;
        }
    
    }
    long int ans = r* b *g;
  
    for(i = 0;i<N-2;++i){
          for(int j =i + 1;j<N-1;++j){
              long int k = 2*j - i;
              if(k < N){
              if(S[i]!=S[j] && S[i]!=S[k] && S[j]!=S[k]){
                           ans--;
           }
              }
         
    } 

         
    } 

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

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define LL long long
#define REP(i, n) for(int i=0;i<(n);++i)
#define REPA(i, n) for(int i=1;i<(n);++i)
#define lp(i, n) for(int i=-;i<(n);++i)
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define DEKAI ((int)1e9+7)
#define ALL(x) (x).begin(), (x).end()
#define BIT(x) (1<<(x))
#define foreach(i, n) for(auto &i:(n))
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> line(N);
    vector<int> dl;
    foreach(i, line)cin>>i;
    int ans = 0;
    for(int i=1;i<N;++i){
        dl.assign(N, INF);
        REP(j, i){
            if(line[j] < i)continue;
            *upper_bound(ALL(dl), line[j])=line[j];
        }
        ans = max(ans, (int)(lower_bound(ALL(dl), INF) - dl.begin()));
    }
    cout << min(ans+K, N/2) << endl;
    return 0;
}



Measured memory_bytes: 3156
N = int(input())
txy = [list(map(int, input().split())) for _ in range(N)]

for i in range(N):
    if i == 0:
        dt = txy[0][0]
        dxy = txy[0][1] + txy[0][2]
    else:
        dt = txy[i][0] - txy[i-1][0]
        dxy = abs(txy[i][1] - txy[i-1][1]) + abs(txy[i][2] - txy[i-1][2])
    if dxy > dt:
        print("No")
        break
    else:
        if (dxy - dt) % 2 == 1:
            print("No")
            break
        else:
            continue
else:
    print("Yes")

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

#define M 10
#define REQUIRED 3

bool ascending (int i, int j) { return i > j; }

int main() {
  vector<int> heights(M, 0);
  for (int i = 0; i < M; i++) {
    cin >> heights[i];
  }

  std::sort(heights.begin(), heights.end(), ascending);
  for (int i = 0; i < REQUIRED; i++) {
    cout << heights[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
    cin >> a >> b;
    if(a+b == 5)
    {
    	cout << 1;
    }
    if(a+b == 4)
    {
    	cout << 2;
    }
    if(a+b == 3)
    {
     	cout << 3;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn = 100100;
int arr[maxn];
long long solve(int lst, int l, int r){
  long long ans = 0;
  int pl = lst, pr = lst;
  while(l <= r){
    int pt0 = abs(pl - arr[l]);
    int pt1 = abs(pl - arr[r]);
    int pt2 = abs(pr - arr[l]);
    int pt3 = abs(pr - arr[r]);
    int mx = max({pt0, pt1, pt2, pt3});
    ans += mx;
    if(mx == pt0){
      pl = arr[l++];
    } else if(mx == pt1){
      pl = arr[r--];
    } else if(mx == pt2){
      pr = arr[l++];
    } else {
      pr = arr[r--];
    }
  }
  return ans;
}
int main(){
  int n;
  cin >> n;
  for(int e = 0;  e < n; e++) cin >> arr[e];
  sort(arr, arr + n);
  long long ans = 0;
  ans = max(ans, solve(arr[0], 1, n - 1));
  ans = max(ans, solve(arr[n - 1], 0, n - 2));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{

    int n, y, b, t, maxb;
    double m = 100, r, maxv, res;
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        maxv = 0, maxb = -1;
        scanf("%d", &y);
        for (int i = 0;  i < n; i++) {
            scanf("%d %lf %d", &b, &r, &t);
            if (t == 1) res = m * (1 + (r/ 100) * y);
            else if (t == 2) res = m * (pow((1+ r/100), y));
            //printf("%lf\n", res);
            if (res > maxv) maxv = res, maxb = b;
        }
        printf("%d\n", maxb);
    }
    return 0;
}


Measured memory_bytes: 2712
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

p = 0
for k in range(1,X):
    if k in A:
        p += 1
q = 0
for k in range(X+1,N+1):
    if k in A:
        q += 1

print(min(p,q))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<P> g(n);
	rep(i,n){
		ll x,l;
		cin>>x>>l;
		g[i].fi=x-l,g[i].se=x+l;
	}
	sort(begin(g),end(g),[&](const P &a,const P &b){
		return a.se<b.se;
	});
	ll ans=0,now=-inf;
	rep(i,n){
		if(now<=g[i].fi){
			ans++;
			now=g[i].se;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h> 
using namespace std;
const int N=5e5+7;
typedef long long ll;
const ll mod=1e9+7;
ll arr[N];
ll mark[N];
ll right_[N];
ll ans=0;

void merage_sort(ll l,ll r){
	if(l>=r) return ;
    ll mid=(l+r)/2;
    merage_sort(l,mid);
    merage_sort(mid+1,r);
    ll i=l,j=mid+1,k=l;
    
	while(i<=mid&&j<=r){
        if(arr[i]<=arr[j]){
            right_[k++]=arr[i++];
        }
        else {
            right_[k++]=arr[j++];
            ans+=1ll*mid-i+1;
        }
    }
    while(i<=mid)    right_[k++]=arr[i++];
    while(j<=r)   right_[k++]=arr[j++];    
    for(ll i=l;i<=r;i++)    arr[i]=right_[i];
}
int main(){
    ll n,k;
    cin>>n>>k;
    for(ll i=1;i<=n;i++){
        cin>>arr[i];
        mark[i]=arr[i];
    }
    ll ans1;
    merage_sort(1,n);
    ans1=ans;
    ll ans2=0;
	for(int i=1;i<=n;i++){
		arr[i]=mark[i];
	}
	for(int i=n+1;i<=2*n;i++){
		arr[i]=mark[i-n];
	}
	ans=0;
	merage_sort(1,2*n);
	ans2=ans-(ll)2*ans1;
//	cout<<ans2<<endl;	
	cout<<(k%mod*ans1%mod+k%mod*(k-1)/2%mod*ans2%mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>

using namespace std;

typedef long long ll;

const int kMaxN = 100000;
const ll kMod = 1000000000 + 7; 

int main () {
    int n;
    ll ans = 1;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        ans = (i * ans) % kMod;
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var ps = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var pp = new List<int>();
        for (var i = 0; i < num; i++)
            if (ps[i] == i + 1)
                pp.Add(i);
        var ct = 0;
        for(var i = 0; i < pp.Count-1; i++)
            if (pp[i] == pp[i + 1] - 1)
            {
                ct++;
                i++;
            }
        WriteLine(pp.Count - ct);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 19936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  n%=1000;
  int ans=1000-n;
  ans%=1000;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<stdbool.h>
#include<math.h>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long ll;

int main(void) {
	ll n;
	cin >> n;
	vector<ll>a(n+1);
	for (ll i = 1;i <= n;i++)cin >> a[i];
	if (n == 1) {
		cout << a[1] << endl;
		return 0;
	}
	if (n % 2 == 0) {
		for (ll i = n/2;i >=1;i--) {
			cout << a[2 * i] << " " ;
		}
		for (ll i = 1;i <= n / 2;i++) {
			if (i == n / 2)cout << a[2 * i - 1] << endl;
			else cout << a[2 * i - 1] << " ";
		}
	}
	else {
		for (ll i = n / 2;i >= 0;i--) {
			cout << a[2 * i + 1] << " ";
		}
		for (ll i = 1;i <= n / 2;i++) {
			if (i == n / 2)cout << a[2 * i] << endl;
			else cout << a[2 * i] << " ";
		}
	}
	return 0;
}

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

int main(){
	string s;
	int k;
	cin>>s>>k;

	vector<string> vec;
	for(int i = 0; i < (int)s.size(); i++){
		for(int j = i; j < min((int)s.size(),i+6);j++) vec.push_back(s.substr(i,j-i+1));
	}
	
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	cout<<vec[k-1];
}

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

int main()
{
    string S; cin >> S;
    int n=S.size();
    vector<vector<int>> dp(n+1,vector<int> (10,0));
    vector<int> cnt(2019,0);
    for (int i=1;i<10;i++) dp[1][i]=i;
    for (int i=2;i<n+1;i++)
    {
        for (int j=1;j<10;j++)
        {
            dp[i][j]=dp[i-1][j]*10%2019;
        }
    }
    int mod=0;
    int m;
    for (int i=1;i<n+1;i++)
    {
        m=S[n-i]-'0';
        mod=(mod+dp[i][m])%2019;
        cnt[mod]++;
    }
    int ans=0;
    for (int i=0;i<2019;i++)
    {
        if (i==0) ans+=cnt[i]*(cnt[i]+1)/2;
        else ans+=cnt[i]*(cnt[i]-1)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 17644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main() {
	while (1) {
		int sum, a[9];
		cin >> sum;
		if (sum == 0) break;
		for (int i = 0; i < 9; ++i) {
			cin >> a[i];
		}
		cout << sum - accumulate(a, a + 9, 0) << endl;
	}

	return 0;
}

Measured memory_bytes: 2944
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

int main()
{
  int n;
  cin >> n;
  vector<int> p(n), where(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
    p[i]--;
    where[p[i]] = i;
  }

  int right = -1;
  int left = 0;
  int result = 0;
  while (left < n) {
    left = right + 1;
    right = left;
    while (right + 1 < n && where[right] < where[right + 1]) {
      right++;
    }
    result = max(result, right - left + 1);
  }

  cout << n - result << endl;

  return 0;
}


Measured memory_bytes: 1792
dice1=list(map(int,input().split()))
dice2=list(map(int,input().split()))

def E(ls):
    ls=[ls[3],ls[1],ls[0],ls[5],ls[4],ls[2]]
    return ls

def N(ls):
    ls=[ls[1],ls[5],ls[2],ls[3],ls[0],ls[4]]
    return ls

def R(ls):
    ls=[ls[0],ls[2],ls[4],ls[1],ls[3],ls[5]]
    return ls
    
dice1_ls=[dice1,]

for i in range(3):
    dice1=E(dice1)
    dice1_ls.append(dice1)
dice1=E(dice1)
dice1=N(dice1)
dice1_ls.append(dice1)
dice1=N(N(dice1))
dice1_ls.append(dice1)
for i in range(6):
    dice=dice1_ls[i]
    for j in range(3):
        dice=R(dice)
        dice1_ls.append(dice)
if dice2 in dice1_ls:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 5608
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int N = scan.nextInt();
		int x[] = new int[N+1];
		int y[] = new int[N+1];
		int a[] = new int[N+1];

		int a_1 , a_2 , a_3 , a_4;
		a_1 = a_3 = 0;
		a_2 = a_4 = 0;

		x[0] = y[0] = a[0] = -1;

		for(int i=1;i<N+1;i++){
			x[i] = scan.nextInt();
			y[i] = scan.nextInt();
			a[i] = scan.nextInt();
			if(a[i]==1){
				if(a_1==0){
					a_1 = i;
				}
				if(Math.max(x[a_1],x[i])==x[i]){
					a_1 = i;
				}
			}else if(a[i]==2){
				if(a_2==0){
					a_2 = i;
				}
				if(Math.min(x[a_2],x[i])==x[i]){
					a_2 = i;
				}
			}else if(a[i]==3){
				if(a_3==0){
					a_3 = i;
					continue;
				}
				if(Math.max(y[a_3], y[i])==y[i]){
					a_3 = i;
				}
			}else if(a[i]==4){
				if(a_4==0){
					a_4 = i;
					continue;
				}
				if(Math.min(y[a_4], y[i])==y[i]){
					a_4 = i;
				}
			}
		}
			int x_l, x_r;
			int y_t, y_b;
			if(a_1!=0){
				x_l = x[a_1];
			}else{
				x_l = 0;
			}
			if(a_2!=0){
				x_r = x[a_2];
			}else{
				x_r = W;
			}
			if(a_3!=0){
				y_b = y[a_3];
			}else{
				y_b = 0;
			}
			if(a_4!=0){
				y_t = y[a_4];
			}else{
				y_t = H;
			}
			/*
			System.out.println(x_l);
			System.out.println(x_r);
			System.out.println(y_b);
			System.out.println(y_t);
			*/
			if(x_l>=x_r||y_b>=y_t){
				System.out.println(0);
				return;

			}else{
				System.out.println((x_r-x_l)*(y_t-y_b));
			}

	}
}

Measured memory_bytes: 10196
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        boolean b=false;
        int x=s.nextInt();
        for(int i=1;i<10;i++){
            for(int j=1;j<10;j++){
                if(i*j==x)
                {b=true;}
            }
        }
        if(b==true){System.out.println("Yes");}
        if(b==false){System.out.println("No");}
        }
        
    }

Measured memory_bytes: 21972
import itertools

N,M,Q=map(int,input().split())

ABCD=[]

max_result=0

for i in range(Q):
    ABCD.append(list(map(int,input().split())))

for j in itertools.combinations([k for k in range(M+N-1)],N):
    result=0
    for l in ABCD:
        if  j[l[1]-1]-j[l[0]-1]==l[1]-l[0]+l[2]:
            result+=l[3]
    
    if result>max_result:
        max_result=result

print(max_result)


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

using namespace std;

int main() {
	char c;
	cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'u' || c == 'o') {
		cout << "vowel" << endl;
		return 0;
	}
	cout << "consonant" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>

int main() {
  int i;
  char a[10], b[10];
  scanf("%s%s", a, b);
  strcat(a, b);
  i = atoi(a);
  printf(((int)sqrt((double)i)) == sqrt((double)i) ? "Yes\n" : "No\n");
}


Measured memory_bytes: 128
N=int(input())
A=list(map(int,input().split()))
DP=[[1000,1000,0] for i in range(N+1)]
for i in range(N):
  DP[i+1][0]=max(DP[i][0],DP[i][1]+DP[i][2]*A[i])
  DP[i+1][1]=DP[i+1][0]%A[i]
  DP[i+1][2]=DP[i+1][0]//A[i]
print(DP[N][0])


Measured memory_bytes: 62016
#include <iostream>

using namespace std;

int main() {
    int a, b, tmp;
    cin >> a >> b;
    
    tmp = a + b;
    if(tmp < a - b) {
        tmp = a - b;
    }
    if(tmp < a * b) {
        tmp = a * b;
    }

    cout << tmp << endl;

    return 0;
    
}

Measured memory_bytes: 256