akhauriyash/Code-Regression huggingface dataset:
people, meals = map(int, input().split(" "))
count = {i:0 for i in range(1, meals+1)}

for person in range(people):
    meals = input().split(" ")
    number_liked = int(meals[0])
    meals_liked = [int(m) for m in meals[1:]]
    for i in meals_liked:
        count[i] += 1
ans = 0
for k, v in count.items():
    if people==v:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#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;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		double dp[110][110]={0};
		double in[110][110]={0};
		rep(i,n)rep(j,n)cin>>in[i][j];
		rep(i,110)dp[0][i]=1;
		loop(i,1,m){
			rep(j,n)rep(k,n)dp[i][k]=max(dp[i][k],dp[i-1][j]*in[j][k]);
		}
		double ma=-1;
		rep(i,n)ma=max(ma,dp[m-1][i]);
		printf("%.2f\n",ma);
		
	}
}

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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>=1 && a<=9 && b>=1 && b<=9)
    {
        cout<<a*b<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    int tmp = d;
    while (tmp < l) {
        tmp += d;
    }
    
    int cnt = 1;
    if (tmp > r) {
        cnt = 0;
    }

    while (tmp < r) {
        tmp += d;
        cnt++;
        //cout << tmp << endl;
    }
    if (tmp > r && cnt > 0) {
        cnt--;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3592
N, K = map(int, input().split())
x = list(map(int, input().split()))

if 0 in x:
    K -= 1
    x.remove(0)

if K == 0:
    ans = 0
else: # Kが1以上
    ans = 10**9
    for i in range(N-K+1):
        left = i # 0からN-K
        right = i+K-1 # K-1からN-1
        ans = min(ans, x[right] - x[left] + min(abs(x[right]), abs(x[left])))

print(ans)

Measured memory_bytes: 14568
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    if(n==10||n==100||n==1000||n==10000||n==100000)printf("%d\n",10);
    else printf("%d\n",n/10000+n/1000%10+n/100%10+n/10%10+n%10);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main() {
    char n[999];
    scanf("%s",n);
    if(n[strlen(n) - 1] == '2' || n[strlen(n) - 1] == '4' || n[strlen(n) - 1] == '5' || n[strlen(n) - 1] == '7' || n[strlen(n) - 1] == '9') {
        printf("hon");
    } else if(n[strlen(n) - 1] == '0' || n[strlen(n) - 1] == '1' || n[strlen(n) - 1] == '6' || n[strlen(n) - 1] == '8') {
        printf("pon");
    } else if(n[strlen(n) - 1] == '3') {
        printf("bon");
    }
}

Measured memory_bytes: 1692
#include <iostream>
#include <stack>

using namespace std;

int main() {
    stack<int> stack;

    string s;
    while (cin >> s) {
        if (s == "+" || s == "*" || s == "-") {
            int x = stack.top();
            stack.pop();
            int y = stack.top();
            stack.pop();

            if (s == "+") {
                stack.push(x + y);
            } else if (s == "-") {
                stack.push(y - x);
            } else {
                stack.push(x * y);
            }
        } else {
            int n = stoi(s);
            stack.push(n);
        }
    }
    int r = stack.top();
    cout << r << endl;
}

Measured memory_bytes: 3188
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> a = new ArrayList<>();
        int s = sc.nextInt();
        a.add(s);
        while (true) {
            if (s % 2 == 0) {
                s = s / 2;
                a.add(s);
            } else {
                s = 3 * s + 1;
                a.add(s);
            }
            for (int i = 0; i < a.size() - 1; i++) {
                for (int j = i + 1; j < a.size(); j++) {
                    if (a.get(i) == a.get(j)) {
                        System.out.println(j + 1);
                        return;
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 24276
#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<<"Case "<<x<<": "
#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*/
	ll r;
	cin>>r;
	cout<<3*r*r<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
ans = 0

def dfs(s):
    global ans
    if int(s) > N:
        return

    if s.count('7') and s.count('5') and s.count('3'):
        ans += 1
    
    dfs(s + '7')
    dfs(s + '5')
    dfs(s + '3')

dfs('0')

print(ans)

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

int main (){

  int a,b;

  cin >>  a >> b;
  
  if(a<b) cout << "a < b"  <<'\n';

  else if(a>b) cout << "a > b" <<'\n';

  else if (a=b) cout << "a == b" <<'\n';


  return 0;

}

Measured memory_bytes: 1124
import math
import collections

N = input()
nums = list(map(int, input().split()))
counter = collections.Counter(nums)
patterns = {}
for k, v in counter.items():
    patterns[k] = math.comb(v, 2)

baseline = sum(v for v in patterns.values())

cache = {}
for n in nums:
    if n in cache:
        print(cache[n])
    else:
        val = baseline - patterns[n] + math.comb(counter[n] - 1, 2)
        cache[n] = val
        print(val)

Measured memory_bytes: 41612
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int a[10001];
int f(int x)
{
	int ans=0,k=1;
	for(int i=1;1;i++)
	{
		k*=2;
		if(x%k)
			break;
		ans++;
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	int n,b;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>b;
		if(b%2==0)
			a[i]=f(b);
	}
	long long s=0;
	for(int i=1;i<=n;i++)
		s+=a[i];
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

pl dp[60][60];
int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	vector<ll> v(n);
	rep(i,n)cin>>v[i];
	rep(i,n){
		rep(j,n){
			dp[i][j].fi=-1;
		}
	}
	dp[0][0].fi=0;
	dp[0][0].se=1;
	rep(i,n){
		rep(j,n){
			//何も追加しない場合
			if(dp[i+1][j].fi<dp[i][j].fi){
				dp[i+1][j].se=dp[i][j].se;
				dp[i+1][j].fi=dp[i][j].fi;
			}else if(dp[i+1][j].fi==dp[i][j].fi){
				dp[i+1][j].se+=dp[i][j].se;
			}
			//追加する場合
			// dp[i+1][j+1]=max(dp[i][j]+v[i],dp[i+1][j+1]);
			if(dp[i+1][j+1].fi<dp[i][j].fi+v[i]){
				dp[i+1][j+1].se=dp[i][j].se;
				dp[i+1][j+1].fi=dp[i][j].fi+v[i];
			}else if(dp[i+1][j+1].fi==dp[i][j].fi+v[i]){
				dp[i+1][j+1].se+=dp[i][j].se;
			}
		}
	}

	long double ans=-1;
	ll num=0;
	FOR(i,a,b+1){
		if(ans<(long double)dp[n][i].fi/i){
			ans=(long double)dp[n][i].fi/i;
			num=dp[n][i].se;
		}else if((int)((ans-(long double)dp[n][i].fi/i)*1000000)==0){
			num+=dp[n][i].se;
		}
	}

	printf("%.10Lf\n", ans);
	cout<<num<<endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    k, n = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]

    ma = A[0] + k - A[n - 1]
    mai = n - 1
    for i in range(n - 1):
        if A[i + 1] - A[i] > ma:
            ma = A[i + 1] - A[i]
            mai = i

    if mai == n - 1:
        ans = A[mai] - A[0]
    else:
        ans = A[mai] + k - A[mai + 1]

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 77388
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int n = s.length;
		char zero = '0';
		char one = '1';
		// 0101...
		int t1 = 0;
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				if (s[i] != zero) {
					t1++;
				}
			} else {
				if (s[i] != one) {
					t1++;
				}
			}
		}
		int t2 = 0;
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				if (s[i] != one) {
					t2++;
				}
			} else {
				if (s[i] != zero) {
					t2++;
				}
			}
		}
		System.out.println(Math.min(t1, t2));
	}
}

 
 

 
 
 
 


