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

int n, x, y;

bitset<100> used;
int ans;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> n;
    vector<pair<int, pair<char, int>>> a;
    for (int i = 0; i < 2 * n; i++) {
		cin >> x >> y;
		if (i < n) a.push_back({x, {'r', y}});
		else a.push_back({x, {'b', y}});
	}
	sort(a.begin(), a.end());
	
	multiset<int, greater<int>> cur;
	for (auto& i : a) {
		if (i.second.first == 'r') cur.insert(i.second.second);
		else {
			int by = i.second.second;
			for (auto it = cur.begin(); it != cur.end(); it++) {
				if (by > *it) {
					ans++;
					cur.erase(it);
					break;
				}
			}
		}
	}

    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
 
long long n,dp[100005],w,v,k,mxw,ans,pt,lpt;
bool d[100005];
int main(){
	scanf("%lld%lld",&n,&mxw);
	for (int i=100000;i>=1;i--){
		dp[i]=1e9+1;
	}
	d[0]=true; dp[0]=0;
	for (int i=1;i<=n;i++){
		scanf("%lld%lld",&w,&v); 
		for (int j=100000;j>=0;j--){
			if (d[j] == true && j+v <= 100000 && dp[j]+w <= mxw){
				d[j+v]=true;
				dp[j+v]=min(dp[j+v],dp[j]+w);
			}
		}
	}
	for (int i=0;i<=100000;i++){
		if	(d[i])
		ans=i;
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	var (
		a   = nextString()
		b   = nextString()
		ans = 0
	)
	switch {
	case len(a) == len(b):
		for i := range a {
			if a[i] > b[i] {
				ans = 1
			}
			if a[i] < b[i] {
				ans = 2
			}
			if ans != 0 {
				break
			}
		}
	case len(a) > len(b):
		ans = 1
	default:
		ans = 2
	}
	fmt.Println([]string{"EQUAL", "GREATER", "LESS"}[ans])
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
		}
		return r.Text()
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#define ll long long 
#define d double
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
	string s;
	cin>>s;
	map<char,int> count;
	for(char c:s){
      count[c]++;
	}
	 
	 
	if(count['A']<3&&count['A']>=1){
		cout<<"Yes"<<endl;	
	}
	
	else{	
		cout<<"No"<<endl;
	 } 
	
    return 0;
}

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

#define thegamebegins   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fileio          freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define int             long long
#define float           long double
#define test            int T; cin>>T; while(T--)
#define in(a,n)         for(int i=0; i<n; ++i)  cin>>a[i]
#define r0              return 0
#define E               "\n"
#define S               " "
#define elif            else if 
#define M               1000000007
#define fi(i,x,y)       for(int i=x; i<y; ++i)
#define fa(i,s)         for(auto i:s)
#define fp(i,s)         for(auto i=(s).begin(); i!=(s).end(); ++i)
#define sz(s)           (s).size()
#define vi              vector <int>
#define vpii            vector <pair <int,int> >
#define mii             map <int,int>
#define pii             pair <int,int>
#define seti            set <int>
#define setd            set <int,greater <int> >
#define all(s)          (s).begin(),(s).end()
#define sortd(a,n)      sort(a, a+n, greater<int>())
#define pb              push_back
#define mp              make_pair
#define fr              first
#define sc              second
#define lb              lower_bound
#define ub              upper_bound
#define er              equal_range
 
const int INF = 0x3f3f3f3f;

signed main()
{
    thegamebegins

    int a,b,c;  cin>>a>>b>>c;
    swap(a,b);  swap(a,c);
    cout<<a<<S<<b<<S<<c;
    r0;
}


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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		long wa = 0;
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				for(long k = 1; k <= n; k++)
				{
					wa += GCD(GCD(i,j), k);
				}
				
			}
		}
		Console.WriteLine(wa);
	}

	
	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];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

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

# 登校した順番のリスト
B = []

for i in range(len(A)):
    B.append([i + 1, A[i]])

# 2番目の要素に注目してソート
B.sort(key=lambda x: x[1])

for i in (B):
    print(i[0], end=" ")

# 改行
print()


Measured memory_bytes: 22592
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007

using namespace std;

int a,b,c,d,e,f;
bool ok[400000],ok2[400000];
int res1,res2;
double res=-1.0;

void fir()
{
	ok[0]=ok2[0]=true;
	for(int i=0;i<=3000;i++)
	{
		if(ok[i])ok[i+a]=ok[i+b]=1;
		if(ok2[i])ok2[i+c]=ok2[i+d]=1;
	}
	
}

