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

int n;
vector<vector<pair<int,int>>> tes(15,vector<pair<int,int>>());

bool isConsistent(bitset<15> s){
    bool res = true;
    rep(i,n){
        if(!s.test(i)) continue;
        for(auto p : tes[i]){
            if(s.test(p.first) != p.second) res = false;
        }
    }
    return res;
}

int main() {
    cin >> n;
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            int x,y;
            cin >> x >> y;
            x--;
            tes[i].push_back(make_pair(x,y));
        }
    }
    int ans = 0;
    for(int bit = 0;bit < (1<<n);bit++){
        bitset<15> s(bit);
        if(isConsistent(s)) ans = max(ans,(int)s.count());
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
// const ll MOD = 1000000007;

int main() {
  int Q;
  cin>>Q;
  multiset<ll> st1,st2;
  st1.insert(-(1e9 + 1));
  st2.insert(1e9 + 1);
  ll res = 0;
  for (int i = 0; i < Q; i++) {
    int c; cin>>c;
    if (c == 1) {
      ll a,b;
      cin>>a>>b;
      res += b;
      ll left = *st1.rbegin();
      ll right = *st2.begin();
      if (left <= a && a <= right) {
        st1.insert(a);
        st2.insert(a);
      } else if (a < left) {
        st1.insert(a);
        st1.insert(a);
        st1.erase(--st1.end());
        st2.insert(left);
        res += left - a;
      } else {
        st2.insert(a);
        st2.insert(a);
        st2.erase(st2.begin());
        st1.insert(right);
        res += a - right;
      }
    } else {
      ll kyoku = *st1.rbegin();
      cout<<kyoku<<" "<<res<<endl;
    }
  }
  return 0;
}

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

int main () {
  int N ;
  cin >> N ;
  long long line[N+10] ;
  long long A[N+10] = {} ;
  for(int i= 1 ; i <= N ; i++ ) cin >> line[i] ;
  A[0] = 0 ;
  for(int i = 1 ; i <= N ; i++ ) A[i] += line[i] + A[i-1];
  long long ans = 0 ;
  sort(A,A+N+1) ;
  long long tmp = A[0] ;
  int count = 1 ;
  for(int i = 1 ; i <= N ; i++ ){
    if(tmp==A[i]){
      ans += count ;
      count++ ;
    } else {
      tmp = A[i];
      count =  1 ;
    }
  }
  cout << ans << endl ;
  //for(int i = 0 ; i < N + 1 ; i++  ) cout << A[i] << endl ;
}

Measured memory_bytes: 3328
#include <cstdio>
typedef long long ll;
ll n, i, d=1;
ll f(ll p) {
	ll s;
	for(s=0; p; p/=10) s += p%10;
	return s;
}

int main() {
	scanf("%lld", &n);
	while(n--) {
		if((i+d) * f(i+d*2) > (i+d*2) * f(i+d)) d *= 10;
		i += d;
		printf("%lld\n", i);
	}
    return 0;
}

Measured memory_bytes: 128
# from collections import deque
import numpy as np
def main():
    n, m, k = map(int, input().split())
    A = np.array([0] + list(map(int, input().split())))
    B = np.array([0] + list(map(int, input().split())))
    X = np.cumsum(A)
    Y = np.cumsum(B)
    # print(P,Q)

    cnt = 0
    j = m
    # Aをi個、Bをj個選ぶ
    for i, x in enumerate(X):
        if x > k:
            break

        while x + Y[j] > k:
            j -= 1
        cnt = max(cnt, i + j)

    print(cnt)

if __name__ == "__main__":
    main()


Measured memory_bytes: 53840
// Author: Harshdeep Sharma , IIT  Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
// #define MOD  998244353
#define ll long long
const double PI = atan(1.0) * 4;
// const ll INF = (int)1e9 ;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const ll INF = (ll)2e18 + 50;
const int maximum  = numeric_limits<int>::min();
const int minimum  = numeric_limits<int>::max();




ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a;
		a =  a * a  ;
		e /= 2 ;
	}
	return res ;
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t ;
	// cin >> t ;
	// while (t--) {
	// int n , d ;
	// cin >> n >> d ;
	// int ans = 0 ;
	// for (int i = 0 ; i < n ; i++) {
	// 	int x  , y ;
	// 	cin >> x >> y ;
	// 	if (sqrt(x * x + y * y + 0.0) >= d) {
	// 		ans++ ;
	// 	}
	// }
	// cout << ans << "\n";
	int x ; 
	cin >> x ; 
	if(x >= 30) {
		cout << "Yes\n";
	}else {
		cout << "No\n";
	}




	// }









	return 0 ;

}