Measured memory_bytes: 39652
#abc161d
from collections import deque
k=int(raw_input())
d=deque([1,2,3,4,5,6,7,8,9])
for i in range(k):
 x=d.popleft()
 if x%10!=0:
  d.append(10*x+x%10-1)
 d.append(10*x+x%10)
 if x%10!=9:
  d.append(10*x+x%10+1)
print x


Measured memory_bytes: 12152
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  string s,t;
  cin >> s >> t;
  
  if(s.size() < t.size()) cout << "LESS" << endl;
  if(s.size() > t.size()) cout << "GREATER" << endl;
  

  if(s.size() == t.size()){
    bool flag = true;
    REP(i,s.size()){
      if(s[i] < t[i]){
        cout << "LESS" << endl;
        flag = false;
        break;
      }
      if(s[i] > t[i]){
        cout << "GREATER" << endl;
        flag = false;
        break;
      }
    }
    if(flag) cout << "EQUAL" << endl;
  }

  return 0;
}

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

n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
dif = sorted(list(Counter(d).items()))
check = sorted(list(Counter(t).items()))
cnt = 0
len_check = len(check)
for i, j in dif:
    if i == check[cnt][0]:
        if j >= check[cnt][1]:
            cnt += 1
        else:
            print('NO')
            exit()
    if cnt == len_check:
        print('YES')
        exit()
print('NO')


Measured memory_bytes: 71252
#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 ordered_set tree < pairs ,  null_type , greater<pairs>,  rb_tree_tag ,  tree_order_statistics_node_update > 
#define ll long long
#define lld long double
#define vc vector<ll>
const ll MOD=(1e9 +7);
typedef pair<ll,ll>pairs;
ll power(ll a, ll b){ll res=1;a=a%MOD;while(b>0){if(b&1){res=(res*a)%MOD;b--;}a=(a*a)%MOD;b>>=1;}
    return res;}

