akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <queue>
using namespace std;

typedef long long ll;
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll m[20][20];

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

struct node
{
    public: ll x;
    public: ll y;

    node(ll xx, ll yy)
    {
        x = xx;
        y = yy;
    }
};

int main(){
    ll a, b;
    cin >> a >> b;
    
    ll l;
    rep(i, b){
        ll p;
        cin >> p;
        l += p;
    }

    string f = l >= a ? "Yes" : "No";

    cout << f << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){

  int a,b;

  cin >> a >> b;

  if(a<b)
  cout << "a < b" <<endl;

  if(a>b)
    cout << "a > b" <<endl;

  if(a==b)
    cout << "a == b" <<endl;

  return 0;

}

Measured memory_bytes: 3076
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
int binary_search_index(Int Y, vi &q){
    int left = 0, right = q.size() - 1;
    while (right >= left) {
        int mid = left + (right - left) / 2;
        if (q[mid] == Y) return mid;
        else if (q[mid] > Y) right = mid - 1;
        else if (q[mid] < Y) left = mid + 1;
    }
    return -1;
}


Int combination(Int n, Int r) {
    if(n == 1){return 0;}
    if ( r * 2 > n ) r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor  = 1;
    for ( unsigned int i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

unsigned GetDigit(Int num){
    return std::to_string(num).length();
}
int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}

int ans =0;

void dfs(string bit, int length,vector<vector<pii>> &answers){
    if(bit.size() == length){
        int tmp_ans = 0;
        int count_shoujiki = 0;
        rep(i,length){
            if(bit[i] =='1'){
                count_shoujiki++;
                bool goal = true;
                rep(j,answers[i].size()){
                    int x = answers[i][j].first;
                    int y = answers[i][j].second;

                    if (ctoi(bit[x]) != y) {goal = false;}
                }

                if(goal){
                    tmp_ans++;
                }
            }
        }
        if(tmp_ans == count_shoujiki){
            ans = max(ans,count_shoujiki);
        }

        return;
    }
    dfs(bit+"1", length, answers);
    dfs(bit+"0", length, answers);
    return ;
}

int main() {
    Int N;

    cin >> N;
    vector<vector<pii>> answers;
    rep(i,N){
        int A;
        cin >> A;
        vector<pii> answer;
        rep(j,A){

            int x,y;
            cin >> x >> y;
            answer.push_back(make_pair(x-1,y));
        }
        answers.push_back(answer);
    }

    dfs("1",N,answers);
    dfs("0",N,answers);


    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 256
import itertools
import math

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
num = [x for x in range(1, n + 1)]
perm = itertools.permutations(num)
cnt = 0
a = 0
b = 0
for i in perm:
    i = list(i)
    cnt += 1
    if p == i:
        a = cnt
    if q == i:
        b = cnt
print(abs(a - b))

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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};
#define PI 3.141592653589793238

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

signed main() {
    SCIN(S);
    ll N = S.length();
    ll p = 0;
    REP(i, N) if(S[i] == 'p') p++;
    cout << (N / 2) - p << "\n";
}


Measured memory_bytes: 512
package main

import "fmt"

type dice struct {
	o, tw, th, fo, fi, s int
}

func main() {
	var Dice dice
	fmt.Scan(&Dice.o, &Dice.tw, &Dice.th, &Dice.fo, &Dice.fi, &Dice.s)
	var D string
	fmt.Scan(&D)
	for _, d := range D {
		switch d {
		case 'N':
			Dice.o, Dice.tw, Dice.fi, Dice.s = Dice.tw, Dice.s, Dice.o, Dice.fi
		case 'E':
			Dice.o, Dice.th, Dice.fo, Dice.s = Dice.fo, Dice.o, Dice.s, Dice.th
		case 'W':
			Dice.o, Dice.th, Dice.fo, Dice.s = Dice.th, Dice.s, Dice.o, Dice.fo
		case 'S':
			Dice.o, Dice.tw, Dice.fi, Dice.s = Dice.fi, Dice.o, Dice.s, Dice.tw
		}
	}
	fmt.Println(Dice.o)
}



Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
long long a[200005];
int main(){
    long long n, k;
    cin>>k>>n;
    for(int i=0; i<n; ++i) cin>>a[i];
    sort(a, a+n);
    long long mx=a[0]+k-a[n-1];
    for(int i=1; i<n; ++i)
        mx=max(mx, a[i]-a[i-1]);
    cout<<k-mx;
    return 0;
}


Measured memory_bytes: 1920
program partition
  implicit none
  integer(8) :: n, m, i, d
  read(*,*) n, m
  d = m/n
  do i = d, 1, -1
     if (mod(m,i) .eq. 0) then
        write(*,'(i0)') i
        stop
     end if
  end do
end program partition

Measured memory_bytes: 640
x = int(input())
for a in range(1000):
    for b in range(1000):
        if a**5 - b**5 == x:
            print(a, b)
            exit()
        if a**5 - (-b)**5 == x:
            print(a, -b)
            exit()
        if (-a)**5 - b**5 == x:
            print(-a, b)
            exit()
        if (-a)**5 -(-b)**5 == x:
            print(-a, -b)
            exit()

Measured memory_bytes: 9096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],z,m,k,ans=0,fl=0;
	string s;
	cin>>n>>m>>k>>z;
	ll t1,t2,t3,t4;
	t1=n*k;
	t2=n*z;
	t3=m*k;
	t4=m*z;
	cout<<ll(max(max(t1,t2),max(t3,t4)))<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>

