akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)

int main(){
  int N;
  cin >> N;
  vector<string> vec(N);

  for (int i = 0; i < N; i++) cin >> vec.at(i);

  int AC = 0;
  int WA = 0;
  int TLE = 0;
  int RE = 0;

  for (int i = 0; i < N; i++){
    if (vec.at(i) == "AC") AC += 1;
    if (vec.at(i) == "WA") WA += 1;
    if (vec.at(i) == "TLE") TLE += 1;
    if (vec.at(i) == "RE") RE += 1;
  }

  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
}

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

int const N=1e5+5, M=4, OO = 0x3f3f3f3f;

int n,ans;

int main()
{
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);
//    freopen("mo3gza.txt","wt",stdout);
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        if(to_string(i).size()%2)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}





Measured memory_bytes: 256
/*************************************************************************
	> File Name: A.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Created Time: 2020/4/4 20:25:13
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
bool cmp(int a,int b){
	return a>b;
}
int a[10000];
int main()
{
	int sum=0,n=read(),m=read(),k;
	For(i,1,n){
		a[i]=read();
		sum+=a[i];
	}
	k=sum/(4*m);
	if(k*4*m!=sum) k++;
	sort(a+1,a+n+1,cmp);
	
	For(i,1,m)
		if(a[i]<k){
			printf("No");
			return 0;
		}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int A,B;

    private boolean isPalindrome(int x) {
        String s = String.valueOf(x);

        for(int i = 0;i < s.length() / 2;i++) {
            if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
                return false;
            }
        }

        return true;
    }

    private void solve() {
        A = nextInt();
        B = nextInt();

        int ans = 0;
        for(int i = A;i <= B;i++) {
            if (isPalindrome(i)) {
                ans++;
            }
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[2048];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 26708
#include<stdio.h>

int main(){
  int n,i,a[1000];

  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=n-1;i>=0;i--){
    printf("%d",a[i]);
    if(i==0){
      printf("\n");
      break;
    }
    printf(" ");
  }

  return 0;
}


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

typedef long long LL;
const int N = 2e5 + 10;

int n, a[N];

LL solve(){
    LL ret = 0;
    a[n] = -1;
    for(int i=n-1; i>=0; i--){
        if(a[i] > i)	return -1;
        if(a[i] < a[i+1] - 1){
			return -1;
        }
        if(a[i] != a[i+1] - 1){
			ret = ret + a[i];
        }
    }
    return ret;
}

int main(){
	while(~scanf("%d", &n)){
		for(int i=0; i<n; i++)	scanf("%d", a+i);
		printf("%lld\n", solve());
	}
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using P = pair<int, int>;
#define mrep(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) mrep(i, 0, n)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    double d0 = d, s0 = s;
    double t0 = d0 / s0;
    if(t0 <= t) cout << "Yes" << endl;
    else if(t0 > t) cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#template
def inputlist(): return [int(j) for j in input().split()]
#template
N = int(input())
ans = 10**13
for i in range(1,int(N**(1/2))+1):
    if N % i == 0:
        d = (i-1) + (N//i - 1)
        ans = min(ans,d)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long int

signed main(){
    int n;
    cin >> n;
    if(n%2 == 0){
        cout << n/2 << endl;
    }else{
        cout << n/2 + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector> //可変長配列
#include <queue> //キュー
#include <unordered_map> //ハッシュ連想配列
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define ll long long int
#define INFTY (1<<21)
#define maxN 100000

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    int N,x=0,y=0,t=0,cx=0,cy=0,ct=0;
    cin>>N;
    for(int i = 0; i < N; i++){
        cin>>t>>x>>y;
        if((t-ct)<(abs(cx-x)+abs(cy-y)) || (t-ct-abs(cx-x)-abs(cy-y))%2!=0){
            cout<<"No"<<endl;
            return 0;
        }
        cx=x; cy=y; ct=t;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int A = 26;
bool used[A];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	string s;
	cin >> s;
	for (char c : s)
		used[c - 'a'] = 1;
	if (s.length() < A) {
		cout << s;
		for (char c = 'a';; c++) {
			if (!used[c - 'a']) {
				cout << c << endl;
				return 0;
			}
		}
	}

	for (int i = s.length() - 2; i >= 0; i--) {
		used[s[i + 1] - 'a'] = 0;
		for (int x = 0; x < A; x++) {
			if (used[x]) continue;
			if ('a' + x > s[i]) {
				cout << s.substr(0, i) << (char)('a' + x) << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32
w =  ['SUN','MON','TUE','WED','THU','FRI','SAT']

def solve(S: str):
    we = w+w
    n = w.index(S)
    if n == 0:
        print(7)
    else:
        print(we[n:].index('SUN'))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

const int maxn = 5e5 + 10;

int n;
long long a[maxn];
long long ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
}

void solve(){
    ans = n;
    int t = 1;
    for(int i = 0; i < n; i++){
        if(a[i] == t){
            t++;
            ans--;
        }
    }
    if(ans == n)
        ans = -1;
}

void out(){
    cout << ans;
}


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

s = []
for i in range(n):
    s.append(input())
a = {}
for i in range(n):
    tmp = [u for u in s[i]]
    tmp.sort()
    tmp="".join(tmp)
    if tmp in a:
        a[tmp] +=1
    else:
        a[tmp] =1

c =0
for  k,d in a.items():
    c +=d * (d-1) /2
print(int(c))

Measured memory_bytes: 24976
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;
ll inf = 1001001001;
int main(){
  int n, m;
  cin>>n>>m;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(m);
  vector<ll> d(m);
  rep(i, n) {
    cin>>a[i]>>b[i];
  }
  rep(i,m)
    cin>>c[i]>>d[i];
  rep(i,n){
    ll t = inf;
    ll ans;
    rep(j,m) {
      ll x = abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(x < t) {
	ans = j+1;
	t = x;
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}



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

using namespace std;

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

  int ans = 1e9;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;

    int counter = 0;
    while (a % 2 == 0) {
      a /= 2;
      counter++;
    }

    ans = min(ans, counter);
  }

  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

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


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

int main()
{
	int n, s = 0, rmin, imin;
	int a[100][100];
	int b[100];

	cin >> n;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];

	for (int i = 0; i < n; i++)
			b[i] = -1;

	b[0] = 0;
	int ct = 0;

	while (ct < n - 1) {
		imin = 0;
		rmin = 10000;
		for (int j = 0; j < n; j++) {
			if (b[j] > -1) {
				for (int i = 1; i < n; i++) {
					if (a[j][i] > -1 && b[i] < 0 && rmin > a[j][i]) {
						rmin = a[j][i];
						imin = i;
					}
				}
			}
		}
		b[imin] = rmin;
		ct++;
	}

	for (int i = 0; i < n; i++)
		s += b[i];

	cout << s << endl;

	return 0;
}


Measured memory_bytes: 3140
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    const ll M = 1000000007;

    int N;  cin >> N;
    string S; cin >> S;

    map<char, int> mp;
    REP(i, N) mp[S[i]]++;


    ll ans = 1;
    for(char c = 'a'; c<='z'; c++) {
        if (mp.count(c) > 0) {
            ans *= (mp[c] + 1);
            ans %= M;
        }
    }
    ans--;

    cout << ans << endl;

    return 0;
}

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

const int MAXK = 1e5 + 10;
const int MAXN = 1e3 + 10;

int A[MAXN],dp[MAXK],N,K;

int solve(int k){

	if(dp[k] != -1) return dp[k];

	if(k == 0) return dp[k] = 0;

	int ans = 0;
	for(int i = 1;i<=N;i++){
		if(A[i] > k) continue;
		if(solve(k - A[i]) == 0){
			ans = 1;
			break;
		}
	}

	return dp[k] = ans;

}

int main(){

	memset(dp,-1,sizeof(dp));
	cin >> N >> K;
	for(int i = 1;i<=N;i++){
		cin >> A[i];
	}

	if(solve(K)) printf("First\n");
	else printf("Second\n");

	return 0;

}

Measured memory_bytes: 3712
/*input
10 13 15
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;

ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
ll sub(ll x,ll y){
    return (x % MOD - y % MOD + MOD) % MOD;
}
ll mult(ll a,ll b) 
{ 
    return ((a%MOD)*(b%MOD))%MOD;
} 

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k,q;
    cin>>n>>k>>q;
    int arr[n];
    FILL(arr);
    REP(i,q){
        int x;
        cin>>x;
        --x;
        arr[x]++;
    }
    REP(i,n){
        if(q-arr[i]<k) cout<<"Yes\n";
        else cout<<"No\n";
    }
}

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

int main() {
int a,b,c,x,cnt=0;
  cin >> a >> b >> c >> x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(i*500+j*100+k*50==x){
        cnt++;
        }
      }
    }
  }

  cout << cnt << endl;
}



Measured memory_bytes: 256
/*input
1
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

vector<pair<ll, int>> prime_factors(ll n) {
    vector<pair<ll, int>> ret;
    for(ll i=2; i*i<=n; i++){
        int cnt = 0;
        while(n % i == 0){
            n /= i;
            cnt++;
        }
        if(cnt) ret.emplace_back(i, cnt);
    }
    if(n > 1) ret.emplace_back(n, 1);
    return ret;
}

void run() {
	ll x, ret = 0;
	cin >> x;
	auto factors = prime_factors(x);
	for(auto f : factors) {
		int count = f.second, n = 1;
		while (count >= n) {
			count -= n;
			n++;
			ret++;
		}
	}
	cout << ret << endl;
}

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


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
inline int read(){
	#define gc getchar
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return ans;
	#undef gc
}
typedef long long ll;
typedef pair<int,int> pii;
const int mod=998244353;
inline int add(const int&a,const int&b){return a+b>=mod?a+b-mod:a+b;}
inline int dec(const int&a,const int&b){return a>=b?a-b:a-b+mod;}
inline int mul(const int&a,const int&b){return (ll)a*b%mod;}
inline void Add(int&a,const int&b){a=a+b>=mod?a+b-mod:a+b;}
inline void Dec(int&a,const int&b){a=a>=b?a-b:a-b+mod;}
inline void Mul(int&a,const int&b){a=(ll)a*b%mod;}
inline int ksm(int a,int p){int ret=1;for(;p;p>>=1,a=mul(a,a))if(p&1)Mul(ret,a);return ret;}
const int N=505;
int s=0,n,k,a[N];
inline bool check(int x){
	ll ss=0,sss=0;
	vector<int>s;
	for(ri i=1;i<=n;++i)s.push_back(a[i]%x),sss+=x-a[i]%x;
	sort(s.begin(),s.end());
	ss=s[0],sss-=x-s[0];
	for(ri i=1,up=s.size();i<up;++i){
		if(ss+s[i]>k)break;
		ss+=s[i],sss-=x-s[i];
	}
	return ss<=k&&sss<=k;
}
int main(){
	n=read(),k=read();
	for(ri i=1;i<=n;++i)a[i]=read(),s+=a[i];
	int ans=1;
	if(check(s))return cout<<s<<'\n',0;
	for(ri i=2;i*i<=s;++i){
		if(s!=s/i*i)continue;
		if(check(i))ans=max(ans,i);
		if(check(s/i))ans=max(ans,s/i);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)

typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
int N;
int block[200005];
int main()
{
	cin >> N;
	rep(i, N) {
		cin >> block[i];
	}
	int ans = 0, num = 1,pre =0;
	bool flag = false;
	rep(i, N) {
		if (block[i] == num) {
			//cout << "work" << endl;
			ans += i - pre;
			pre = i+1;
			num++;
			flag = true;
		}
		else if(i==N-1){
			ans += N - pre;
		
		}
	}
	if (!flag) {
		ans = -1;
	}
	cout << ans << endl;
	
	
}

Measured memory_bytes: 1024
#include<stdio.h>

int main()
{
  int data[99], n, i, j, A, M;
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    scanf("%d", &data[i]);
  }
  
  printf("%d", data[0]);
  for (j = 1; j < n; j++){
      printf(" %d", data[j]);
  }
  printf("\n");
  
  
  for(i = 1; i < n; i++){
    if (data[i] < data[i-1]){
      M = data[i];
      for(j = 0; j < i; j++){
        if(M < data[j]){
          A = data[j];
          data[j] = M;
          M = A;
        }
        data[i] = M;
        
      }
    }
    printf("%d", data[0]);
    for (j = 1; j < n; j++){
      printf(" %d", data[j]);
    }
  printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1804
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n, k = map(int, input().split())\n"
"x = list(map(int, input().split()))\n"
"i = 0\n"
"while i < n and x[i] < 0:\n"
"    i += 1\n"
"jl = i - 1\n"
"cl = []\n"
"cr = []\n"
"for l in range(k):\n"
"    if jl - l < 0:break\n"
"    cl.append(-x[jl - l])\n"
"for l in range(k):\n"
"    if i + l >= n:break\n"
"    cr.append(x[i + l])\n"
"la = 10**18\n"
"lb = 10**18\n"
"for l in range(len(cl)):\n"
"    c = k - l - 2\n"
"    if c >= len(cr):continue\n"
"    if c < 0:\n"
"        la = min(la, cl[l])\n"
"    else:\n"
"        la = min(la, cl[l] + cr[c] * 2)\n"
"for l in range(len(cr)):\n"
"    c = k - l - 2\n"
"    if c >= len(cl):continue\n"
"    if c < 0:\n"
"        lb = min(lb, cr[l])\n"
"    else:\n"
"        lb = min(lb, cr[l] + cl[c] * 2)\n"
"print(min(la, lb))\n"
"\"";
  system(s);
  return 0;
}            

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

class Program
{
    #region library
    static int n = 0;
    static int m = 0;
    static int r = 0;
    static int c = 0;
    static int x = 0;
    static int y = 0;
    static int[] arr;
    static string s = "";
    static string[] ss;
    static string alpha = "abcdefghijklmnopqrstuvwxyz";
    static long sum = 0;
    static long cnt = 0;
    static long max = -1;
    static long min = 2147483647;
    static bool flg = false;
    static bool flg2 = false;
    static char[,] map;
    static int[,] imap;
    static string rl()
    {
        return Console.ReadLine();
    }
    static string[] rls()
    {
        return Console.ReadLine().Split();
    }
    static void wl(object obj = null)
    {
        Console.WriteLine(obj);
    }
    static void w(object obj)
    {
        Console.Write(obj);
    }
    static int Int(string s)
    {
        return int.Parse(s);
    }
    static long Max(long a, long b)
    {
        return Math.Max(a, b);
    }
    static long Min(long a, long b)
    {
        return Math.Min(a, b);
    }
    static long Abs(long a)
    {
        return Math.Abs(a);
    }
    static void yes()
    {
        wl("YES");
    }
    static void no()
    {
        wl("NO");
    }
    static void Sum()
    {
        wl(sum);
    }
    static void Cnt()
    {
        wl(cnt);
    }
    static void setarray(int num = -1)
    {
        arr = new int[n];
        if(num == -1) ss = rls();
        for (int i = 0; i < n; i++)
        {
            if (num == -1)
                arr[i] = Int(ss[i]);
            else
                arr[i] = num;
        }
    }
    static void setmap(char def = '@')
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        map = new char[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == '@') s = rl();
            for (int j = 0; j < c; j++)
            {
                map[i, j] = (def == '@') ? s[j] : def;
            }
        }
    }
    static void setimap(int def = -1)
    {
        if (r == 0 && c == 0)
        {
            ss = rls();
            r = Int(ss[0]);
            c = Int(ss[1]);
        }
        imap = new int[r, c];
        for (int i = 0; i < r; i++)
        {
            if (def == -1) s = rl();
            for (int j = 0; j < c; j++)
            {
                imap[i, j] = (def == -1) ? Int(s[j].ToString()) : def;
            }
        }
    }
    #endregion

    static void Main(string[] args)
    {
        n = Int(rl());
        wl(Lcm(2, n));
    }

    /* 最大公約数 */
    static long Gcd(long a, long b)
    {
        var v = new[] { a, b };
        while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
        return v[0];
    }

    /* 最小公倍数(上記Gcdとセットで使うこと） */
    static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }


}



