akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int64_t powten(int64_t k){
    if(k==0){
        return 1;
    }
    else{
        return 10*powten(k-1);
    }
}
int main(){
    int n;
    cin >> n;
    bool seven,five,three=false;
    bool igai = false;
    int count=0;
    int i=1;
    while(i<=n){
        string s = to_string(i);
        //cout <<"i=" << i <<endl;
        //cout << s <<endl;
        //cout <<"size =" <<s.size() <<endl;
        seven = false;
        five = false;
        three = false;
        igai = false;
        int size=s.size();
        for(int j=0;j<size;j++){
           // cout <<"s[j]="<<s[j] <<endl;
            if(s[j]=='7'){
                seven = true;
               // cout <<" seven" <<endl;
            }
            else if(s[j]=='5'){
                five=true;

            }
            else if(s[j]=='3'){
                three = true;
                //cout << "three"<<endl;
            }
            else{
                igai = true;
                i += powten(size-j-1); 
                break;
                cout << "igai" <<endl;
            }
        }
        if(seven && five && three&&!igai ){
            count++;
        }
       if(!igai){
        i++;
       }
   }
    cout <<count <<endl;
}

Measured memory_bytes: 256
def p_b():
    n = int(input())

    a = list(map(int, list(str(n))))
    a.reverse()

    ans = 0

    for i in range(len(a)):
        if i % 2 == 1:
            continue

        if i == len(a) - 1:
            ans += n - 10 ** i + 1
        else:
            ans += 9 * 10 ** i

    print(ans)
    
p_b()

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

using namespace std;

const int MAXN = 302;

int n;
double dp[MAXN][MAXN][MAXN];
bool vis[MAXN][MAXN][MAXN];

double solve(int x, int y, int z) {
  if(vis[x][y][z])
    return dp[x][y][z];
  vis[x][y][z] = 1;

  if(!x && !y && !z)
    return dp[x][y][z] = 0;

  int total = x + y + z;
  dp[x][y][z] = (double)(n - total)/total;

  if (x) dp[x][y][z] += x*((solve(x-1, y, z)+1)/total);
  if (y) dp[x][y][z] += y*((solve(x+1, y-1, z)+1)/total);
  if (z) dp[x][y][z] += z*((solve(x, y+1, z-1)+1)/total);
  return dp[x][y][z];
}

int main() {
  int a[4] = {0};
  cin >> n;
  for(int i=1; i<=n; ++i) {
    int x;
    cin >> x;
    ++a[x];
  }
  cout.precision(10);
  cout << solve(a[1],a[2],a[3]) << '\n';
  return 0;
}


Measured memory_bytes: 241920
#include<iostream>
#include<algorithm>
#define MAX 100005
using namespace std;
int a[MAX],minn[MAX], maxx[MAX], maxdif,ans;
int main() {
	int n, t;
	cin >> n >> t;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	minn[1] = a[1];
	for (int i = 2; i <= n; i++) {
		minn[i] = min(minn[i-1], a[i]);
	}
	maxx[1] = a[n];
	for (int i = n; i >= 1; i--) {
		maxx[i] = max(maxx[i + 1], a[i]);
	}
	for (int i = 1; i <= n; i++) {
		maxdif = max(maxdif,maxx[i] - minn[i]);
	}
	int ma=-1,mi = -1;
	for (int i = 1; i <= n; i++) {
		if (maxx[i]-minn[i] == maxdif && maxx[i] != ma &&
			minn[i] != mi) {
			ma = maxx[i];
			mi = minn[i];
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvb = vector<vb>;

const int INF = 1e9;
const int MOD = 1e9+7;

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; }

bool isKaibun(string s)
{
    for(int i = 0; i < s.length(); i++)
    {
        if(s[i] != s[s.length()-1-i]) return false;
    }
    return true;
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll N; cin >> N;
    vl A(N); REP(i, N) cin >> A[i];
    vl count(N+1, 0);
    REP(i, N) count[A[i]]++;
    ll sum = 0;
    REPS(i, N) sum += count[i]*(count[i]-1)/2;
    //cout << sum << endl;
    REP(i, N)
    {
        cout << sum - count[A[i]] + 1 << endl;
    }
}

Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			int a = in.nextInt();
			int oturi = (in.nextInt() - a) / 100;
			if (a == 0 && oturi == 0) {
				break;
			}
			System.out.print(oturi % 5);
			oturi /= 5;
			System.out.print(" ");
			System.out.print((oturi % 2));
			oturi /= 2;
			System.out.print(" ");
			System.out.println(oturi);
		}
		in.close();
	}
}

