akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;

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

public class Main {
    final static int INF = 1000000007;

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

            int N = Integer.parseInt(s);

            int power = 1;

            for (int i = 1; i <= N; i++) {
                power = modmulti(power, i);
            }

            System.out.println(power);
        }
    }

    // aとbを掛けた値をmodする(a * b mod p)
    static int modmulti(int a, int b)
    {
        int res = 0;
        int mod = a % INF;
        while (b > 0)
        {
            if ((b & 1) == 1)
            {
                res += mod;
                if (res > INF)
                {
                    res -= INF;
                }
            }
            mod <<= 1;
            if (mod > INF)
            {
                mod -= INF;
            }
            b >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  int ans=0;
  vector<int>num(n);
  for(int i=0; i<n; i++){
    cin>>num.at(i);
  }
  for(int i=0; i<n; i++){
    if((i+1)%2==1&&num.at(i)%2==1)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  string S;
  cin>>S;
  int N = S.size();

  vector<int> L, R;
  for(int i=0;i<N;i++)
    if(S[i] == 'L') L.push_back(i);
    else R.push_back(i);

  auto calc=[&](int x){
    int y;
    if(S[x] == 'L'){
      y = upper_bound(R.begin(), R.end(), x) - R.begin() - 1;
      y = R[y];
    }
    else {
      y = lower_bound(L.begin(), L.end(), x) - L.begin();
      y = L[y];
    }

    if(abs(x - y) % 2 == 0) return y;
    else return x < y? y-1:y+1;
  };


  vector<int> cnt(N);
  for(int i=0;i<N;i++){
    int p = calc(i);
    cnt[p]++;
  }

  cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 1996
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vi ans(n, k-q);
    for(int i =0; i < q; i++) {
        int num;
        cin >> num;
        ans[num - 1]++;
    }
    rep(i,n) {
        if(ans[i] <= 0) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
}


Measured memory_bytes: 1024
w,h,n = map(int,input().split())

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

max_x = 0
min_x = w
max_y = 0
min_y = h

for i in range(n):
    if p[i][2] == 1:
        if p[i][0] > max_x:
            max_x = p[i][0]
        
    if p[i][2] == 2:
        if p[i][0] < min_x:
            min_x = p[i][0]
    
    if p[i][2] == 3:
        if p[i][1] > max_y:
            max_y = p[i][1]
    
    if p[i][2] == 4:
        if p[i][1] < min_y:
            min_y = p[i][1]
        
        
if max_x > min_x:
    new_x = 0
else:
    new_x = min_x - max_x
    
if max_y > min_y:
    new_y = 0
else:
    new_y = min_y - max_y
    
print(new_x*new_y)
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<vector<char>> g;
int main(){
    ll h, w, d; cin >> h >> w >> d;
    map<ll, pair<ll, ll>> mp;
    rep(i, h)   rep(j, w){
        ll x;   cin >> x;
        mp[x] = {i+1, j+1};
    }
    vector<ll> g(h*w+1, 0);
    rep(i, h*w+1){
        if(i<d) continue;
        g[i] = g[i-d];
        g[i] += abs(mp[i-d].first-mp[i].first)+abs(mp[i-d].second-mp[i].second);
    }
    ll q;   cin >> q;
    rep(times, q){
        
        ll from, to;    cin >> from >> to;
        cout << g[to] - g[from] << endl;
    }
}


Measured memory_bytes: 9572
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int a;
    cin >>a ;
    if(a==1){
        cout<<"Hello World"<<endl;
        return 0;
    }
    int b,bb;
    cin >>b>>bb;
    b+=bb;
    cout<<b<<endl;
}
    



Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

char S[200050];

Int calc(const vector<int>& x) {
  Int res = 0, as = 0;
  for (const int t : x) {
    if (t == 0) {
      ++as;
    } else {
      res += as;
    }
  }
  return res;
}

int main() {
  scanf("%s", S);
  const int N = strlen(S);

  Int res = 0;
  vector<int> V;
  for (int i = 0; i < N; ) {
    bool reset = false;
    if (S[i] == 'A') {
      V.push_back(0);
      ++i;
    } else if (S[i] == 'B') {
      if (i + 1 < N && S[i + 1] == 'C') {
        V.push_back(1);
        i += 2;
      } else {
        ++i;
        reset = true;
      }
    } else {
      ++i;
      reset = true;
    }

    if (reset) {
      res += calc(V);
      V.clear();
    }
  }
  res += calc(V);

  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 1528
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int x,co=1;
        while(true){
            x = s.nextInt();
            if(x==0)break;
            else System.out.println("Case "+co+": "+x);
            co++;
        }
    }
}


Measured memory_bytes: 41616
//Same as CF 652F
#include <bits/stdc++.h>

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

typedef long long ll;

int n, m; ll t;
int s[300005]; int d[300005];
pair<int,int> o[300005];
int res[300005];

int main() {
    scanf("%d%d%lld", &n, &m, &t);
    FO(i,0,n) scanf("%d %d", s+i, d+i);
    FO(i,0,n) o[i] = make_pair(s[i],i);
    sort(o,o+n);
    vector<ll> p;
    ll nc = 0;
    FO(i,0,n) {
        int dir = d[i] == 2 ? -1 : 1;
        ll pos = s[i] + dir * t;
        ll fp = ((pos%m)+m)%m;
        ll g = pos > 0 ? pos / m : (pos-m+1) / m;
        nc += g;
        p.push_back(fp);
    }
    nc = ((nc%n)+n)%n;
    sort(p.begin(),p.end());
    FO(i,0,n) res[o[i].second] = p[(i+nc)%n];
    FO(i,0,n) printf("%d\n", res[i]);
}


Measured memory_bytes: 5748
s=input()
k=int(input())
a=[]
for i in range(len(s)):
    for j in range(1,k+1):
        if i+j<=len(s)+1:
            a.append(s[i:i+j])
        #print(a)
a=list(set(a))
a.sort()
#print(a)
print(a[k-1])

Measured memory_bytes: 5068
#include<bits/stdc++.h>
using namespace std;
const int maxn=500;
vector<int> G[maxn];
int dfn[maxn],low[maxn];
int n,m,u,v,dep,ans;

void init()
{
    dep=ans=0;
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    for(int i=0;i<=n;i++) G[i].clear();
}

void Tarjan(int u,int fa)
{
    dfn[u]=low[u]=++dep;
    for(int i=0;i<G[u].size();i++){
        int v=G[u][i];
        if(!dfn[v]){
            Tarjan(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]) ans++;
        }else if(v!=fa)
            low[u]=min(low[u],dfn[v]);
    }
}