Measured memory_bytes: 3648
def max_minus_min(areas):
    # print("areas", areas)
    return max(areas) - min(areas)
 
def solve2(h, w):
    area1 = h * (w // 2)
    area2 = h * w - area1
    return [area1, area2]
 
def solve(h, w):
    w_div_3 = w // 3;
    ans = 1e9
    for w2 in range(w_div_3, w_div_3 + 2):
        area1 = w2 * h

        tmp = solve2(h, w - w2)
        tmp = max_minus_min([area1, tmp[0], tmp[1]])
        ans = min(ans, tmp)

        tmp = solve2(w - w2, h)
        tmp = max_minus_min([area1, tmp[0], tmp[1]])
        ans = min(ans, tmp)
    return ans
 
H, W = map(int, input().split())
print(min(solve(H,W), solve(W,H)))


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

struct Node{
	int key;
	Node *prev, *next;
};

Node *nil;

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}
void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* search(int key){
	Node *cur = nil->next;
	while (cur != nil && cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if (t ==nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(search(key));
}

void printList(){
	int isf = 0;
	Node *cur = nil->next;
	while(cur != nil){
		if (isf > 0) printf(" ");
		printf("%d", cur->key);
		isf++;
		cur = cur->next;
	}
	printf("\n");
}

int main(){
	int n;
	scanf("%d", &n);
	char com[20];
	int key;
	init();
	for (int i = 0; i < n; i++){
		scanf("%s%d",com, &key);
		if (!strcmp(com, "insert")) insert(key);
		if (!strcmp(com, "delete")) deleteKey(key);
		if (!strcmp(com, "deleteFirst")) deleteFirst();
		if (!strcmp(com,"deleteLast")) deleteLast();
	}
	printList();
}


Measured memory_bytes: 33860
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        // 主処理
        int result = (int) Math.ceil(n / 2.0);

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];

  ll res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i+1; j < n; ++j) {
      for (int k = j+1; k < n; ++k) {
        if(v[i] + v[j] > v[k] && v[i] + v[k] > v[j] && v[j] + v[k] > v[i]){
          if(v[i] != v[j] && v[k] != v[j] && v[i] != v[k]) res ++;
        }
      }
    }
  }

  cout << res << endl;
}


Measured memory_bytes: 3592
main=mapM_(putStrLn.solve.map read.words).lines=<<getContents
solve [n,a,b,c,d]=if any f[0..(n-1)`div`2] then"YES"else"NO"where
 f i=max 0 (cn-(d-c)*i)<=abs(a-b)&&abs(a-b)<=dn+(d-c)*i
  where [cn,dn]=map(*(n-1-i*2))[c,d]

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>s;
  n=s.length();
   vector<ll>v(n+1,0);
   ll rig=0,lef=0;
   rep(i,0,n)
   {
     if(s[i]=='<') rig++;
     else rig=0;
     v[i+1]=rig;
   }
   per(i,n-1,-1)
   {
     if(s[i]=='>') lef++;
     else lef=0;
    v[i]=max(v[i],lef);
   }
   rep(i,0,n+1) k+=v[i];
   cout<<k;
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
 //  cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 7676
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a, b, k = iim()
l = []
if b-a+1 > 2*k:
    for i in range(a,a+k):
        l.append(i)
    for j in range(b-k+1,b+1):
        l.append(j)
else:
    for n in range(a,b+1):
        l.append(n)

for k in l:
    print(k)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    // スペース区切りの整数の入力
    int n,a,b;
    cin >> n >> a >> b;
    int answer;
    if(n*a>=b){
      answer = b; 
    }else{
      answer =n*a;
    }
    // 出力
    cout << answer;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
        int n, i, A[10000], minv, maxv;