using namespace std;

string reverse(string s);

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

    cout << reverse(str) << endl;
}

string reverse(string s)
{
    string rev;
    int len = s.length();

    for(int i = 1; i <= len; i++)
        rev += s.substr(len - i, 1);

    return rev;
} 

Measured memory_bytes: 1180
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		int m, f, r;

		Scanner stdIn = new Scanner(System.in);

		boolean flag = true;
		while (flag) {
			m = stdIn.nextInt();
			f = stdIn.nextInt();
			r = stdIn.nextInt();

			if (m == -1 && f == -1 && r == -1) {
				flag = false;
				break;
			} else if (m == -1 || f == -1) {
				System.out.println("F");
			}
			else if (m + f >= 80) {
				System.out.println("A");
			} else if (m + f >= 65) {
				System.out.println("B");
			} else if (m + f >= 50 || r >= 50) {
				System.out.println("C");
			} else if (m + f >= 30) {
				System.out.println("D");
			} else {
				System.out.println("F");
			}
		}
	}
}

Measured memory_bytes: 26216
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

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

    ll n;
    cin>>n;
    vector<ii> v;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        if(i==0){
            v.push_back({a[i], 0});
        }
        else{
            if(a[i]!=v.back().F){
                v.push_back({a[i], i});
            }
        }
    }

    ll ans=1000;
    ll i = 0; 
    while (i<(n-1)){ 
        while ((i<n-1) && (a[i + 1]<=a[i])) {
            i++;
        }
        if(i ==n-1){
            break; 
        }
        ll buy = i;
        i++;
        while ((i < n) && (a[i] >= a[i - 1])) {
            i++; 
        }
        ll sell = i-1;
        ll bought_stocks = ans/a[buy];
        ll rem = ans%a[buy];
        ll sold_money = bought_stocks*a[sell];
        ans=sold_money+rem;
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <cstdio>
#define fastio {ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define nln cout << '\n'
#define ll long long int
#define INF (ll)1e+12
#define MAX 300100
#define mp(i, j) make_pair(i, j)
#define here cout  << "here";nln;
#define mul(a, b, mod) (((a % mod) * (b % mod)) % mod)
#define add(a, b, mod) (((a % mod) + (b % mod)) % mod)
#define inf 100000
#define M 1000000000LL

using namespace std;

int main()
{
    ll n;

    ll i, ans = 0, j, k;

    cin >> n;

    vector <pair <ll , ll> > v;

    for(i = 1, j = (n>>1)*2; i < j; i++, j--){
        for(k = i+1; k < j; k++){
            v.push_back(make_pair(i, k));
            v.push_back(make_pair(j, k));
        }
        if(n&1)v.push_back(make_pair(i, n)), v.push_back(make_pair(j, n));
    }


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

    for(i = 0; i < v.size(); i++)cout << v[i].first << ' ' << v[i].second << endl;

}


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

int main(){
    int m, n;
    vector<int> a(4);
    for(int i = 0; i < 4; i++){
        cin >> a[i];
    }
    cin >> m >> n;
    sort(a.rbegin(), a.rend());
    int ans = a[0] + a[1] + a[2] + max(m,n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3092
import sys
sys.setrecursionlimit(10**8)
#def main():　if __name__ == "__main__":　main()
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

S = input()
l = len(S)
d = defaultdict(int)

for m in S:
    d[m] += 1

d2 = sorted(d.items(), key=lambda x:x[1], reverse=True)
if d2[0][1] > 1:
    e = []
    i = 0
    for i in range(len(d2)):
        e.append(d2[i][0])
else:
    e = [S[l//2]]

ans = l
for a in e:
    cnt = 0
    num_list = []
    for m in S:
        if m != a:
            cnt += 1
        else:
            num_list.append(cnt)
            cnt = 0
    num_list.append(cnt)
    #print(a, num_list)
    ans = min(ans, max(num_list))

print(ans)

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


int main(){
    int d;
    cin >> d;
    vector<int> c(26,0);
    vector<int> last(26,0);
    vector<int> t(d,0);
    vector<int> v(d,0);

    int s[d][26];
    for(int i=0;i<26;i++){
        cin >> c[i];
    }

    for(int i=0;i<d;i++){
        for(int j=0;j<26;j++){
            cin >> s[i][j];
        }
    }

    for(int i=0;i<d;i++){
        cin >> t[i];
        t[i]--;
    }

    for(int i=0;i<d;i++){
        last[t[i]] = i+1;
        if(i==0){
            v[i] = s[i][t[i]];
        }else{
            v[i] = v[i-1] + s[i][t[i]];
        }

        for(int j=0;j<26;j++){
            v[i] -= c[j]*(i+1-last[j]);
        }
    }

    for(int i=0;i<d;i++){
        cout << v[i] << endl;
    }

}

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

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<#x<<" :"<<x<<endl;
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	int N, M;
	cin >> N >> M;
	int X, Y, Z;
	cin >> X >> Y >> Z;
	int a[X+5], b[Y+5], c[Z+5];
	rep(i,X)cin >> a[i];

	rep(i,Y)cin >> b[i];

	rep(i,Z)cin >> c[i];

	sort(a,a+X);
	sort(b,b+Y);
	sort(c,c+Z);
	reverse(a,a+X);
	reverse(b,b+Y);
	reverse(c,c+Z);

	vector<int> v;
	rep(i,N)v.pb(a[i]);

	rep(i,M)v.pb(b[i]);

	rep(i,min(N+M,Z))v.pb(c[i]);

	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());

	ll ans = 0;
	rep(i,N+M)ans+=v[i];

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


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;

const int mx=100010;
const ll mod=1e9+7;

int n,m,par[mx],dist[mx];
vector<int> v[mx], inv[mx];

void dfs(int x,int p){
  par[x] = p;
  for(auto to:v[x]){
    if(to==p)continue;
    if(dist[to]==dist[x]+1){dfs(to,x);}
  }  
}

int main(){
  cin >> n >> m;
  for(int i=0; i<(n-1+m); i++){
    int a,b;
    cin >> a >> b;
    v[a].push_back(b);
    inv[b].push_back(a);
  }
  
  queue<int> que;
  vector<int> sz(n+5);
  int root;
  
  for(int i=0; i<n; i++){
    sz[i+1]=inv[i+1].size();
    if(inv[i+1].empty()){		//root?
      que.push(i+1);
      root=i+1;
    }
  }
  
  while(!que.empty()){
    int x = que.front(); que.pop();
    for(auto to:v[x]){
      dist[to] = max(dist[x]+1, dist[to]);
      sz[to]--;
      if(sz[to] == 0){que.push(to);}			//second oya
    }
  }
  
  dfs(root,0);  
  for(int i=1; i<=n; i++){
    cout << par[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 17664
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    string S;
    cin >> S;
    int count = 0;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0 && S[i] == '0')count++;
        else if(i % 2 == 1 && S[i] == '1')count++;
    }

    cout << min(count, ((int)S.size() - count)) << endl;

    return 0;
}

Measured memory_bytes: 512
;;(declaim (optimize (speed 0) (safety 3) (debug 3)))
#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))
(declaim (optimize (speed 3) (safety 0) (debug 0)))

(princ (loop for i fixnum from 1 to (read)
	     when (and (/= 0 (mod i 3))
		       (/= 0 (mod i 5))) summing i))



Measured memory_bytes: 24552
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import math
import collections
N = int(input())
tmp = prime_factorize(N)
C = collections.Counter(tmp)
S = set()
for k, v in C.items():
    for i in range(v):
        S.add(k**(i+1))
ans = 0
for s in sorted(S):
    if N%s == 0:
        N = N//s
        ans += 1
print(ans)


Measured memory_bytes: 68008
from fractions import gcd


def lcm(c, d):
    return (c * d) // gcd(c, d)


def main():
    a, b, c, d = map(int, input().split())
    c_num = (b//c-(a-1)//c)
    d_num = (b//d-(a-1)//d)
    cd_num = (b//lcm(c, d)-(a-1)//lcm(c, d))
    ans = b-a+1-c_num-d_num+cd_num
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5076
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

typedef pair<int, int> P;
 
bool pairCompare(const P firstElof, const P secondElof)
{
    return firstElof.second > secondElof.second;
}

int main() {
  int n;
  scanf("%d", &n);
  P p1[100010], p2[100010];
  for (int i = 0; i < 100010; i++) {
    p1[i].first = 0;
    p1[i].second = 0;
    p2[i].first = 0;
    p2[i].second = 0;
  }
  for (int i = 0; i < n/2; i++) {
    int i1, i2;
    scanf("%d %d", &i1, &i2);
    p1[i1].first = i1;
    p2[i2].first = i2;
    p1[i1].second += 1;
    p2[i2].second += 1;
  }
  sort(p1, p1+100000, pairCompare);
  sort(p2, p2+100000, pairCompare);
  int ans = 0;
  if (p1[0].first == p2[0].first) {
    ans += n - max(p1[0].second+p2[1].second, p1[1].second+p2[0].second);
  } else {
    ans += n - (p1[0].second+p2[0].second);
  }
  //printf("%d %d %d", a[0], a[1], a[2]);
  //printf("%d %d %d %d\n", p1[0].first, p1[1].first, p1[0].second, p1[1].second);
  //printf("%d %d %d %d\n", p2[0].first, p2[1].first, p2[0].second, p2[1].second);
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
signed main(){
    int n;
    cin>>n;
    while(n>=1000){
        n=n%1000;
    }
    if(n==0){
        cout<<"0"<<"\n";
    }else{
        cout<<1000-n<<"\n";
    }
    return(0);
}

Measured memory_bytes: 3592
/**akshaykumar99**/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
template<typename T> using id_setp = tree<pair<T,T>,null_type,less<pair<T,T>>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=2e5+1;
 
typedef long long ll;
typedef long double ld;
 
int main()
{
    IOS();
   
    ll a,b,k;
    cin>>a>>b>>k;
    ll z=min(a,k);
    k-=min(a,k);
    a-=z;
    b-=min(b,k);
    cout<<a<<' '<<b<<'\n';
 
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    string res = "Yes";
    if(n%2!=0) res = "No";
    else{
        FOR(i,0,n/2){
            if(s[i] != s[i + n/2]) res = "No";
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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; }

int res = INF;
int n, a, b, c;
vector<int> take;

void dfs(vector<vector<int>> list, int cnt, int cost){
    if(cnt == n){
        if(list[0].size()==0 || list[1].size()==0 || list[2].size()== 0) return;
        int len[3] = {0, 0, 0};
        rep(i, 3){
            rep(j, list[i].size()){
                len[i] += take[list[i][j]];
            }
        }
        int sum[6];
        sum[0] = abs(len[0]-a)+abs(len[1]-b)+abs(len[2]-c);
        sum[1] = abs(len[0]-a)+abs(len[1]-c)+abs(len[2]-b);
        sum[2] = abs(len[0]-b)+abs(len[1]-a)+abs(len[2]-c);
        sum[3] = abs(len[0]-b)+abs(len[1]-c)+abs(len[2]-a);
        sum[4] = abs(len[0]-c)+abs(len[1]-a)+abs(len[2]-b);
        sum[5] = abs(len[0]-c)+abs(len[1]-b)+abs(len[2]-a);
        rep(i, 6) chmin(res, sum[i] + cost);


    }else{
        dfs(list, cnt + 1, cost);
        rep(i, 3){
            list[i].push_back(cnt);
            dfs(list, cnt + 1, cost + 10);
            list[i].pop_back();
        }
    }
}

int main() {
    cin >> n >> a >> b >> c;
    take.resize(n);
    rep(i, n) cin >> take[i];
    vector<vector<int>> list(3, vector<int>());

    dfs(list, 0, -30);
    
    cout << res << ln;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,x,cou=0;
  int i,j,k;
  
  while(1){
    scanf("%d %d",&n,&x);
    if(n==0 && x==0)break;

  for(i=1;i<=n-2;i++){
    for(j=i+1;j<=n-1;j++){
      for(k=j+1;k<=n;k++){
	if((i+j+k)==x)cou++;
      }
     
    }
  } printf("%d\n",cou);
    cou=0;
  
  }
  return 0;
}

Measured memory_bytes: 600
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, d = tin()
	#s = input()
	ret = 0
	for i in range(n):
		x, y = tin()
		if x*x + y*y <= d*d:
			ret += 1
	print(ret)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main(void){
	int n; cin >> n;
	long long a,b,c,d;cin >> a >> b >> c >> d;
	for(int i = 0;i <= n-1;i++){
	    long long x = b - a;
	    long long lb = i*(c+d) - (n-1)*d;
	    long long ub = i*(c+d) - (n-1)*c;
	    if(lb <= x && x <= ub){
	        cout << "YES" << endl;
	        return 0;
	    }
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
fact = [1]
inv_fact = [1]
MOD = 10**9+7
temp = 1
for i in range(1,5*10**5+2):
    temp *= i
    temp %= MOD
    fact += [temp]
    inv_fact += [pow(temp,MOD-2,MOD)]

def bino(a,b):
    MOD = 10**9+7
    up = fact[a]
    down = (inv_fact[a-b]*inv_fact[b])%MOD
    return (up*down)%MOD

def find(N,M):
    MOD = 10**9+7
    temp1 = fact[M]*pow(inv_fact[M-N],2,MOD)
    temp2 = fact[M]
    for k in range(1,N+1):
        temp2 += (-1)**k*bino(N,k)*fact[M-k]
        temp2 %= MOD
    
    ans = (temp2*temp1)%MOD
    return ans

N,M = list(map(int,input().strip().split()))

print(find(N,M))
    


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

#define ll long long

int main(){
    ll n,f=0;
	cin >> n;
	for(int i=1;i<=n;i++){
	   if(i%15!=0 && i%5!=0 && i%3!=0)
	   f+=i;
	}
	cout<<f;
	
	return 0;
}

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

int main(){

 
    int n;
    cin>>n;
    int ans=0;
    int init=-1;
    while(n--){
        int x;
        cin>>x;
        if(x>=init){
            init=x;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define INF 1000000000
using namespace::std;


long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int a) {
	if (a < 0) {
		return -a;
	}
	return a;
}

int N, M,F,K, W,L,sa,X[2000000], Y[2000000], Z[2000000], ans, k[5],B,C,n[2];
string s, t[100];
bool a, b, c;
int main() {
	cin >> N>>M;
	if (N > M) {
		cout << N-1 << endl;
	}
	else {

		cout << N<< endl;
	}
	
	return 0;
}




Measured memory_bytes: 256
/**
 * Author: Behradm
 * Created: 14-04-2020 19:39:07
**/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define LOCAL

#ifdef LOCAL
	#define debugi(x) cerr << "{" << #x << "}: " << (x) << '\n'
	#define debug(v, begin, end) cerr << "{ | "; for(auto i = begin; i < end; i++){cerr << #v << "[" << i << "]: " << v[i] << " | ";} cerr << " }\n"
	#define debugp(a, b) cerr << "\n{ " << a << " " << b << " }\n"
#else
	#define debugi(x) 42
	#define debug(v, begin, end) 42
	#define debugp(a, b) 42 
#endif

const int maxn = 100+1;
int a[maxn][maxn];
bool mark[maxn];

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout.precision(6);
	cout << fixed;
	int n = 3;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
		}
	}

	cin >> n;
	for(int t = 0; t < n; t++){
		int b;
		cin >> b;
		mark[b] = true;
	}

	if(mark[a[0][0]] && mark[a[1][1]] && mark[a[2][2]]){
		cout << "Yes" << '\n';
		return 0;
	}
	if(mark[a[0][2]] && mark[a[1][1]] && mark[a[2][0]]){
		cout << "Yes" << '\n';
		return 0;
	}
	if(mark[a[0][0]] && mark[a[0][1]] && mark[a[0][2]]){
		cout << "Yes" << '\n';
		return 0;
	}
	if(mark[a[1][0]] && mark[a[1][1]] && mark[a[1][2]]){
		cout << "Yes" << '\n';
		return 0;
	}
	if(mark[a[2][0]] && mark[a[2][1]] && mark[a[2][2]]){
		cout << "Yes" << '\n';
		return 0;
	}
	if(mark[a[0][0]] && mark[a[1][0]] && mark[a[2][0]]){
		cout << "Yes" << '\n';
		return 0;
	}
	if(mark[a[0][1]] && mark[a[1][1]] && mark[a[2][1]]){
		cout << "Yes" << '\n';
		return 0;
	}
	if(mark[a[0][2]] && mark[a[1][2]] && mark[a[2][2]]){
		cout << "Yes" << '\n';
		return 0;
	}

	cout << "No\n";
	return 0;
}



Measured memory_bytes: 256
n = int(input())
a_b = []
b_sum = 0
for i in range(n):
    ai, bi = map(int, input().split())
    a_b.append(ai+bi)
    b_sum += bi
a_b.sort(reverse=True)
ans = 0
for i in range(len(a_b)):
    if i%2==0:
        ans += a_b[i]
print(ans-b_sum)


Measured memory_bytes: 7380
#template
def inputlist(): return [int(k) for k in input().split()]
#template
X,Y,Z,K = inputlist()
A = inputlist()
B = inputlist()
C = inputlist()
li = []
for i in range(X):
    for j in range(Y):
        li.append(A[i]+B[j])
li.sort(reverse=True)
lis = []
lit=[]
for i in range(min(X*Y,K)):
    lis.append(li[i])
for i in range(min(X*Y,K)):
    for j in range(Z):
        lit.append(lis[i]+C[j])
lit.sort(reverse=True)
for i in range(K):
    print(lit[i])

Measured memory_bytes: 147900
while True:
    i = input()
    if i == "0 0":
        break
    else:
        i_list = i.split()
        int_list = []
        int_list.append(int(i_list[0]))
        int_list.append(int(i_list[1]))
        int_list.sort()
        print(int_list[0],int_list[1])

Measured memory_bytes: 7540
#include<iostream>
#include <algorithm>
#include <cstdlib>
#define INF 1<<30
using namespace std;
int main(){
  for(;;){
    int m;
    cin >> m;
    if(m==0){
      break;
    }
    pair<int, int> s[m];
    for(int i=0; i<m; i++){
      int temp, temp2;
      cin >> temp >> temp2;
      s[i] = make_pair(temp, temp2);
    }
    int dx, dy, n;
    cin >> n;
    pair<int, int> d[n];
    for(int i=0; i<n; i++){
      int temp, temp2;
      cin >> temp >> temp2;
      d[i] = make_pair(temp, temp2);
    }
    sort(d,d+n);
    pair<int, int> l[m];
    for(int i=0; i<n; i++){
      dx = d[i].first-s[0].first;
      dy = d[i].second-s[0].second;
      for(int j=0; j<m; j++){
        l[j].first =  s[j].first + dx;
        l[j].second = s[j].second + dy;
        if(binary_search(d, d+n, l[j])==0){
          break;
        }
        if(binary_search(d, d+n, l[m-1])==1){
          cout << dx << " " << dy << endl;
          l[m-1]= make_pair(INF, INF);

        }
      }
    }

  }

}



Measured memory_bytes: 3072
# coding: utf-8


II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N = II()
    if N == 0: return 0
    neg = N < 0
    if neg: N = -N
    bn = bin(N)[2:]
    bl = [int(c) for c in bn[::-1]]
    bl.extend([0] * 10)

    begin = 0 if neg else 1
    for i in range(begin, len(bl), 2):
        if bl[i]:
            bl[i + 1] += 1
        for j in range(i + 1, len(bl)):
            if bl[j] == 2:
                bl[j] = 0
                bl[j + 1] += 1
            else:
                break
    while bl[-1] == 0: bl.pop()
    return "".join(map(str, bl[::-1]))


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 3064
program distance
  implicit none
  integer :: n, i, m = 0
  integer(8) :: d, x, y
  read(*,*) n, d
  d = d * d
  do i = 1, n
    read(*,*) x, y
    if (x * x + y * y <= d) m = m + 1
  end do
  write(*,'(i0)') m
end program distance

Measured memory_bytes: 2896
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,s,ans=0;
	scanf("%d%d",&k,&s);
	for(int i=0;i<=k;i++)
	for(int j=0;j<=k;j++)
	if(s-i-j<=k&&s-i-j>=0) ans++;
	printf("%d\n",ans);
    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e18;

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

  int N, K;
  cin >> N >> K;
  VL xs(N);
  cin >> xs;

  VL dp(N, INF);
  dp[0] = 0;

  REP(i,N){
    FOR(k,1,K+1)
      if(i+k<N) mini(dp[i+k], dp[i] + abs(xs[i+k] - xs[i]));
  }

  cout << dp.back() << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main()
{
    string s;
    cin >> s;
    int n=s.size();
    int ans[s.size()];
    rep(i,n)ans[i]=0;
    vector<int>RL;
    int len=0;

    rep(i,n){
        len++;
        if(s[i]=='R'&&s[i+1]=='L'){
            RL.push_back(i);
            ans[RL[RL.size()-1]]+=(len+1)/2;
            ans[RL[RL.size()-1]+1]+=len-(len+1)/2;
            len=0;
        }

        if((s[i]=='L'&&i+1<n&&s[i+1]=='R')||i==n-1){
            ans[RL[RL.size()-1]]+=len-(len+1)/2;
            ans[RL[RL.size()-1]+1]+=(len+1)/2;
            len=0;
        }
    }
    rep(i,n)cout << ans[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 1280
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdlib;

immutable int INF = 1 << 29;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto cnt = new int[](N);
    foreach (_; 0..K) {
        auto D = readln.chomp.to!int;
        auto A = readln.split.map!(to!int).array;
        foreach (a; A) cnt[a-1] += 1;
    }

    cnt.map!(a => a == 0).sum.writeln;
}


Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

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

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

    long long n,m;
    string s,t;
    cin>>n>>m>>s>>t;
    long long num=n*m/gcd(n,m);
    long long posn=num/n,posm=num/m;
    bool f=true;
    for(int i=0;i<gcd(n,m);i++){
        if(s[posm*i]!=t[posn*i])f=false;
    }

    if(f)cout<<num<<endl;
    else cout<<-1<<endl;

}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
typedef long long LL;
const LL MAX=1e17;
const LL N=2100;
struct qq
{
    LL x,y,z,z1,last;
}e[N*10];LL num,last[N];
void init (LL x,LL y,LL z,LL z1)
{
    num++;
    e[num].x=x;e[num].y=y;e[num].z=z;e[num].z1=z1;
    e[num].last=last[x];
    last[x]=num;
    swap(x,y);z=0;z1=-z1;
    num++;
    e[num].x=x;e[num].y=y;e[num].z=z;e[num].z1=z1;
    e[num].last=last[x];
    last[x]=num;
}
LL from[N];
LL f[N];
bool in[N];
LL st,ed;
bool SPFA ()
{
    for (LL u=1;u<=ed;u++) from[u]=-1,f[u]=-MAX,in[u]=false;
    queue<int> q;q.push(st);
    f[st]=0;in[st]=true;
    while (!q.empty())
    {
        LL x=q.front();q.pop();
        for (LL u=last[x];u!=-1;u=e[u].last)
        {
            LL y=e[u].y;
            if (e[u].z>0&&f[y]<f[x]+e[u].z1)
            {
                f[y]=f[x]+e[u].z1;
                from[y]=u;
                if (in[y]==false)
                {
                    in[y]=true;
                    q.push(y);
                }
                /*
                in[x]=true;
                q.push(y);
                from[y]=u;
                f[y]=f[x]+e[u].z1;
                if(e[u].z>0&&f[y]<f[x]+e[u].z1)
                {
                	LL y=e[u].y;
                }
                */
            }
        }
        in[x]=false;
    }
    return from[ed]!=-1;
}
LL ans=0;
void lalal ()
{
    LL x=from[ed],t=MAX;
    while (x!=-1)	{t=min(t,e[x].z);x=from[e[x].x];}
    x=from[ed];
    while (x!=-1)	{ans=ans+t*e[x].z1;e[x].z-=t;e[x^1].z+=t;x=from[e[x].x];}
    return ;
}
int main()
{
	num=1;memset(last,-1,sizeof(last));
	LL n; 
	scanf("%lld",&n);st=2*n+10+1;ed=st+1;
	LL cnt=0;
	for (LL u=1;u<=n;u++)
	{
		LL x,y,c;
		scanf("%lld%lld%lld",&x,&y,&c);
		init(st,u,c,0);
		init(u,2*n+1,MAX,x+y);
		init(u,2*n+2,MAX,x-y);
		init(u,2*n+3,MAX,-x+y);
		init(u,2*n+4,MAX,-x-y);
	}
	for (LL u=1;u<=n;u++)
	{
		LL x,y,c;
		scanf("%lld%lld%lld",&x,&y,&c);
		init(u+n,ed,c,0);
		init(2*n+1+4,u+n,MAX,x+y);
		init(2*n+2+4,u+n,MAX,x-y);
		init(2*n+3+4,u+n,MAX,-x+y);
		init(2*n+4+4,u+n,MAX,-x-y);
	}
	init(2*n+1,2*n+4+4,MAX,0);
	init(2*n+2,2*n+3+4,MAX,0);
	init(2*n+3,2*n+2+4,MAX,0);
	init(2*n+4,2*n+1+4,MAX,0);
	while (SPFA()) lalal();
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int graph[101][101],d[101],f[101],t=1;
void dfs(int);

int main(){
  int j,i,n,k,u,id;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
      scanf("%d%d",&u,&k);
      for(j=1;j<=k;j++) scanf("%d",&graph[i][j]);
      graph[i][j]=-1;
    }
  for(i=1;i<=n;i++) dfs(i);
  for(id=1;id<=n;id++) printf("%d %d %d\n",id,d[id],f[id]);
  return 0;
}

void dfs(int i){
  int j;
  if(d[i]==0){
      d[i]=t;
      t++;
      for(j=1;graph[i][j]!=-1;j++) if(d[graph[i][j]]==0) dfs(graph[i][j]);
      f[i]=t;
      t++;
    }
}


Measured memory_bytes: 2004
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main () {
	cin >> a >> b;
	if (a==1) a+=13;
	if (b==1) b+=13;
	if (a>b){
		cout << "Alice" << endl;
	} else if (a<b) {
		cout << "Bob" << endl;
	} else{
		cout << "Draw" << endl;
	}
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

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

	scanf("%lld%lld%lld", &a, &b, &c);
	if (c-(a+b) >= 0 && a*b*4 < (c - (a + b)) * (c - (a + b)))
		printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
import sys
from collections import deque

def solve(n: int, a: "List[int]"):
    ## 左右左と追加していく
    li = deque()

    for i in range(n):
        if i%2!=n%2:
            li.appendleft(a[i])
        else:
            li.append(a[i])
    
    print(" ".join(map(str,list(li))))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)

if __name__ == '__main__':
    main()


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

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

int isprime[1299710];

int main() {
  int i,j,k;
  memset(isprime, 0, sizeof(isprime));
  for(i=4; i<1299710; i+=2) isprime[i] = 1;

  for(i=3; i<=1141; i+=2)
    if(isprime[i] == 0)
      for(j=2; i*j<1299710; ++j)
	isprime[i*j] = 1;

  int in;
  while(cin>>in, in) {
    if(isprime[in] == 0) {
      cout<<0<<endl;
      continue;
    }

    int up=0,low=0;
    while(isprime[in+up] == 1) up++;
    while(isprime[in-low] == 1) {
      low++;
    }
    cout<<up+low<<endl;
  }
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000






int main(){
	vector<int>a;
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d%d", &n,&k);
	f(i, n){
		scanf("%d", &x);
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	ans = 1000000010;
	f(i, n - k + 1){
		ans = min(ans, a[i + k - 1] - a[i]);
	}

	printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)

const int INF = 100000000;

using namespace std;


int main() {
	int a, b;
	cin >> a >> b;
	if (a + b > 23)cout << a + b - 24 << endl;
	else cout << a + b << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	cin>>n;
	while(n--){
		int a,b,c;
		cin>>a>>b>>c;
		int co=0;
		while(a&&b&&c){
			co++;
			a--;b--;c--;
		}
		while(a>1&&b){
			co++;
			a-=2;b--;
		}
		while(a>2){
			co++;
			a-=3;
		}
		cout<<co<<endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <string.h>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, r;
	cin >> n >> r;
	if (n < 10) {
		r += 100 * (10 - n);
	}
	cout << r;
}



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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int q; cin >> q;
    bool dir = 0;
    string fr, ba;
    while (q--) {
        int t; cin >> t;
        if (t == 1) dir = !dir;
        else {
            int f; char c; cin >> f >> c;
            if (dir) f = 3 - f;
            if (f == 1) {
                fr += c;
            } else {
                ba += c;
            }
        }
    }
    if (dir) {
        reverse(s.begin(), s.end());
        swap(fr, ba);
    }
    reverse(fr.begin(), fr.end());
    cout << fr << s << ba << "\n";
    return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	string S, T;
	cin >> S >> T;
	cout << T << S << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]

maximum = max(A)
count_max = A.count(maximum)
if count_max > 1:
    for i in range(N):
        print(maximum)
else:
    for i in range(N):
        if A[i] != maximum:
            print(maximum)
        else:
            num = A[i]
            A[i] = 0
            print(max(A))
            A[i] = num


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

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

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

  int ans = 1e9;
  for(int i = 0; i <= p[0]; ++i) {
    auto v = p;
    v[0] -= i;

    int res = i;
    for(int j = 0; j < n - 1; ++j) {
      if(v[j] > 0) {
        res += v[j] * 2;
        v[j + 1] -= v[j];
      }
    }

    if(v[n - 1] > 0) res += v[n - 1];
    ans = min(ans, res);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3248
a = input()
if a == 'SUN':
    print(7)
elif a == 'MON':
    print(6)
elif a == 'TUE':
    print(5)
elif a == 'WED':
    print(4)
elif a == 'THU':
    print(3)
elif a == 'FRI':
    print(2)
elif a == 'SAT':
    print(1)


Measured memory_bytes: 2940
import java.util.Scanner;

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

        String O = sc.next();
        String E = sc.next();

        String ans = "";
        for(int i=0;i<O.length();i++){
            ans += O.charAt(i);
            if(i<=E.length()-1){
                ans += E.charAt(i);
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21716