int main()
{
    while(cin>>n>>m)
    {
        init();
        for(int i=0;i<m;i++){
            cin>>u>>v;
            G[u].push_back(v);
            G[v].push_back(u);
        }
        Tarjan(1,-1);
        cout<<ans<<endl;
    }
    return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,y;
	cin>>n>>y;
	for(ll i=0;i<n+1;i++){
		for(ll j=0;j<n+1;j++){
				if(i*10000+j*5000+( (y-10000*i-5000*j)/1000  )*1000==y && (y-10000*i-5000*j)/1000>=0  && i+j+(y-10000*i-5000*j)/1000 ==n){
					cout<<i<<" "<<j<<" "<< (y-10000*i-5000*j)/1000<<endl;
					return 0;
			}
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1<<endl;
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, a, b, c, d;
  std::cin >> n >> a >> b >> c >> d;
  std::string s;
  std::cin >> s;
  a--;
  b--;
  c--;
  d--;

  int64_t i = b;
  while (i != d) {
    if (s[i + 1] == '.') {
      i++;
    } else {
      if (s[i + 2] == '#') {
        std::cout << "No" << std::endl;
        return 0;
      } else {
        i += 2;
      }
    }
  }
  i = a;
  while (i != c) {
    if (s[i + 1] == '.') {
      i++;
    } else {
      if (s[i + 2] == '#') {
        std::cout << "No" << std::endl;
        return 0;
      } else {
        i += 2;
      }
    }
  }
  if (c < d) {
    std::cout << "Yes" << std::endl;
  } else {
    for (int64_t i = b - 1; i < d; i++) {
      if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
        std::cout << "Yes" << std::endl;
        return 0;
      }
    }
    std::cout << "No" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 640
N,K = map(int, input().strip().split(' '))
V = list(map(int, input().strip().split(' ')))
V += V
# まず宝石をi個取る、その後j個返す
# i個の取り方はi+1通り
# 返す時は負のもののみ、絶対値が大きいtopj個を返すので、取り方が決まるとそのときの最大点はすぐ決まる
# 0 <= i <= K, 0 <= j <= K-i
now_max = 0
for i in range(1, min(K+1, N+1)):
  for offset in range(i+1):
    jewel = sorted(V[-offset+N: -offset+i+N])
    remain_del = K-i
    while True:
      if len(jewel) == 0 or remain_del == 0 or jewel[0] > 0:
        break
      jewel.pop(0)
      remain_del -= 1
    now_max = max(now_max, sum(jewel))
print(now_max)

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC   
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve(ll testnum)
{
    ll n,k;
    cin >> n >> k;
    vll a(n);
    for(ll i=0;i<n;i++) {
    	cin >> a[i];
    }
    sort(all(a));
    ll mn = 1, mx = a[n-1] + 1;
    while(mn <= mx) {
    	ll md = (mn + mx)/2;
    	ll cnt = 0;
    	for(ll i=0;i<n;i++) {
    		cnt += ((a[i] + md - 1)/md - 1);
    	}
    	// cout << md << " " << cnt << "\n";
    	if(cnt <= k) {
    		mx = md - 1;
    	} else {
    		mn = md + 1;
    	}
    }
    cout << mn << "\n";
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        solve(i);
    }
}

Measured memory_bytes: 4752
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
#include <stdio.h>
using namespace std;
 
int main()
{
    unsigned long long int n,d;
    cin >> n >> d;
    int cnt = 0;
    long long int x[n],y[n];
    std::vector<int> v;
    for(int i=0; i<n; i++){
        long long int tmp1, tmp2;
        cin >> tmp1 >> tmp2;
        x[i] = tmp1;
        y[i] = tmp2;
        if(tmp1*tmp1+tmp2*tmp2 <= d*d){
            cnt++;
        }
    }
    
    int a = n;
    //if(n >= 30) cout << "Yes" << endl;
    //else cout << "No" << endl;
    cout << cnt << endl;
    //cout << "Yes" << endl;
    //printf("%d\n", n);

    
    return 0;
}

Measured memory_bytes: 6756
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;

int main(){
    int n,k;cin>>n>>k;
    vi v(n+1);
    rep(i,n)cin>>v[i+1];
    ll ans = 0;
    rep(i,n+1){
        rep2(j,i+1,n+2){
            ll sum =0;
            vi t;
            if(j==n+1){
                if(i>k)continue;
                rep(a,i){
                    t.push_back(v[a+1]);
                }
                sort(been(t));
                int l =t.size();
            rep(a,min(l,k-l)){
                if(t[0]>0)break;
                t.erase(t.begin());
            }
            rep(a,t.size())sum+=t[a];
            ans=max(ans,sum);
            continue;
            }
            if(n-j+i+1>k)continue;
            
            rep(a,i){
                t.push_back(v[a+1]);
            }
            rep(a,n-j+1){
                t.push_back(v[n-a]);
            }
            sort(been(t));
            int l =t.size();
            rep(a,min(l,k-l)){
                if(t[0]>0)break;
                t.erase(t.begin());
            }
            rep(a,t.size())sum+=t[a];
            ans=max(ans,sum);
        }
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
import itertools
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]

def get_dist(i,j):
  return ((i[0] - j[0])**2 + (i[1] - j[1])**2) ** 0.5

leng = [get_dist(i,j) for i,j in itertools.product(l,l)]
print(sum(leng)/n)

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

namespace _0383
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] vs = RArInt();
            int a = vs[0], b = vs[1], x = vs[2];

            int res = 0;
            if (2 * b <= a)
            {
                res = x / 500 * b;
                if (x % 500 > 0) res += b;
            }
            else
            {
                res = x / 1000 * a;
                int r = x % 1000;

                if (r > 500) res += a;
                else if (r > 0) res += Math.Min(a, b);
            }
            Console.WriteLine(res);
        }
        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 17940
#include <stdio.h>
#define N 10000
#define Q 500
#define NOT_FOUND -1



int count=0,n;

int linear(int a[],int key){
  int i=0;
  a[n]=key;
  while(a[i]!=key)
    i++;
  if(i==n)return NOT_FOUND;
  return i;
}




int main(){
  int a[N],b[Q],i,q;

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

  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&b[i]);

  for(i=0;i<q;i++)
    if(linear(a,b[i])!=NOT_FOUND)count++;

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





Measured memory_bytes: 2104
require 'set'
N = gets.to_i
A=gets.chomp.split(" ").map(&:to_i)
gets
M=gets.chomp.split(" ").map(&:to_i)

memo = Set.new
(1..N).each do |n|
    A.combination(n) do |combi|
        memo.add(combi.inject(:+))
    end
end

ret = M.map {|e| memo.include?(e) ? "yes" : "no" }
puts ret


Measured memory_bytes: 9164
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <numeric>
using namespace std;
#define MAX_N 400

// Input
int A, B;

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

    int ans = 0;
    if (A >= 13) {
        ans = B;
    } else if (A >= 6) {
        ans = B / 2;
    } else {
        ans = 0;
    }
    cout << ans;
}