long int sum;
        minv = 1000001;
        maxv = -1000001;
        sum = 0;
        i = 0;
        cin >> n;
        for (i ; i < n; i++) cin >> A[i];
        for (int j = 0; j < i; j++) {
                sum = sum + A[j];
                maxv = max(maxv, A[j]);
                minv = min(minv, A[j]);
        }
        cout << minv << " " << maxv << " " << sum << endl;
}

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

#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N;
    cin>>N;
    vector<LL> h(N),p(N);
    REP(i,N)cin>>h[i]>>p[i];
    vector<pair<LL,int>> x;
    REP(i,N)x.pb({p[i]+h[i],i});
    sort(ALL(x));
    vector<LL> H(N+1,1e15);
    int ret=0;
    H[0]=0;
    for(auto &it:x){
        REP(i,N){
            int num = N-i-1;
            if(H[num]<=h[it.se]){
                chmin(H[num+1],H[num]+p[it.se]);
                chmax(ret,num+1);
            }
        }
    }
    cout<<ret<<endl;
    
    return 0;
}


Measured memory_bytes: 512
//https://atcoder.jp/contests/abc116/tasks/abc116_a
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
    return 0;
}

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

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

using ll = long long;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int x = max(a,max(b,c));//big
  int y = min(a,min(b,c));//small
  int z = a+b+c-x-y;//middle
  int ans = 0;
  if((z-y)%2!=0){
    ans++;
    x++;
    z++;
  }
  //bigとの差に変換
  y = x-y;
  z = x-z;

  if(y%2!=0){
    y--;
    z--;
    ans++;
  }
  ans+=(y/2+z/2);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
using namespace std;

bool a[7368792];

int sieve(int m,int n){
  memset(a,true,sizeof(a));
  int next = m;
  for(int i=0;i<n;i++){
    for(int k=1;k*next<=7368791;k++){
      a[next*k] = false;      
    }
    while(!a[next])next++;
  }
  return next;
}

int main(){
  int n;int m;
  while(cin >> n >> m,n&&m){
    cout << sieve(n,m) << endl;
  }
}

Measured memory_bytes: 10228
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int main(){
  int l;cin>>l;
  int u;
  for(int i=0;;i++){
    int y=pow(2,i);
    if(y>l){
      u=i;
      break;
    }
  }
  vector<pii> v[u+1];
  int cnt=0;
  for(int i=1;i<u;i++){
    int r=pow(2,u-1-i);
    v[i].push_back(make_pair(i+1,r));
    v[i].push_back(make_pair(i+1,0));
    cnt+=2;
  }
  int now=l;
  for(int i=0;i<u-1;i++){
    int y=pow(2,i);
    int e=l/y;
    if(e%2){
      v[1].push_back(make_pair(u-i,now-y));
      cnt++;
      now-=y;
    }
  }
  cout<<u<<" "<<cnt<<endl;
  for(int i=1;i<u;i++){
    for(int j=0;j<v[i].size();j++){
      cout<<i<<" "<<v[i][j].first<<" "<<v[i][j].second<<endl;
    }
  }
}
        
  

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

using namespace std;

