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

int n, k, ia[100005], ib[100005];

vector<int> x[4], def;

vector<int> operator + (vector<int> A, vector<int> B) {
    vector<int> R;
    for(int i=0;i<n;i++) {
        R.push_back(A[B[i]]);
    }
    return R;
}

vector<int> calc (vector<int> V, int C) {
    if(!C) return def;
    vector<int> R = calc(V, C/2);
    R = R + R;
    if(C % 2) R = R + V;
    return R;
}

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<n;i++) {
        int T;
        scanf("%d",&T);
        T--;
        x[0].push_back(T);
        ia[T] = i;
    }
    for(int i=0;i<n;i++) {
        int T;
        scanf("%d",&T);
        T--;
        x[1].push_back(T);
        ib[T] = i;
    }
    for(int i=0;i<n;i++) {
        x[2].push_back(ia[i]);
        x[3].push_back(ib[i]);
        def.push_back(i);
    }
    vector<int> C;
    if(k == 1) C = x[0];
    else if(k == 2) C = (x[1]);
    else if(k == 3) C = (x[1] + x[2]);
    else if(k == 4) C = (x[1] + x[2] + x[3]);
    else {
        int A = (k-5)/6, B = (k-5)%6;
        C = calc(x[3]+x[2]+x[1]+x[0], A) + x[3];
        if(B == 1) C = x[0] + C;
        else if(B == 2) C = x[1] + x[0] + C;
        else if(B == 3) C = x[1] + x[2] + x[1] + x[0] + C;
        else if(B == 4) C = x[1] + x[2] + x[2] + x[1] + x[0] + C;
        else if(B == 5) C = x[1] + x[2] + x[3] + x[2] + x[1] + x[0] + C;
        C = calc(x[1] + x[2] + x[3] + x[0], A+1) + C;
    }
    for(int i=0;i<n;i++) {
        printf("%d ", C[i]+1);
    }
    puts("");
}


Measured memory_bytes: 19196
#include <stdio.h>
#include <iostream>
#include <ctime>
#include <climits>
#include <chrono>
#include <bits/stdc++.h>

#define ll long long
#define f first
#define s second

using namespace std;
using namespace chrono;

mt19937_64 randGen(system_clock().now().time_since_epoch().count());
mt19937 rnd(42);

#ifdef local
  const int N = 1e3+1;
#else
  const int N = 1e5+1;
#endif

const int LIM = 2e9+1;

struct Solver {
  ll n, w, dp[N];
  vector<pair<ll, ll>> q;

  void read() {
    ll wi, v;
    cin >> n >> w;
    for(int i = 0; i < N; i++) {
      dp[i] = LIM;
    }
    for(int i = 0; i < n; i++) {
      cin >> wi >> v;
      q.push_back({wi, v});
    }
  }
  
  void solve() {
    int tmp[N] = {};
    for(auto &e : q) {
      for(int j = 0; j+e.s < N; j++) {
        int to = e.s+j;
        tmp[to] = min(dp[to], dp[j]+e.f);
      }
      tmp[e.s] = min(dp[e.s], e.f);
      for(int j = 0; j < N; j++) {
        if(tmp[j] == 0) { continue; }
        dp[j] = tmp[j];
      }
    }
    for(int i = N-1; i >= 0; i--) {
      if(dp[i] <= w) {
        cout << i;
        return;
      }
    }
    cout << 0;
  }
};

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

  #ifdef local
    freopen("input-e.txt", "r", stdin);
  #endif

  Solver sol;
  sol.read();
  sol.solve();

  #ifdef local
    auto tspent = 1.0 * clock() / CLOCKS_PER_SEC;
    cerr << "\nTime elapsed: " << tspent << " s.\n";
  #endif
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

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

    vector<i64> a(n), b(n);
    i64 aneed = 0, bneed = 0;

    for (int i = 0; i < n; i++)
        scanf("%lld", &a[i]);

    for (int i = 0; i < n; i++)
        scanf("%lld", &b[i]);

    for (int i = 0; i < n - 1; i++)
    {
        if (a[i] > b[i])
        {
            bneed += a[i] - b[i];
        }
        else if (b[i] > a[i])
        {
            if ((b[i] - a[i]) % 2 == 0)
            {
                aneed += (b[i] - a[i]) / 2;
            }
            else
            {
                bneed++;
                aneed += (b[i] + 1 - a[i]) / 2;
            }
        }
    }

    if (aneed > bneed)
        b[n - 1] += aneed - bneed;
    else
        a[n - 1] += (bneed - aneed) * 2;

    if (a[n - 1] > b[n - 1])
        printf("No\n");
    else
        printf("Yes\n");

    return 0;
}

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