Measured memory_bytes: 888
m,t,ans,h,i,a,j;
main(n){
	for(;scanf("%d%d",&n,&m)*n;){
		t=1e7;
		h=0;
		for(i=0;i<n;i++){
			scanf("%d",&a);
			j=m/a*a;
			if(j*2000+a<=t){
				h=j*2000+a==t;
				t=j*2000+a;
				ans=i;
			}
		}
		printf("%d\n",h?n:ans+1);
	}
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
class Program{
  public static int min(int x, int y){
    if (x >= y){
      return y;
    }
    else{
      return x;
    }
  }
  public static void Main(){
    int N, K;
    var NKL = Console.ReadLine().Split(' ');
    N = int.Parse(NKL[0]);
    K = int.Parse(NKL[1]);
    var A = new int[N];
    var line = Console.ReadLine().Split(' ');
    for (int i=0;i<N;i++){
      A[i] = int.Parse(line[i]);
    }
    int M = 2147483646;
    for (int k=0;k<N-K+1;k++){
      if (A[k] < 0 && A[k+K-1] > 0){
        int s = min(A[k+K-1] - 2 * A[k], 2 * A[k+K-1] - A[k]);
        M = min(s, M);
      }
      else if (A[k] <= 0 && A[k+K-1] <= 0){
        M = min(-A[k], M);
      }
      else if (A[k] >= 0 && A[k+K-1] >= 0){
        M = min(A[k+K-1], M);
      }
    }
    Console.WriteLine(M);
  }
}

Measured memory_bytes: 22368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    vector<int> a(5);
    for(int i=0; i<5; i++) cin >> a[i];
    int k; cin >> k;

    if(a[4]-a[0] > k){
        cout << ":(" << endl;
        return 0;
    }

    cout << "Yay!" << endl;
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    int f[10010]={0};
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                int mul=x*x+y*y+z*z+x*y+x*z+y*z;
                if(mul<N+1){
                    f[mul]++;
                }
            }
        }
    }
    for(int i=1;i<=N;i++) cout << f[i] << endl;
    return 0;


    
}