#define cin_desync()                                                           \
    do {                                                                       \
        ios_base::sync_with_stdio(false);                                      \
        cin.tie(0);                                                            \
    } while (0)

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int max_N = 110;

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

    vector<int> B(N);
    for (auto &b : B) {
        cin >> b;
    }

    vector<int> ops;
    while(B.size()) {
        int N = B.size();
        bool ok = false;
        for (int i = N - 1; i >= 0; --i) {
            if (B[i] == i + 1) {
                ops.push_back(i + 1);
                B.erase(B.begin() + i);
                ok = true;
                break;
            }
        }

        if (!ok) {
            cout << -1 << endl;
            return 0;
        }
    }

    reverse(ops.begin(), ops.end());
    trace(ops.size());
    for (int i = 0; i < N; ++i) {
        if (ops[i] > i + 1) {
            cout << -1 << endl;
            return 0;
        }
    }

    for (int i = 0; i < N; ++i) {
        cout << ops[i] << '\n';
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  rep(i, 5){
    int x;
    cin >> x;
    if(x == 0){
      cout << i+1 << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		
		int B = sc.nextInt();
		
		int C = sc.nextInt();
		
		
	    if (A>=B&&A>=C) {
	    	System.out.println(A*10+B+C); 	
	    }
	    if (B>A&&B>=C) {
	    	System.out.println(B*10+A+C);
	    }
		if(C>A&&C>B) {
			System.out.println(C*10+A+B);
			
		}
	}

}


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

int main() {

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



    double ave = accumulate(begin(a), end(a), 0.0) / a.size();
    double min_diff = 1e9;
    // vector<double> diff;
    vector<int> diff;
    for(int i = 0; i < N; i++){
        // double tmp_diff = abs(N*a[i] - N*ave);
        int tmp_diff = abs(N * a[i] -  N *ave);
        diff.push_back(tmp_diff);
    }

    auto minitr = min_element(begin(diff), end(diff));
    size_t idx = distance(begin(diff), minitr);
    cout << idx << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<complex>
#include<map>
using namespace std;

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

  int cnt = 0;
  for(int i = 0; i < n-1; i++){
    int mn = i;
    bool flg = false;
    for(int j = i+1; j < n; j++){
      if(a[j] < a[mn]){
        mn = j;
        flg = true;
      }
    }
    if(flg) cnt++;
    swap(a[i], a[mn]);
  }
  for(int i = 0; i < n; i++){
    cout << a[i];
    if(i == n-1) cout << endl;
    else cout << " ";
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3100
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define roop(a,t) for(int a=0;a<t;a++) 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
if(n==0){break;}
        int sum[5001];
        roop(i, n) {
            cin >> sum[i];
            if (i != 0) { sum[i] += sum[i - 1]; }
        }
        int ans = -9000000000;
        for (int i = -1; i < n-1; i++) {
            int sumi = 0;
            if (i != -1)
            {
                sumi = sum[i];
            }
            for (int j = i + 1; j < n; j++) {
 
                int sumj = sum[j];
                ans = max(ans, sumj - sumi);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define pb push_back
#define debug(x) cerr << #x << " = " << x << "\n";
#define debug_v(x) cerr << #x << " ="; for(auto i : x){cerr << " [" << i << "]";} cerr << "\n";
using namespace std;
using ll = long long;
const double PI = acos(-1);
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 1e18 + 100;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	int mx = 0, mx2 = 0, qan = 0;
	for (int i = 0; i < n; i++){
		mx = max(mx, a[i]);
	}
	for (int i = 0; i < n; i++){
		if(a[i] != mx){
			mx2 = max(mx2, a[i]);
		}
		else{
			qan++;
		}
	}
	if(qan > 1){
		mx2 = mx;
	}
	for (int i = 0; i < n; i++){
		if(a[i] == mx){
			cout << mx2 << '\n';
		}
		else{
			cout << mx << '\n';
		}
	}
	
	return 0;
}
 


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9;
const int maxn_v=3e5+10;
struct edge{int to,cost;};
typedef pair<int,int>P;
int d[maxn_v];
priority_queue<P,vector<P>,greater<P> >que;
vector<edge>G[maxn_v];
void add_edge(int x,int y,int z)
{
    G[x].push_back((edge){y,z});
}
void dij(int s)
{
    for(int i=0;i<maxn_v;i++)
        d[i]=inf;
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty())
    {
        P p=que.top();
        que.pop();
        int v=p.second;
        if(d[v]<p.first)
            continue;
        for(int i=G[v].size()-1;i>=0;i--)
        {
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost)
            {
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}


const int maxn=1e5+20;
int n,m,from[maxn],to[maxn];
vector<int>in[maxn],out[maxn];
int main()
{
    int n,m,s,t;scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&from[i],&to[i]);
        in[to[i]].push_back(from[i]);
        out[from[i]].push_back(to[i]);
    }
    scanf("%d%d",&s,&t);
    for(int i=1;i<=n;i++)
    {
        for(int j=in[i].size()-1;j>=0;j--)
        {
            int x=in[i][j];
            add_edge(x,i+n,0);
        }
        for(int j=out[i].size()-1;j>=0;j--)
        {
            int x=out[i][j];
            add_edge(i+2*n,x,0);
        }
    }
    for(int i=1;i<=m;i++)
    {
        int x=from[i],y=to[i];
        add_edge(x+n,y+2*n,1);
    }
    dij(s);
    if(d[t]==inf)
        d[t]=-1;
    printf("%d\n",d[t]);
    return 0;
}


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



void showArray(int* datas,int n){
	int i;
	 for(i = 0;i<n-1;i++){
		 cout<<datas[i]<<" ";
		 
     }
	 cout << datas[n-1] << endl;
}
int main(){
	int n,i,j,k,key;
	cin >> n;
	int datas[1000];
	for(i=0;i<n;i++){
		cin >> datas[i];
	}

	for(j=1;j<n;j++){
	 showArray(datas,n);
	 key=datas[j];
	 for(k=j-1;k>=0;k--){
	  if(datas[k]<key) {break;}
	  datas[k+1] = datas[k];
	  datas[k] = key;
	 }

	}
	showArray(datas,n);
}

Measured memory_bytes: 1164
// abc053c: X: Yet Another Die Game
#include <stdio.h>
#define in(a) scanf("%lld",(a))
#define out(a) printf("%lld\n",(a))

int main(){
  long x;in(&x);
  long c= (x/11)*2;
  x %= 11;
  // dice face 5 start: snuke-kun's favorite number
  if(x==0) out(c);
  else if(x<7) out(c+1);
  else out(c+2);
  return 0;
}

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

struct UnionFind {
    vector<long long> par;
    UnionFind(long long size):par(size+1,-1){}
    bool unite(long long x,long long y){
        x=root(x);
        y=root(y);
        if (x!=y){
            if(par[y]<par[x]) swap(x,y);
            par[x]+=par[y];
            par[y]=x;
        }
        return x!=y;
    }
    bool same(long long x,long long y){ return root(x)==root(y); }
    int root(long long x){ return par[x]<0?x:par[x]=root(par[x]); }
    int size(long long x){ return -par[root(x)]; }
};

int main()
{
    int n, m;
    cin >> n >> m;
    UnionFind tree(n);
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        tree.unite(--a, --b);
    }
    int ans = 0;
    for(int i = 0; i < n; i++) ans = max(ans, tree.size(i));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4836
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H,W,i,j;
    while(1){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                if(i%2==1){
                    if(j%2==1){
                        cout<<'#';    
                    }
                    else{
                        cout<<'.';    
                    }    
                }
                else{
                    if(j%2==1){
                        cout<<'.';
                    }
                    else{
                        cout<<'#';
                    }
                }
            }
            cout<<endl;
        }
        cout<<endl;
        
    }
}