int main() {
  int x,y; cin>>x>>y;
  if(0<=x && x<y){cout<<y-x;}
  else if(0<y && y<x){cout<<x-y+2;}
  else if(0<=-y && -y<=x){cout<<x+y+1;}
  else if(0<=x && x<=-y){cout<<1-y-x;}
  else if(0<=-x && -x<=y){cout<<1+x+y;}
  else if(0<y && y<=-x){cout<<1-y-x;}
  else if(0<-x && -x<-y){cout<<x-y+2;}
  else {cout<<y-x;}
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<62;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	int n;cin>>n;
	vector<ll> a(n+10);
	for(int i=1;i<=n;i++)cin>>a[i];
	vector<vector<ll>> dp(n+10,vector<ll>(5,LINF));
	for(int i=0;i<5;i++)dp[0][i]=0;
	for(int i=1;i<=n;i++){
		ll mi=dp[i-1][0];
		chmin(dp[i][0],mi+a[i]);
		chmin(mi,dp[i-1][1]);
		if(a[i]==0){
			chmin(dp[i][1],mi+2);
		}else if(a[i]%2){
			chmin(dp[i][1],mi+1);
		}else{
			chmin(dp[i][1],mi);
		}
		chmin(mi,dp[i-1][2]);
		chmin(dp[i][2],mi+(a[i]%2?0LL:1LL));
		chmin(mi,dp[i-1][3]);
		if(a[i]==0){
			chmin(dp[i][3],mi+2);
		}else if(a[i]%2){
			chmin(dp[i][3],mi+1);
		}else{
			chmin(dp[i][3],mi);
		}
		chmin(mi,dp[i-1][4]);
		chmin(dp[i][4],mi+a[i]);
	}
	cout<<min({dp[n][0],dp[n][1],dp[n][2],dp[n][3],dp[n][4]})<<endl;
}


Measured memory_bytes: 15872
/*
 
*/ 
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAXN = 2e5+5;
vector<int> graph[MAXN];
bool visited[MAXN];
int n, m, ans = 0, cc = 0;