Measured memory_bytes: 11220
open Scanf
open Printf

type heap = Nil | Node of int * heap * heap

let rec merge a b =
  match a, b with
  | a, Nil -> a
  | Nil, b -> b
  | Node (av, al, ar), Node (bv, bl, br) ->
    if av > bv then
      Node (av, (merge ar b), al)
    else
      Node (bv, (merge br a), bl)

let is_empty = function
  | Nil -> true
  | _ -> false

let push a v = merge a (Node (v, Nil, Nil))
let peek = function
  | Nil -> invalid_arg "nil"
  | Node (v, _, _) -> v

let pop = function
  | Nil -> invalid_arg "nil"
  | Node (_, l, r) -> merge l r


let () =
  let n, m = scanf " %d %d" (fun a b -> a, b) in
  let ab = Array.init n (fun _ -> scanf " %d %d" (fun a b -> a, b)) in
  Array.sort compare ab;
  let k = ref 0 in
  let q = ref Nil in
  let ans = ref 0 in
  for i = m - 1 downto 0 do
    while !k < n && i + fst ab.(!k) <= m do
      q := push !q (snd ab.(!k));
      incr k
    done;
    if not (is_empty !q) then begin
      ans := !ans + peek !q;
      q := pop !q
    end;
  done;
  printf "%d\n" !ans