Measured memory_bytes: 3100
#include <math.h>
#include <stdio.h>
 
int main(void)
{
  int n,t,a,i,p;
  int b[1000];
  double m,k=9999999,q;
  
  scanf("%d",&n);
  scanf("%d %d",&t,&a);
   for(i=0;i<n;i++)
  {
    scanf("%d",&b[i]);
  }
  for(i=0;i<n;i++)
  {
    q=(double)b[i];
    q=(double)t-(q*(0.006));
    m=fabs((double)a-q);
    if(m<k)
    {
      k=m;
      p=i+1;
    }
  }
  
  printf("%d",p);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

int n;
pair<double,pair<double,double>> points[110];

double getx(int k) {
    return points[k % n].se.fi;
}
double gety(int k) {
    return points[k % n].se.se;
}

void solve() {
    cin >> n;
    REP(i,n) {
        double x,y;
        cin >> x >> y;
        points[i] = {atan2(y,x),{x,y}};
    }
    sort(points,points + n);
    double ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            double x = 0, y = 0;
            for (int k = 0; k < j; k++) {
                x += getx(i + k);
                y += gety(i + k);
            }
            ans = max(ans,x * x + y * y);
        }
    }
    cout << setprecision(20) << sqrt(ans) << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >>S;
    int n=S.size();
    int t=0;
    for(int i=0;i<n;i++){
        if(i%2==1){
            if(S.at(i)=='R'){
                t+=1;
            }
        }
        if(i%2==0){
            if(S.at(i)=='L'){
                t+=1;
            }
        }
    }
    if(t>=1){
        cout <<"No"<<endl;
    }
    if(t==0){
        cout <<"Yes"<<endl;
    }
}


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

