akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin>>a>>b;
    if(a%3==0||b%3==0||(a+b)%3==0){
        cout1("Possible")
    }else{
        cout1("Impossible")
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String text = sc.next();
		String[] texts = text.split("");
		int count = 0;
		for (String s : texts) {
			if(s.equals("1")) {
				count++;
			}
		}
		System.out.println(count);
		sc.close();
	}

}

Measured memory_bytes: 23380
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <stack>

using namespace std;
string S,part;
string T;

bool check(string sub){
  for(int i=0;i<sub.length();++i){
    if(sub[i] != T[i] && sub[i] != '?'){
      return false;
    }
  }
  return true;
}

int main(){
  vector<int> v;
  int Snum,Tnum,count;
  cin >> S >> T;

  if(S.length() < T.length()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  count = 0;
  Snum = S.length();
  Tnum = T.length();
  for(int i=0;i<Snum-Tnum+1;++i){
    part = S.substr(Snum-Tnum-i,Tnum);
    if(check(part)){
      for(int j=0;j<Tnum;++j){
        S[Snum-Tnum-i+j] = T[j];
      }
      for(int j=0;j<Snum;++j){
        if(S[j] == '?'){
          S[j] = 'a';
        }
      }
      cout << S << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}


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

ll culc(ll x, int i){
    x++;
    ll div = x / ((ll)1 << i);
    ll rem = x % ((ll)1 << i);
    ll res = (div / 2) * ((ll)1 << i);
    if(div % 2) res += rem;
    return res;
}

int main(){
    cin >> A >> B;
    A--;
    for(int i = 0; i < 40; i++){
        ll d1 = culc(A, i);
        ll d2 = culc(B, i);
        if((d1 - d2) % 2) ans += (ll)1 << i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static Node nil = new Node();

	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
			int n = Integer.parseInt(br.readLine());
			Main main = new Main();
			for (int i = 0; i < n; i++) {
				String[] tmpStr = br.readLine().split(" ");

				switch (tmpStr[0]) {
				case "insert":
					main.insert(Integer.parseInt(tmpStr[1]));
					break;

				case "delete":
					main.deleteKey(Integer.parseInt(tmpStr[1]));
					break;

				case "deleteFirst":
					main.deleteFirst();
					break;

				case "deleteLast":
					main.deleteLast();
					break;

				}
			}

			// 連結リストの中身の値を先頭からすべて表示
			Node cur = nil.next;
			while (cur != nil) {
				if (cur == nil.prev) {// 末尾のノードの場合
					System.out.println(cur.key);
				} else {
					System.out.print(cur.key + " ");
				}
				cur = cur.next;
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	void insert(int key) {
		Node x = new Node(key);
		x.next = nil.next;
		nil.next.prev = x;
		nil.next = x;
		x.prev = nil;

	}

	// 特定のキーを持つノードを検索して返す
	Node listSearch(int key) {
		Node cur = nil.next;
		while (cur != nil && cur.key != key) {
			cur = cur.next;
		}
		return cur.key == key ? cur : null;
	}

	// キーを削除する処理
	void deleteNode(Node t) {
		// listSearch で null が帰ってきたときにヌルポになってしまう
		// if (t == nil) {
		if (t == nil || t == null)
			return;
		t.prev.next = t.next;
		t.next.prev = t.prev;
		t = null;
	}

	// 先頭のノードを削除する
	void deleteFirst() {
		deleteNode(nil.next);
		// deleteNodeの方でnilが渡された場合の対処済み
		// if (nil.next != nil) {
		// deleteNode(nil.next);
		// }
	}

	// 末尾のノードを削除する
	void deleteLast() {
		deleteNode(nil.prev);
	}

	// 特定のキーを持つノードを削除する
	void deleteKey(int key) {
		deleteNode(listSearch(key));

	}

}

class Node {
	int key;
	Node prev, next;

	// 番兵(nil)用
	public Node() {
		prev = this;
		next = this;
	}

	public Node(int key) {
		this.key = key;

	}

}


Measured memory_bytes: 189216
#include<bits/stdc++.h>
	using namespace std;
	#define int long long int
	#define pb push_back
	const int mod=1e9+7;
	#define all(x) x.begin(),x.end()
	#define endl '\n'
	#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

	
	int32_t main(){
		IOS;
		int n;
		cin>>n;
		int arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i];
		}
		int sum=arr[0];
		int ans=0;
		
		for(int i=1;i<n;i++){
			ans=(ans+(sum*arr[i])%mod)%mod;
			sum=(sum+arr[i])%mod;
		}
		cout<<ans<<endl;
		return 0;
	}


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

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

	long long int n,m;
	long long int a,b;
	vector <pair<long long int,long long int>> s;
	long long int res = 0;

	cin >> n >> m;

	for(int i=0;i<n;i++)
	{
		cin >> a >> b;
		s.push_back(make_pair(a,b));
	}

	sort(s.begin(),s.end());

	for(int i=0;i<n;i++)
	{
		if(m==0)
		{
			break;
		}
		long long int can = min(s[i].second,m);
		res += (can*s[i].first);
		m -= can;
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 2420
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<vi> vvi;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    fastIO;
    int N;
    cin >> N;
    vi a(N);
    for (auto& i : a)    cin >> i;
    sort(a.begin(), a.end(), greater<ll>());
    ll ans = 0;
    for (int i = 1; i < N; ++i) {
        ans += a[i / 2];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N), x(N);
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    int s_x = 0;
    for (int i = 0; i < N - 2; i += 2)
    {
        s_x += 2 * A[i];
    }
    x[N - 1] = sum - s_x;
    x[0] = 2 * A[N - 1] - x[N - 1];
    for (int i = 0; i < N - 1; i++)
    {
        x[i + 1] = 2 * A[i] - x[i];
    }
    for (int i = 0; i < N; i++)
    {
        cout << x[i] << " ";
    }
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<chrono>
using namespace std;
using namespace std::chrono;
using namespace __gnu_pbds; 
#define lli long long int
#define fr(i,a,b) for(lli i=a;i<b;i++)
#define bfr(i,a,b) for(lli i=a;i>=b;i--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
#define tc int t;cin>>t;while(t--)
#define mod 1000000007LL
#define mod2 998244353LL
#define all(vec) vec.begin(),vec.end()  
#define ld long double
#define pb push_back
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> 

int main()
{
              
     fio

          
     lli x,n,var;
     cin>>x>>n;
     set<lli> a;
     fr(i,0,n){cin>>var;a.insert(var);}
     a.insert(10000000);

     fr(i,0,100)
     {
     	 if(a.find(x-i)==a.end()){cout<<x-i;return 0;}
     	 if(a.find(x+i)==a.end()){cout<<x+i;return 0;}


     }


              


return 0;}    


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


int main(int argc, char *argv[]){
  int n;
  cin >> n;
  for (int r = 0; r < n; r++) {

    string x, y;
    cin >> x >> y;
    int dp[y.length() + 1][x.length() + 1];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < y.length(); i++) {
      for (int j = 0; j < x.length(); j++) {
        if(y[i] == x[j]){
          dp[i + 1][j + 1] = dp[i][j] + 1;
        }else{
          dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
        }
      }
    }
    std::cout << dp[y.length()][x.length()] << std::endl;
  }
  return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;
const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmax(const T &a, T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(const T &a, T b){if(a > b){a=b; return true;} return false;}

int main(){
    ll X, K, D;
    cin >> X >> K >> D;
    ll a1, a2;
    ll ans;
    if(X > 0){
        a1=X-X/D*D;
        a2=a1-D;
        if(K < X/D) ans=X-K*D;
        else{
            if(K%2 == X/D%2) ans=a1;
            else ans=-a2;
        }
        cout << ans << endl;
    }
    else{
        a1=X-X/D*D;
        a2=a1+D;
        if(K < -X/D) ans=llabs(X+K*D);
        else{
            if(K%2 == -X/D%2) ans=-a1;
            else ans=a2;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>

int sosu[10000] = {0};
//int factors[31] = {0};

int getSosuu(int N) {
	int i,j;
	int count_prime = 1;
	int flag;

	sosu[0] = 2;
	for (i = 2; i<=N;++i) {
		flag = 0;
		for ( j = 0; sosu[j] != 0; ++j) {
			if (i%sosu[j] == 0) {
				flag = 1;
				break;
			}
		}

		if (flag == 0) {
			sosu[count_prime] = i;
			count_prime++;
		}
	}
	return 0;
}

int add(int factor, int factors[]) {
	int i;
	for (i = 0; i < 31; ++i) {
		if (factors[i] == 0) {
			factors[i] = factor;
			break;
		}
	}
	return 0;
}

int factor(int N, int factors[]) {
	int i;
	for (i = 0; sosu[i] != 0; ++i) {
		if (N % sosu[i] == 0) {
			add(sosu[i], factors);
			factor(N / sosu[i], factors);
			break;
		}
	}
	return 0;
}

int main()
{
	int n;
	int i;
//	int n_root;
	int factors[31] = {0};
	getSosuu(100000);
	scanf("%d", &n);
//	n_root = (int)sqrt((double)n);
	factor(n, factors);
	printf("%d:", n);
	for (i = 0; factors[i] != 0; ++i) {
		printf(" %d", factors[i]);
	}

	if (factors[0] == 0) {
		printf(" %d", n);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 636
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

typedef complex<double> P;
typedef vector<P> Poly;
const double PI = acos(-1.0);
#define EPS  1e-8

inline int signum(double x) { return abs(x) < EPS ? 0 : x > 0 ? 1 : -1; }

namespace std {
    template<class T>
    bool operator<(const complex<T> &a, const complex<T> &b) {
        return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
    }
}

double dot(P a, P b) {
    return a.real() * b.real() + a.imag() * b.imag();
}

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

int ccw(P a, P b, P c) {
    b -= a;
    c -= a;
    int sign = signum(cross(b, c));
    if (sign != 0) return sign;
    if (signum(dot(b, c)) < 0) return -2;
    if (abs(b) < abs(c)) return 2;
    return 0;
}

Poly convex_hull(Poly poly) {
    vector<P> g;
    int n = poly.size();

    if (n < 3) return poly;

    int m;
    sort(poly.begin(), poly.end());

    for (int i = 0; i < poly.size(); i++) {
        while ((m = g.size()) >= 2 && ccw(g[m - 2], g[m - 1], poly[i]) <= 0) g.pop_back();
        g.push_back(poly[i]);
    }

    int t = g.size();

    for (int i = n - 2; i >= 0; i--) {
        while ((m = g.size()) > t && ccw(g[m - 2], g[m - 1], poly[i]) <= 0) g.pop_back();
        g.push_back(poly[i]);
    }
    g.pop_back();
    return g;
}

int main() {

    int N;
    cin >> N;

    Poly poly(N);
    for (int i = 0; i < N; i++) {
        double x, y;
        cin >> x >> y;
        poly[i] = P(x, y);
    }

    auto res = convex_hull(poly);

    cout << res.size() << endl;

    int s = 0;
    for (int i = 1; i < res.size(); i++) {
        if ((res[i].imag() < res[s].imag()) ||
            (res[i].imag() == res[s].imag() && res[i].real() < res[s].real())) {
            s = i;
        }
    }

    for (int i = 0; i < res.size(); i++) {
        cout << (int) res[(s + i) % res.size()].real() << " " <<  (int) res[(s + i) % res.size()].imag()<< endl;
    }

}














































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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;

const int maxn = 300 + 10, INF = 0x3f3f3f3f , MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

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


void init() {

}

char mp[maxn][maxn];
int n;

int f(int x) {
    return x % n;
}

bool check(int x,int y) {
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (mp[f(i + x)][f(j + y)] != mp[f(j + x)][f(i + y)]) return false;
        }
    }
    return true;
}


int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    init();
    cin>>n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) cin>>mp[i][j];
    }
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        if (check(i,0)) cnt += n;
    }
    cout<<cnt<<endl;
    return 0;
}


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

using namespace std;

int main(){
  int x = 0;
  int y = 0;
  char S[3];
  cin >> S;
  int i;
  for(i=0;i<=2;i++){
    if(S[i]=='A') x = 1;
    if(S[i]=='B') y = 1;
    }
  if(x * y == 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> numberList = new ArrayList<>();
		for(int i=0;i<n;i++) {
			numberList.add(Integer.parseInt(sc.next()));
		}
		sc.close();
		List<Integer> sortList =  new ArrayList<>(numberList);
		Collections.sort(sortList);
		int onesmall=sortList.get(n/2 - 1);
		int center=sortList.get(n/2);
		for(int i=0;i<n;i++) {
			if(numberList.get(i)<=onesmall) {
				System.out.println(center);
			} else {
				System.out.println(onesmall);
			}
		}
	}
}

Measured memory_bytes: 72188
import sys
import io, os
#input = sys.stdin.buffer.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n,k = map(int, input().split())
A = [int(input()) for _ in range(n)]

class SegTree:
    def __init__(self, init_val, ide_ele, segfunc):
        self.n = len(init_val)
        self.num = 2**(self.n-1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.seg = [ide_ele]*2*self.num
        # set_val
        for i in range(self.n):
            self.seg[i+self.num] = init_val[i]
        # built
        for i in range(self.num-1, 0, -1):
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])

    def update(self, k, x):
        k += self.num
        self.seg[k] = x
        while k:
            k = k >> 1
            self.seg[k] = self.segfunc(self.seg[2*k], self.seg[2*k+1])

    def query(self, l, r):
        if r <= l:
            return self.ide_ele
        l += self.num
        r += self.num
        res = self.ide_ele
        while l < r:
            if r & 1:
                r -= 1
                res = self.segfunc(res, self.seg[r])
            if l & 1:
                res = self.segfunc(res, self.seg[l])
                l += 1
            l = l >> 1
            r = r >> 1
        return res

def segfunc(x, y):
    if x >= y:
        return x
    else:
        return y

maxa = 300005
#INF = 10**18
seg = SegTree([0]*maxa, 0, segfunc)

for a in A:
    l = max(0, a-k)
    r = min(a+k, maxa-1)
    t = seg.query(l, r+1)
    seg.update(a, t+1)
ans = seg.query(0, seg.n)
print(ans)


Measured memory_bytes: 109324
#include<stdio.h>
#include<stdlib.h>

struct pair {
    long x;
    long n;
};

int cmp(const void *a,const void *b)
{
  // return *(int*)a-*(int*)b;
   return (*(struct pair*)a).x - (*(struct pair*)b).x;
}



int main(void)
{
  // int n, k, a[2][100000], i;
   int n, i;
   long k;
   struct pair a[100000];

   scanf("%d%ld",&n,&k);
   for(i=0;i<n;i++)
//      scanf("%d%d",&a[0][i],&a[1][i]);
      scanf("%ld%ld",&a[i].x,&a[i].n);

   qsort(a  ,n,sizeof(struct pair),cmp);

   for(i=0;i<n;i++){
      k-=a[i].n;
      if(k<=0){
         printf("%ld\n",a[i].x);
         return 0;
      }
   }
}


Measured memory_bytes: 4668
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
	int a[11];
	rep(i, 0, 10) cin >> a[i];
	sort(a, a + 10);
	repb(i, 9, 7){
		cout << a[i] << endl;
	}
}

Measured memory_bytes: 3112
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.


int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int64 n;
    pll ab[200200];
    scanf("%lld", &n);
    rep(i, n) scanf("%lld %lld", &ab[i].first, &ab[i].second);

    // b 降順
    sort(begin(ab), begin(ab) + n, [](pll a, pll b) {return a.second > b.second;});

    int64 t = INF64;
    rep(i, n) {
        if (t > ab[i].second) t = ab[i].second;
        t -= ab[i].first;
    }

    print(t >= 0 ? "Yes" : "No");

    return 0;
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, d[500000];
pair<int, ll>MAX;
ll a, b, s[500001], c[500000], ans;
vector<lP>v;

int main() {
	cin >> N;
	for (int i = 0; i != N; ++i) {
		cin >> a >> b;
		v.push_back(mkp(a, b));
	}
	sort(v.begin(), v.end());
	for (int i = 0; i != N; ++i) {
		s[i + 1] = v[i].second + s[i];
	}
	for (int i = 0; i != N; ++i) {
		c[i] = s[i + 1] - v[i].first;
	}
	MAX.second = ans = -llmax;
	for (int i = N - 1; i != -1; --i) {
		if (MAX.second < c[i])
			MAX = mkp(i, c[i]);
		d[i] = MAX.first;
	}
	for (int i = 0; i != N; ++i) {
		ans = max(ans, s[d[i] + 1] - s[i] + v[i].first - v[d[i]].first);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 20648
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int count = 0;
		for(int i = 0;i < 3;i++) {
		    if(s[i] - '0' == 1) count++; 
		}

		System.out.println(count);
    }

}

Measured memory_bytes: 23380
#include <iostream>
 
using namespace std;
 
bool isLeap(int y){
    if(y % 400 == 0) return true;
    if(y % 100 == 0) return false;
    if(y % 4 == 0) return true;
    return false;
}
 
int main(){
    int a, b;
    bool f = false;
    while(true){
        cin >> a >> b ;
        if(a == 0 && b == 0) return 0;
 
        if(f) { cout << endl; }
        f = false;
        for (int i = a; i < b + 1; i++){
            if(isLeap(i)) {
                cout << i << endl;
                f = true;
            }
        }
        if(!f) { cout << "NA" << endl; f = true;}
    }
    return 0;
}

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

using namespace std;

int main()
{
    int n;
    string s;

    cin>>n>>s;

    if(n%2)
    {
        cout<<"No";
        exit(0);
    }
    else
    {
        int i;
        for(i=n/2;i!=s.size();i++)
        {
            if(s[i-n/2] != s[i])
            {
                cout<<"No";
                exit(0);
            }
        }

        cout<<"Yes";
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#define DIM 100005
#define mod 1000000007
using namespace std;
int n, i, j, x, sol, ok;
char s[DIM];
int sum[DIM], nxt[DIM][3], d[DIM];
int main(){
    cin>> s + 1;
    n = strlen(s + 1);
    nxt[n][0] = nxt[n][1] = nxt[n][2] = -1;
    for(i = 1; i <= n; i++){
        sum[i] = (sum[i - 1] + s[i] - 'a' + 1) % 3;
        if(s[i] == s[i - 1]){
            ok = 1;
        }
    }
    for(i = n - 1; i >= 0; i--){
        nxt[i][0] = nxt[i + 1][0];
        nxt[i][1] = nxt[i + 1][1];
        nxt[i][2] = nxt[i + 1][2];
        nxt[i][ sum[i + 1] ] = i + 1;
    }
    if(ok == 0){
        cout<< 1;
        return 0;
    }
    d[0] = 1;
    for(i = 0; i <= n; i++){
        for(j = 1; j <= 2; j++){
            x = (sum[i] + j) % 3;
            if(nxt[i][x] != -1){
                d[ nxt[i][x] ] = (d[i] + d[ nxt[i][x] ]) % mod;
            }
        }
        if(sum[i] == sum[n] && i != 0){
            sol = (sol + d[i]) % mod;
        }
    }
    cout<< sol;
}


Measured memory_bytes: 2304
Q, H, S, D = map(int, input().split())
N = int(input())
liter_1 = min(4*Q, 2*H, S)
liter_2 = min(2*liter_1, D)
q, r = divmod(N, 2)
ans = q * liter_2 + r * liter_1
print(ans)

Measured memory_bytes: 3060
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::marker::Usize1;
use proconio::{fastout, input};
//use proconio::marker::Chars;
//use std::collections::HashSet;
// use std::cmp::*;
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
    N:usize,
    M:usize,
    AB:[(Usize1,Usize1);M]
    }
    // 部屋iから繋がっている部屋のリスト
    let mut tonari: Vec<Vec<usize>> = vec![Vec::with_capacity(M); N];
    let mut ans: Vec<usize> = vec![N; N];
    for (a, b) in AB {
        tonari[a].push(b);
        tonari[b].push(a);
    }
    //    for i in 0..N {
    //        println!("{}={:?}", i, tonari[i]);
    //    }
    let mut nexts: VecDeque<usize> = VecDeque::new();
    nexts.push_back(0);
    while let Some(i) = nexts.pop_front() {
        //        println!("{}={:?}", i, tonari[i]);
        for &j in tonari[i].iter() {
            if ans[j] == N {
                ans[j] = i;
                nexts.push_back(j);
            }
        }
    }
    println!("Yes");
    for &j in ans.iter().skip(1) {
        println!("{}", j + 1);
    }
}


Measured memory_bytes: 16840
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
using namespace std;
ll L = 1000000007;

#define MAX 100000

int N;
int A[MAX];

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

	long long h = 0, v = 0;
	sort(A, A + N);
	for (int i = N - 1; i >= 0; i--) {
		if (h == 0) {
			if (A[i] == A[i - 1]) {
				h = A[i];
				i--;
			}
		}
		else if (v == 0) {
			if (A[i] == A[i - 1]) {
				v = A[i];
				break;
			}
		}
	}
	long long ans = h * v;

	cout << ans << endl;

	return 0;
}

int dsum(ll a) {
	int ans = 0;
	while (a != 0) {
		ans += a % 10;
		a /= 10;
	}
	return ans;
}


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

#define REP(i,a) for(long i=0;i<(a);++i)

typedef std::vector<int>  VI;

int N;
VI imos(100002, 0);
int main() {
    std::cin >> N;

    REP(i, N) {
        int a, b;
        std::cin >> a >> b;
        ++imos[a];
        --imos[b+1];
    }

    int x = 0, ans = 0;
    for(int i=0; i<=N+1; ++i) {
        x += imos[i];
        if(x + 1 >= i) {
            ans = i - 1;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3096
A = list(input() + 'A')
B = list(input() + 'B')
C = list(input() + 'C')

player = A
while True:
    if len(player) == 1:
        print(*player)
        break

    if player == A:
        card = A.pop(0)
    elif player == B:
        card = B.pop(0)
    else:
        card = C.pop(0)

    if card == 'a':
        player = A
    elif card == 'b':
        player = B
    else:
        player = C


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <array>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <utility>
#include <iomanip>
#include <numeric>
#include <climits>
#include <algorithm>
#include <cstdint>
using namespace std;

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

    vector<int> niz(n);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> niz[i];
        sum += niz[i];
    }
    int max = *max_element(niz.begin(), niz.end());
    sum -= max;
    if (max < sum)
        cout << "Yes";
    else cout << "No";
}

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

#define SIZE 50001

int main() {
	bool prime[SIZE];
	fill(prime, prime + SIZE, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i * i < SIZE; i++) {
		for (int j = 2; j * i < SIZE; j++) {
			if (!prime[i * j]) continue;
			prime[i * j] = false;
		}
	}

	int n, count;
	while (cin >> n) {
		if (n == 0) break;

		count = 0;
		for (int i = 0; i <= n / 2; i++) {
			if (prime[i] && prime[n - i]) count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back
// const ll mod = 1000000007;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void sayNo() {
	cout << "No" << endl;
}

void sayYes() {
	cout << "Yes" << endl;
}

vector< ll > divisor(ll n) {
	vector< ll > ret;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	// sort(begin(ret), end(ret));
	return (ret);
}


int main() {
	ll N, K;
	cin >> N >> K;

	// N = 2 * 10e5;
	// K = 10e12;

	vi A(N, 0);

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

		// A[i] = i + 1;
	}

	unordered_map<ll, ll> map;

	ll lgNK = floor(log2(N) + log2(K));
	vector<vector<ll>> G(lgNK + 1, vector<ll>(N, 0));

	for (ll i = 0; i < 2 * N; i++) {
		ll a = A[i % N];
		if (map[a] == 0) {
			map[a] = i + 1;
		}
		else {
			if (map[a] - 1 < N) {
				G[0][map[a] - 1] = i - (map[a] - 1) + 1;
				map[a] = i + 1;
			}
		}
	}

	/*
	for (auto g : G[0]) {
		cout << g << " ";
	}
	cout << endl;
	// */

	ll inf = LLMAX / 3;

	// cout << lgNK << endl;
	for (ll k = 0; k < lgNK; k++) {
		// cout << k << endl;
		for (ll i = 0; i < N; i++) {
			ll y = i + G[k][i];
			ll ny = min(inf, G[k][y % N] + y - i);
			G[k + 1][i] = ny;
		}
	}

	ll pos = 0;
	// cout << "pos: 0" << endl;
	for (ll k = lgNK; k >= 0; k--) {
		ll newPos = pos + G[k][pos % N];
		if (newPos < N * K) {
			pos = newPos;
			// cout << " -> " << pos << " (+" << G[k][pos % N] << ")" << endl;
		}
		else {
			// cout << " ---------------------- " << endl;
		}
	}
	// cout << endl;


	vi s;
	for (ll i = pos % N; i < N;) {
		// cout << i << ", " << G[0][i] << ", " << A[i] << endl;
		if (i + G[0][i] > N) {
			s.push_back(A[i]);
			i++;
			continue;
		}
		i = i + G[0][i];
	}

	for (auto a : s) {
		cout << a << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 104932
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int64_t lcm (int64_t a, int64_t b) {
    int64_t c = a, d = b;
    if (c < d) swap(c, d);
    int64_t r = c % d;
    while (r > 0) {
        c = d;
        d = r;
        r = c % d;
    }
    return a / d * b;
}

int64_t n_divided(int64_t a, int64_t b, int64_t c) {
    if (a % c == 0) return b / c - a / c + 1;
    else return b / c - a / c;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int64_t a, b, c, d; cin >> a >> b >> c >> d;
    
    int64_t e = lcm(c, d);
    
    cout << b - a + 1 - n_divided(a, b, c) - n_divided(a, b, d) + n_divided(a, b, e) << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var A, B, C int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d", &A, &B, &C)

	var K int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &K)

	arr := make([]int, 3)
	arr[0] = A
	arr[1] = B
	arr[2] = C

	sort.Sort(sort.Reverse(sort.IntSlice(arr)))
	for K > 0 {
		arr[0] = arr[0] * 2
		K--
	}
	ans := 0
	for _, a := range arr {
		ans = ans + a
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;
 
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
 
    int n, q;
    cin >> n >> q;
    vector<list<string> > v(n+1);
    for(int i=1; i<=n; ++i){
        string s;
        cin >> s;
        for(unsigned j=0; j<s.size(); j+=1000)
            v[i].push_back(s.substr(j, 1000));
    }
 
    while(--q >= 0){
        int type;
        cin >> type;
 
        if(type == 1){
            int a, b, c, d;
            cin >> a >> b >> c >> d;
 
            auto it1 = v[a].begin();
            auto it2 = v[c].begin();
            while((int)it1->size() < b){
                b -= it1->size();
                ++ it1;
            }
            while((int)it2->size() < d){
                d -= it2->size();
                ++ it2;
            }
 
            string s = it2->substr(0, d-1) + it1->substr(b-1);
            string t = it1->substr(0, b-1) + it2->substr(d-1);
            *it1 = s;
            *it2 = t;
 
            list<string> x, y;
            x.splice(x.end(), v[a], v[a].begin(), it1);
            y.splice(y.end(), v[c], v[c].begin(), it2);
            x.splice(x.end(), v[c], v[c].begin(), v[c].end());
            y.splice(y.end(), v[a], v[a].begin(), v[a].end());
            v[a].swap(x);
            v[c].swap(y);
        }
        else{
            int a, b;
            char c;
            cin >> a >> b >> c;
 
            auto it = v[a].begin();
            while((int)it->size() < b){
                b -= it->size();
                ++ it;
            }
            (*it)[b-1] = c;
        }
    }
 
    for(int i=1; i<=n; ++i){
        for(const string& s : v[i])
            cout << s;
        cout << endl;
    }
 
    return 0;
}

Measured memory_bytes: 6372
#include<iostream>
#include<set>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<stdlib.h>
#include<stdio.h>
#include<queue>
#include<stack>
#include<string.h>
#include<limits.h>
using namespace std;
typedef unsigned long long ull;

string str;
set<string>se;

int solve(string s){
    if(s.length()>str.length()){
        return 9999999;
    }
    if(se.count(s)){
        return 9999999;
    }
    se.insert(s);
    bool b=true;
    char c=s[0];
    for(int i=1;i<s.length();i++){
        if(s[i]!=c){
            b=false;
            break;
        }
    }
    if(b){
        return 0;
    }
    int mi=9999999;
    string ns='B'+s;
    
    while(ns.length()&&ns[0]=='B'){
        ns=ns.substr(1);
    }
    mi=min(mi,solve(ns));
    ns='W'+s;
    while(ns.length()&&ns[0]=='W'){
        ns=ns.substr(1);
    }
    mi=min(mi,solve(ns));
    ns=s+'B';
    while(ns.length()&&ns[ns.length()-1]=='B'){
        ns=ns.substr(0,ns.length()-1);
    }
    mi=min(mi,solve(ns));
    ns=s+'W';
    while(ns.length()&&ns[ns.length()-1]=='W'){
        ns=ns.substr(0,ns.length()-1);
    }
    mi=min(mi,solve(ns));
    return 1+mi;
}
bool dfs(){
    
    return false;
}
int main(){
    
    cin>>str;
    int ans=0;
    char last=str[0];
    int a1=0,a2=0;
    for(int i=1;i<str.length();i++){
        if(str[i]!=last){
            last=str[i];
            a1++;
        }
    }
    last=str[str.length()-1];
    for(int i=str.length()-2;i>=0;i--){
        if(str[i]!=last){
            last=str[i];
            a2++;
        }
    }
    cout<<min(a1,a2)<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N = 1003;
char ch[1003][1003];
int dp[N][N];
const int MOD = 1e9 + 7;

int recur(int r, int c, int n, int m)
{
    if(ch[r][c] == '#')
        return 0;
    
    if(r >= n || c >= m)
        return 0;

    if(r == n - 1 && c == m - 1)
        return 1;

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

    int ans = 0;

    ans = (ans + recur(r, c + 1, n, m)) % MOD;
    ans = (ans + recur(r + 1, c, n, m) ) % MOD;

    return dp[r][c] = ans % MOD;
}

int32_t main()
{
    int n, m;
    cin >> n >> m;

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

    memset(dp, -1, sizeof(dp));
    cout << recur(0, 0, n, m) % MOD << "\n";
}

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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    ll n,i=1,sum=0;
    cin>>n;
    while(sum<n){
        sum+=i;
        i++;
    }
    cout <<i-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;

int main(void){
    ll x,y;
    cin>>x>>y;
    ll ans=1;
    for(ll i=0;1;i++){
        if(x>y/2) break;
        x*=2;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#coding utf-8
N,M=map(int,input().split())
a =[int(input()) for i in range(M)]
a.append(0)
mod =10**9+7
dp = [1]
j = 0
for i in range(1,N+1):
  if i != a[j]:
    if i ==1:
      dp.append(dp[-1])
    else:
      dp.append((dp[-1]+dp[-2])%mod)
  else:
    dp.append(0)
    j +=1 

print(dp[-1])

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

int main() 
{
    int r, D, x;
    cin >> r >> D >> x;

    int X[11];
    X[0] = x;

    for(int i=1; i<=10; i++) {
        X[i] = r*X[i-1] - D;
    }

    for(int j=1; j<=10; j++) {
        cout << X[j] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

struct dsu {
    vector<int> p;
    vector<int> sz;
    int n;

    dsu(int _n) : n(_n) {
        p.resize(n);
        iota(p.begin(), p.end(), 0);
        sz.assign(n, 1);
    }

    inline int get(int x) {
        if (p[x] == x) {
            return x;
        } else {
            return p[x] = get(p[x]);
        }
    }
    inline bool unite(int x, int y) {
        x = get(x);
        y = get(y);
        if (x == y) {
            return false;
        }
        if (sz[x] < sz[y]) {
            swap(x, y);
        }
        p[x] = y;
        sz[y] += sz[x];
        return true;
    }
    inline bool same(int x, int y) {
        return (get(x) == get(y));
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    dsu uf(2 * n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        uf.unite(x, n + y);
        uf.unite(y, n + x);
    }
    int b = 0;
    for (int i = 0; i < 2 * n; i++) {
        if (uf.get(i) == i) {
            b++;
        }
    }
    if (b == 1) {
        ll ans = 1LL * n * (n - 1) / 2;
        ans -= m;
        cout << ans << '\n';
    } else if (b == 2) {
        vector<ll> t(2 * n);
        for (int i = 0; i < n; i++) {
            t[uf.get(i)]++;
        }
        sort(t.rbegin(), t.rend());
        ll ans = t[0] * t[1] - m;
        cout << ans << '\n';
    } else {
        assert(false);
    }
    return 0;
}

Measured memory_bytes: 6376
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n,m;
  cin>>n>>m;
  int p[n];
  REP(i,n){
    cin>>p[i];
    p[i]--;
  }
  UnionFind uni(n);
  int x,y;
  REP(i,m){
    cin>>x>>y;
    x--;y--;
    uni.connect(x,y);
  }
  int ans=0;
  REP(i,n){
    if(uni.root(i)==uni.root(p[i])){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>

using namespace std;

int n;
int array[100000];

int partition(int a[], int p, int r);

int main(){
    cin>>n;
    for (int i=0; i<n; i++) {
        cin>>array[i];
    }
    int pivot = partition(array, 0, n-1);
    if (pivot == n-1) {
        for (int i=0; i<n-1; i++) {
            cout<<array[i]<<" ";
        }
        cout<<"["<<array[n-1]<<"]"<<endl;
    }
    else{
        for (int i=0; i<n-1; i++) {
            if (i==pivot) {
                cout<<"["<<array[i]<<"] ";
            }else{
                cout<<array[i]<<" ";
            }
        }
        cout<<array[n-1]<<endl;
    }
    return 0;
}

int partition(int a[], int p, int r){
    int x = a[r];
    int i=p-1;
    for (int j=p; j<r; j++) {
        if (a[j]<=x) {
            i++;
            swap(a[i],a[j]);
        }
    }
    swap(a[i+1],a[r]);
    return i+1;
}

Measured memory_bytes: 1548
def main():
    N = int(input())
    price = [int(input()) for i in range(N)]
    minv = float("inf")
    maxv = -float("inf")
    for p in price:
        maxv = max(maxv, p-minv)
        minv = min(minv, p)
    print(maxv)



if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()

Measured memory_bytes: 15700
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long t = sc.nextLong();
		int q = sc.nextInt();
		TreeSet<Long> place = new TreeSet<>();
		place.add(Long.MIN_VALUE);
		place.add(Long.MAX_VALUE);
		Person[] persons = new Person[n];
		long[] ans = new long[n];
		persons[0] = new Person(sc.nextLong(), sc.nextInt() == 1);
		for (int i = 1; i < n; i++) {
		    persons[i] = new Person(sc.nextLong(), sc.nextInt() == 1);
		    if (persons[i - 1] != null && persons[i - 1].isEast && !persons[i].isEast && persons[i].point - persons[i - 1].point <= 2 * t) {
		        long x = (persons[i].point + persons[i - 1].point) / 2;
		        ans[i - 1] = x;
		        ans[i] = x;
		        persons[i] = null;
		        persons[i - 1] = null;
		        place.add(x);
		    }
		}
		for (int i = 0; i < n; i++) {
		    Person p = persons[i];
		    if (p == null) {
		        continue;
		    }
		    long x;
		    if (p.isEast) {
		        x = Math.min(place.higher(p.point), p.point + t);
		    } else {
		        x = Math.max(place.lower(p.point), p.point - t);
		    }
		    ans[i] = x;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int x = sc.nextInt() - 1;
		    sb.append(ans[x]).append("\n");
		}
		System.out.print(sb);
	}
	
	static class Person {
	    long point;
	    boolean isEast;
	    
	    public Person (long point, boolean isEast) {
	        this.point = point;
	        this.isEast = isEast;
	    }
	}
}



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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);
    int n; cin >> n;
    cout << (n - 2) * 180 << endl;
}

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

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int a;
        cin >> a;
        n -= a;
    }
    if(n < 0) {
        cout << -1 << endl;
    } else {
        cout << n << endl;
    }
}

Measured memory_bytes: 3656