int main()
{
	cin>>a>>b>>c>>d>>e>>f;
	
	fir();

	for(int i=100;i<=f;i++)
		for(int j=0;j+i<=f;j++)
		{
			if(i%100)continue;
			if(ok[i/100]==0||ok2[j]==0)continue;
			if(j>i/100*e)continue;
			
			if(j*1.0/i>res)
			{
				res=j*1.0/i;
				res1=i;
				res2=j;
			}
		}
	printf("%d %d\n",res1+res2,res2);

	return 0;	
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout," ");
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((n*m)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
//ll min(ll a, ll b){
//    if(a>b){
//        return b;
//    }
//    return a;
//}
// 
//ll max(ll a, ll b){
//    if(a>b){
//        return a;
//    }
//    return b;
//}
bool pairdec(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
       	return (a.fi> b.fi);
		else return a.se>b.se;  
} 

ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = x%mod; 
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % mod; 
  
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 
  
    return result; 
} 

set<ll> primeFactors(ll n)  
{  
    set<ll>s;
    while (n % 2 == 0)  
    {  
       s.insert(2);
        n = n/2;  
    }  
  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
    
        while (n % i == 0)  
        {  
           s.insert(i); 
            n = n/i;  
        }  
    }  
    if (n > 2) s.insert(n);
    return s;
}  
//cout<<setprecision(9)<<fixed<<sum<<endl; --- precision for double numbers
//copy(v.beg,v.en,outp);
ll N=1e9+7;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b && b!=c)|| (b==c && c!=a)|| (c==a && a!=b )) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>

using namespace std;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n, 0);
  int total = 0;
  for(int i = 0; i < n; i++)
  {
    cin >> a[i];
    total += a[i];
  }
  double mean = double(total) / n;
  double mind = 100.0;
  for(int i = 0; i < n; i++)
  {
    mind = min(mind, abs(mean - a[i]));
  }
  for(int i = 0; i < n; i++)
  {
    if(abs(mean - a[i]) == mind)
    {
      cout << i << endl;
      break;
    }
  }
	return 0;
}


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

constexpr int MOD = 1000000007;
constexpr int MAX = 500005;

long long modpow(long long a, long long n, long long m)
{
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

long long fact[MAX], invfact[MAX];

void init() 
{
  fact[0] = 1;
  for (ll i = 1; i < MAX; ++i) {
    fact[i] = fact[i-1] * i % MOD;
  }

  invfact[MAX-1] = modpow(fact[MAX-1], MOD-2, MOD);
  for (ll i = MAX-1; i >= 1; --i) {
    invfact[i-1] = invfact[i] * i % MOD;
  }
}

long long nCr(long long n, long long r)
{
  return fact[n] * invfact[r] % MOD * invfact[n-r] % MOD;
}

long long nPr(long long n, long long r)
{
  return fact[n] * invfact[n-r] % MOD;
}

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

  init();

  int n, m;
  cin >> n >> m;

  ll ans = 0;
  for (int k = 0; k <= n; ++k) {
    ll tmp = (nCr(n, k) * nPr(m, k) % MOD * modpow(nPr(m-k, n-k), 2, MOD) % MOD);
    
    if (k % 2 == 0) ans += tmp;
    else ans -= tmp;

    ans %= MOD;
  }

  cout << (ans + MOD) % MOD << '\n';

  return (0);
}

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

using namespace std;

int main(){
    int a, b;
    string res = "";
    cin>>a>>b;
    if(a < b){
        for(int i = 0; i < b; i++) res += to_string(a);
    }else{
        for(int i = 0; i < a; i++) res += to_string(b);
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1,2,0,-2,0};
const int dy[]={0,1,-1,0,1,1,-1,-1,0,2,0,-2};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
int main(){
	int N,A,B,C,X;
	while(scanf("%d%d%d%d%d",&N,&A,&B,&C,&X),N){
		int c = 0;
		bool f = false;
		rep(i,N){
			int tmp;
			scanf("%d",&tmp);
			if(f)continue;
			while(tmp != X){
				X = (A*X+B)%C;
				c++;
				if(c > 10000){
					f = true;
					break;
				}
			}
			X = (A*X+B)%C;
			c++;
		}
		if(f)puts("-1");
		else printf("%d\n",c-1);	
	}
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;
int a,b,c,x,n,maxi,mini,i,v[10],nrblank,nrmin;

int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x<400) v[1]++;
        else if(x<800) v[2]++;
        else if(x<1200) v[3]++;
        else if(x<1600) v[4]++;
        else if(x<2000) v[5]++;
        else if(x<2400) v[6]++;
        else if(x<2800) v[7]++;
        else if(x<3200) v[8]++;
        else nrblank++;
    }
    for(i=1;i<=8;i++) if(v[i]>0) nrmin++;
    cout<<max(1,nrmin)<<' '<<nrmin+nrblank<<'\n';
    return 0;
}