//create arrays outside of main()
int a[300000] = {};

int main()
{
    int a, b, c;

    cin >> a >> b >> c;

    int c_eaten;

    if (c < (a + b))
    {
        c_eaten = c;
    }
    else if (c == (a + b))
    {
        c_eaten = c;
    }
    else
    {
        c_eaten = a + b + 1;
    }

    cout << c_eaten + b;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8



int main() {
    ll N,X[100007],G;cin >> N >> X[0];
    rep(i,N){
        cin >> X[i+1];
        if(i==0){
            G=abs(X[i+1]-X[i]);
        }
        else{
            G=gcd(G,abs(X[i+1]-X[i]));
        }
    }
    cout << G << endl;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

bool Ok(const string&s,int n){
  bool f = true;
  if(n%2==1)return false;
  for(int i = 0; i < n/2; ++i)f &= s[i] == s[i+n/2];
  return f;
}

int main(){
  string s; cin >> s;
  int n = (int)s.size();
  for(int i = n-2; i >= 0; i-=2){
    if(Ok(s,i)){
      cout << i << endl;
      return 0;
    }
  }
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a >= b) {
		int tmp = a;
		a = b;
		b = tmp;
	}

	if (b <= c) cout << a << " " << b << " " << c << endl;
	else if (c <= a) cout << c << " " << a << " " << b << endl;
	else cout << a << " " << c << " " << b << endl;
	
	return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n, m;
    cin >> n >> m;
    if(n==1 && m==1){
        cout << 1 <<endl;
    }else if(n==1 && m!=1){
        cout << m-2 << endl;
    }else if(m==1 && n!= 1){
        cout << n-2 << endl;
    }else{
        cout << (m-2) * (n-2) << endl;
    }
}


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

#define endl '\n'

using namespace std;

int N;

int h[100001];

long long dp[100001];

long long ans(int i){

  if(dp[i]!=-1){
    return dp[i];
  }
  
  if (i==N-1){
    return dp[i]=0;
  }else if(i==N-2){
    return dp[i]=ans(i+1)+abs(h[i+1]-h[i]);
  }else{

    return dp[i]=min(ans(i+1)+abs(h[i+1]-h[i]),ans(i+2)+abs(h[i+2]-h[i]));
    
  }
 
}

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  cin>>N;

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

  cout<<ans(0)<<endl;

  return 0;

}


Measured memory_bytes: 2944
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <vector>
#include <iomanip>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;

typedef long long ll;




int main(){

    int N;
    cin>>N;

    string str;

    ll num[5];

    rep(i,5){
        num[i]=0;
    }

    for(int i=0;i!=N;++i){
        cin>>str;

        switch(str[0]){
            case 'M':
            num[0]++;
            break;
            case 'A':
            num[1]++;
            break;
            case 'R':
            num[2]++;
            break;
            case 'C':
            num[3]++;
            break;
            case 'H':
            num[4]++;
            break;
        }
    }

    ll ans=0;
/*
    rep(i,5){
        cout<<num[i]<<" ";
    }
    cout<<endl;
    */

    for(int i=0;i<=2;++i){
        for(int j=i+1;j<=3;++j){
            for(int k=j+1;k<=4;++k){
               // cout<<"num["<<i<<"]:"<<num[i]<<" num["<<j<<"]:"<<num[j]<<" num["<<k<<"]:"<<num[k]<<":"<<num[i]*num[j]*num[k]<<endl;
                ans+=num[i]*num[j]*num[k];
            }
        }
    }

    cout<<ans<<endl;
    
}


Measured memory_bytes: 3656
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
        self.rank=[-1]*n

    def Find_Root(self,x):
        if self.root[x]<0:return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def size(self,x):
        return -self.root[self.Find_Root(x)]