Measured memory_bytes: 10368
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
int n,b[200005],tot,bel[200005],r[200005],l[200005],f[200005],sum[200005];
struct que
{
	int x,v;
}a[200005];
bool cmp(que a,que b)
{
	return a.v<b.v;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].v);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++) b[i]=a[i].x;
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
	{
		a[i].x=lower_bound(b+1,b+n+1,a[i].x)-b;
		bel[a[i].x]=i;
	}
	for(int i=1;i<=n;i++) r[i]=max(r[i-1],bel[i]);
	l[n]=bel[n];
	for(int i=n-1;i>0;i--) l[i]=min(l[i+1],bel[i]);
	f[0]=sum[0]=1;
	int p=0;
	for(int i=1;i<=n;i++)
	{
		while(r[p]<l[i]-1) p++;
		f[i]=(sum[i-1]-(p?sum[p-1]:0)+mod)%mod;
		sum[i]=(sum[i-1]+f[i])%mod;
	}
	while(r[p]<n) p++;
	printf("%d\n",(sum[n]-(p?sum[p-1]:0)+mod)%mod);
}

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

#define int             long long
#define ip(x)           int x; cin>>x;
#define w(x)            int x; cin>>x; while(x--)
#define mk(arr,n,type)  type *arr=new type[n];
#define mod             pow(10,9)+7
#define inf             1e18
#define endl			"\n"
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >

void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	c_p_c();
	ip(n);
	int temp = n;
	temp = n % 10 ;
	if (temp == 2 || temp == 4 || temp == 5 || temp == 7 || temp == 9)
		cout << "hon" << endl;
	else if (temp == 3)
		cout << "bon" << endl;
	else
		cout << "pon" << endl;
	return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N;
    cin >> N;
    cout << 800 * N - 200 * (N / 15) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 5005
using namespace std;

int n, k, c, s, a[N];
int main()
{
	int i;
	cin >> n >> k;
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n);
	for (i = n - 1; i >= 0; i--) {
		if (s + a[i] < k) s += a[i], c++;
		else c = 0;
	}
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long
#define mod 1000000007;


int main() {
	string s;
	string hoge[] = { "Sunny","Cloudy","Rainy " };
	cin >> s;
	if (s == hoge[0])cout << hoge[1];
	else if (s == hoge[1])cout << hoge[2];
	else cout << hoge[0];
	cout << endl;
	return 0;
}

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

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

int main () {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll max = a*c;
    if(max < a*d) max = a*d;
    if(max < b*c) max = b*c;
    if(max < b*d) max = b*d;
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <vector>

int64_t getAmidaNum(const int h, const int w, const int k) {
  std::vector<std::bitset<7>> horizontal_candidates;
  for (int i = 0; i < static_cast<int>(std::pow(2, w - 1)); ++i) {
    std::bitset<7> current(static_cast<unsigned long long>(i));
    bool valid = true;
    for (int j = 0; j < w - 2; ++j) {
      if (current[j] && current[j + 1]) {
        valid = false;
      }
    }
    if (valid) {
      horizontal_candidates.emplace_back(std::move(current));
    }
  }
  std::vector<int> bridge_counts(w + 1, 0);
  for (int i = 1; i <= w; ++i) {
    bridge_counts[i] = std::count_if(
        horizontal_candidates.begin(), horizontal_candidates.end(),
        [i](const std::bitset<7> &bit) {
          return (bit & std::bitset<7>(static_cast<unsigned long long>(
                            std::pow(2, i - 1))))
              .any();
        });
  }
  const int candidate_total_num =
      static_cast<int>(horizontal_candidates.size());
  // edges are guards
  std::vector<int64_t> current_amida_num(w + 2, 0);
  current_amida_num[1] = 1L;
  static const int64_t CONSTANT = 1000000007L;

  for (int i = 0; i < h; ++i) {
    std::vector<int64_t> current_amida_num2(w + 2, 0);
    for (int j = 1; j <= w; ++j) {
      current_amida_num2[j] +=
          (current_amida_num[j] *
           (candidate_total_num - bridge_counts[j] - bridge_counts[j - 1])) %
          CONSTANT;
      current_amida_num2[j - 1] +=
          (current_amida_num[j] * bridge_counts[j - 1]) % CONSTANT;
      current_amida_num2[j + 1] +=
          (current_amida_num[j] * bridge_counts[j]) % CONSTANT;
    }
    current_amida_num = std::move(current_amida_num2);
    for (auto &num : current_amida_num) {
      num %= CONSTANT;
    }
  }
  return current_amida_num[k];
}
int main() {
  int h, w, k;
  std::cin >> h >> w >> k;
  std::cout << getAmidaNum(h, w, k);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,i,j,k,sum=0;
    cin>>a>>b>>c>>d;
    for (i=0;i<=a;i++)
    for (j=0;j<=b;j++)
    for (k=0;k<=c;k++)
    if (i*500+j*100+k*50==d) sum++;
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <stdlib.h>
#include <cmath>
using namespace std;

int d, c[29], s[409][29], p[409], cp[29], rs;
set<int> st[29];

int cc()
{
	for (int i = 0; i < 26; i++)
		cp[i] = 0;
	int ans = 0;
	for (int i = 1; i <= d; i++) {
		for (int j = 0; j < 26; j++) {
			if (p[i] == j) {
				cp[j] = i;
				ans += s[i][j];
			}
			else
				ans -= (i - cp[j]) * c[j];
		}
	}
	return ans;
}

void rm(int n, int k)
{
	auto pi = st[k].find(n);
	auto l = pi; l--;
	auto r = pi; r++;
	int pl = (n - (*l) - 1), pr = ((*r) - n - 1), plr = ((*r) - (*l) - 1);
	st[k].erase(n);
	rs -= s[n][k];
	rs += pl * (pl + 1) / 2 * c[k]; rs += pr * (pr + 1) / 2 * c[k];
	rs -= plr * (plr + 1) / 2 * c[k];
}

void ins(int n, int k)
{
	auto r = st[k].lower_bound(n);
	auto l = r; l--;
	int pl = (n - (*l) - 1), pr = ((*r) - n - 1), plr = ((*r) - (*l) - 1);
	st[k].insert(n);
	rs += s[n][k];
	rs -= pl * (pl + 1) / 2 * c[k]; rs -= pr * (pr + 1) / 2 * c[k];
	rs += plr * (plr + 1) / 2 * c[k];
}

void up(int n, int k)
{
	rm(n, p[n]);
	p[n] = k;
	ins(n, p[n]);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> d;
	for (int i = 0; i < 26; i++) {
		cin >> c[i];
		st[i].insert(0); st[i].insert(d + 1);
	}
	for (int i = 1; i <= d; i++) {
		for (int j = 0; j < 26; j++)
			cin >> s[i][j];
		p[i] = rand() % 26;
		st[p[i]].insert(i);
	}
	rs = cc();
	double k = 1, sc = 350000, kt = 0.9992;
	for (int i = 0; i < 4000000; i++) {
		double e1 = rs;
		int n = (rand() % d) + 1, kp = (rand() % 25) + 1;
		int hk = p[n], tk = (hk + kp) % 26;
		up(n, tk);
		int e2 = rs;
		double pb = exp((e2 - e1) / (k * sc));
		if (pb < rand() / (double)RAND_MAX)
			up(n, hk);
		k *= kt;
	}
	for (int i = 1; i <= d; i++)
		cout << p[i] + 1 << '\n';
	return 0;
}

Measured memory_bytes: 4380
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    int N = s.length();

    map<char, int> m;
    for(int i=0; i<s.length(); i++){
        char c = s[i];
        if(!m[c]) m[c] = 1;
        else m[c]++;
    }

    int np = N/2;
    int win;
    if(np >= m['g']){
        win = m['g'];
    }else{
        win = np;
    }

    int ng = N - np;
    int lose;
    if(ng <= m['p']){
        lose = ng;
    }else{
        lose = m['p'];
    }

    cout << win - lose << endl;

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){

   int n,a,min=1000000,max=-1000000,i;
   long int sum=0;
   scanf("%d",&n);
   
   for(i=0;i<n;i++){
      scanf("%d",&a);
      if(min>a){
         min=a;
}
      if(max<a){
         max=a;
}
      sum+=a;
}
   printf("%d %d %ld\n",min,max,sum);
   
   return 0;
}

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

typedef long long ll;
const ll N = 1000 * 100;
ll n, m;

int main() {
	cin >> n >> m;
	if (n < m)
		swap(m, n);
	while (n--)
		cout << m;
	cout << endl;
}
	


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mxn=2e5+5;

int main() {
	ll n;
	cin>>n;
	ll a[n],i;
	unordered_map<ll,ll> mp;
	ll s=0;
	for(i=0;i<n;i++) {
		cin>>a[i];
		mp[a[i]]++;
		s+=a[i];
	}
	ll q;
	cin>>q;
	while(q--) {
		ll b,c;
		cin>>b>>c;
		s+= (c*mp[b]);
		s-= (b*mp[b]);
		mp[c]+=mp[b];
		mp[b]=0;
		cout<<s<<"\n";
	}
	return 0;
}

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

int main()
{
	int N, K, ans;
	cin >> N >> K;
	rep(i, N) {
		if (pow(K, i) > N) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
}

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

typedef std::pair <int, int> pr;
typedef std::map <int, int> map;
const int N = 500054, M = 2000054, INF = 0x3f3f3f3f;

struct edge {
	int u, v, w;
	edge (int u0 = 0, int v0 = 0, int w0 = 0) : u(u0), v(v0), w(w0) {}
} e[M];

int n, m, V, E = 0;
int first[N], next[M];
int d[N];
map g[M];
std::priority_queue <pr, std::vector <pr>, std::greater <pr> > pq;

inline void addedge(int u, int v, int w1, int w2) {
	e[++E] = edge(u, v, w1), next[E] = first[u], first[u] = E;
	e[++E] = edge(v, u, w2), next[E] = first[v], first[v] = E;
}

inline int get(int ty, int id) {
	map::iterator it; bool ret;
	std::tie(it, ret) = g[ty].emplace(id, V + 1);
	return ret ? ++V : it->second;
}

void Dijkstra(int s) {
	int i, x, y, di;
	memset(d, 63, (V + 1) << 2);
	for (pq.emplace(d[s] = 0, s); !pq.empty(); ) {
		std::tie(di, x) = pq.top(), pq.pop();
		if (d[x] != di) continue;
		for (i = first[x]; i; i = next[i])
			if (di + e[i].w < d[y = e[i].v])
				pq.emplace(d[y] = di + e[i].w, y);
	}
}

int main() {
	int i, u, v, w;
	scanf("%d%d", &n, &m), V = n;
	for (i = 0; i < m; ++i)
		scanf("%d%d%d", &u, &v, &w), addedge(get(w, u), get(w, v), 0, 0);
	for (i = 0; i < M; ++i)
		for (const pr &p : g[i]) addedge(p.first, p.second, 1, 0);
	Dijkstra(1), printf("%d\n", d[n] >= INF ? -1 : d[n]);
	return 0;
}

Measured memory_bytes: 150136
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;
	a--; b--;
	c--; d--;
	
	for(int i = a; i < c; ++i) {
		if( s[i] == '#' && s[i + 1] == '#' ) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	for(int i = b; i < d; ++i) {
		if( s[i] == '#' && s[i + 1] == '#' ) {
			cout << "No" << endl;
			return 0;
		}
	}
		
	if( c < d ) {
		cout << "Yes" << endl;
	} else if( c > d ) {
		bool threeDot = false;
		
		for(int i = b; i <= d; ++i) {
			if( s.substr(i - 1, 3) == "..." ) {
				threeDot = true;
			}
		}
	
		if( threeDot ) cout << "Yes" << endl;
		else cout << "No" << endl;
	}	
	
	return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_bacm
#define mp mame_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    int x;
    cin >> x;
    int ans = 0;
    ans += 1000 * (x/500);
    x %= 500;
    ans += 5 * (x / 5);
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,m,c;
int b[25],a[25];
int s;
int ans;
int main(void){
    cin>>n>>m>>c;
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    while(n--){
        s=0;
        for(int i=0;i<m;i++){
            cin>>a[i];
            s+=a[i]*b[i];
        }
        s+=c;
        if(s>0){
            ans++;
        }
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

int main()
{
	for(;;){
		int H, W;
		cin >> H >> W;

		if(H == 0 && W == 0)
			break;

		REP(j, H){
			if(j % 2 == 0){
				REP(i, W){
					if(i % 2 == 0){
						cout << "#";
					}
					else{
						cout << ".";
					}
				}
			}
			else{
				REP(i, W){
					if(i % 2 == 0){
						cout << ".";
					}
					else{
						cout << "#";
					}
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}




Measured memory_bytes: 3096
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (true) {
        string S; getline(cin,S);
        if (S == ".") break;
        int N = S.size();
        
        bool flag = true;
        stack<char> data;
        data.emplace('#');
        rep(i,N) {
            if (S[i] == '(' || S[i] == '[') data.emplace(S[i]);
            if (S[i] == ')') {
                if (data.top() != '(') flag = false;
                else data.pop();
            }
            if (S[i] == ']') {
                if (data.top() != '[') flag = false;
                else data.pop();
            }
        }
        if (data.size() != 1) flag = false;

        cout << (flag ? "yes" : "no") << endl;
    }
}


Measured memory_bytes: 3176
N = int(input())
s = [int(input()) for _ in range(N)]

xs = [x%10 for x in s]

if xs.count(0) == N:
  print(0)
elif sum(s) % 10 != 0:
  print(sum(s))
else:
  minimum = 999
  for n in range(N):
    if s[n] % 10 != 0:
      minimum = min(minimum,s[n])
  print(sum(s)-minimum)
    

Measured memory_bytes: 9100
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define MAX_N (1<<18)
struct SegTree {
  int seg[MAX_N*2-1] = {}, lazy[MAX_N*2-1] = {};
  SegTree() {
    rep(i, MAX_N*2-1) lazy[i] = 1;
  }
  void setLazy(int k, int v) {
    seg[k] = (1LL*seg[k]*v)%MOD;
    lazy[k] = (1LL*lazy[k]*v)%MOD;
  }
  void push(int k) {
    if (lazy[k] == 1) return;
    setLazy(k*2+1, lazy[k]);
    setLazy(k*2+2, lazy[k]);
    lazy[k] = 1;
  }
  void add(int k, int v) {
    sum(k, k+1);
    k += MAX_N-1;
    seg[k] = (seg[k]+v)%MOD;
    while (k > 0) {
      k = (k-1)/2;
      seg[k] = (seg[k*2+1]+seg[k*2+2])%MOD;
    }
  }
  int sum(int a, int b, int k=0, int l=0, int r=MAX_N) {
    if (b <= l || r <= a) return 0;
    if (a <= l && r <= b) return seg[k];
    push(k);
    return (sum(a, b, k*2+1, l, (l+r)/2) + sum(a, b, k*2+2, (l+r)/2, r)) % MOD;
  }
  void mul(int a, int b, int x, int k=0, int l=0, int r=MAX_N) {
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) return setLazy(k, x);
    push(k);
    mul(a, b, x, k*2+1, l, (l+r)/2);
    mul(a, b, x, k*2+2, (l+r)/2, r);
    seg[k] = (seg[k*2+1]+seg[k*2+2])%MOD;
  }
} seg;

int N;
int V[200000];
int L[200000], R[200000];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  vector<P> ps;
  vector<int> vs;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    vs.pb(y);
    ps.pb(P(x, y));
  }
  sort(all(vs));
  sort(all(ps));
  rep(i, N) V[i] = index(vs, ps[i]._2);
  int cur = -1;
  rep(i, N) {
    cur = max(cur, V[i]);
    R[i] = cur;
  }
  cur = vs.size();
  for (int i=N-1; i>=0; i--) {
    cur = min(cur, V[i]);
    L[i] = cur;
  }
  vector<P> segs;
  rep(i, N) segs.pb(P(L[i], R[i]));
  sort(all(segs));
  seg.add(0, 1);
  rep(i, N) {
    int l = segs[i]._1, r = segs[i]._2;
    seg.add(r+1, seg.sum(l, r+2));
    seg.mul(r+2, MAX_N, 2);
  }
  cout << seg.sum(N, N+1) << "\n";
  return 0;
}


Measured memory_bytes: 12136
#include <algorithm>
#include <complex>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];
    sort(l.begin(), l.end(), greater<int>());
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}

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

public class Main{

	static long [][]memo;
	static int n,W;
	static int []w,v;
	static long dp(int idx,int rem) {
		if(idx==n)
			return 0;
		if(memo[idx][rem]!=-1)
			return memo[idx][rem];
		long ans=dp(idx+1,rem);
		if(w[idx]<=rem)
			ans=Math.max(ans, dp(idx+1,rem-w[idx])+v[idx]);
		return memo[idx][rem]=ans;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		n=sc.nextInt();
		W=sc.nextInt();
		w=new int [n];
		v=new int [n];
		memo=new long [n][W+1];
		for(int i=0;i<n;i++) {
			w[i]=sc.nextInt();
			v[i]=sc.nextInt();
			Arrays.fill(memo[i], -1);
		}
		
		
		out.println(dp(0, W));
		
		out.close();

	}
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 125908
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;


int MAX_V = 200; // 頂点数
vector<vector<int>> d(MAX_V, vector<int>(MAX_V, INF));
void warshall_floyd() {
  for(int k = 0; k < MAX_V; ++k)
    for(int i = 0; i < MAX_V; ++i)
      for(int j = 0; j < MAX_V; ++j)  d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  vector<int> t(r);
  rep(i, r) {
    cin >> t[i];
    t[i]--;
  }
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    d[a][b] = c;
    d[b][a] = c;
  }
  rep(i, n) d[i][i] = 0;

  int ans = INF;
  warshall_floyd();
  sort(t.begin(), t.end());
  do {
    int dist = 0;
    rep(i, r - 1) {
      int now = t[i];
      int next = t[i + 1];
      dist += d[now][next];
    }
    chmin(ans, dist);
  } while (next_permutation(t.begin(), t.end()));
  cout << ans << endl;
}

Measured memory_bytes: 384
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;

int n, m, c[mxn], mx[mxn];
list<int> g[mxn];
pair<pair<int, int>, int> q[mxn];

void dfs(int u, int d, int col) {
    if (mx[u] >= d) return;
    if (mx[u] == -1) c[u] = col;
    mx[u] = d;
    for (auto &v : g[u]) {
        dfs(v, d-1, col);
    }
}

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11);
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> q[i].first.first >> q[i].first.second >> q[i].second;
    }

    memset(mx, -1, sizeof(mx));
    for (int i = Q-1; i >= 0; i--) {
        dfs(q[i].first.first, q[i].first.second, q[i].second);
    }

    for (int i = 1; i <= n; i++) {
        cout << c[i] << '\n';
    }
}

Measured memory_bytes: 10496