Measured memory_bytes: 256
def main():
    a, b, c = [input() for _ in [0]*3]
    p = [(a, b, c), (a, c, b), (b, a, c), (b, c, a), (c, a, b), (c, b, a)]

    def check(x, y):
        lx, ly = len(x), len(y)
        ans = {lx}
        for i in range(lx):
            for j in range(min(ly, lx-i)):
                if x[i+j] != y[j] and (x[i+j] != "?" and y[j] != "?"):
                    break
            else:
                ans.add(i)
        return ans

    def check2(x, y, z):
        lx, ly, lz = len(x), len(y), len(z)
        ans = lx+ly+lz
        dxy, dyz, dxz = d[(x, y)], d[(y, z)], d[(x, z)]
        for i in dxy:
            ans = min(ans, max(lx, i+ly)+lz)
            for j in dyz:
                if i+j in dxz or i+j >= lx:
                    ans = min(ans, max(lx, i+ly, i+j+lz))
            for j in range(ly, lx-i):
                if i+j in dxz:
                    ans = min(ans, max(lx, i+j+lz))
        return ans

    d = {(x, y): check(x, y) for x, y, z in p}
    print(min([check2(x, y, z) for x, y, z in p]))


main()


Measured memory_bytes: 46188
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;



int main(){
 int n,m;
//  cin >> n >> m;
 char a;
 cin >> a;
 string s = "abcdefghijklmnopqrstuvwxyz";
rep(i,s.length()){
  if(a == s.at(i)){
  cout << s.at(i+1);
  return 0;
  }
}




}







Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n,i,j,k;
  int ans = 0;
  scanf("%d", &n);
  int L[n];
  for (i = 0; i < n; i++){
    scanf("%d", &L[i]);
  }
  for (j = 0; j < n; j++){
    for (k = j+1; k < n; k++){
      ans += L[j]*L[k];
    }
  }
  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#define N 36
int main(){
	int i,j,k,n,min,flag;
	char a[N][2],b[N][2],hoge[2];
	scanf("%d",&n);
	for ( i = 0; i < n; i++){
		scanf("%s",a[i]);
		for(j = 0; j < 2; j++) b[i][j] = a[i][j];
	}
	//Bubble
	for( i = 0; i < n; i++){
		for( j = n - 1; j > i; j--){
			if(a[j][1] < a[j - 1][1]){
				for(k = 0; k < 2; k++) hoge[k] = a[j][k];
				for(k = 0; k < 2; k++) a[j][k] = a[j - 1][k];
				for(k = 0; k < 2; k++) a[j - 1][k] = hoge[k];
			}
		}
	}
	for ( i = 0; i < n; i++) {
		printf("%c%c",a[i][0],a[i][1]);
		if(i != (n-1)) printf(" ");
		else printf("\nStable\n");
	}

	//Selection
	for(i = 0; i < n; i++){
		min = i;
		for( j = i; j < n; j++){
			if(b[j][1] < b[min][1]){
				min = j;
			}
		}
		for(k = 0; k < 2; k++) hoge[k] = b[i][k];
		for(k = 0; k < 2; k++) b[i][k] = b[min][k];
		for(k = 0; k < 2; k++) b[min][k] = hoge[k];
	}
	flag = 0;
	for(i = 0; i < n; i++){
		for( j = 0; j < n; j++){
			if(a[i][j] != b[i][j]) flag++;
		}
	}
	for ( i = 0; i < n; i++) {
		printf("%c%c",b[i][0],b[i][1]);
		if(i != (n-1)) printf(" ");
		else if(flag == 0){
			printf("\nStable\n");
		}else{
			printf("\nNot stable\n");
		}
	}
	return 0;
}



Measured memory_bytes: 2104
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var AB = ReadSplitLong();
            if (AB[0] % 2 != AB[1] % 2)
                Println("IMPOSSIBLE");
            else
                Println(AB.Sum() / 2);
        }

        static List<long> ReadLines(long n)
        {
            var l = new List<long>();
            for (long i = 0; i < n; i++)
            {
                l.Add(ReadLong());
            }
            return l;
        }

        static void YESOrNO(bool e) => Println(e ? "YES" : "NO");

        static void YesOrNo(bool e) => Println(e ? "Yes" : "No");

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        static long Lcm(long a, long b) => a / Gcd(a, b) * b;

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());
        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}



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

int main(){
  
int A,B,C;
  cin >> A >> B>> C;
  if(C-A+B>0)
  cout << C-A+B << endl;
  else
    cout << '0' << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[N];
    int b[N];
    rep(i, n)
    {
        cin >> a[i];
    }
    rep(i, n)
    {
        cin >> b[i];
    }
    ll need = 0;
    ll have = 0;
    ll ctA = 0;
    priority_queue<ll> pq;
    rep(i, n)
    {
        ll diff = abs(a[i] - b[i]);
        if (a[i] > b[i])
        {
            have += diff;
            pq.push(diff);
        }
        else if (a[i] < b[i])
        {
            need += diff;
            ++ctA;
        }
    }
    if (need > have)
    {
        cout << -1 << endl;
    }
    else
    {
        while (need > 0)
        {
            need -= pq.top();
            ++ctA;
            pq.pop();
        }
        cout << ctA << endl;
    }
}


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