n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(m)]
UnionFind=UnionFind(n)
count=[n*(n-1)//2]

for a,b in AB[::-1]:
    if UnionFind.isSameGroup(a-1,b-1):
        count.append(count[-1])
    else:
        s,t=UnionFind.size(a-1),UnionFind.size(b-1)
        count.append(count[-1]-s*t)
    UnionFind.Unite(a-1,b-1)

for i in count[::-1][1:]:
    print(i)

Measured memory_bytes: 38772
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define double long double
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int k;
    cin>>k;
    int x=0;int r=0;
    while(true)
    {   x++;
        r*=10;
        r+=7;
        if(r%k==0)break;
        else
        {
            r=r%k;
        }
        if(x>100000000)break;
    }
    if(r%k!=0)cout<<-1<<endl;
    else cout<<x<<endl;
}


return 0;
}





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


int p, q, r;

int main() {
    cin >> p >> q >> r;
    if (( p >= q ) && ( p >= r )) cout << q + r << endl;
    else if (( q >= p ) && ( q >= r)) cout << p + r << endl;
    else cout << q + p << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
//template <typename... T> void read(T& ... t){ ((cin >> t), ...); }
//template <typename... T> void write(T ... t){ ((cout << t), ...); }
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
using LL = long long;
using pii = pair<int,int>;
const int INF = 2e9;
const int MAXN = 2e5 +3;
int n;
int arr[MAXN];

int32_t main(){ FAST;
	cin >> n;
	for(int i=1; i<=n; ++i) cin >> arr[i];
	
	set<int> put;
	for(int i=n; i>=1; --i){
		int nb = 0;
		for(int j=i*2; j<=n; j+=i) nb += put.count(j);
		if(nb%2 != arr[i]) put.insert(i);
	}

	cout << size(put) << ln;
	for(int ind: put) cout << ind << " ";
	cout << ln;
}

Measured memory_bytes: 7808
#include<stdio.h>
int
max2 (int i, int j)
{
  if (i < j)
    {
      return j;
    }
  else
    {
      return i;
    }
}

int
max (int i, int j, int k)
{
  if (i < j)
    {
      return max2 (j, k);
    }
  else
    {
      return max2 (i, k);
    }
}

int
main (void)
{
  int n;
  scanf ("%d", &n);

  int i, j;
  int a[4];
  a[3] = 0;
  int l, m;
  for (i = 0; i < n; i++)
    {
      scanf ("%d %d %d", &a[0], &a[1], &a[2]);
      m = max (a[0], a[1], a[2]);
      l = 0;
      int *p = a;
      int v;
      while (0 != *p)
	{
	  v = *p++;
	  if (v == m)
	    continue;
	  l += v * v;
	}
      if (l == m * m)
	puts ("YES");
      else
	puts ("NO");
    }
  return 0;
}

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

#define ll long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(int i = l;i<r;i++)

#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

void kekek()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef EBUCHKA
        freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
    #endif
}

const int MAXN = 2e5 + 10000;

vector<int> encode(string s) {
    vector<int> ans(26);
    for (auto it: s) {
        ans[it - 'a']++;
    }
    return ans;
}

int main() {
    kekek();
    int n;
    cin >> n;
    map<vector<int>, long long> heh;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        auto tmp = encode(s);
        ans += heh[tmp];
        heh[tmp]++;
    }
    cout << ans;
}


Measured memory_bytes: 19072
#d
A,B,N=map(int,input().split())
b=[]
if N>=B:
    b.append((N//B)*B-1)
b.append(N)
a=0
for x in b:
    p=(A*x)//B-A*(x//B)
    if p>a:
        a=p
print(a)

Measured memory_bytes: 61732
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    long int n,sum;
    cin>>n;
    sum=(n/500)*1000;
    n-=(n/500)*500;
    sum+=(n/5)*5;
    cout<<sum;
    return 0;
}    

Measured memory_bytes: 256
from collections import Counter
N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]

counter = Counter(((b1[0] - b2[0], b1[1] - b2[1]) for b1 in xy for b2 in xy if b1 != b2))
print(N - (list(counter.most_common())+[(0,0)])[0][1])


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	lli h;
	cin >> h;
	lli num = 1;
	lli ans = 0;
	while(h != 0){
		ans += num;
		h /= 2;
		num *= 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}


int main(){
    int n,x;cin>>n>>x;
    vector<ll>v(n);
    rep(i,n)cin>>v[i];
    ll res = 0;
    rep(i,n-1){
        ll r = v[i+1]+v[i];
        if(r>x){
            v[i+1] -= min(r-x,v[i+1]);
            res += (r-x);
        }
    }
    cout<<res;
}



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