int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	ll t,n,i,j,k,l,f;
	ll ac=0,wa=0,tle=0,re=0;
	cin>>n;string s;
	for(i=1;i<=n;i++)
	{
	    cin>>s;
	    if(s=="WA")wa++;
	    else if(s=="TLE")tle++;
	    else if(s=="AC")ac++;
	    else re++;
	}
	cout<<"AC x "<<ac<<"\n";
	cout<<"WA x "<<wa<<"\n";
	cout<<"TLE x "<<tle<<"\n";
	cout<<"RE x "<<re<<"\n";
	return 0;
}

Measured memory_bytes: 3656
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      aa: [usize1; n],
    }

    let mut direct = vec![0; m];
    let mut imos = vec![0i64; m*2];

    for i in 0..n-1 {
        let a = aa[i];
        let mut b = aa[i+1];
        if a == b {
            continue;
        }
        if b < a {
            b += m;
        }

        imos[a+1] += 1;
        imos[b] -= 1;
        direct[b%m] += b - a - 1;
    }

    let mut count = vec![0; m];
    let mut cur = 0;
    for i in 0..2*m {
        cur += imos[i];
        count[i%m] += cur;
    }

    let mut score = 0;
    let x = 0;
    for i in 0..n-1 {
        let a = aa[i];
        let b = aa[i+1];
        score += min((b + m - a) % m, (b + m - x) % m + 1);
    }
    let mut ans = score;

    for x in 1..m {
        score += direct[x-1];
        score -= count[x-1] as usize;
        ans = min(ans, score);
    }
    puts!("{}\n", ans);
}


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

using lint = long long;

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

    lint ans = 0, sum = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] > 0) {
            sum += A[i];
        } else if (A[i] == 0) {
            ans += sum/2;
            sum = 0;
        }
    }

    ans += sum/2;

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

Measured memory_bytes: 640
import java.util.*;

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

	public Main() {
		AOJ2151 obj = new AOJ2151();
		while(true){
			int n = in.nextInt(),m = in.nextInt(),l = in.nextInt();
			if(n+m+l==0)break;
			new AOJ2151().doIt(n, m, l);
		}
	}
	class AOJ2151{
		int n,m,l;
		int cost[][];
		int teki[][];
		int result;
		void dikstra(int s){
			PriorityQueue<State> q = new PriorityQueue<State>();
			int[][] kyori = new int[n][l+1];
			int INF = Integer.MAX_VALUE/2;
			for(int i=0;i<n;i++)Arrays.fill(kyori[i], INF);
			kyori[s][l] = 0;
			q.add(new State(s, l, 0));
			while(q.size()>0){
//				if(q.size()>1000000){
//					System.out.println("*");return;
//				}
				State now = q.remove();
//				System.out.println(now);
				int v = now.v;
				if(v==n-1){
					result = now.teki;return;
				}
				for(int i=0;i<n;i++)if(cost[i][v]>0){
					if(i==v)continue;
					int t = teki[i][v];
					if(now.kin < cost[i][v]){//敵の数が超えるとき
						if(kyori[i][now.kin] <= now.teki + t){
							//                          System.out.println(i+" "+kyori[i][now.kin] +" "+ (now.teki+t));
							continue;
						}
						kyori[i][now.kin] = now.teki + t;
						q.add(new State(i, now.kin, now.teki+t));
					}else{//敵の数が超えない。 どっちもやる。
						int nkin = now.kin - cost[i][v];
						if(kyori[i][nkin] > now.teki){
							kyori[i][nkin] = now.teki;
							q.add(new State(i, nkin, now.teki));
						}
						if(kyori[i][now.kin] > now.teki + teki[i][v]){
							kyori[i][now.kin] = now.teki + teki[i][v];
							q.add(new State(i, now.kin, now.teki+teki[i][v]));
						}
					}
					//                  System.out.println(q);
				}
			}
		}
		void doIt(int n,int m,int l){//宿場 道の数 護衛予算(距離1で1円)
			this.n = n;this.m = m;this.l = l;
			cost = new int[n][n];
			teki = new int[n][n];
			for(int i=0;i<m;i++){
				int a = in.nextInt()-1;
				int b = in.nextInt()-1;
				cost[a][b] = cost[b][a] = in.nextInt();
				teki[a][b] = teki[b][a] = in.nextInt();
			}
			//          for(int i=0;i<n;i++){
				//              for(int s=0;s<n;s++)System.out.print(cost[i][s]+" ");
			//              System.out.println();
			//          }
			dikstra(0);
//			System.out.print("ans=");
			System.out.println(result);
		}
		class State implements Comparable<State>{
			int kin,v,teki;
			public State(int v,int kin,int teki) {
				this.v = v;
				this.kin = kin;
				this.teki = teki;
			}
			public int compareTo(State o){
				if(this.teki<o.teki)return -1;
				else if(this.teki > o.teki)return 1;
				return 0;
			}
			public String toString(){
				return v+" "+kin+" "+teki;
			}
		}
	}
}