Measured memory_bytes: 24288
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
map<int,int> f;
vector<int> hve;
int ans=0,n,k;
int qpower(int a,int c){
	int re=1;
	while (c){
		if (c&1) re=1ll*re*a%mod;
		c>>=1;a=1ll*a*a%mod;
	}
	return re;
}
int solveit(int v){
	if (f.find(v)!=f.end()) return f[v];
	int re=qpower(k,(v+1)/2);
	for (int i=1;i*i<=v;i++){
		if (v%i==0 && i!=v){
			re=(re-solveit(i)+mod)%mod;
			if (i!=1 && i*i!=v) re=(re-solveit(v/i)+mod)%mod;
		}
	}
	f[v]=re;
	return re;
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i*i<=n;i++){
		if (n%i==0){
			hve.push_back(i);
			if (i*i!=n) hve.push_back(n/i);
		}
	}
	sort(hve.begin(),hve.end());
	for (int i=0;i<hve.size();i++){
		int ff=solveit(hve[i]);
		ans=(ans+1ll*ff*((hve[i]&1)?hve[i]:hve[i]/2)%mod)%mod;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 256
#include<cmath>
#include<vector>
#include<iostream>
#include<algorithm>
#include<map>
#define MAX 1000000000
#define debug(ARGS) cout << #ARGS << ": " << ARGS << endl;

using namespace std;

int main(){
  map<long long, bool> sister_said;
  int num; cin >> num;  

  for(int i = 0; i < num; i++){
    long long tmp;
    
    cin >> tmp;
    auto key = sister_said.find(tmp);
    if (key == sister_said.end()) sister_said[tmp] = true;
    else sister_said[tmp] = not sister_said[tmp];
  }
  
  int sum = 0;
  
  for(auto itr = sister_said.begin(); itr != sister_said.end(); itr++){
    if (itr->second) sum++;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 6528
n, m, c = map(int, input().split())
B = list(map(int, input().split()))

ans = 0
for i in range(n):
    A = list(map(int, input().split()))
    s = c
    for a, b in zip(A, B):  s += a*b
    if s > 0:  ans += 1

print(ans)


Measured memory_bytes: 9084
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define up(i, a, b) for (int i = (a); i <= (b); i++)
#define down(i, a, b) for (int i = (a); i >= (b); i--)
#define mem(x, y) memset(x, (y), sizeof x)
#define ff first
#define ss second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define sc(a) scanf("%d", &a)
#define scl(a) scanf("%lld", &a)
#define scs(a) scanf("%s", a)
#define pr(a, b) printf("%d%c", a, b)
#define prl(a, b) printf("%lld%c", a, b)
#define PQ priority_queue
#define ld long double
#define all(v) v.begin(), v.end()
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> V;

map<string,vector<pii> > m;
int main(){
	int n;cin>>n;
	up(i,1,n){
		string s;int x;
		cin>>s>>x;
		m[s].pb(mp(x,i));
	}
	for(auto i:m){
		sort(all(i.ss),greater<pii>());
		for(auto o:i.ss)cout<<o.ss<<"\n";
	}
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	n,x = MI()
	a = LI()
	a.sort()
	ans=0
	for i,aa in enumerate(a,1):
		if(x>=aa and i!=n):
			x-=aa
			ans+=1
		if(i==n and x==aa):
			ans+=1
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N 500003
#define MOD 1000000007
#define int long long
using namespace std;


signed main()
{
    string s;
    string t;
    cin>>s>>t;
    int dp[s.length()+1][t.length()+1];

    pair<int,int> p[s.length()+1][t.length()+1];

   // int ab[s.length()+1][t.length()+1]={0};

    for(int i=0;i<=s.length();i++){

        for(int j=0;j<=t.length();j++){

            if(i==0 || j==0){
                dp[i][j]=0;
            }
            else{
                if(s[i-1]==t[j-1]){
                        p[i][j]={i-1,j-1};
                        dp[i][j]=1+dp[i-1][j-1];
                }

                else{

                    if(dp[i-1][j]>dp[i][j-1]){
                        p[i][j]={i-1,j};
                        dp[i][j]=dp[i-1][j];
                    }
                    else{
                        p[i][j]={i,j-1};
                        dp[i][j]=dp[i][j-1];
                    }

                }
            }
        }
    }

    p[0][0]={-1,-1};
    string ans;
    int i=s.length();
    int j=t.length();

    while(i!=0 && j!=0){
     //cout<<i<<" "<<j<<endl;
       if(s[i-1]==t[j-1]){
        i--;j--;
        ans+=s[i];
       }
       else if(dp[i][j-1]>dp[i-1][j]){
        j--;
       }
       else{
        i--;
       }



    }

    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;


}


Measured memory_bytes: 211328
#include<bits/stdc++.h>
using namespace std;
typedef struct ss{
    int a,b;
    bool operator < (const ss &x)const{
        if(x.b!=b)
            return b<x.b;
        else
            return a<x.a;
    }
}s;
s node[200007];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d%d",&node[i].a,&node[i].b);
    }
    sort(node+1,node+1+n);
    long long time=0;
    for(int i=1;i<=n;++i){
        time+=1ll*node[i].a;
        if(time>1ll*node[i].b){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<numeric>
#include<vector>

int main(void)
{
  int number = 0;
  std::cin >> number;
  int kind = 0;
  std::cin >> kind;
  std::vector<int> priceList;
  priceList.resize(number);
  for(int index = 0; number > index; ++index)
  {
    std::cin >> priceList[index];
  }
  
  std::sort(priceList.begin(), priceList.end());
  std::cout << std::accumulate(priceList.begin(), priceList.begin() + kind, 0) << std::endl;
}

Measured memory_bytes: 3156
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> aa;
    vector<int> bb;
    for (int i = 0; i < 2 * n; i++) {
        if (s[i] == 'a') aa.push_back(i); else bb.push_back(i);
    }

    vector<int> p(2 * n);
    for (int i = 0; i < n; i++) {
        p[aa[i]] = bb[i];
        p[bb[i]] = aa[i];
    }

    vector<string> mx(2 * n + 1);
    for (int i = 2 * n - 1; i >= 0; i--) {
        mx[i] = mx[i + 1];
        if (p[i] > i) {
            if (s[i] == 'a') {
                mx[i] = std::max(mx[i], "ab" + mx[p[i] + 1]);
            } else {
                int r = i;
                string ss = "";
                for (int j = i; j <= 2 * n; j++) {
                    if (j > r) {
                        break;
                    }
                    if (s[j] == 'b' && p[j] > j) {
                        ss += 'b';
                        r = std::max(r, p[j]);
                    } else if (s[j] == 'a' && p[j] < j && p[j] >= i) {
                        ss += 'a';
                    }
                }
                mx[i] = std::max(mx[i], ss + mx[r]);
            }
        }
//        cout << i << " " << mx[i] << "\n";
    }

    cout << mx[0] << "\n";

    return 0;
}

Measured memory_bytes: 14592
#include <cstdio>

int main (int argc, char const* argv[])
{
	int a=0,b,i;
	while(true){
	
	for(i=0;i<10;i++){
		scanf("%d",&b);
		if(i)a-=b;
		else if(b) a=b;
		else break;
	}
	if(i==0) break;
	printf("%d\n",a);
		
	}
	return 0;
}

Measured memory_bytes: 1032
def sum(arr)
  arr.inject(:+)
end

while str = gets
  arr = str.split(',').map(&:to_f)
  l_list, v_list = arr[0..9], arr[10..11]

  l1 = sum(l_list) * v_list[0] / sum(v_list)

  sum = 0
  l_list.each_with_index do |l, idx|
    sum += l
    if l1 <= sum
      puts idx + 1
      break
    end
  end
end

Measured memory_bytes: 8568
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

                string input = Console.ReadLine();
                string[] rc = input.Split(' ');
                int r = int.Parse(rc[0]);
                int c = int.Parse(rc[1]);
                int rowsum,colsum = 0;
                int sum = 0;
                int[,] answer = new int[r+1, c+1];

                for (int row = 0; row < r; row++)//????¬???????????????¨???????????\??????
                {
                    string rcin = Console.ReadLine();
                    string[] rcinput = rcin.Split();
                    for (int col = 0; col < c; col++)
                    {
                        answer[row, col] = int.Parse(rcinput[col]);
                    }
                }


                for (int i = 0; i < r; i++)//??????????¨?
                {
                    rowsum = 0;
                    for (int j = 0; j < c; j++)
                    {
                        rowsum = rowsum + answer[i, j];
                    }
                    answer[i, c] = rowsum;
                }

                for (int i = 0; i < c; i++)//??????????¨? //missssssss
                {
                    colsum = 0;
                    for (int j = 0; j < r; j++)
                    {
                        colsum = colsum + answer[j,i];//miss
                    }
                    answer[r, i] = colsum;
                }

                for (int i = 0; i < r; i++)//??¨??¨??????????¨????????±???????
                {
                    for (int j = 0; j < c; j++)
                    {
                        sum = sum + answer[i, j];
                    }
                }

                answer[r, c] = sum;//????????????????????¨??¨??????????¨?????????£??\



                    for (int a = 0; a <= r; a++)
                    {
                        for (int b = 0; b <= c; b++)
                        {
                            Console.Write(string.Format("{0}", answer[a, b]));
                            if (b == c)
                                break;
                            Console.Write(" ");
                        }
                        Console.WriteLine("");
                    }
       
        }
    }
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

const int Max = 303;

int main() {

  for(string s_; cin >> s_ && s_ != "#END";) {
    const int N = s_.size();

    string max_string;
    int max_length = 0;

    REP(k, 1, N) {
      const int sn = k;
      const int tn = N - k;
      string s = string(s_.begin(), s_.begin() + sn);
      string t = string(s_.begin() + sn, s_.end());
      int dp[Max][Max];
      int trans[Max][Max];

      zero(dp);
      minus(trans);

      rep(i, sn) {
        rep(j, tn) {
          if(s[i] == t[j]) {
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
            trans[i + 1][j + 1] = 0;
          }
          else if(dp[i + 1][j] > dp[i][j + 1]) {
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j]);
            trans[i + 1][j + 1] = 1;
          }
          else {
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1]);
            trans[i + 1][j + 1] = 2;
          }
        }
      }

      if(dp[sn][tn] > 0) {
        int i = sn, j = tn;
        string res;
        while(trans[i][j] >= 0) {
          if(trans[i][j] == 2) i--;
          else if(trans[i][j] == 1) j--;
          else {
            i--, j--;
            res.push_back(s[i]);
          }
        }

        if(max_length < res.size()) {
          reverse(res.begin(), res.end());
          max_length = res.size();
          max_string = res;
        }
      }
    }

    cout << max_string << endl;
  }
  
  return 0;
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    int n; cin >> n;
    V<ll> a(n), b(n);
    for(int i = 0; i < n; i++){
        ll x; cin >> x;
        a[i] = x;
        b[i] = x;
    }

    sort(all(b));
    ll ml = b[n / 2 - 1];
    ll mr = b[n / 2];

    for(int i = 0; i < n; i++){
        if(a[i] <= ml) cout << mr << endl;
        else if(mr <= a[i]) cout << ml << endl;
    }

}