Measured memory_bytes: 3636
//i=1,2,3,… [i番目を塗る→r_j = iなる条件を判定]とすると、判定で必要な情報は
//最後に各色を塗った時刻の集合{t1,t2,t3} (塗ってないなら0). (色は区別しなくてOK)
//直前に塗った色の時刻は2つの時刻から復元できるので、{t1, t2}を持てばOK.
//dp[i][t1][t2].
//遷移は「時刻t1に塗った色」か「時刻t2に塗った色」か「直前の色」を塗る.
//判定はよしなに. O(N^3 + N^2M). * 実装は1-indexed.

#include <iostream>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;

int mod = 1000000007;
int n, m;
int l[300], r[300], x[300];
vector<P> conds[301];		//conds[r] = (l, count)
int dp[302][302][302];		//dp[i][t1][t2]

bool check(int t1, int t2, int t) {
	for (int i = 0; i < conds[t].size(); i++) {
		int l = conds[t][i].first;
		int x = conds[t][i].second;
		if (l <= t1) x--;
		if (l <= t2) x--;
		if (l <= t) x--;
		if (x != 0) return false;
	}
	return true;
}

signed main() {
	int i, t1, t2;
	
	cin >> n >> m;
	rep(i, m) {
		cin >> l[i] >> r[i] >> x[i];
		conds[r[i]].push_back(P(l[i], x[i]));
		
		//最初の1マスは事前に処理しておくと楽
		if (r[i] == 1) { if (x[i] >= 2) { cout << 0 << endl; return 0; } }
	}
	
	//1マスだけ塗った状態
	dp[2][0][0] = 3;
	
	for (i = 2; i <= n; i++) {
		for (t1 = 0; t1 < i; t1++) {
			for (t2 = 0; t2 < i; t2++) {
				if (dp[i][t1][t2] == 0) continue;
				//t1 -> i
				if (check(t2, i - 1, i)) {
					dp[i + 1][t2][i - 1] += dp[i][t1][t2];
					dp[i + 1][t2][i - 1] %= mod;
				}
				//t2 -> i
				if (check(t1, i - 1, i)) {
					dp[i + 1][t1][i - 1] += dp[i][t1][t2];
					dp[i + 1][t1][i - 1] %= mod;
				}
				//i - 1 -> i
				if (check(t1, t2, i)) {
					dp[i + 1][t1][t2] += dp[i][t1][t2];
					dp[i + 1][t1][t2] %= mod;
				}
			}
		}
	}
	
	int ans = 0;
	rep(t1, n + 1) {
		rep(t2, n + 1) {
			ans += dp[n + 1][t1][t2];
			ans %= mod;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 110164
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf double
#define vll vector<ll> 
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define per(i,a,b)  for(ll i=a;i>b;i--)
#define fast_io()  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
void setnum(ll n,ll d) {cout<<setw(d)<<setfill('0')<<n;}

int main() {
	fast_io();
	ll t=1; //cin>>t;
	while(t--){
	    ll k,a,b,flag=0; cin>>k>>a>>b;
	    rep(i,a,b+1){
	        if(i%k==0) flag=1;
	    }
	    flag==1?cout<<"OK":cout<<"NG";
	    
	    
	}
	return 0;
}

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

int main() {
  int N, A = 0;
  string x;
  cin >> N;
  for(int i = 0; i < N; i++){
  	cin >> x;
    if(x == "Y"){
      cout << "Four" << endl;
      A = 1;
      break;
    }
  }
  if(A != 1){
  cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

N = int(input())

if N == 3:
    print("2 5 63")
    import sys
    sys.exit()

A = []
for i in range(3, 30001):
    if len(A) == N - 1:
        break
    if i % 2 == 0 or i % 3 == 0 or i % 5 == 0:
        A.append(i)

s = sum(A)
if s % 2 == 1:
    A[0] = 2
s = sum(A)
    
l = 30000 - s % 30
A.append(l)
print(" ".join(str(n) for n in A))



Measured memory_bytes: 5192
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int N, Q;
vector<vector<int>> graph;
vector<int> cost;
vector<ll> ans;

void dfs(int node, int prev, ll c) {
  dump(node, prev, c);
  ans[node] = c;
  for(auto next : graph[node]) {
    if(next == prev) {
      continue;
    } else {
      dfs(next, node, c + cost[next]);
    }
  }
}

int main() {
  cin >> N >> Q;
  graph = vector<vector<int>>(N);
  cost = vector<int>(Q, 0);
  ans = vector<ll>(N, 0);
  REP(i, N - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  REP(i, Q) {
    int p, x;
    cin >> p >> x;
    p--;
    cost[p] += x;
  }
  dfs(0, -1, cost[0]);
  dump(ans);

  REP(i, N) { cout << ans[i] << " "; }
  cout << endl;
}


Measured memory_bytes: 25088
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void) {
	char s[1001];
	int w, i=0, l;
	scanf("%s", s);
	scanf("%d", &w);
	while (1) {
		if (s[i] == '\0')break;
		i++;
	}
	l = i;
	for (i = 0; i < l; i += w) {
		printf("%c", s[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    vector<vector<int>> C(3, vector<int>(3));
    for(int i = 0; i < 3; i++){
        for(int k = 0; k < 3; k++){
            cin >> C[i][k]; 
        }
    }

    int MIN = *min_element(C[0].begin(), C[0].end());
    for(int a0 = 0; a0 <= MIN; a0++){
        vector<int>  a(3), b(3);
        for(int i = 0; i < 3; i++) b[i] = C[0][i] - a0;
        for(int i = 0; i < 3; i++) a[i] = C[i][0] - b[0];
        
        bool ok = true;
        for(int i = 0; i < 3; i++) ok &= (C[1][i] == a[1] + b[i]);
        for(int i = 0; i < 3; i++) ok &= (C[2][i] == a[2] + b[i]);
        if(ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
//# pragma GCC target ("sse4")
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,m,t;
    IOS;
    fi>>n>>m>>t;
    static vector < pair < int , int > > s[1 << 20];
    static int ans[1 << 20];
    while (t --)
    {
        int a,b,c;
        fi>>a>>b>>c;
        b += n;
        s[a].push_back({b,c});
        s[b].push_back({a,c});
    }
    static int was[1 << 20];
    ll A = 1e18,B = 1e18;
    function < void(int) > dfs = [&](int node)
    {
        was[node] = 1;
        if (node <= n) A = min(A,1ll * ans[node]);
        else           B = min(B,1ll * ans[node]);
        for (auto it : s[node])
            if (!was[it.x])
                ans[it.x] = it.y - ans[node],dfs(it.x);
            else
                if (ans[it.x] + ans[node] != it.y)
                    {
                        puts("No");
                        exit(0);
                    }
    };
    for (int i = 1;i <= n + m;++i)
        if (!was[i])
            {
                A = B = 1e18,dfs(i);
                if (A + B < 0) return puts("No") * 0;
            }
    return puts("Yes") * 0;
}

Measured memory_bytes: 35840
#include<iostream>
#include<string>

int main()
{
//    freopen("B.INP","r",stdin);
    std::string s;
    std::cin>>s;
    for(int i=0;i<(int)s.size();++i)
    {
        if(i%2==0)
        {
            if(!(s[i]=='R'||s[i]=='U'||s[i]=='D'))
            {
                std::cout<<"No";
                return 0;
            }
        }
        else
        {
            if(!(s[i]=='L'||s[i]=='U'||s[i]=='D'))
            {
                std::cout<<"No";
                return 0;
            }
        }
    }
    std::cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
while 1:
    if input()=='0':break
    a=sorted(list(map(int,input().split())))[::-1]
    b=sorted(list(map(int,input().split())))[::-1]
    p=0;c=0;
    for i,x in enumerate(a):
        if i/2<c:print(i);break
        if x<=b[p]:p+=1
        else:c+=1
    else:print('NA')

Measured memory_bytes: 15688
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
ll dp[100001];
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int main(void) {
  int n,m,p;
  scanf("%d %d %d",&n,&m,&p);
  int a[m],ans,x=0,y=0,h;
  FOR(m){
    scanf("%d",&a[i]);
    a[i]-=p;
    if(a[i]>n/2)a[i]-=n;
    if(a[i]>0){
      x=max(x,n-a[i]);
      y=max(y,a[i]);
    }else{
      x=max(x,-a[i]);
      y=max(y,n+a[i]);
    }
  }
  ans=min(x,y);
  qsort(a,m,sizeof(int),u);
  FOR(m){
    if(!(a[i]<0&&a[(i+1)%m]>0)){
      h=z(a[i])+z(a[(i+1)%m])+min(z(a[i]),z(a[(i+1)%m]));
      if(a[i]*a[(i+1)%m]>0){
        h=a[i]+n-a[(i+1)%m]+min(z(a[i]),z(a[(i+1)%m]));
      }
      ans=min(ans,h);
      //printf("%d %d %d\n",a[i],a[(i+1)%m],h);
    }
  }
  PRN(ans*100);
  return 0;
}


Measured memory_bytes: 2780
using System;


namespace StillTBD
{
    class Program
    {
        public static void Main(string[] args)
        {
            var time = "2019/04/30";
            DateTime dateTime = DateTime.Parse(Console.ReadLine());
            DateTime compTime = DateTime.Parse(time);

            if (dateTime.CompareTo(compTime) == -1 || dateTime.CompareTo(compTime) ==0)
            {
                Console.Write("Heisei");
            }
            else
            {
                Console.Write("TBD");
            }

        }
    }
}


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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long
#define uint unsigned int
#define ushort unsigned short
#define ulong unsigned long

ll MOD = 10e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    REP(i, n) cin >> v[i];
    REP(i, n) cin >> c[i];
    int xy = 0;
    REP(i, n) {
        if (v[i]-c[i] > 0) xy += v[i]-c[i];
    }
    cout << xy << endl;
    return 0;
}



Measured memory_bytes: 256
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()

    ret = 0
    for n in range(1, N + 1):
        if len(str(n)) % 2 != 0 and len(str(n)) <= len(str(N)):
            ret += 1
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 10000
#define MAP 100
#define Pair pair<int,int>

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    ll n; cin >> n;
    ll a[n];
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i]-1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

void IO(){
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
}

const int MX=3e5+10;
int R,C,M;

vi adj[MX+1]; // sharing same  X-cord
int cnt[MX+1]; // cnt[i]= nb having same Y-cord
set <pi> s;

int32_t main(){
   boost;
   IO();

   for(int i=0; i<=MX; i++) cnt[i]=0;
   
   cin>>R>>C>>M;
   for(int i=0; i<M; i++){
   	int x,y; cin>>x>>y;
   	adj[x].pb(y);
   	cnt[y]++;
   }

   for(int i=1; i<=MX; i++) s.insert({cnt[i],i});

   int ans=0;
   for(int i=1; i<=MX; i++){ //ignite these Xs
   	int x=sz(adj[i]);
   	for(auto j: adj[i]){
   		s.erase({cnt[j],j});
   		cnt[j]--;
   		s.insert({cnt[j],j});
   	}

   	auto it=s.end(); it--;
   	x+=(*it).fi;

   	for(auto j: adj[i]){
   		s.erase({cnt[j],j});
   		cnt[j]++;
   		s.insert({cnt[j],j});
   	}
   	ans=max(ans,x);
   }

   cout << ans << endl;
	

   return 0;
}



Measured memory_bytes: 41108
#include<stdio.h>
int main()
{

  int N,x;
  scanf("%d",&N);
  if(N>1000){
  x=N%1000;
  if(x==0){
    printf("%d\n",0);
  }
  else
  printf("%d\n",1000-x);
  }
  else
    printf("%d\n",1000-N);
  return 0;
}


Measured memory_bytes: 1708
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
int main() {
    int H,W,h ,w ;
    //vector<long long int> v(n);
    cin >> H>> W>> h >>w ;
    cout << H*W-  h*W -w*H + h*w;
    return 0;
   
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;

int main() {
	int n;
	pair<int, int> x[100000];
	cin >> n;
	for(int i = 0; i < n; i++) {
		int xi, li;
		cin >> xi >> li;
		x[i] = make_pair(xi-li, xi+li);
	}
	sort(x, x + n, [](auto x, auto y) {return x.second < y.second;});
	int s = 0;
	int last_end = -1000000000 - 5;
	for(int i = 0; i < n; i++) {
		if (last_end <= x[i].first) {
			s++;
			last_end = x[i].second;
		}
	}
	cout << s << endl;
}


Measured memory_bytes: 1024
(h,w,m),*s=[[*map(int,i.split())]for i in open(0)]
r,c=[0]*-~h,[0]*-~w
for x,y in s:
    r[x]+=1
    c[y]+=1
print((R:=max(r))+(C:=max(c))-(r.count(R)*c.count(C)==sum(r[x]+c[y]==R+C for x,y in s)))


Measured memory_bytes: 68332
n, m = map(int, input().split())
ab = []
c= []
keys = ["" for _ in range(m)]

for i in range(m):
    ab.append(list(map(int, input().split())))
    kari = list(map(int, input().split()))
    c.append(kari)
    for j in range(n):
        if j+1 in kari:
            keys[i] = keys[i]+"1"
        else:
            keys[i] = keys[i] + "0"

all_patterns = ["0","1"]
options = ["0", "1"]

for _ in range(n-1):
    all_patterns = [j+i for i in (options) for j in all_patterns]

dp = [1e+10 for i in range(2**n)]
dp[0] = 0

#%%
for j in range(m):
    for i in range(len(dp)):
        kari1 = dp[i]+ab[j][0]
        kari2 = dp[i|int(keys[j],2)]
        if kari1 < kari2:
            dp[i|int(keys[j],2)] = kari1

if dp[-1] != 1e+10:
    print(dp[-1])
else:
    print(-1)

Measured memory_bytes: 50008
def main():
    from collections import Counter

    n = int(input())
    *a, = map(int, input().split())

    if n % 3 == 0:
        ctr = Counter(a)
        if len(ctr) == 1:
            print('Yes' if 0 in ctr else 'No')
            return

        elif len(ctr) == 2:
            print('Yes' if ctr[0] == n // 3 else 'No')
            return

        elif len(ctr) == 3:
            x = 0
            p = None
            for k, v in ctr.items():
                if p is None:
                    p = v
                elif p != v:
                    print('No')
                    return
                x ^= k
            print('Yes' if x == 0 else 'No')
            return

        else:
            print('No')
            return

    else:
        print('Yes' if all(map(lambda x: x == 0, a)) else 'No')
        return


if __name__ == '__main__':
    main()


Measured memory_bytes: 14468
#include<stdio.h>
#include<math.h>
#define N 1000

int main(){
    int flag,i,j,a,b,cnt = 0;

    scanf("%d",&a);

    for(i = 0;i < a;i++){
        flag = 0;
        scanf("%d",&b);
        for(j = 2;j <= sqrt(b);j++){
        if(b%j == 0)flag = 1;
    }
    if(flag == 0)cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 2032
public class Main {

	public static void main(String[] args) {
		java.util.Scanner scanner = new java.util.Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		int num = a*b;
		int num2 = 2*(a+b);
		
		System.out.println(num + " " + num2);
		
	}

}

Measured memory_bytes: 25948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, q;
    cin >> n >> q;
    vector<vector<int>> g(n);
    rep(i, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    ll cnt[n] = {};
    int p[q], x[q];
    rep(i, 0, q) {
        cin >> p[i] >> x[i];
        p[i]--;
        cnt[p[i]] += x[i];
    }

    queue<int> que;
    que.push(0);
    bool visited[n] = {};
    visited[0] = true;
    while (!que.empty()) {
        int now = que.front();
        que.pop();
        for (auto i : g[now]) {
            if (visited[i]) continue;
            que.push(i);
            visited[i] = true;
            cnt[i] += cnt[now];
        }
    }
    rep(i, 0, n) cout << cnt[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 18036
#include <algorithm>
#include <bitset>
#include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>
#include <numeric>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr int I_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
static boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
  // INFILE();
	int h, w;
	cin >> h >> w;

	vector<string> img(h);
	scan(img);

	for(const auto& row : img) {
		cout << row << endl << row << endl;
	}
  return 0;
}

template <class T> static void scan(vector<T> &v) {
  map<type_index, const char *const> m = {{typeid(int), "%d"},
                                          {typeid(ll), "%lld"},
                                          {typeid(double), "%lf"},
                                          {typeid(char), "%c"}};

  auto tFormat = m[typeid(T)];

  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string> &v, bool isWord) {
  if (isWord) {
    for (auto &n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

static boost::dynamic_bitset<> scan(char trueValue) {
  string s;
  getline(cin, s);

  if (s.size() == 0) {
    getline(cin, s);
  }

  for_each(begin(s), end(s),
           [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
  return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  long N, M;
  std::cin >> N >> M;

  long r;
  for (r = M / N; r > 0; r--) {
    if (M % r == 0) {
      break;
    }
  }

  std::cout << r << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
    string s,p,q,r,a,b,c,d;
    int l,k,cnt=0,m = 0,n=0,e=0;;
    cin>>s;
    a = s;
    reverse(a.begin(),a.end());
    l = s.size();
    for(int i=0; i<((l-1)/2); i++)
       {
           p+=s[i];

       }
       r = p;
    for(int i=((l+3)/2)-1; i<l; i++)
    {
        q+=s[i];

    }
    c = q;
    reverse(r.begin(),r.end());
    reverse(c.begin(),c.end());
    if(a==s && q==c && p==r)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;



    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 200000

typedef unsigned long long ULL;
int main(){
    ULL a_sum[MAX+1],b_sum[MAX+1];
    int a,b;
    int read_time;
    int *readed;
    int N,M,K;
    ULL time = 0;
    int max;
    int i,j;


    scanf("%d%d%d",&N,&M,&K);

    a_sum[0] = b_sum[0] = 0;
    for(i=0;i<N;i++){
        scanf("%d",&a);
        a_sum[i+1] = a_sum[i] + a;
    }
    for(i=0;i<M;i++){
        scanf("%d",&b);
        b_sum[i+1] = b_sum[i] + b;
    }

    max = 0;
    for(i=0;i<=N;i++){
        if( a_sum[i] > K){
            break;
        }
        for(j = max - i ;j<=M; j++){
            time = a_sum[i] + b_sum[j];
            if(time > K){
                break;
            }
            if( time <= K){
                if( max < i + j){
                    max = i + j;
                }
            }
        }
    }
    printf("%d\n",max);
    
}

Measured memory_bytes: 4856