void DFS(int curr)
{
    ++cc;
    visited[curr] = true;
    for(auto& v : graph[curr])
    {
        if(!visited[v]) DFS(v);
    }
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // FOR QUERY PROBLEM DON'T FORGET TO UNCOMMENT THIS
    cin >> n >> m;
    for(int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    for(int i = 1; i <= n; ++i)
    {
        cc = 0;
        if(!visited[i]) DFS(i);
        ans = max(ans, cc);
    }
    cout << ans << "\n";
    return 0;
}
 
/*
 
*/  

Measured memory_bytes: 20908
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <iomanip>
using namespace std;
 
 
 
int main(){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    int s=0;
    for (int j=0; j<K; j++){
      s += A[j];
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000000,mod=998244353;
int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    ll arr[k][2];
    for(ll i=0;i<k;i++)cin>>arr[i][0]>>arr[i][1];
    ll dp[n+1]={0},pre[n+1]={0};
    dp[0]=1;pre[0]=1;
    for(ll i=1;i<=n;i++){
        dp[i]=0;
        for(ll j=0;j<k;j++){
            if(i-arr[j][0]>0)
            dp[i]=(dp[i]+pre[i-arr[j][0]])%mod;
            if(i-arr[j][1]-1>0)
            dp[i]=(dp[i]-pre[i-arr[j][1]-1]+mod)%mod;
        }

        pre[i]=(pre[i]+dp[i])%mod;
        pre[i]=(pre[i]+pre[i-1])%mod;
    }
    cout<<dp[n]<<" ";
}


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

// ループによる最大公約数
int gcd(int x, int y) {
    int r;
    if (x < y) swap(x, y); // y < x を保障する

    while (y > 0) {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main() {
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;

    return 0;
}


Measured memory_bytes: 3080
#include <stdio.h>

int main(void){
    int middle, final, retest;
    int sum;
    char grade;

    while (1){
        scanf("%d %d %d", &middle, &final, &retest);
        sum = middle + final;

        if (middle == -1 && final == -1 && retest == -1){
            break;
        }else if (middle == -1 || final == -1){
            grade = 'F';
        }else if (sum >= 80){
            grade = 'A';
        }else if (sum < 80 && sum >= 65){
            grade = 'B';
        }else if (sum < 65 && sum >= 50){
            grade = 'C';
        }else if (sum < 50 && sum >= 30){
            if (retest < 50){
                grade = 'D';
            }else{
                grade = 'C';
            }
        }else{
            grade = 'F';
        }

        printf("%c\n", grade);
    }

    return 0;
}

Measured memory_bytes: 1032
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"YES"<<"\n"
#define no cout<<"NO"<<"\n"

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin>>n;
	int s=5;
	int m=inf;
	rep(i,5){
		int a;cin>>a;
		cmin(m,a);
	}
	cout<<5+(n-1)/m<<endl;
}






Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
int a,b,x,y;
  scanf("%d%d%d%d",&a,&b,&x,&y);
  printf("%lf %d\n",double(a)*double(b)/2,x+x==a&&y+y==b);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a, b, c, d;

int main() {
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d ||
        (abs(a - b) <= d && abs(b - c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 888
N = int(input())
A = list(map(int, input().split()))

import collections
ans = 0
c = collections.Counter(A)
lis = []
for k,v in c.items():
  if v>=2:
    lis.append(k)
  if v>=4:
    lis.append(k)
if len(lis)>=2:
  lis.sort()
  ans = lis[-1]*lis[-2]
print(ans)

#print(*ans, sep='\n')


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

using namespace std;
int main() {
    int c,t,sum=0,a,b;
    cin >>t;
    int arr[t];
    for(int i=0;i<t;i++){
        cin >> arr[i];
        sum += arr[i];
    }
    a = sum;
    b=0;
    for(int i=0;i<t;i++){
        b += arr[i];
        c = sum-b;
        a = min(a, abs(b-c));
    }
    cout << a;
    
 }

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

class Main {

	private static int n;
	private static List<String> a = new ArrayList<>();

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		dfs(0, new StringBuilder(), new HashMap());
		StringBuilder sb = new StringBuilder();
		for (String b : a) {
			sb.append(b).append("\n");
		}
		System.out.print(sb);
	}

	private static void dfs(int x, StringBuilder sb, Map<Character, Integer> s) {
		if (sb.length() == n) {
			//if (ok(sb.toString())) {
			a.add(sb.toString());
			//}
			return;
		}

		for (int i = 0; i <= x && i <= s.size(); i++) {
			char c = (char) ('a' + i);
			s.put(c, s.getOrDefault(c, 0) + 1);
			sb.append(c);
			dfs(x + 1, sb, s);
			sb.deleteCharAt(sb.length() - 1);
			if (s.getOrDefault(c, 1) == 1) {
				s.remove(c);
			} else {
				s.put(c, s.get(c) - 1);
			}
		}
	}

	private static boolean ok(String a) {
		if (a.charAt(a.length() - 1) == (char) ('a' + n - 1)) {
			for (int i = 0; i < a.length(); i++) {
				if (a.charAt(i) != (char) ('a' + i)) return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 52796
#include <stdio.h>
int solve(int ,int);

int A[2000];
int n;
int main() {
  int i;
  int m;
  int j;
  int q;
  int mi[2000];
  

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&mi[i]);
  }
  for(i=0;i<q;i++){
    if(solve(0,mi[i])==1) printf("yes\n");
    else printf("no\n");
  }
  
  return 0;
}

int solve(int i,int mi){

  int res;
  if(mi==0) return 1;
  if(i>=n) return 0;

  res= solve(i+1,mi) || solve(i+1,mi-A[i]);
  return res;
}

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

int main(void){
	int A,B,C,X,Y;
	int ans = 0;
	cin >> A>>B>>C>>X>>Y;
	if(C*2<A+B){
		ans += min(X,Y)*C*2;
		if(X>Y)ans+=A*(X-Y);
		else ans+=B*(Y-X);
	}
	else ans = A*X+B*Y;
	if((X-Y>0&&A>C*2)||(Y-X>0&&B>C*2))ans = min(max(X,Y)*C*2,ans);
	cout << ans <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main(){
    ll n,x;cin >> n >> x;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }
    ll count=0;
    REP(i,n-1){
        if(a[i]+a[i+1]>x){
            if(a[i+1]>a[i]+a[i+1]-x){
                count += a[i] + a[i + 1] - x;
                a[i + 1] -= (a[i] + a[i + 1] - x);
            }
            else{
                count += a[i] + a[i + 1] - x;
                a[i]-=a[i]-x;
                a[i+1]=0;
            }
        }
    }
    cout << count << endl;
}

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

using namespace std;
typedef long long int ll;

int dh[4] = {1,0,-1,0};
int dw[4] = {0,1,0,-1};

int main()
{
    int q;
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        string X,Y;
        cin >> X >> Y;
        int lx = X.length();
        int ly = Y.length();
        vector<vector<int>>dp(lx+1,vector<int>(ly+1,0));
        for(int i = 1; i <= lx; i++)
        {
            for(int j = 1; j <= ly; j++)
            {
                if(X[i-1] == Y[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
                else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
        cout << dp[lx][ly] << endl;
    }
}


Measured memory_bytes: 6836
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 100010;

int dp[MAX];

void solve(void){

	int N;
	cin >> N;

	rep(MAX, i)
	{
		dp[i] = i;
	}

	rep(MAX, n)
	{
		int x = 6;

		while(x+n <= N)
		{
			int i = 1;
			while(i * x + n <= N && i < 6)
			{
				dp[i*x+n] = min(dp[i*x+n], dp[n]+i);
				i++;
			}
			x *= 6;
		}

		int y = 9;

		while(y+n <= N)
		{
			int i = 1;
			while(i * y + n <= N && i < 9)
			{
				dp[i*y+n] = min(dp[i*y+n], dp[n]+i);
				i++;
			}
			y *= 9;
		}

	}

	cout << dp[N] << endl;


}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

ll T[101];

template<class T>
T gcd(T a, T b, T* px = NULL, T* py = NULL){
	if(py == NULL){
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	T d = a;
	if(b != 0){
		d = gcd(b, a % b, py, px);
		*py -= (a / b) * *px;
	}else{
		*px = 1; *py = 0;
	}
	return d;
}

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

	ll res = T[0];
	ll a;

	for(int i = 1; i < N; i++){
		a = gcd(res, T[i]);
		res = res / a * T[i];
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 384
_, *_XL = open(0).read().split()

XL = list(zip(*[map(int, iter(_XL))]*2))

ans = 0
t = -10**10 # 数直線のマイナス方向からスタートする

arms = [(X-L, X+L) for X, L in XL]
arms_sorted = sorted(arms, key=lambda k:k[1])

ans = 0

for s, e in arms_sorted:
    if t <= s:
        t = e
        ans += 1
        
print(ans)

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

struct S {
    mint x,w;
    S(mint x=0, mint w=1): x(x),w(w) {}
};
S op(S a, S b){
    return S(a.x*b.w + b.x , a.w*b.w);
}
S e() { return S(); }

S mapping(int f, S a) {
    if(f==0) return a;
    return S((a.w-1)/9 * f, a.w);
}
int composition(int f, int g){
    if(f == 0) return g;
    return f;
}
int id() { return 0; }

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

    int n,q; cin>>n>>q;
    lazy_segtree<S,op,e,int,mapping,composition,id> tree(n);
    rep(i,n) tree.set(i, S(1, 10));
    
    while(q--){
        int l, r, d; cin>>l>>r>>d; l--;
        tree.apply(l,r,d);
        
        S ans = tree.prod(0,n);
        cout << ans.x.val() << endl;
    }

    return 0;
}

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

int main() {
    int N;
    cin>>N;
    vector<string> s(N);
    rep(i,N) cin>>s[i];
    int M;
    cin>>M;
    vector<string> t(M);
    rep(i,M) cin>>t[i];

    int ans=0;
    rep(i,N) {
        int tmp=0;
        rep(j,N) {
            if (s[j]==s[i]) {
                tmp++;
            }
        }
        rep(j,M) {
            if (t[j]==s[i]) {
                tmp--;
            }
        }
        if (tmp>ans) {
            ans=tmp;
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 3592
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=220,P=998244353;
int i,j,k,n,m,ch,ans,g;
int tm2[N];
struct point {
	int x,y;
	bool operator < (const point &n) const {
		if (x==n.x) return y<n.y;
		return x<n.x;
	}
} A[N],B[N];
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
int gcd(int a,int b) {
	if (!b) return a;
	return gcd(b,a%b);
}
int main() {
	R(n);
	tm2[0]=1;
	for (i=1;i<=n;i++) tm2[i]=(tm2[i-1]+tm2[i-1])%P;
	for (i=1;i<=n;i++) R(A[i].x),R(A[i].y);
	sort(A+1,A+n+1);
	ans=1;
	for (i=1;i<=n;i++) {
		m=0;
		ans=(ans+1)%P;
		for (j=i+1;j<=n;j++) {
			m++;
			B[m].x=A[j].x-A[i].x;
			B[m].y=A[j].y-A[i].y;
			if (B[m].y<0) g=gcd(B[m].x,-B[m].y);
			else g=gcd(B[m].x,B[m].y);
			B[m].x/=g;
			B[m].y/=g;
		}
		sort(B+1,B+m+1);
		B[m+1].x=-1;
		k=1;
		for (j=1;j<=m;j++) {
			if (B[j].x==B[j+1].x && B[j].y==B[j+1].y) k++;
			else {
				ans=(ans+tm2[k]-1)%P;
				k=1;
			}
		}
	}
	ans=(tm2[n]+P-ans)%P;
	printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

void Acout(int A[],int N){
    rep(i,N){
        if(i)cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
}

int main(){
    int N;
    cin>>N;
    int a[N];
    rep(i,N)cin>>a[i];
    int Q;
    cin>>Q;
    int t;
    int ans=0;

    rep(i,Q){
        cin>>t;
        rep(j,N){
            if(a[j]==t){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
	int N, M, X, Y, temp;
	char flag;
	cin >> N >> M >> X >> Y;
	vector<int> x;
	vector<int> y;
	for (int i = 0; i < N; i++)
	{
		cin >> temp;
		x.push_back(temp);
	}
	for (int i = 0; i < M; i++)
	{
		cin >> temp;
		y.push_back(temp);
	}
	for (int Z = X + 1; Z < Y; Z++)
	{
		flag = 'N';
		for (int i = 0; i < N; i++)
		{
			if (Z > x[i])
			{
				continue;
			}
			else
			{
				flag = 'Y';
				break;
			}
		}
		if (flag == 'Y')
		{
			continue;
		}
		else;
		for (int i = 0; i < M; i++)
		{
			if (Z <= y[i])
			{
				continue;
			}
			else
			{
				flag = 'Y';
				break;
			}
		}
		if (flag == 'N')
		{
			cout << "No War" << endl;
			return 0;
		}
		else;
	}
	cout << "War" << endl;
	return 0;
}

Measured memory_bytes: 256
count_ary = []
for i in "a".."z" do 
    count_ary.push([i, 0])
end

while (line_input = gets) do

    line = line_input.downcase

    line.chars{|ch|
        for i in 0..25 do
            if ch == count_ary[i][0] then
                count_ary[i][1] += 1
            end
        end
    }
end

26.times{|i|
    puts count_ary[i].join(" : ")
}


Measured memory_bytes: 6860
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a, b;
  cin >> a;
  cin >> b;
  if (a.size() > b.size()) {
    cout << "GREATER" << endl;
  } else if (a.size() < b.size()) {
    cout << "LESS" << endl;
  } else if (a == b) {
    cout << "EQUAL" << endl;
  } else {
    int digit = 0;
    while (digit < a.size()) {
      if (a[digit] > b[digit]) {
        cout << "GREATER" << endl;
        break;
      } else if (a[digit] < b[digit]) {
        cout << "LESS" << endl;
        break;
      }
      digit++;
    }
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;

            while (true)
            {
                str = Console.ReadLine ().Split (' ');
                int a = int.Parse (str[0]);
                int b = int.Parse (str[2]);
                string op = str[1];

                if (op == "+") Console.WriteLine (a + b);
                if (op == "-") Console.WriteLine (a - b);
                if (op == "*") Console.WriteLine (a * b);
                if (op == "/") Console.WriteLine (a / b);
                if (op == "?") break;

            }

        }
    }

    class MyLibrary
    {

        // 自作の関数
        public static int MyFunction (int n)
        {
            return 0;
        }
    }
}


Measured memory_bytes: 17920
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
  int n; cin >> n;
  cout << n * (n+1) / 2 << ln;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve() {
    ll H, n = 1;
    cin >> H;
    ll ans = 0;
    while ( H > 0 ) {
        ans += n;
        n *= 2;
        H /= 2;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

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

    int n;
    string s;
    cin >> n >> s;
    deque<char> deq;
    int c = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == '(') ++c, deq.push_back(s[i]);
        else{
            if(deq.empty()){
                deq.push_front('(');
                deq.push_back(s[i]);
            }
            else{
                if(c > 0){
                    --c;
                    deq.push_back(s[i]);
                }
                else{
                    deq.push_front('(');
                    deq.push_back(s[i]);
                }
            }
        }
    }
    for(int i = 0; i < c; ++i)  deq.push_back(')');
    while(!deq.empty()){
        cout << deq.front();
        deq.pop_front();
    }
    cout << endl;
}

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

int main(){
  int N, M;
  
  cin >> N >> M;
  
  bool ans = true;
  
  if(N >= 10 || N == 0) ans = false;
  if(M >= 10 || M == 0) ans = false;
  
  if(ans){
    cout << N * M << endl;
  }else{
    cout << -1 << endl;
  }
}

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

#define ll long long

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

	int n;
	cin >> n;

	ll sum = 0;
	for (int i = 1; i <= n; ++i) {
		if (i % 3 != 0 && i % 5 != 0) sum += i;
	}
	cout << sum;
}


Measured memory_bytes: 3636
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       int  N = sc.nextInt();
       int  M = sc.nextInt();
       int[] a = new int[N];
       Arrays.fill(a, -1);
       boolean flg=false;
       for(int i=0;i<M;i++) {
    	   int keta=sc.nextInt();
    	   int su=sc.nextInt();
    	   if(a[N-keta]==-1) {
    		   if(keta==1&&su==0&&N!=1) {
    			   flg=true;
    		   } else {
        		   a[N-keta]=su;    			   
    		   }
    	   } else {
    		   if(a[N-keta]!=su) {
    			   flg=true;
    		   }
    	   }
       }
       int ans=0;
       int tmp=0;
       int keta=1;
       for(int i=0;i<N;i++) {
    	   if(a[i]==-1) {
    		   if(i==N-1&&N!=1) {
    			   tmp=1;
    		   } else {
    			   tmp=0;
    		   }
    	   } else {
    		   tmp=a[i];
    	   }
    	   ans=ans+tmp*keta;
    	   keta=keta*10;
       }
       if(flg==true) {
    	   ans=-1;
       }
       System.out.println(ans);
   }
}

Measured memory_bytes: 24916
N = int(input())

user_name = []

for i in range(N):
    user_name.append(input())

M_group = [x for x in user_name if x[0] == 'M']
A_group = [x for x in user_name if x[0] == 'A']
R_group = [x for x in user_name if x[0] == 'R']
C_group = [x for x in user_name if x[0] == 'C']
H_group = [x for x in user_name if x[0] == 'H']

choice_cnt = 0
choice_list = []

for i in range(2):
    choice_cnt += i
    for j in range(2):
        choice_cnt += i
        for k in range(2):
            choice_cnt += i
            for l in range(2):
                choice_cnt += i
                for m in range(2):
                    choice_cnt += i

                    if i+j+k+l+m == 3:
                        choice_list.append([i,j,k,l,m])

sums = 0
march = [len(M_group), len(A_group), len(R_group), len(C_group), len(H_group)]

prod = 0
choice_num = []

for x in choice_list:
    choice_num.append([march[i] for i in range(len(x)) if x[i] > 0])

prod_sum = 0

for y in choice_num:
    prod = 1

    for k in range(len(y)):
        prod = prod * y[k]
    prod_sum += prod

print(prod_sum)


Measured memory_bytes: 10552
#include<stdio.h>

int main(void){
	
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a<b && b<c){
		printf("Yes\n");
	}
	
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	ll x,k,d; cin >> x >> k >> d;
	x = abs(x);
	if(x / k >= d){
		cout << x - k * d << endl;
	}else{
		ll t = x / d;
		k -= t;
		x -= t * d;
		if(k % 2){
			cout <<  d - x << endl;
		}else{
			cout << x << endl;
		}
	}
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  if(a>=k){
    cout << k << endl;
    return 0;
  }
  else if(b>=k-a){
    cout << a << endl;
    return 0;
  }
  else if(c>=k-a-b){
    cout << 2*a+b-k << endl;
    return 0;
  }
  else {
    cout <<a-c <<endl;
    return 0;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

class Watch {
public:
	explicit Watch(int X) : X(X), startA(0), curA(0), startB(X), curB(X), up(true) {}
	int query(int time, int a){
		int cur = calcStart_(a) + (up ? -time : time);
		if(cur <= 0) return 0;
		if(cur >= X) return X;
		return cur;
	}
	int progress(int time){
		if(up){
			curA -= time;
			curB -= time;
			if(curB <= 0){
				startA = startB;
				curA = curB = 0;
			} else if(curA <= 0){
				startA -= curA;
				curA = 0;
			}
		} else {
			curA += time;
			curB += time;
			if(curA >= X){
				startB = startA;
				curA = curB = X;
			} else if(curB >= X){
				startB -= curB - X;
				curB = X;
			}
		}
		up = !up;
	}
private:
	int calcStart_(int a){
		if(a <= startA) return curA;
		if(a >= startB) return curB;
		return curA + a - startA;
	}
private:
	const int X;
	int startA, curA, startB, curB;
	bool up;
};

int main(){
	std::ios::sync_with_stdio(false);
	int X, K;
	while(cin >> X >> K){
		vector<int> times;
		times.push_back(0);
		for(int i=0;i<K;i++){
			int a; cin >> a;
			times.push_back(a);
		}
		times.push_back(1000000007);
		Watch watch(X);
		int timeIdx = 0;
		int Q; cin >> Q;
		for(int i=0;i<Q;i++){
			int t, a; cin >> t >> a;
			while(t >= times[timeIdx+1]){
				watch.progress(times[timeIdx+1] - times[timeIdx]);
				++timeIdx;
			}
			cout << watch.query(t - times[timeIdx], a) << endl;
		}
	}
}

Measured memory_bytes: 1784
#include <iostream>
#define min(a, b) a > b ? b : a
using namespace std;

int main () {
	int share, remain, cost = 0;
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	share = min (x, y);
	if (a + b > 2 * c) cost += share * 2 * c;
	else cost += share * (a + b);
	if (x - share) {
		remain = x - share;
		if (a > 2 * c) cost += 2 * c * remain;
		else cost += a * remain;
	} else {
		remain = y - share;
		if (b > 2 * c) cost += 2 * c * remain;
		else cost += b * remain;
	}
	cout << cost << "\n";
	return 0;
}

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

#define dbg(x) cout << #x"=" << x << endl;
typedef long long LL;
LL N,A,B;

int main(){
  //  freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> A >> B;
	LL det = B-A;
    if(det&1){
        cout << min(A, N-B+1)+((B-A-1)/2LL) << endl;
    } else {
        cout << det/2L << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <cassert>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdint>
#include <ctime>

#include <fstream>

#include <cassert>

using namespace std;

#define MY_PI 3.14159265358979323846264338327950288
using LL = long long;
const int INF = 1e9;
const int MAXN = 60000000;

const long double kek = 1.0;
const float eps = 1e-9;
#define DB(x) cerr << #x << " " << x << endl;

int main()
{
    //gen(1001);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    //cout << fixed;
    //cout.precision(6);
    int n;
    cin >> n;
    vector < LL > a(n), b(n);
    for (int i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
    }
    LL add = 0;
    for (int i = n - 1; i >= 0; --i) {
        if ( (a[i]+add) % b[i] != 0) {
            add += b[i] - (a[i]+add) % b[i];
        }
    }
    cout << add;
    return 0;
}

Measured memory_bytes: 2424
from sys import stdin

def getval():
    n,m,k = map(int,stdin.readline().split())
    a = [list(map(int,stdin.readline().split())) for i in range(m)]
    c = [list(map(int,stdin.readline().split())) for i in range(k)]
    return n,m,k,a,c 

def main(n,m,k,a,c):
    #Compute all members' friends
    friends = [[] for i in range(n)]
    for i in a:
        friends[i[0]-1].append(i[1]-1)
        friends[i[1]-1].append(i[0]-1)
    
    #Group all members in the isolated "friend groups"
    frgroups = []
    visited = [False for i in range(n)]
    for i in range(n):
        if visited[i]:
            continue
        q = [i]
        temp = [i]
        visited[i] = True
        while q:
            idx = q.pop(0)
            adj = friends[idx]
            for j in adj:
                if visited[j]:
                    continue
                visited[j] = True
                q.append(j)
                temp.append(j)
        frgroups.append(temp)    

    #Number all members with their friend groups respectively
    groups = [-1 for i in range(n)]
    for i in range(len(frgroups)):
        for j in frgroups[i]:
            groups[j] = i 
            
    #For each member, refer to the friend groups of blocked peope
    #Compute ans accordingly
    ans = [len(frgroups[groups[i]])-1-len(friends[i]) for i in range(n)]
    for i in c:
        if groups[i[0]-1]==groups[i[1]-1]:
            ans[i[0]-1] -= 1
            ans[i[1]-1] -= 1
    s = str(ans[0])
    for i in range(1,n):
        s += " " + str(ans[i])
    print(s)
    

if __name__=="__main__":
    n,m,k,a,c = getval()
    main(n,m,k,a,c)

Measured memory_bytes: 79148
#include <stdio.h>

int main(void){
	int n,i;

	scanf("%d", &n);

	if(n > 100){
		return 0;
	}

	int data[n];

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

	/*output reversing numbers*/
	for(i = n - 1;i >= 0;i--){
		printf("%d", data[i]);
		if(i == 0){
			printf("\n");
			break;
		}
		printf(" ");
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,n,ans=0;
  cin>>h>>w>>n;
  if(h>=w)
    while(n>0){
      	n-=h;
      	ans++;
    }
  else
    while(n>0){
      	n-=w;
      	ans++;
    }
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 256
import sys
h=['light ','']
for e in sys.stdin:
 e=float(e)
 for i in range(7):
  if[81,69,60,57,54,51,0][i]<e:
   print([h[e>91]+'heavy',h[e>75]+'middle',h[e>64]+'welter','light','feather','bantam',h[e>48]+'fly'][i])
   break


Measured memory_bytes: 5584
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t;cin >> n >> t;
  vector<int> a(n),b(n);
  vector<pair<int,int>> c(n);
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
  }
  int dp[n+1][t][2];
  for(int i=0;i<=n;i++){
    for(int j=0;j<t;j++){
      dp[i][j][0]=0;
      dp[i][j][1]=0;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<t;j++){
      dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][0]);
      dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][1]);
      if(j+a[i]<t){
        dp[i+1][j+a[i]][0]=max(dp[i+1][j+a[i]][0],dp[i][j][0]+b[i]);
        dp[i+1][j+a[i]][1]=max(dp[i+1][j+a[i]][1],dp[i][j][1]+b[i]);
      }
      dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][0]+b[i]);
    }
  }
  int ans=0;
  for(int i=0;i<t;i++){
    ans=max(ans,max(dp[n][i][0],dp[n][i][1]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;

typedef tuple<ll, ll, ll> T;
vector<T> v;

ll dp[5010][5010];

int main(){

  n = in();
  REP( i , n ){
    ll h = in();
    ll p = in();
    v.pb(h + p, h, p);
  }

  SORT( v );
  REP( i , n+1 ){
    REP( j , n+1 ){
      dp[i][j] = INFLL;
    }
  }
  dp[0][0] = 0;
  REP( i , n ){
    ll a, h, p;
    tie(a, h, p) = v[i];

    REP( j , i+1 ){
      if( dp[i][j] <= h ){
        chmin( dp[i+1][j+1], dp[i][j] + p );
      }
      chmin( dp[i+1][j], dp[i][j] );
    }
  }

  ll ans = 0;
  REP( i , n+1 ){
    if( dp[n][i] < INFLL ){
      chmax( ans, i );
    }
  }
  printf( "%lld\n" , ans );
  
  return 0;
}


Measured memory_bytes: 197184
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n = input_n

if n == 1
  puts 0
else
  puts 1
end


Measured memory_bytes: 14384
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
signed main(){
	int a,b;
	cin>>a>>b;
	cout<<(a-1)/(b*2+1)+1<<endl;
}


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

int main() {
    int n, k;
    string s;
    cin >> n >> s >> k;
    char c = s.at(k - 1);
    for(int i = 0; i < n; i++)
    {
        if (s.at(i) != c) s.at(i) = '*';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    long n, m;
    scan(n, m);
    if (n > m) swap(n, m);

    if (n == 1 && m == 1) {
        writeln(1);
    }
    else if (n == 1) {
        writeln(m - 2);
    }
    else {
        writeln((n-2)*(m-2));
    }
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n = int(input())
n,*a = [int(i) for i in read().split()]

from collections import Counter
d = Counter()

ans = 0
for i in range(n):
    ans += d[a[i]-i]
    d[-i-a[i]] += 1

print(ans)

Measured memory_bytes: 40392
N, M = gets.chop.split.map(&:to_i)

graph = Hash.new{ |h, k| h[k] = [] }

M.times do
  from, to = gets.chop.split.map(&:to_i)
  graph[from] << to
  graph[to] << from
end

graph[N].each do |i|

  if graph[i].include?(1)
    puts 'POSSIBLE'
    exit
  end
end

puts 'IMPOSSIBLE'

Measured memory_bytes: 30844
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            while (sc.hasNext()) {
                String s = sc.nextLine();
                if (s.equals("-")) {
                    break;
                }
                int m = Integer.parseInt(sc.nextLine());
                while (m > 0) {
                    int h = Integer.parseInt(sc.nextLine());
                    String s1 = s.substring(0, h);
                    String s2 = s.substring(h);
                    s = s2 + s1;
                    --m;
                }
                System.out.println(s);
            }
        } catch (NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }
}



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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll N, K;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif
  cout << setprecision(20);

  cin >> N >> K;
  if (K > (N - 1) * (N - 2) / 2) {
    cout << "-1" << endl;
    return 0;
  }
  ll M = 0;
  vector<ll> u;
  vector<ll> v;
  for (ll i = 2; i <= N; i++) {
    u.push_back(1);
    v.push_back(i);
    M++;
  }
  ll t = 1;
  for (ll j = 2; j <= N; j++) {
    for (ll k = j + 1; k <= N; k++) {
      if (t > K) {
	u.push_back(j);
	v.push_back(k);
	M++;
      }
      t++;
    }
  }
  cout << M << "\n";
  for (ll i = 0; i < M; i++) {
    cout << u[i] << " " << v[i] << "\n";
  }

  return 0;
}



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

int main() {
	int a;
	cin >> a;
	vector<int> b(a+1);
	vector<int> c(a+1);
	vector<int> tinnko;
	for(int i  = 0;i < a ;i++){
		cin >> b.at(i);
	}
	for(int i  = 0;i < a ;i++){
		cin >> c.at(i);
	}
	for(int i  = 0;i < a ;i++){
		tinnko.push_back(i+1);
	}

	int big,small,count = 0;
	do {
		bool x = true,y = true;
		for(int i  = 0;i < a ;i++){
			if(tinnko[i] != b[i]){
				x = false;
			}
		}
		for(int i  = 0;i < a ;i++){
			if(tinnko[i] != c[i]){
				y = false;
			}
		}
		if(x == true){
			small = count;
		}
		if(y == true){
			big = count;
		}

		count++;

	} while (next_permutation(tinnko.begin(), tinnko.end()));
	
	cout << abs(big-small) << endl;
}



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

int main() {
    int64_t A, V, B, W, T;
    cin >> A >> V >> B >> W >> T;
    if (A > B) {
        swap(A, B);
    }

    int64_t x1 = A + V * T;
    int64_t x2 = B + W * T;
    cout << (x1 < x2 ? "NO" : "YES") << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using ll = long long;

int main() {
  int k;
  std::cin >> k;
  std::string S;
  std::cin >> S;
  int n = S.length();
  if (n <= k) {
    std::cout << S << std::endl;
  } else {
    std::cout << S.substr(0, k) << "..." << std::endl;
  }
}

Measured memory_bytes: 3632