Measured memory_bytes: 5376
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a)      cout<<a<<" "
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll minize(ll& a,ll b){return a=(a>b?b:a);}
inline ll maxize(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	fu(i,1,4)sc(A[i]);
	sort(A+1,A+1+4);
	if(A[1]==1 and A[2]==4 and A[3]==7 and A[4]==9)pr("YES");
	else pr("NO");


	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
  #define cerrendl 42
#endif
//}}}

signed main() {
  int n,k,q;cin>>n>>k>>q;/*{{{*/
  vector<int> a(n);

  set<int> v;
  rep(i, n) {
    cin>>a[i];
    v.insert(a[i]);
  }
  dump(a);/*}}}*/

  int res = INF;
  each(x, v){
    // x以上で構成するとする。
    vi tmp, box;
    rep(i, n){
      if (a[i]<x){
        if (sz(tmp)>=k){
          sort(all(tmp));
          rep(i, sz(tmp)-(k-1)) box.pb(tmp[i]);
        }
        tmp = vi();
      }
      else{
        tmp.pb(a[i]);
      }
    }
    if (sz(tmp)>=k){
      sort(all(tmp));
      rep(i, sz(tmp)-(k-1)) box.pb(tmp[i]);
    }

    sort(all(box));
    dump(x, box);
    if (sz(box)>=q){
      chmin(res, box[q-1] - box[0]);
      dump(x, res);
    }
  }
  cout << res << endl;/*}}}*/
  return 0;
}


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

int main() {
  string x, y;
  cin >> x >> y;
  string g1 = "|1||3||5||7||8||10||12|";
  string g2 = "|4||6||9||11|";

  if (g1.find("|" + x + "|") != -1 && g1.find("|" + y + "|") != -1) {
    cout << "Yes" << endl;
  } else if (g2.find("|" + x + "|") != -1 && g2.find("|" + y + "|") != -1) {
    cout << "Yes" << endl;
  } else if (x == "2" && y == "2") {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import sys,collections
input = sys.stdin.readline

def main():
    N,M,K = list(map(int,input().split()))
    fr = [[] for i in range(N+1)]
    bl = [[] for i in range(N+1)]

          
    for _ in range(M):
        a,b = map(int,input().split())
        fr[a].append(b)
        fr[b].append(a)
    for _ in range(K):
        c,d = map(int,input().split())
        bl[c].append(d)
        bl[d].append(c)

    fl = [-1 for i in range(N+1)]
    fl[0] = 0
    fl[1] = 1
    nxt = 1
    dic = {}
    s = set(range(1,N+1))
    while nxt != 0:
        q = collections.deque([nxt])
        
        fl[nxt]=nxt
        cnt = 0
        while q:
            now = q.popleft()
            s.discard(now)
            for f in fr[now]:
                if fl[f] == -1:
                    fl[f] = nxt
                    cnt +=1
                    q.append(f)
        dic[nxt] = cnt
        #try:
            #nxt = fl.index(-1)
        #except:
            #nxt = 0
        if len(s) == 0:
            nxt = 0
        else:
            nxt = s.pop()


    mbf = collections.deque()
    for i in range(1,N+1):
        ff = 0
        for j in bl[i]:
            if fl[j] == fl[i]:
                ff -= 1
        
        ff += dic[fl[i]]-len(fr[i])
        mbf.append(ff)
    print(*mbf)

if __name__ == '__main__':
    main()


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

int main() {
  long long a,b;
  cin >> a >> b;
  if (a*b <= 0) {
    cout << "Zero" << endl;
  }
  else if (a > 0) {
    cout << "Positive" << endl;
  }
  else if ((b-a) % 2 == 1) {
    cout << "Positive" << endl;
  }
  else {
    cout << "Negative" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
//46
#include<iostream>
#include<algorithm>
#include<numeric>

using namespace std;

int main(){
  int t;
  cin>>t;
  while(t--){
    int n,k,p;
    cin>>n>>k>>p;
    int d[100000];
    for(int i=0;i<n-1;i++){
      int c;
      cin>>c;
      d[i]=c-p;
      p=c;
    }
    sort(d,d+n-1);
    cout<<((n<=k)?0:accumulate(d,d+n-1-(k-1),0))<<endl;
  }
  return 0;
}

Measured memory_bytes: 1568
#include <stdio.h>

void division(int x,int y);
 
int main(void) {
    int x,y;
    
    scanf("%d %d",&x,&y);
    division(x,y);

    return 0;
}

void division(int x,int y){
	int d,r;
	double f;
	
	d = x / y;
	r = x % y;
    f = 1.0000 * x / y;
    
    printf("%d %d %f\n",d,r,f);
}

Measured memory_bytes: 636
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
#define N 200127
#define INF 0x3f3f3f3f
int n,m,a[N],mi=INF,L[N],R[N],vl[N],vr[N],v1[N],v2[N];
struct Point{
	int x,v;
	inline bool operator<(const Point &b)const{return (v>b.v)||((v==b.v)&&(x>b.x));}
};
priority_queue<Point>q;
int b[N],cn=0;long long ans=0;
int main(){
	scanf("%d%d",&n,&m);ans=n;int i,j,k,v,l,r,p,sum;for(i=1;i<=n;i++)scanf("%d",&a[i]),L[i]=i-1,R[i]=i+1,vl[i]=vr[i]=1,q.push((Point){i,a[i]});
	while(!q.empty())
	{
		cn=0;v=q.top().v;while((!q.empty())&&(v==q.top().v))b[++cn]=q.top().x,q.pop();
		for(i=1;i<=cn;i=r+1)
		{
			l=r=i;while((r<cn)&&(R[b[r]]==b[r+1]))++r;
			sum=0;for(i=l;i<=r;i++){if(i-m+1>=l)sum+=vl[b[i-m+1]];ans+=1ll*sum*vr[b[i]];}
			if(r-l+1<m){R[L[b[l]]]=n+1;L[R[b[r]]]=0;continue;}p=(r-l+1)/m;
			for(i=l;i<=r;i++)k=b[i],v1[k]=vl[k],v2[k]=vr[k],vl[k]=vr[k]=0;
			for(i=r-m+1,k=p;i>=l;i-=m,--k)for(j=i;(j>=l)&&(j>=i-m+1);j--)vl[b[l+k-1]]+=v1[b[j]];
			for(i=l+m-1,k=1;i<=r;i+=m,++k)for(j=i;(j<=r)&&(j<=i+m-1);j++)vr[b[l+k-1]]+=v2[b[j]];
			for(i=l;i<=l+p-1;i++)++a[b[i]],q.push((Point){b[i],a[b[i]]});L[R[b[r]]]=b[l+p-1];R[b[l+p-1]]=R[b[r]];
			sum=0;for(i=l;i<=l+p-1;i++){if(i-m+1>=l)sum+=vl[b[i-m+1]];ans-=1ll*sum*vr[b[i]];}
		}
	}printf("%lld",ans);return 0;
}

Measured memory_bytes: 7792
#include<iostream>
#include<vector>
using namespace std;
#define MAXN 101
#define MAXW 10001

int N,W;
vector<vector<int> > dp(MAXN,vector<int>(MAXW,0)); 
vector<int> v(MAXN),w(MAXN);
int main(){
    cin>>N>>W;
    for(int i=0;i<N;i++){
        cin>>v[i]>>w[i];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j<w[i]) dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
        }
    }
    cout<<dp[N][W]<<endl;
    return 0;
}


Measured memory_bytes: 6688
N, W = map(int, input().split())
items = [[] for _ in range(4)]
for i in range(N):
    w, v = map(int, input().split())
    if i == 0:
        w0 = w
        items[0].append(v)
    else:
        items[w-w0].append(v)

items = [[0]+sorted(items[i], reverse=True) for i in range(4)]
for i in range(4):
    for j in range(1, len(items[i])):
        items[i][j] += items[i][j-1]

ans = 0
for i in range(len(items[0])):
    for j in range(len(items[1])):
        for k in range(len(items[2])):
            for l in range(len(items[3])):
                if w0*(sum((i, j, k, l))) + j + k*2+l*3 <= W:
                    ans = max(
                        ans, sum((items[0][i], items[1][j], items[2][k], items[3][l])))

print(ans)


Measured memory_bytes: 42220
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main(){
 
  int n,w,h,x,y,haba,i;
  pair <int,int> x1[100000],y1[100000];
   
  cin>>n>>w>>h;
 
  for(i=0;i<n;i++){
 
    cin>>x>>y>>haba;
    int a,b,c,d;
    a=x-haba;
    b=x+haba;
    c=y-haba;
    d=y+haba;
    if(a<0) a=0;
    if(b>w) b=w;
    if(c<0) c=0;
    if(d>h) d=h;
    x1[i]=make_pair(a,b);
    y1[i]=make_pair(c,d);
 
  }
  sort(x1,x1+n);
  sort(y1,y1+n);
  int wa=0,ha=0;
  int maxza=0;
  if(x1[0].first!=0) wa++;
  else{
    for(i=1;i<n;i++){
      if(x1[i-1].first!=x1[i].first){
        maxza=max(x1[i-1].second,maxza);
        if(maxza<x1[i].first){
          wa++;
          break;
        }
      }
    }
    if(max(maxza,x1[n-1].second)<w) wa++;
  }
  maxza=0;  
  if(y1[0].first!=0) ha++;
  else{
    for(i=1;i<n;i++){
      if(y1[i-1].first!=y1[i].first){
        maxza=max(y1[i-1].second,maxza);
        if(maxza<y1[i].first){
          ha++;
          break;
        }
      }
    }
    if(max(maxza,y1[n-1].second)<h) ha++;
  }      
     
 
  if(wa==0 || ha==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
 
  return 0;
 
}

Measured memory_bytes: 4652
#include<iostream>
#include<vector>
#include<complex>

using namespace std;

typedef complex<double> P;

P p[3];
double ih;

double cross(P a,P b){
  return (conj(a)*b).imag();
}

bool intersects(P a,double ra,P b,double rb){
  return abs(a-b)<=ra+rb;
}

P angle_bisector(P a,P b){
  return a/abs(a)+b/abs(b);
}
  
P rtop(int x,double r){
  P a=p[(x+1)%3]-p[x];
  P b=p[(x+2)%3]-p[x];
  P m=angle_bisector(a,b);
  return p[x]+m*r*abs(a)/cross(a,m);
}

bool isx(int a,double ra,int b,double rb){
  return intersects(rtop(a,ra),ra,rtop(b,rb),rb);
}

vector<double> os(double r){
  vector<double> v(2);
  for(int i=0;i<2;i++){
    double l=0,h=ih;
    for(int j=0;j<99;j++){
      double m=(l+h)/2;
      if(isx(i,m,2,r)){
	h=m;
      }else{
	l=m;
      }
    }
    v[i]=l;
  }
  return v;
}

int main(){
  for(;;){
    bool f=false;
    for(int i=0;i<3;i++){
      int x,y;
      cin>>x>>y;
      f|=x|y;
      p[i]=P(x,y);
    }
    if(!f)break;
    P a=p[1]-p[0];
    P b=p[2]-p[0];
    ih=cross(a,b)/(abs(a)+abs(b)+abs(p[1]-p[2]));
    double l=0,h=ih;
    for(int i=0;i<99;i++){
      double m=(l+h)/2;
      auto r=os(m);
      if(isx(0,r[0],1,r[1])){
	l=m;
      }else{
	h=m;
      }
    }
    auto r=os(l);
    cout.precision(9);
    cout<<fixed<<r[0]<<' '<<r[1]<<' '<<l<<endl;
  }
}

      

Measured memory_bytes: 1284
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=105;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,m,K,Mod;
int C[N][N],P[N][N],f[2][N][N];
int mod(int x){return x>=Mod?x-Mod:x;}
void Prepare(){
	for(int i=0;i<N;i++){C[i][0]=1;for(int j=1;j<=i;j++)C[i][j]=mod(C[i-1][j-1]+C[i-1][j]);}
	for(int i=0;i<N;i++){P[i][0]=1;for(int j=1;j<N;j++)P[i][j]=1ll*P[i][j-1]*i%Mod;}
}
void Clear(int t){for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)f[t][i][j]=0;}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();m=read();K=read();Mod=read();Prepare();
	int t=0;f[t][0][0]=1;
	for(int T=1;T<=K;T++){
		Clear(t^=1);
		for(int i=0;i<=n;i++){
			for(int j=0;j<=m;j++){
				if(!f[t^1][i][j])continue;
				int tmp=f[t^1][i][j],mul=1ll*P[T][m-j]*P[K-T+1][j]%Mod;
				for(int a=0;i+a<=n;a++,tmp=1ll*tmp*mul%Mod){
					f[t][i+a][j]=(f[t][i+a][j]+1ll*C[n-i][a]*tmp)%Mod;
				}
			}
		}
		Clear(t^=1);
		for(int i=0;i<=n;i++){
			for(int j=0;j<=m;j++){
				if(!f[t^1][i][j])continue;
				int tmp=f[t^1][i][j],mul=1ll*P[T][n-i]*P[K-T+1][i]%Mod;
				for(int b=0;j+b<=m;b++,tmp=1ll*tmp*mul%Mod){
					f[t][i][j+b]=(f[t][i][j+b]+1ll*C[m-j][b]*tmp)%Mod;
				}
			}
		}
		Clear(t^=1);
		for(int i=0;i<=n;i++){
			for(int j=0;j<=m;j++){
				if(!f[t^1][i][j])continue;
				int tmp=f[t^1][i][j],mul=1ll*P[T][m-j]*(Mod-P[K-T][j])%Mod;
				for(int c=0;i+c<=n;c++,tmp=1ll*tmp*mul%Mod){
					f[t][i+c][j]=(f[t][i+c][j]+1ll*C[n-i][c]*tmp)%Mod;
				}
			}
		}
		Clear(t^=1);
		for(int i=0;i<=n;i++){
			for(int j=0;j<=m;j++){
				if(!f[t^1][i][j])continue;
				int tmp=f[t^1][i][j],mul=1ll*P[T][n-i]*(Mod-P[K-T][i])%Mod;
				for(int d=0;j+d<=m;d++,tmp=1ll*tmp*mul%Mod){
					f[t][i][j+d]=(f[t][i][j+d]+1ll*C[m-j][d]*tmp)%Mod;
				}
			}
		}
	}
	printf("%d",f[t][n][m]);
	return 0;
}

Measured memory_bytes: 3932
//============================================================================
// Name        : BinarySearch.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;

void BubbleSort(vector<int>&);
int BinarySearch(const vector<int>&, const vector<int>&);
void WriteVector(const vector<int>&);

void WriteVector(const vector<int>& v){
	for(int i=0; i<v.size(); i++){
		cout << v.at(i) << "\n";
	}
}

void BubbleSort(vector<int>& v){
	bool changed = true;
	while(changed){
		changed = false;
	    for(int i=v.size()-1; 1<=i; i--){
		    if(v.at(i) < v.at(i-1)){
			    int tmp = v.at(i-1);
			    v.at(i-1) = v.at(i);
			    v.at(i) = tmp;
			    changed = true;
		    }
	    }
	}
	cout << "sorted" << "\n";
	WriteVector(v);
}

int BinarySearch(const vector<int>& unsorted_s, const vector<int>& sorted_t){

	int n_common = 0;

	for(int i=0; i<unsorted_s.size(); i++){
		int begin = 0;
		int end = sorted_t.size();
		//cout << "searching: " << unsorted_s.at(i) << "\n";
		while(begin < end){
		    int mid = (begin + end) / 2;

		    if(sorted_t.at(mid) == unsorted_s.at(i)){
		    	n_common = n_common + 1;
		    	//cout << "found: " << unsorted_s.at(i) << "\n";
		    	break;
		    }else if(sorted_t.at(mid) < unsorted_s.at(i)){
		    	//cout << "case1:  begin: " << begin << ", mid: " << mid << ", end: "
		    	//	 << end << ", unsorted_s.at(i): " << unsorted_s.at(i) << "\n";
		    	begin = mid+1;
		    }else{ //sorted_t.at(mid) > unsorted_s.at(i)
		    	//cout << "case2:  begin: " << begin << ", mid: " << mid << ", end: "
		    	//	 << end << ", unsorted_s.at(i): " << unsorted_s.at(i) << "\n";
		    	end = mid;
		    }
		}
	}
	return n_common;
}

int main() {
	int n;
	vector<int> s;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		int input;
		scanf("%d", &input);
		s.push_back(input);
	}

	int m;
	vector<int> t;
	scanf("%d", &m);
	for(int i=0; i<m; i++){
		int input;
		scanf("%d", &input);
		t.push_back(input);
	}

	//BubbleSort(t);

	int n_common = 0;
	n_common = BinarySearch(t, s);

	//cout << n_common << "\n";
	printf("%d\n", n_common);

	return 0;
}



Measured memory_bytes: 3680
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int main(){
    ll N,M;
    cin >>N>>M;
    if(2*N>M) cout <<M/2<<endl;
    else cout << N+(M-2*N)/4<<endl;
}

Measured memory_bytes: 256
while True:
    m,f,r = [int(x) for x in input().split()]
    if (m,f,r)==(-1,-1,-1): break
    s_mf = m + f
    if   m < 0 or f < 0: print('F')
    elif s_mf <  30:     print('F')
    elif s_mf >= 80:     print('A')
    elif s_mf >= 65:     print('B')
    elif s_mf >= 50:     print('C')
    elif r    >= 50:     print('C')
    else:                print('D')


Measured memory_bytes: 5600
//This Code was made by Chinese_zjc_.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <ctime>
// #include<windows.h>
#define int long long
#define double long double
using namespace std;
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
int n, ans;
signed main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            int b = i - 1, c = n / i;
            if (b > c)
            {
                ans += b;
            }
            if (i * i != n)
            {
                b = n / i - 1, c = i;
                if (b > c)
                {
                    ans += b;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

class Main
{
    static int mod=1000000007;
    static long dp[][];
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        List<List<Integer>> list=new ArrayList<>();
        dp=new long[n+1][2];
        for(int i=0;i<dp.length;i++)
            for(int j=0;j<dp[0].length;j++)
                dp[i][j]=-1;
        for(int i=0;i<=n;i++)
        {
            list.add(new ArrayList<>());
        }
        for(int l=0;l<n-1;l++)
        {
            String str[]=br.readLine().split(" ");
            int a=Integer.parseInt(str[0]);
            int b=Integer.parseInt(str[1]);
            list.get(b).add(a);
            list.get(a).add(b);
        }
        System.out.println(calculate(list,1,0,-1));

    }

    private static long calculate(List<List<Integer>> list, int index, int black,int parent) {
        long res=1;
        long ans=0;
        if(dp[index][black]!=-1)
            return dp[index][black]%mod;
        for(int child:list.get(index))
        {
            if(child!=parent)
                res=((res%mod)*(calculate(list,child,0,index)%mod))%mod;
        }
        ans=((ans%mod)+(res%mod))%mod;
        if(black==0)
        {
            res=1;
            for(int child:list.get(index))
            {
                if(child!=parent)
                    res=((res%mod)*(calculate(list,child,1,index)%mod))%mod;
            }
            ans=((ans%mod)+(res%mod))%mod;

        }
        return dp[index][black]=ans%mod;
    }
}

Measured memory_bytes: 76644
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <cmath> 
#include <algorithm>
#include <vector> 
using namespace std; 
inline int gi() {
    register int data = 0, w = 1;
    register char ch = 0;
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 
    return w * data; 
} 
const int MAX_N = 1e5 + 5; 
int N, M, a[MAX_N], b[MAX_N], p[MAX_N]; 
int pa[MAX_N]; 
int getf(int x) { while (x != pa[x]) x = pa[x] = pa[pa[x]]; return x; } 
vector<int> G[MAX_N]; 
long long f[MAX_N], sum[MAX_N];
bool vis[MAX_N]; 
int main () { 
	N = gi(), M = gi();
	for (int i = 1; i <= N; i++) { 
		a[i] = gi(), b[i] = gi(); 
		a[i] = max(a[i] - b[i], 0);
		p[i] = i, pa[i] = i; 
	} 
	sort(&p[1], &p[N + 1], [](const int &l, const int &r) { return a[l] < a[r]; } ); 
	for (int i = 1; i <= M; i++) { 
		int u = gi(), v = gi(); 
		G[u].push_back(v), G[v].push_back(u); 
	} 
	for (int i = 1; i <= N; i++) { 
		vector<int> son;
		int x = p[i]; 
		vis[x] = 1, sum[x] = b[x]; 
		for (auto v : G[x]) {
			if (!vis[v] || getf(x) == getf(v)) continue; 
			son.push_back(getf(v)); 
			sum[x] += sum[getf(v)]; 
			pa[getf(v)] = x; 
		} 
		f[x] = sum[x] + a[x]; 
		for (auto v : son) f[x] = min(f[x], sum[x] - sum[v] + max(1ll * a[x], f[v])); 
	} 
	printf("%lld\n", f[p[N]]); 
    return 0; 
} 

Measured memory_bytes: 12544
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
 
//辺edge->e : 逆辺edge->path[e.to][e.rev]
struct edge{
    int to,cap,rev;
};
 
vector<vector<edge>> path;
vector<int> visited;

void add_edge(int from,int to,int cap){
    path[from].push_back((edge){to,cap,(int)path[to].size()});
    path[to].push_back((edge){from,0,(int)path[from].size()-1});
}

int dfs(int v,int t,int f){
	if (v==t)
		return f;
	visited[v]=1;
	for(edge &e:path[v]){
		if (visited[e.to]==0 && e.cap>0){
			int d=dfs(e.to,t,min(f,e.cap));
			if (d>0){
				e.cap-=d;
				path[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow=0;
	while(1){
		visited.assign(visited.size(),0);
		int f=dfs(s,t,inf);
		if (f==0){
			return flow;
		}
		flow+=f;
	}
}

int main(){
	int n; cin>>n;
    vector<pp> R(n),B(n);
    rep(i,n){
        int a,b; cin>>a>>b;
        R[i]=mk(a,b);
    }
    rep(i,n){
        int c,d; cin>>c>>d;
        B[i]=mk(c,d);
    }
    path.assign(2*n+2,vector<edge>(0));
    visited.assign(2*n+2,0);
    rep(i,n){
        add_edge(0,i+1,1);
        add_edge(n+i+1,2*n+1,1);
    }
    rep(i,n)rep(j,n){
        int a,b,c,d;
        tie(a,b)=R[i];
        tie(c,d)=B[j];
        if(a<c && b<d){
            add_edge(i+1,n+j+1,1);
        }
    }
    cout<<max_flow(0,2*n+1)<<endl;
}

Measured memory_bytes: 384
use std::io::*;
use std::str::FromStr;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
#[allow(non_snake_case, unused_variables)]
fn main() {
    let R: u32 = read();
    let ans = 
        if R<1200 {
            "ABC"
        } else if R<2800 {
            "ARC"
        } else {
            "AGC"
        };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
int w,h,c,t,i,j,n;
scanf("%d %d %d",&w,&h,&c);
if(w>h){
t=w;
w=h;
h=t;
}
for(i=1;i<=w;i++){
if(w%i==0&&h%i==0)
j=i;
}
printf("%d\n",w*h/(j*j)*c);
return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;



int main() {
    int n; cin >> n;
    map<ll,int> m;
    for(int i = 0;i < n;i++){
        ll a; cin >> a;
        auto x = m.find(a);
        if(x == m.end()){
            m.insert(make_pair(a,1));
        }else{
            x->second++;
        }
    }
    
    int y; cin >> y;
    string ans = "YES";
    for(int i = 0;i < y;i++){
        ll b; cin >> b;
        auto z = m.find(b);
        if(z == m.end()){
            ans = "NO";
            break;
        }else{
            z->second--;
            if(z->second == 0){
                m.erase(z);
            }
        }
    }
    cout << ans;
}



Measured memory_bytes: 12800
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
ll a[105];
int main(){
	std::ios::sync_with_stdio(false);
	ll n,x,s=0,i;
	cin>>n>>x;
	s=0;
	rep(i,n){
		cin>>a[i];
		s+=a[i];
	}
	if(s<x){
		cout<<n-1<<endl;
		return 0;
	}
	if(s==x){
		cout<<n<<endl;
		return 0;
	}
	s=0;
	sort(a,a+n);
	rep(i,n){
		s+=a[i];
		if(s>x){
			cout<<i<<endl;
			return 0;
		}
	}
} 
	

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int i, n, ans = 0;
  scanf("%d", &n);
  for(i = 1; i < 10; ++i) if(i <= n) ++ans;
  for(i = 100; i < 1000; ++i) if(i <= n) ++ans;
  for(i = 10000; i < 100000; ++i) if(i <= n) ++ans;
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
# sum??????????????????
module Main
  extend self

  def make_combination(n)
    [0, 1].repeated_permutaion(n).to_a
  end

  @@memo = {}
  def can_assemble?(elements, index, sum, raw_elements_length)
    if sum == 0
      true
    elsif index >= raw_elements_length
      false
    else
      can_assemble?(elements, index + 1, sum, raw_elements_length) || can_assemble?(elements, index + 1, sum - elements[index], raw_elements_length)
    end
  end

  def main
    lines = STDIN.read.split(/\n/)
    lines.shift

    elements = lines.shift.split(' ').map{|s|s.to_i}
    lines.shift

    sums = lines.shift.split(' ').map{|s|s.to_i}
    sums.each{ |sum|
      puts can_assemble?(elements, 0, sum, elements.size) ? 'yes' : 'no'
    }

  end
end

Main::main

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

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

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

    // start
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
n,a,b = map(int, input().split())

counter = 0

for i in range(1,n+1):
  tent = i //10000
  thou = (i - tent * 10000) // 1000
  hund = (i - thou * 1000 - tent * 10000) // 100
  ten  = (i - thou * 1000 - hund * 100 - tent * 10000) // 10
  one  =  i - thou * 1000 - hund * 100 - ten * 10 - tent * 10000
  sum_all = tent + thou + hund + ten + one
  if sum_all >= a and sum_all <= b:
    counter += i

print(counter)


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }


void compute() {

}

int main() {
  int n;
  cin >> n;
  vector<int> X(n);
  vector<bool> s(2025,false);
  rep(i,n) {
    cin >> X[i];
    s[X[i]] = true;
  }

  int m;
  cin >> m;
  rep(i,m) {
    int a;
    cin >> a;
    --a;
    if( X[a] == 2019 ) continue;
    if( s[X[a]+1] ) continue;
    s[X[a]+1] = true;
    s[X[a]] = false;
    ++X[a];
  }
  rep(i,n) {
    cout << X[i] << endl;
  }
  compute();
  return 0;
}



Measured memory_bytes: 3120