int main() {
string s, t;
cin >> s >> t;
int ans = 0;
if(s[0] == t[0]) ans++;
if(s[1] == t[1]) ans++;
if(s[2] == t[2]) ans++;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    int q;
    cin >> n >> q;
    
    vector<vector<int>> graph(n);
    for (int i = 0; i + 1 < n; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    int rt = 0;


    vector<int> res(n, 0);
    while (q-- > 0) {
        int v, x;
        cin >> v >> x;
        --v;
        res[v] += x;
    }

    function<void(int,int)> dfs = [&](int u, int p) {
        for (auto v : graph[u]) {
            if (v == p) {
                continue;
            }
            res[v] += res[u];
            dfs(v, u);
        }
    };

    dfs(rt, -1);

    for (int i = 0; i < n; ++i) {
        cout << res[i] << (i == n - 1 ? '\n' : ' ');
    }

    return 0;
}

Measured memory_bytes: 29824
#include <stdio.h>
int Partition(int * ,int ,int );
int A[100000];
 int Partition(int *A, int p,int r){
  int x,i,h,j;
  
  x = A[r];
  i = p - 1;
  for(j = p ; j <= r - 1; j++){
    if(A[j] <= x){
      i = i + 1;
    h = A[i];
    A[i] = A[j];
    A[j] = h;
    }
  }
  h = A[i + 1];
  A[i + 1] = A[r];
  A[r] = h;
  
  return i + 1;
}
main(){
  
  int i,n,a;
  
  scanf("%d",&n);
 n=n-1;
  for(i = 0 ; i <=n ; i++ ){
    scanf("%d",&A[i]);
  }
  
   a = Partition(A,0,n);
  
  for(i = 0 ; i <=n ; i++ ){
    if(i != 0) printf(" ");
    if(i == a) printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
  
  printf("\n");
  
  return 0;
    
}

Measured memory_bytes: 992
#include <iostream>
#include <string>
#include <map>
using namespace std;
string s, t;
 
int main() {
    cin >> s >> t;
    map<char, char> m1;
    map<char, char> m2;
    if (s.size() != t.size()) {
        cout << "No"<<endl;
        return 0;
    }
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != t[i]) {
            if (m1.find(s[i]) != m1.end() && m1[s[i]] != t[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        m1[s[i]] = t[i];
    }
    for (int i = 0; i < t.size(); i++) {
        if (t[i] != s[i]) {
            if (m2.find(t[i]) != m2.end() && m2[t[i]] != s[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        m2[t[i]] = s[i];
    }
    if (m1.size() != m2.size()) {
        cout << "No" << endl;
        return 0;
    }
    map<char, char>::iterator iter = m1.begin();
    while (iter != m1.end()) {
        if (m2.find(iter->second) == m2.end() || m2[iter->second] != iter->first) {
            cout << "No" << endl;
            return 0;
        }
        iter++;
    }
    cout << "Yes" << endl;
}

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

int main(){
  int K;
  string S;
  cin>>K>>S;
  for(int i=0;i<S.size() && i<K;i++)
    cout<<S[i];
  if(S.size()>K)
    cout<<"...";
  cout<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
using namespace std;
int main(){
	long long n;
	while(true){
	cin>>n;
	if(n==0)
		break;
	int i=1;
	if(n==1)
		i=-2;
	while(true){
		if(n%2==0)
			n/=2;
		else{
			n*=3;
			n+=1;
		}
		if(n==1)
			break;
		i++;
	}
	cout<<i<<endl;
	}
    return 0;
}
 

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main (){
  string std;
  int i,r=0;
  cin>>std;
  for(i=0;i<4;i++){
    if(std[i]=='-')
      r--;
    else if(std[i]=='+')
      r++;
  }
  cout<<r;
  return 0;
}

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

int main(){
    string s,t;
    cin >> s >> t;
    vector<set<int>> sets(26);
    long long s_size = s.size();
    for(int i=0;i<s_size;i++){
        sets[s[i]-'a'].insert(i);
    }
    long long ans =0;
    long long cur = 0;
    for(int i=0;i<t.size();i++){
        auto it = sets[t[i]-'a'].lower_bound(cur);
        if(it == sets[t[i]-'a'].end()){
            ans += s_size;
            auto it2 = sets[t[i]-'a'].lower_bound(0);
            if(it2 == sets[t[i]-'a'].end()){
                cout << -1 << endl;
                return 0;
            }
            cur = *it2+1;
        }else{
            cur = *it+1;
        }

    }
    cout << ans + cur  << endl;
    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

const int OFS = 50000;
bool ab[2 * OFS], ac[2 * OFS], bc[2 * OFS];

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a, b, c;
  cin >> a >> b >> c;
  int A = a.length(), B = b.length(), C = c.length();
  auto check = [](char c1, char c2) {
    return (c1 == '?') || (c2 == '?') || (c1 == c2);
  };
  for (int i = 0; i < A; i++)
    for (int j = 0; j < B; j++)
      if (!check(a[i], b[j])) ab[i - j + OFS] = true;
  for (int i = 0; i < A; i++)
    for (int j = 0; j < C; j++)
      if (!check(a[i], c[j])) ac[i - j + OFS] = true;
  for (int i = 0; i < B; i++)
    for (int j = 0; j < C; j++)
      if (!check(b[i], c[j])) bc[i - j + OFS] = true;
  int ans = INT_MAX;
  const int M = 4010;
  for (int i = -M; i <= M; i++)
    for (int j = -M; j <= M; j++)
      if (!ab[i + OFS] && !ac[j + OFS] && !bc[j - i + OFS]) {
        int L = min({0, i, j});
        int R = max({A, i + B, j + C});
        ans = min(ans, R - L);
      }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3688
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():

    H,W = NMI()
    N = NI()
    A = NLI()
    
    ls = []
    
    
    for n in range(N):
        for _ in range(A[n]):
            ls.append(n+1)
    
    
    for h in range(H):
        if h % 2 == 0:
            print(" ".join(map(str,ls[h*W:(h+1)*W])))
        else:
            print(" ".join(map(str,list(reversed(ls[h*W:(h+1)*W])))))



if __name__ == '__main__':
    main()

Measured memory_bytes: 9792
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int N, W;
int v[100], w[100];
int dp[101][100001];

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


Measured memory_bytes: 7420
#include <iostream>

using namespace std;

int main()
{
    int n;
    
    while (cin >> n){
        int cnt = 0;
        for (int a = 0; a <= 9; a++) {
            for (int b = 0; b <= 9; b++) {
                for (int c = 0; c <= 9; c++) {
                    for (int d = 0; d <= 9; d++) {
                        if ((a + b + c + d) == n){
                            cnt ++;
                        }
                    }
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

/**
 * Created by Santa on 2016/10/16.
 */
public class Main {

    static class pair {
            public int a;
            public int b;

            pair(){
                this.a = 0;
                this.b = 0;
            }

            pair(int a, int b){
                this.a = a;
                this.b = b;
            }

            public void set(int a, int b) {
                this.a = a;
                this.b = b;
            }
        }

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

        int N = scanner.nextInt();
        long[] map = new long[5];

        for (int i = 0; i < N; i++) {
            String s = scanner.next();

            if(s.charAt(0) == 'M')map[0]++;
            if(s.charAt(0) == 'A')map[1]++;
            if(s.charAt(0) == 'R')map[2]++;
            if(s.charAt(0) == 'C')map[3]++;
            if(s.charAt(0) == 'H')map[4]++;
        }

        long ans = 0;
        for (int i = 0; i < 5; i++) {
            for (int j = i + 1; j < 5; j++) {
                for (int k = j + 1; k < 5; k++) {
                    ans += map[i] * map[j] * map[k];
                }
            }
        }

        System.out.println(ans);
    }



}




Measured memory_bytes: 45944
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <climits>
#include <queue>
#include <assert.h>
#include <set>
#include <numeric>
#include <memory.h>

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define REP(i,n) FOR(i,0,n)

//#define int long long
typedef long long ll;

const ll INF = 1e18;

using namespace std;

int bit[300000], n;

int sum(int i)
{
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x)
{
    while (i <= n) {
        bit[i] += x;
        i += i & -i;
    }
}

int N, Q;
int com, x, y;

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> N >> Q;
    n = N + 1;
    REP(i,Q) {
        cin >> com >> x >> y;
        if (com == 0) {
            add(x, y);
        } else {
            cout << sum(y) - sum(x - 1) << endl;
        }
    }
}

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

int main() {
	int N, a[1000];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a+N);

	N = a[N-1] - a[0];

	cout << N<< endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<utility>
#include<string.h>
#include<queue>
using namespace std;
typedef long long ll;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define CHMIN(a,b) (a) = min((a),(b))
#define CHMAX(a,b) (a) = max((a),(b))

int main()
{
    std::queue<pair<int,int> > que;
    int w,h;
    char ban[25][25]={};
    int dx[4]={1,0,-1,0};
    int dy[4]={0,-1,0,1};
    int ans;
    while(1==1)
    {
        ans=0;
        scanf("%d %d\n",&w,&h);
        if(w==0&&h==0)return 0;
        REP(i,25)REP(j,25)ban[i][j]='\0';
        REP(i,h)
        {
            REP(j,w)
            {
                scanf("%c",&ban[i][j]);
                if(ban[i][j]=='@')que.push(pair<int,int>(i,j));
            }
            scanf("\n");
        }
        while(!que.empty())
        {
            pair<int,int> p=que.front();
            que.pop();
            if(ban[p.first][p.second]=='.'||ban[p.first][p.second]=='@')
            {
                ban[p.first][p.second]='#';
                ans++;
                REP(i,4)
                {
                    if(ban[p.first+dy[i]][p.second+dx[i]]=='.')
                    {
                        que.push(pair<int,int>(p.first+dy[i],p.second+dx[i]));
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


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

using namespace std;

# define ll long long
# define pll pair<ll,ll>
# define F first
# define S second
# define pb push_back
# define ld long double
ll mod=1000000007;
ll func1(vector<vector<ll>>&dp,vector<vector<ll>>&v,int k,int a)
{
    if(k==0)
    {
        return v[k][a];
    }
    if(dp[k][a]!=-1)
    return dp[k][a];
    return dp[k][a]=max(func1(dp,v,k-1,(a+1)%3),func1(dp,v,k-1,(a+2)%3))+v[k][a];
}

int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t=1;
        //cin>>t;
        while(t--)
        {
            ll n,i,j,k=0;
            cin>>n;
            vector<vector<ll>>v(n,vector<ll>(3));
           for(i=0;i<n;i++)
           cin>>v[i][0]>>v[i][1]>>v[i][2];
           vector<vector<ll>>dp(n,vector<ll>(3,-1));
           cout<<max(func1(dp,v,n-1,k),max(func1(dp,v,n-1,1),func1(dp,v,n-1,2)));
           
          
            
        }
        
    }

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

int main() {
  int K;
  cin>>K;
  int r=0;
  int ans=0;
  for(long C=1;C<=100000000;C++){
    r=r*10+7;
    if(r%K==0){
      ans=C;
      break;
    }
    else{
      r=r%K;
    }
  }
  if(ans>0){
    cout<<ans<<endl;
  }
  else{
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 3600
x = int(input())
amari = x%100
tiket = x//100
ans = 0
i = 0
if amari == 0:
    ans = 1
while (tiket > 0 and i < 5):
#  print(i,amari,tiket)
  tiket -= amari//(5-i)
  amari = amari % (5-i)
  i += 1
  if (amari == 0 and tiket>=0):
    ans = 1
    break
print(ans)
  

Measured memory_bytes: 3060
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define pb push_back
#define eb emplace_back
#define mt make_tuple
#define MP make_pair
#define fs first
#define sc second
#define F first
#define S second
#define nl "\n"
#define asche cerr<<"Ekhane asche\n";
#define pf printf
#define sf scanf
#define mem(a,x) memset(a,x,sizeof(a))
#define SZ(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define one(x) __builtin_popcount(x)
#define fout(x) fixed<<setprecision(x)
#define BeatMeScanf ios_base::sync_with_stdio(false)
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); deb(_it, args); }
void deb(istream_iterator<string> it) {}
template<typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    deb(++it, args...);
}
//template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
namespace IO
{
    #define in() ( { int a ; scanf("%d",&a); a; } )
    #define LL() ( { ll a ; scanf("%lld",&a); a; } )
       #define ULL() ( { ull a ; scanf("%llu",&a); a; } )
    #define DD() ({ double a; scanf("%lf", &a); a;})
    #define CC() ( { char a ; scanf("%c",&a); a; } )
    #define pf1(a) printf("%d\n",a)
    #define pf1ll(a) printf("%lld\n",a)
}
using namespace IO;

const int mod=1e9+7;
const int N=3e5+9;
const double eps=1e-9;
const double PI=acos(-1.0);
ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}


int32_t main()
{
    int a=in(),b=in();
    if(a<=9&&b<=9) cout<<a*b<<nl;
    else cout<<-1<<nl;
    return 0;
}
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1



Measured memory_bytes: 256
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
ll dp[3001][3001][2];
ll find(vector<ll>&v,ll l,ll r,ll chance){
	if(l>r) return 0;
	ll &ans=dp[l][r][chance];
	if(ans!=-1) return ans;
	if(chance==0){
		ans=max(v[l]+find(v,l+1,r,1-chance),v[r]+find(v,l,r-1,1-chance));
	}
	else{
		ans=min(-v[l]+find(v,l+1,r,1-chance),-v[r]+find(v,l,r-1,1-chance));
	}
	return ans;
}
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		ll n;
		cin>>n;
		vector<ll>v(n);
		for(int i=0;i<n;i++){
			cin>>v[i];
		}
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				dp[i][j][0]=-1;
				dp[i][j][1]=-1;
			}
		}
		cout<<find(v,0,n-1,0)<<endl;
	}
}

Measured memory_bytes: 141184
N, M = map(int, input().split())
H = list(map(int, input().split()))

AL = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A = A-1
    B = B-1

    AL[A].append(B)
    AL[B].append(A)

ans = 0

for i in range(N):
    h = H[i]
    ahl = [H[j] for j in AL[i]]
    if ahl:
        if h > max(ahl):
            ans+=1
    else: ans+=1
    
print(ans)

Measured memory_bytes: 30044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int a,sum=0,ma=0;
	rep(i,n){
		cin >> a;
		sum+=a;
		ma=max(ma,a);
	}
	cout << sum-ma/2 << endl;
}

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

int main(){
    int N, M;
    std::cin >> N >> M;
    std::vector< int > s(M);
    std::vector< char > c(M);
    for(int i=0; i<M; i++){
        std::cin >> s[i] >> c[i];
    }
    
    int begin = 1;
    int end = 10;
    for(int i=1; i<N; i++){
        begin *= 10;
        end *= 10;
    }
    if(begin == 1){ begin = 0;}
    
    int ans = -1;
    for(int i=begin; i<end; i++){
        bool F = true;
        std::string num_str = std::to_string(i);
        for(int j=0; j<M; j++){
            if(num_str[s[j] - 1] != c[j]){
                F = false;
                break;
            }
        }
        if(F){
            ans = i;
            break;
        }
    }
    std::cout << ans << std::endl;
    

}


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

using namespace std;

typedef long long int ll;

int main() {
    int A, B, C;
    bool flag = false;
    cin >> A >> B >> C;
    
    for (ll sum = A; sum <= A * B; sum += A) {
        if ((sum % B) == C) {
            flag = true;
        }
    }

    if (flag) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}



Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
f = 1; c = 0
while f > 0:
  f = 0
  for j in range(n-1, 0, -1):
    if l[j] < l[j-1]:
      l[j], l[j-1] = l[j-1], l[j]
      f = 1; c += 1
print(*l)
print(c)


Measured memory_bytes: 5608
#include <stdio.h>
main(){
  int h,i, j, k,l;
  int c[100];
  scanf("%d", &h);
  for(i=0; i<h; i++){
    scanf("%d", &c[i]);
  }
  for(l=0;l<h;l++){
    printf("%d", c[l]);
    if(l != h-1) printf(" ");
  }
   printf("\n");

  for(i=1; i<h; i++){
     k = c[i];
     j = i - 1;
     while(j >= 0 && c[j] > k){
      c[j+1] = c[j];
      j = j - 1;
    }
     c[j+1] = k;
     for(l=0;l<h;l++){
       printf("%d", c[l]);
       if(l != h-1) printf(" ");
      }
     printf("\n");
  }
 return 0;
}

Measured memory_bytes: 604
n = int(input())
w = []
for _ in range(n):
    w.append(list(map(int,input().split())))
w.sort(key=lambda x:x[1])
now = 0
ans = "Yes"
for t in w:
    now += t[0]
    if now > t[1]:
        ans = "No"
        break
print(ans)

Measured memory_bytes: 53720
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
//max=({});

int main() {
	int a, b;
	cin >> a >> b;
	int ans = max({ a + b,a * b,a - b });
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main(){ 
  int x;
  cin >> x;
  if (x <= 599) cout << 8 << endl;
  else if (x <= 799) cout << 7 << endl;
  else if (x <= 999) cout << 6 << endl;
  else if (x <= 1199) cout << 5 << endl;
  else if (x <= 1399) cout << 4 << endl;
  else if (x <= 1599) cout << 3 << endl;
  else if (x <= 1799) cout << 2 << endl;
  else cout << 1 << endl;
  return 0;
} 

Measured memory_bytes: 3628
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
	ll n, W, w[105], v[105];
	vector<ll> ww[4];
	
	cin >> n >> W >> w[0] >> v[0];

	int w_min = w[0];
	for (ll i = 1; i < n; i++) {
		cin >> w[i] >> v[i];
	}

	for (ll i = 0; i < n; i++) {
		ww[w[i] - w_min].push_back(v[i]);
	}

	sort(ww[0].begin(), ww[0].end(), greater<ll>());
	sort(ww[1].begin(), ww[1].end(), greater<ll>());
	sort(ww[2].begin(), ww[2].end(), greater<ll>());
	sort(ww[3].begin(), ww[3].end(), greater<ll>());

	ll a = ww[0].size();
	ll b = ww[1].size();
	ll c = ww[2].size();
	ll d = ww[3].size();

	ww[0].resize(n);
	ww[1].resize(n);
	ww[2].resize(n);
	ww[3].resize(n);

	for (ll i = 1; i < n; i++) {
		ww[0][i] += ww[0][i - 1];
		ww[1][i] += ww[1][i - 1];
		ww[2][i] += ww[2][i - 1];
		ww[3][i] += ww[3][i - 1];
	}

	ll ans = 0;
	for (ll i = 0; i <= a; i++) {
		for (ll j = 0; j <= b; j++) {
			for (ll k = 0; k <= c; k++) {
				for (ll l = 0; l <= d; l++) {
					if ( w_min * i +
						(w_min + 1) * j +
						(w_min + 2) * k +
						(w_min + 3) * l <= W) {

						ll sum = 0;
						if (i > 0)sum += ww[0][i - 1];
						if (j > 0)sum += ww[1][j - 1];
						if (k > 0)sum += ww[2][k - 1];
						if (l > 0)sum += ww[3][l - 1];

						ans = max(ans, sum);
					}
				}
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)











int main(){
    ll n, k;
    cin >> n >> k;
    if(k > (n - 1) * (n - 2) / 2){
        cout << -1 << endl;
        return 0;
    }
    vector<pair<ll, ll>> ans;
    for(ll i = 1; i < n; i++){
        ans.push_back({i, n});
    }
    for(ll i = 1; i < n; i++){
        if(k < n - 1 - i){
            ll cnt = 0, p = i + 1;
            while(k < n - 1 - i - cnt){
                cnt++;
                ans.push_back({i, p});
                p++;
            }
            k = 0;
        }
        else{
            k -= n - 1 - i;
        }
    }
    cout << ans.size() << endl;
    REP(i, ans.size()){
        cout << ans[i].first << " " << ans[i].second << endl;
    }
}

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

init_x, init_y, init_t = 0, 0, 0
for i in range(N):
    t, x, y = map(int, input().split())
    diff_t = t - init_t
    dist = x - init_x + y - init_y
    if (diff_t >= dist) and ((diff_t % 2 == 0 and dist % 2 == 0) or (diff_t % 2 != 0 and dist % 2 != 0)):
        init_x, init_y, init_t = t, x, y
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 3064
N = int(input())
c = [0] * 4
for i in range(N):
    X = input()
    if X == "AC":
        c[0] += 1
    elif X == "WA":
        c[1] += 1
    elif X == "TLE":
        c[2] += 1
    else:
        c[3] += 1
print("""AC x {}
WA x {}
TLE x {}
RE x {}
""".format(c[0],c[1],c[2],c[3]))

Measured memory_bytes: 9204
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include <sstream>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include <iomanip>
using namespace std;

int main(void){
    int A,B;
    cin >> A >> B;
    cout << A * B << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, A;
  cin >> N >> A;
  vector<int>X(N);
  for (int i = 0; i < N; i ++) {
    cin >> X[i];
    X[i] -= A;
  }
  vector<int>pl;
  vector<int>mn;
  long long zr = 1;
  for (int i = 0; i < N; i ++) {
    if (!(X[i])) zr *= 2;
    if (X[i] > 0) pl.push_back(X[i]);
    if (X[i] < 0) mn.push_back(-X[i]);
  }
  vector<long long>dp(2505, 0);
  vector<long long>dp_(2505, 0);
  dp[0] = 1;
  dp_[0] = 1;
  int si = (int)pl.size();
  int si_ = (int)mn.size();
  for (int i = 0; i < si; i ++) {
    for (int j = 2504; j >= pl[i]; j --) {
      dp[j] += dp[j - pl[i]];
    }
  }
  for (int i = 0; i < si_; i ++) {
    for (int j = 2504; j >= mn[i]; j --) {
      dp_[j] += dp_[j - mn[i]];
    }
  }
  long long ans = 0;
  for (int i = 0; i < 2505; i ++) {
    ans += dp[i] * dp_[i];
  }
  cout << ans * zr - 1 << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=5005;
typedef long long ll;
const ll ms=1e9+7;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct Edg{
	int nxt,poi;
}e[N<<1];
int first[N],l=0,size[N];
ll f[N][N],tmp[N],g[N];
void addedge(int u,int v){
	l++;
	e[l].nxt=first[u];
	e[l].poi=v;
	first[u]=l;
}
void dfs(int u,int fa){
	size[u]=1; f[u][1]=1;
	for (int p=first[u];p;p=e[p].nxt){
		int v=e[p].poi;
		if (v==fa) continue;
		dfs(v,u);
		for (int i=1;i<=size[u]+size[v];i++) tmp[i]=0;
		for (int i=1;i<=size[u];i++)
		for (int j=0;j<=size[v];j++)
		tmp[i+j]=(tmp[i+j]+f[u][i]*f[v][j]%ms)%ms;
		for (int i=1;i<=size[u]+size[v];i++) f[u][i]=tmp[i];
		size[u]+=size[v];
	}
	for (int i=2;i<=size[u];i+=2)
	f[u][0]=(f[u][0]+ms-f[u][i]*g[i]%ms)%ms;
}
int main(){
	int n=read();
	for (int i=1;i<n;i++){
		int u=read(),v=read();
		addedge(u,v); addedge(v,u);
	}
	g[0]=1;
	for (int i=2;i<=n;i+=2)
	g[i]=g[i-2]*(i-1)%ms;
	dfs(1,1);
	ll ans=(ms-f[1][0])%ms;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 194944