using namespace std;
#define taskname "A"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 2e5 + 5;
int n ,m , deg[maxn];
vector<int> adj[maxn];
int res[maxn];

void dfs(int u ,int v){
    vector<int> tmp;
    for(int c : adj[u])if(--deg[c] == 0)tmp.pb(c);
    for(int c : tmp){
        if(deg[c] ==  0){
            res[c] = u;
            dfs(c,u);
        }
    }
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
	}
    cin >> n >> m;
    for(int i = 1 ; i <= m + n - 1  ; ++i){
        int u,v;cin >> u >> v;adj[u].pb(v);
        deg[v]++;
    }
    for(int i =1  ; i <= n ; ++i)if(deg[i]==0){
        dfs(i,0);
        break;
    }
    for(int i =1;i<=n;++i)cout<<res[i]<<"\n";
}


Measured memory_bytes: 22272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define prl(x) cout << (x) << endl

template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {return '"' + s + '"';}
string to_string(char c){return string(1, c);}
string to_string(const char* s) {return to_string((string) s);}
string to_string(bool b){return (b ? "true" : "false");}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p){return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p){return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";}
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) res += ", ";
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template<typename T>
string to_string(priority_queue<T>& q){
    priority_queue<T> copy;
    bool first = true;
    string res = "{";
    while(!q.empty()){
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(q.top());
        copy.push(q.top());
        q.pop();
    }

    swap(q, copy);
    res += "}";
    return res;
}

void debug_out() {cerr << endl;}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef _LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main(void){
    ll m; cin >> m;
    vector<ll> cs(m), ds(m);
    rep(i, m) cin >> ds[i] >> cs[i];
    
    ll answer = 0, cur = 0;
    rep(i, m){
        while (cs[i] >= 10){
            answer += (cs[i] / 10) * (9 + ds[i]);
            cs[i] = cs[i] / 10 + cs[i] % 10;
        }
        rep(j, cs[i]){
            cur += ds[i], answer++;
            if (cur >= 10) (cur += 1) %= 10, answer++;
        }
    }

    prl(answer - 1);

    return 0;
}


Measured memory_bytes: 6312
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

int ans[501][501];

void fill(int start, int end, int color) {
    if (end - start < 3) {
        if (end - start == 1) ans[start][end] = color;
        else {
            ans[start][start+1] = color;
            ans[start][end] = color+1;
            ans[start+1][end] = color+1;
        }
        return;
    }
    int m = (start+end)/2;
    for (int i = start; i <= m; i++) {
        for (int j = m+1; j <= end; j++) {
            ans[i][j] = color;
        }
    }
    fill(start, m, color+1);
    fill(m+1, end, color+1);
}

void solve() {
    int n; sc(n);
    fill(1, n, 1);
    for(int i = 1; i <= n; i++) {
        for (int j = i+1; j <= n; j++) printf("%d ", ans[i][j]);
        printf("\n");
    }
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1408
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s, t, ans;
  cin >> n >> s >> t;
  REP(i,n) {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool vis[1000009];
void seive(){
    vis[0]=vis[1]=1;
    for(int i=4;i<1000009;i+=2){
        vis[i]=1;
    }
    for(int i=3;i<1000009;i+=2){
        if(!vis[i]){
            if(i*i<1000009){
                for(int j=i+i;j<1000009;j+=i){
                    vis[j]=1;
                }
            }
        }
    }
}
int main(){
    int n;
    seive();
    cin >>n;
    if(!vis[n]){
        cout << n << endl;
    }
    else{
        while(1){
            if(!vis[n]){
                cout << n << endl;
                return 0;
            }
            n++;
        }
    }
}


Measured memory_bytes: 1280
#include <stdio.h>

int main(void)
{
	int x, y;
	int i;

	scanf("%d %d", &x, &y);

	while (x != 0 || y != 0) {
		if (x < y)
			printf("%d %d\n", x, y);
		else
			printf("%d %d\n", y, x);

		scanf("%d %d", &x, &y);
	}

	return 0;
}

Measured memory_bytes: 600