Measured memory_bytes: 61052
import sys
input = sys.stdin.readline

N = int(input())
ABC = []
for _ in range(N):
  a, b, c = map(int, input().split())
  ABC.append((a, b, c))

dp = [[0] * 3 for _ in range(N)]

for day, abc in enumerate(ABC):
  for t_act in range(3):
    if (day == 0):
      dp[day][t_act] = abc[t_act]
      continue
    t_max = dp[day][t_act] # 0
    for y_act in range(3):
      if(t_act == y_act):
        continue
      happy = dp[day - 1][y_act] + abc[t_act]
      if (t_max < happy):
        t_max = happy
    
    dp[day][t_act] = t_max

print(max(dp[N - 1]))


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

#define MX 205
pair<int, int> a[MX], b[MX];
vector<int> g[MX];
int lnk[MX];
bool vis[MX];

bool dfs(int u) {
	for (int v : g[u]) {
		if (vis[v]) continue;
		vis[v] = true;
		if (lnk[v] == -1 || dfs(lnk[v])) {
			lnk[v] = u;
			return 1;
		}
	}
	return 0;
}

int main() {
	int n; scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d%d", &a[i].first, &a[i].second);
	for(int i = 0; i < n; i++) scanf("%d%d", &b[i].first, &b[i].second);
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			if(a[i].first < b[j].first && a[i].second < b[j].second) {
				g[i].push_back(j + n);
				g[j + n].push_back(i);
			}
	for(int i = n; i < n + n; i++) lnk[i] = -1;
	int res = 0;
	for(int i = 0; i < n; i++) {
		for(int j = n; j < n + n; j++) vis[j] = 0;
		res += dfs(i);
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 256
/*
	JAI JAGANNATH!
*/
//@Author : zanj0

#include<bits/stdc++.h>
using namespace std;

typedef long long int lli;

#define ff              first
#define ss              second
#define pb              push_back
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            lli x; cin>>x; while(x--)
lli ret;
class UnionFind {
public:
	lli* rank;
	lli* parent;
	lli n;
	UnionFind(lli n) {
		this->n = n;
		parent = new lli[n];
		rank = new lli[n];
		for (lli i = 0; i < n; i++) {
			parent[i] = i;
			rank[i] = 1;
		}
	}
	lli getParent(lli x) {
		if (parent[x] == x) return x;
		return parent[x] = getParent(parent[x]);
	}
	bool unite(lli a, lli b) {
		lli parA = getParent(a);
		lli parB = getParent(b);
		if (parA == parB) return false;
		if (rank[parA] >= rank[parB]) {
			rank[parA] += rank[parB];
			parent[parB] = parA;
			ret = max(ret, rank[parA]);
		} else {
			rank[parB] += rank[parA];
			parent[parA] = parB;
			ret = max(ret, rank[parB]);
		}
		return true;
	}
};
void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
void solve() {
	ret = 1;
	lli n, m;
	cin >> n >> m;
	UnionFind f(n);
	for (lli i = 0, x, y; i < m; i++) {
		cin >> x >> y;
		x--;
		y--;
		f.unite(x, y);

	}
	cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
int main(){
	int t,q,n;
	while(cin>>t>>q>>n,t){
		pair<pair<int,int > ,int >a[50];
		int c[50][10]={0};
		for(int i=0;i<50;i++)a[i].second=i+1;
		while(n--){
			int a1,a2,a3;
			string s;
			cin>>a1>>a2>>a3>>s;
			if(s[0]=='W'){
			c[a1-1][a2-1]++;
			}
			else{
				a[a1-1].first.first--;
				a[a1-1].first.second+=1200*c[a1-1][a2-1]+a3;
			}
		}
		sort(a,a+t);
		for(int i=0;i<t;i++){
			cout<<a[i].second<<' ';
			cout<<-a[i].first.first<<' ';
			cout<<a[i].first.second<<endl;
		}
	}
}

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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

typedef long long ll;

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve() {
    ll N;
    cin >> N;
    map<ll,ll> mp;
    vector<ll> v(N);
    REP(i,N) {
        ll A;
        cin >> A;
        v[i] = A;
        if (mp.count(A) == 0) mp[A] = 0;
        mp[A]++;
    }
    ll all = 0;
    for(const auto &it: mp) {
        all += (it.second*(it.second-1))/2;
    }

    map<ll,ll> ans;
    REP(i,N) {
        cout << all -((mp[v[i]])*(mp[v[i]]-1))/2 + ((mp[v[i]]-1)*(mp[v[i]]-2))/2 << endl;
    }

}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 11008
#include<stdio.h>

int main(){
	long int n,s,ten[1000],i,j,t;
	
	while(0<=scanf("%ld",&n)){
		if(n==0){
			break;
		}
		
		for(i=0;i<n;i++){
			scanf("%ld",&ten[i]);
		}
		
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				if(ten[j]<ten[i]){
					t=ten[j];
					ten[j]=ten[i];
					ten[i]=(int)t;
				}
			}
		}
		t=0;
		for(i=1;i<n-1;i++){
			t=t+ten[i];
		}
		
		printf("%ld\n",(long int)(t/(double)(n-2)));
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)

{
int j, i, H, W;
while (1){
scanf("%d%d" ,&H ,&W);
if(H == 0 && W == 0) break;
for ( j = 0; j < H; j++ ){
	for(i = 0; i<W; i++){
    printf("#");
	}

printf("\n");
}
printf("\n");
}
return 0;
}


Measured memory_bytes: 2068
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int reminbot1=a-b;
  int fin=c-reminbot1;
  if(fin>=0)
    cout<<fin;
  else
    cout<<"0";
  return 0;
}

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

int main() {
  vector<string> s={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string a;
  cin >>a;
  int k=7;
  int i=0;
  for(int j=0; i<7;j++){
    if(a==s.at(j)){
      break;
    }
    else{
      i++;
    }
  }
  cout <<k-i <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;


long long lucas(int n)
{
    long long l[n];
    l[0]=2;
    l[1]=1;
    if(n==1) return l[1]; 
    for(int i=2;i<=n;++i)
    {
        l[i]=l[i-1]+l[i-2];
    }
    return l[n];
}

int main()
{
    int n;
    long long ans;
    cin >> n;
    ans = lucas(n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;




int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

bool canMatch(string a, string b, int index) {
  for (int i = 0; index + i < a.size() && i < b.size(); ++i) {
    if (a[index + i] == '?' or b[i] == '?') {
      continue;
    }
    if (a[index + i] != b[i]) {
      return false;
    }
  }
  return true;
}

int solve(string a, string b, string c) {
  int sum = a.size() + b.size() + c.size();
  vector<bool> pos_ab(sum, true);
  for (int i = 0; i < a.size(); ++i) {
    pos_ab[i] = canMatch(a, b, i);
  }

  vector<bool> pos_ac(sum, true);
  for (int i = 0; i < a.size(); ++i) {
    pos_ac[i] = canMatch(a, c, i);
  }

  vector<bool> pos_bc(sum, true);
  for (int i = 0; i < b.size(); ++i) {
    pos_bc[i] = canMatch(b, c, i);
  }

  int ans = sum;
  for (int i = 0; i < a.size() + 1; ++i) {
    if (not pos_ab[i]) continue;
    for (int j = 0; j < b.size() + 1 or i + j < a.size() + 1; ++j) {
      if (not pos_ac[i + j]) continue;
      if (pos_bc[j]) {
	int len = a.size();
	len = max(len, (int)b.size() + i);
	len = max(len, (int)c.size() + i + j);
	ans = min(ans, len);
      }
    }
  }
  return ans;
}

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

  int ans = a.size() + b.size() + c.size();
  ans = min(ans, solve(a, b, c));
  ans = min(ans, solve(a, c, b));
  ans = min(ans, solve(b, a, c));
  ans = min(ans, solve(b, c, a));
  ans = min(ans, solve(c, a, b));
  ans = min(ans, solve(c, b, a));
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b[100005];
int main()
{
	 cin>>a;
	 b[0]=2;
	 for (int i=1;i<=a;i++)
	   b[i]=b[i-1]*2+2;
	cout<<b[a];
     return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	Scanner sc = new Scanner(System.in);
	
	private void doit(){
		
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int [] data = new int[5];
			data[0] = n;
			for(int i = 1; i < 5; i++){
				data[i] = sc.nextInt();
			}
			int [] freq = new int[4];
			for(int i = 0; i < 5; i++){
				freq[data[i]]++;
			}
			int count = 0;
			for(int i = 0; i < 4; i++){
				if(freq[i] > 0){
					count++;
				}
			}
			if(count == 3 || count == 1){
				for(int i = 0; i < 5; i++){
					System.out.println(3);
				}
			}
			else{
				if(freq[3] == 0){
					for(int i = 0; i < 5; i++){
						if(data[i] == 1){
							System.out.println(1);
						}
						else{
							System.out.println(2);
						}
					}
				}
				else if(freq[2] == 0){
					for(int i = 0; i < 5; i++){
						if(data[i] == 1){
							System.out.println(2);
						}
						else{
							System.out.println(1);
						}
					}
				}
				else{
					for(int i = 0; i < 5; i++){
						if(data[i] == 2){
							System.out.println(1);
						}
						else{
							System.out.println(2);
						}
					}
				}
			}
		}
		
	}
	
	//Stringの配列。データセットの間は空行を入れる
	private String[] toStrArr() {
		StringBuilder sb = new StringBuilder();
		while(sc.hasNext()){
			String s = sc.nextLine().trim();
			if(s.equals("")) break;
			sb.append(s);
		}
		String s = sb.toString().replaceAll("[{}\" ]", "");
		String [] t = s.split(",");
		return t;
	}

	//String
	private String toStr() {
		String s = sc.next().replaceAll("\"", "");
		return s;
	}
	
	//intの配列
	private int[] toIntArr() {
		String [] t = toStrArr();
		int [] res = new int[t.length];
		for(int i = 0; i < t.length; i++){
			res[i] = Integer.parseInt(t[i]);
		}
		return res;
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 20788
taro_score = 0
hanako_score = 0
for _ in range(int(input())):
    taro, hanako = [str(x) for x in input().split()]
    if taro > hanako:
        taro_score += 3
    elif taro == hanako:
        taro_score += 1
        hanako_score += 1
    else:
        hanako_score += 3
print(taro_score, hanako_score)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
		if(b&1)
		    r=(r*a)%m;
		b>>1;
		a=(a*a)%m;
	}
	return r%m;
}

int main(){
    ll n; cin>>n;
    vector<pair<ll,pair<ll,ll> > >arr(n);
    rep(i,0,n)
    {
        cin>>arr[i].se.fi>>arr[i].se.se;
        arr[i].fi  = arr[i].se.fi+arr[i].se.se;
    }
    sort(arr.begin(),arr.end());


    ll ans = 1;
    ll r = arr[0].fi;
    rep(i,1,n)
    {
        if(r <=arr[i].se.fi - arr[i].se.se)
        {
            ans++;
            r = arr[i].se.fi+arr[i].se.se;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<pll> dt(n);
    for (int i = 0; i < n; ++i) {
        cin >> dt[i].second >> dt[i].first;
    }
    sort(dt.begin(), dt.end(), greater<pll>());
    priority_queue<pll> pq;
    priority_queue<pll, vector<pll>, greater<pll>> pq2;
    map<ll, int> cnt;
    ll val = 0;
    ll sum  = 0;
    for (int i = 0; i < k; ++i) {
        sum += dt[i].first;
        if (cnt[dt[i].second] == 0) {
            cnt[dt[i].second]++;
            val++;
        } else {
            pq2.push(dt[i]);
        }
    }
    for (int i = k; i < n; ++i) {
        pq.push(dt[i]);
    }
    sum += val * val;
    ll ret = sum;
    while (!pq.empty() && !pq2.empty()) {
        auto q = pq.top();
        pq.pop();
        if (cnt[q.second] != 0)
            continue;
        cnt[q.second]++;
        auto p = pq2.top();
        pq2.pop();
        sum -= val * val;
        val++;
        sum += val * val;
        sum += q.first - p.first;
        chmax(ret, sum);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 6648
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;



vector<int> A;
vector<int> B;
vector<int> C;
vector<int> D;
vector<int> E;
vector<int> F;
vector<LL> xs;
vector<LL> ys;
int st[6001][6001];
bool isInf=false;
LL f(int p, int q)
{
	stack<P> nex;
	LL ret=0;
	nex.push(P(p,q));
	while(nex.size()){
		p=nex.top().first;
		q=nex.top().second;
		nex.pop();
		if(st[p][q]&16)
		{
			continue;
		}
		st[p][q]|=16;
		//cerr << p << ", " << q << endl;
		if(p==0||q==0||p==xs.size()||q==ys.size())
		{
			isInf=true;
			return 0;
		}
		ret+=(xs[p]-xs[p-1])*(ys[q]-ys[q-1]);
		
		if(!(st[p][q]&1))
		{
			nex.push(P(p,q+1));
		}
		if(!(st[p][q]&2))
		{
			nex.push(P(p+1,q));
		}
		if(!(st[p][q]&4))
		{
			nex.push(P(p,q-1));
		}
		if(!(st[p][q]&8))
		{
			nex.push(P(p-1,q));
		}
	}

	return ret;
}
int main(){
	int N,M;
	cin >> N >> M;
	for(int i=0;i<N;i++){
		int a,b,c;
		cin >> a >> b >> c;
		A.push_back(a);
		B.push_back(b);
		C.push_back(c);
		xs.push_back(a);
		xs.push_back(b);
		ys.push_back(c);
	}
	for(int i=0;i<M;i++){
		int a,b,c;
		cin >> a >> b >> c;
		D.push_back(a);
		E.push_back(b);
		F.push_back(c);
		xs.push_back(a);
		ys.push_back(b);
		ys.push_back(c);
	}
	sort(xs.begin(),xs.end());
	xs.resize(unique(xs.begin(),xs.end())-xs.begin());
	sort(ys.begin(),ys.end());
	ys.resize(unique(ys.begin(),ys.end())-ys.begin());
	for(int i=0;i<N;i++){
		int q=lower_bound(ys.begin(),ys.end(),C[i])-ys.begin();
		int p=lower_bound(xs.begin(),xs.end(),min(A[i],B[i]))-xs.begin();
		while(xs[p]<max(A[i],B[i])){
			st[p+1][q]|=1;
			st[p+1][q+1]|=4;
			p++;
		}
	}
	for(int i=0;i<M;i++){
		int q=lower_bound(ys.begin(),ys.end(),min(E[i],F[i]))-ys.begin();
		int p=lower_bound(xs.begin(),xs.end(),D[i])-xs.begin();
		while(ys[q]<max(E[i],F[i])){
			st[p][q+1]|=2;
			st[p+1][q+1]|=8;
			q++;
		}
	}

	int u=lower_bound(xs.begin(),xs.end(),0)-xs.begin();
	int v=lower_bound(ys.begin(),ys.end(),0)-ys.begin();
	LL r=f(u,v);
	if(isInf)
	{
		cout << "INF" << endl;
		return 0;
	}
	cout << r << endl;




    return 0;
}


Measured memory_bytes: 196640
N = int(input())
abc = []
for _ in range(N):
    a, b, c = map(int, input().split())
    abc.append((a, b, c))
dp = [[0]*3 for _ in range(N)]
for i in range(3):
    dp[0][i] = abc[0][i]
for i in range(1, N):
    a, b, c = abc[i]
    dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a
    dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b
    dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c
print(max(dp[-1][i] for i in range(3)))



Measured memory_bytes: 74968
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<(x)<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Mat = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5+10;


int main(){
    int k, s;
    cin >> k >> s;

    int ans = 0;
    for(int x=0; x<=k; ++x){
        for(int y=0; y<=k; ++y){
            int z = s - x - y;
            if(z>=0 && z<=k) ++ans;
        }
    }

    cout(ans);

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

int minimum(string str) {
	//cout << str << endl;
	vi nums;
	if (str[1] == '[') {
		int l = 1, r = 2;
		while (true) {
			int cnt = 1;
			while (cnt != 0) {
				if (str[r] == '[')cnt++;
				else if (str[r] == ']')cnt--;
				r++;
			}
			nums.push_back(minimum(string(str.begin() + l, str.begin() + r)));
			l = r;
			r = l + 1;
			if (str[l] == ']')break;
		}
		sort(all(nums));
		int ans = 0;
		rep(i, nums.size() / 2 + 1){
			ans += nums[i];
		}
		//cout << ans << endl;
		return ans;
	}
	else {
		int ans = 0;
		repl(i, 1, str.length() - 1) {
			ans = ans * 10 + (str[i] - '0');
		}
		ans = (ans + 1) / 2;
		//cout << ans << endl;
		return ans;
	}
}

int main() {
	int N;
	cin >> N;
	rep(i, N) {
		string str;
		cin >> str;
		cout << minimum(str) << endl;
	}

	return 0;
}

Measured memory_bytes: 3036
#include <cstdio>

int n;

int main(){
	while(scanf("%d", &n),n){
		for(int i = 0; i < n; i++){
			int pm, pe, pj,ave;
			scanf("%d%d%d", &pm, &pe, &pj);
			ave = (pm+pe+pj)/3;
			if(pm == 100 || pe == 100 || pj == 100 || ave >= 80 || (pm+pe)/2 >= 90) printf("A\n");
			else if(ave >= 70 || (ave>=50&&(pm>=80||pe>=80))) printf("B\n");
			else printf("C\n");
		}
	}
}

Measured memory_bytes: 1016
import sys


def main():
    n = int(sys.stdin.readline().strip())
    p = [int(num_s) for num_s in sys.stdin.readline().strip().split(' ')]

    smallest = float('inf')

    ans = 0
    for pi in p:
        if pi <= smallest:
            ans += 1
        smallest = min(smallest, pi)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68288
import math
import sys

def main():

    n = int(input())
    s = [input() for i in range(n)]
    c0,c1,c2,c3 = 0,0,0,0
    
    for i in range(n):
        if "AC" in s[i]:
            c0 += 1
        if s[i] in 'WA':
            c1 += 1
        if s[i] in 'TLE':
            c2 += 1
        if s[i] in 'RE':
            c3 += 1
    print("AC x "+str(c0))
    print("WA x "+str(c1))
    print("TLE x "+str(c2))
    print("RE x "+str(c3))
if __name__ == "__main__":
    main()


Measured memory_bytes: 16316
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int n;
void solve(string s, char c){
	if (s.size() == n){
		cout << s << endl;
		return;
	}
	for (char i = 'a'; i <= c; i++){
		string t = s;
		t.push_back(i);
		solve(t, c);
	}
	string t = s;
	t.push_back(c + 1);
	solve(t, c + 1);
}
int main(){
	scanf("%d", &n);
	solve("a", 'a');
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"

using namespace std;

int main() {
	long long n, x, ans = 0;
	cin >> n >> x;
	long long arr[n];
	for(long long i = 0; i < n; ++i){
        cin >> arr[i];
        if(x == 0)ans += arr[i];
	}
	if(x == 0){
        cout << ans;
        return 0;
	}

	for(long long i = 1; i < n; ++i){
        if(arr[i] + arr[i - 1] > x){
            ans += (arr[i] + arr[i - 1] - x);
            arr[i] = max((long long)0, arr[i] - (arr[i] + arr[i - 1] - x));
        }
	}
	cout << ans;
	return 0;

}


Measured memory_bytes: 1024
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int k = sc.nextInt();
	int s = sc.nextInt();
	int count = 0;
	for(int x = 0; x <= k; x++) {
		for(int y = 0; y <= k; y++) {
			if(x + y <= s && s - x - y <= k) {
					count++;
			}

		}
	}
	System.out.println(count);
}
}


Measured memory_bytes: 21712
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N, M; cin >> N >> M;
    vector<int>a(M);
    vector<int>b(M);
    vector<int>c(N);
    rep(i, M) {
        cin >> a[i] >> b[i];
        c[a[i]-1]++;
        c[b[i]-1]++;
    }
    rep(i, N)cout << c[i] << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
const int inf=1e9;
pair<int,int> v[400010];
vector<int> poz[200010];
 
int main()
{
    int n,max1=0,min1=inf,max2=0,min2=inf,a,b;
    scanf("%d",&n);
    for(int i = 1; i <= n; i ++)
    {
        scanf("%d%d",&a,&b);
        v[2 * i - 1] = {a,i};
        v[2 * i] = {b,i};
        if(a < b) swap(a,b);
        max1=max(max1,a);
        min1=min(min1,a);
        max2=max(max2,b);
        min2=min(min2,b);
    }
    long long sol=1LL*(max1-min1)*(max2-min2);
    sort(v+1,v+1+2*n);
    for(int i=1;i<=2*n;i++) poz[v[i].second].push_back(i);
    a=b=2;
    int nr=0;
    for(int i=1;i<=2*n;i++)
    {
        for(;nr<n && b<2*n;b++)
            if(poz[v[b].second][0]==b || poz[v[b].second][0]<a) nr++;
        if(nr<n) break;
        sol=min(sol,1LL*(v[2*n].first-v[1].first)*(v[b-1].first-v[a].first));
        nr--;
        if(poz[v[a].second][0]==a && poz[v[a].second][1]<b) nr++;
        a++;
    }
    printf("%lld",sol);
    return 0;
}


Measured memory_bytes: 14336
# C
n = int(input())
a_list = list(input().split())

res_list = []
for i in range(n-1, -1, -2):
    res_list.append(a_list[i])
if n % 2 == 0:
    for i in range(0, n, 2):
        res_list.append(a_list[i])
else:
    for i in range(1, n, 2):
        res_list.append(a_list[i])
        
print(" ".join(res_list))

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

int main(){
  int N,Y;cin>>N>>Y;
  int A,B,C;
  A=-1;
  B=-1;
  C=-1;  
  //C=N-A-B;
  //int ans=0;
  
  for (int i=0;i<=N;++i){
    for (int j=0;i+j<=N;++j){
      int k=N-i-j;
      int ans=10000*i+5000*j+1000*k;
      if (ans==Y){
        A=i;
        B=j;
        C=k;
        break;
      }
    }
  }
  cout<<A<< " " <<B<< " " <<C<<endl;
}
      

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int t;
    cin >> t;
    COUT(t+t*t+t*t*t);
    return 0;
}

Measured memory_bytes: 3632