akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b);

int main(void)
{
    int N, L[3000];
    int i, j, k, count=0;
    
    scanf("%d",&N);
    
    for(i=0; i<N; i++){
        scanf("%d",&L[i]);
    }
    
    qsort(L, N, sizeof(int),compare_int);
    /*
    for(i=0; i<N; i++){
        printf("%d ",L[i]);
    }
    printf("\n\n");
    */
    
    for(i=0; i<N-2; i++){
        for(j=i+1; j<N; j++){
            for(k=j+1; k<N; k++){
                if((L[i]+L[j]) > L[k]){
                    //printf("L[%d]%d + L[%d]=%d > L[%d]=%d\n",i,L[i],j,L[j],k,L[k]);
                    count++;
                    //printf("N-j-1=%d-%d-1=%d,  count=%d\n\n",N,j,N-j-1,count);
                }
            }
        }
    }
    
    printf("%d\n",count);
    
    
    return 0;
}

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}



Measured memory_bytes: 252
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a; cin >> a;
    string s; cin >> s;
    int ans = 0;
    for(int i = 1; i < s.size(); i++){
        string a = s.substr(0,i);
        string b = s.substr(i);
        int cnt = 0;
        for(char c = 'a'; c <= 'z'; c++){
            bool flag1 = false, flag2 = false;
            for(char m:a) if(m == c) flag1 = true;
            for(char m:b) if(m == c) flag2 = true;
            if(flag1&&flag2) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}
//Saw the solution video


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

int main () {
    ll n , m , ans ;
    cin >> n >> m ;
    if(n == 1 || m == 1){
         if(n == 1){
             if(m == 1){
                 ans = 1 ;
             }else {
             ans = (m - 2) * n ;
             }
         }else{
             if(n == 1){
                 ans = 1 ;
             }else{
             ans = (n - 2) * m ;
             }
         }
    }else{
        ans = (n - 2) * (m - 2) ;
    }

    if(ans <= 0){
        cout << 0 << endl;
    }else{
        cout << ans << endl;
    }
    return 0 ;
}

 


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<functional>
#include<map>
using namespace std;
typedef long long ll;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b>=c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        long cnt = 0;
        if (N == 1 && M == 1) {
            cnt = 1;
            System.out.println(cnt);
        } else if (N == 1) {
            cnt = M - 2;
            System.out.println(cnt);
        } else if (M == 1) {
            cnt = N - 2;
            System.out.println(cnt);
        } else {
            long N2 = N;
            long M2 = M;
            cnt = (N2 - 2) * (M2 - 2); 
            System.out.println(cnt);
        }   

        return;
    }   

}

Measured memory_bytes: 23124
#!/usr/bin/perl
use Data::Dumper;
my ($n,$m) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @aa = map { $_ - 0 } split(/\s+/,<STDIN>);
my @bc = ();
for(my $i=0;$i<$m;$i++){
  my ($b,$c) = map { $_ - 0 } split(/\s+/,<STDIN>);
  push(@bc,+[$b,$c]);
}
my @s_bc = sort {$b->[1] <=> $a->[1]} @bc;
my @s_aa = sort {$a <=> $b} @aa;

my $p = 0;
foreach my $bc1 (@s_bc){
  my $b = $bc1->[0];
  my $c = $bc1->[1];
  while( $s_aa[$p] < $c and $b > 0 ){
    $s_aa[$p] = $c;
    $p++;
    $b--;
    last if( $p>=$n );
  }
  last if( $p>=$n );
}

my $res = 0;
for(my $i=0;$i<$n;$i++){
  $res += $s_aa[$i];
}
print "$res\n";


Measured memory_bytes: 35920
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int main(){
	long long k,a,b,ans;
	cin>>k>>a>>b;
	k++;
	if(k<=a+1){
		cout<<k;
		return 0;
	}
	long long times=a+2;
	long long ma1=b;
	long long ma2=a+2;
	long long kk=k-a;
	long long res1=a+kk/2*(b-a);
	if(kk%2) res1++;
	cout<<max(res1,k);
}

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

int main(){
	int N;
	cin >> N;
	int t[N+1] = {0}, x[N+1] = {0}, y[N+1] = {0};
	for(int i = 1; i < N+1; i++)
		cin >> t[i] >> x[i] >> y[i];
	for(int i = 0; i < N; i++){
		int dt = t[i+1] - t[i];
		int dx = abs(x[i+1] -x[i]);
		int dy = abs(y[i+1] -y[i]);
		int a = dt - dx - dy;
		if(a < 0 || a % 2 != 0){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

int main(){
	int n, x;
	long sum = 0;
	vector<int> a;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		a.push_back(x);
		sum += x;
	}

	sort(a.begin(), a.end());
	
	cout<<a[0]<<" "<<a[a.size()-1]<<" "<<sum<<endl;

	return 0;
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
string s;

ll ans = 0;
ll flg = 0;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>s;
  if(s.size() == 1) {
    cout<<s[0]-'0'<<endl;
    return ;
  }
  if(s[0] != '9') {
    repl(i,1,s.size()) if(s[i] != '9') flg = 1;
    if(flg) ans += s[0] - '1' + 9 *  (s.size() -1);
    else ans += s[0] - '0' + 9 *  (s.size() -1);
  } else {
    rep(i,s.size()){
      if(s[i]=='9') ans+= 9;
      else ans += 8 + 9 * (s.size() -1 - i);
    }
  }
  cout<<ans<<endl;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;

namespace AIZU_Cs_
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j;
            for (i = 1; i <= 9; i++)
                for (j = 1; j <= 9; j++)
                    Console.WriteLine(i + "x" + j + "=" + i * j);
        }
    }
}

Measured memory_bytes: 9000
n = (int)(input())
a = (int)(input())
b = (int)(input())
c = (int)(input())
d = (int)(input())
e = (int)(input())

time = 0
array = a, b, c, d, e
ind = array.index(min(array))
time = - (-n // array[ind])
time = ind+time+(4-ind)
print(time)

Measured memory_bytes: 3064
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
#define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 1000005
#define PP pair<pair<ll,ll>,pair<pair<ll,ll>,ll>>
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 1e9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

signed main() {

	fast
	// cases
	{
		ll n;
		cin >> n;
		vl a(n);
		unordered_map<ll, ll> f;
		ll sum = 0;
		loop(i, n)	cin >> a[i] , ++f[a[i]] , sum += a[i];
		ll q;
		cin >> q;
		while (q--)
		{
			ll b, c;
			cin >> b >> c;
			sum += ((-1) * f[b] * b + f[b] * c);
			f[c] += f[b];
			f[b] = 0;
			cout << sum << END;
		}
	}


// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}

Measured memory_bytes: 7928
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

vector<pint> v;
void add_edge(int a,int b){
    if(b-a<=1)return;
    int m=(b-a)/2;
    rep(i,m){
        v.emplace_back(a,a+i+1);
    }
    add_edge(a+1,a+m+1);
    add_edge(a+m+1,b);
}
int main(){
    int n,k;
    cin>>n>>k;
    add_edge(1,n+1);
    int m=v.size();
    cout<<m<<endl;
    rep(i,m){
        cout<<v[i].first<<" "<<v[i].second<<endl;
    }
    while(k--){
        int ans=1;
        int right=n+1;
        while(1){
            cout<<ans<<endl;
            string ret;
            cin>>ret;
            if(ret=="Yes")break;
            int mid=(right-ans)/2;
            if(ret=="No"){
                ans+=mid+1;
            }
            else {
                right=ans+mid+1;
                ++ans;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3308
import itertools
import math

n = int(input())
x = [0]*n
y = [0]*n

for i in range(n):
    x[i], y[i] = map(int, input().split())

a = [list(e) for e in zip(x, y)]

c = list(itertools.permutations([i for i in range(n)]))

ans = [0]*len(c)

for i in range(len(c)):
    x_f = x[c[i][0]]
    y_f = y[c[i][0]]
    for j in range(1, n):
        x_s = x[c[i][j]]
        y_s = y[c[i][j]]

        ans[i] += math.sqrt((x_f-x_s)**2 + (y_f-y_s)**2)

        x_f = x[c[i][j]]
        y_f = y[c[i][j]]

print(sum(ans)/len(c))

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

using namespace std;

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

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 18) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 1<<18;

int n;
ll a[MAXN];
ll ans;

int main()
{
	
	n = inp();
	map<ll, int> F;
	F[0] = 1;
	for (int i = 1; i <= n; ++ i)
	{
		a[i] = a[i-1]+inp();
		ans += F[a[i]];
		F[a[i]] ++;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 14592
def main():

    N  = int(input())
    A = list(map(int, input().split()))

    mod = pow(10, 9) + 7
    k1, k2 = 0, 0
    l1, l2 = 0, 0
    for i in range(N):
        k1 += A[i] // mod
        k2 += A[i] % mod
        l1 += (l2 + A[i] * A[i]) // mod
        l2 = (l2 + A[i] * A[i]) % mod
    # print(k1, k2, l1, l2)

    u = (k2*k2 - l2)
    v = (k1 * k1 - l1) * mod
    return ((u + v) // 2) % mod

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


Measured memory_bytes: 94224
#include "bits/stdc++.h"
using namespace std;
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;
#ifdef LOCAL
mt19937 rng(unsigned(70));
#else
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif
#define rand rng


int main() {
	// fios;
	int s, w;
	cin >> s >> w;
	if(w >= s) {
		puts("unsafe");
	} else {
		puts("safe");
	}

}

Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= b; --i)
#define range(i, a, b, c) for (int i = a;             \
                               c > 0 ? i < b : i > b; \
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define dump(x) cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else
const bool test = false;
#endif

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while (getline(ss, buffer, sep))
    {
        v.push_back(buffer);
    }
    return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
    return accumulate(begin, end, 0ll);
}

void solve();

signed main()
{
    cout << fixed << setprecision(20);
    solve();
    while (true)
    {
        char s[MAX];
        if (scanf("%s", s) == EOF)
            break;
        int n = strlen(s);
        for (int i = n - 1; i > -1; i--)
        {
            ungetc(s[i], stdin);
        }
        solve();
    }
    return 0;
}

int n;
int a[3 * MAX];

void solve() {
    cin >> n;
    rep(i, 3 * n) cin >> a[i];
    sort(a, a + 3 * n);
    rep(i, 3 * n) cerr << a[i] << " ";
    cerr << endl;
    int res = 0;
    rep(i, n) {
        cerr << a[3 * n - 2 - 2 * i] << " ";
        res += a[3 * n - 2 - 2 * i];
    }
    cerr << endl;
    cout << res << endl;
}


Measured memory_bytes: 4352
/**
 *     ____              _    
 *    / __ \____ _____  (_)___
 *   / /_/ / __ `/ __ \/ /_  /
 *  / _, _/ /_/ / /_/ / / / /_
 * /_/ |_|\__,_/ .___/_/ /___/
 *            /_/             
 *           code@rapiz.me
 *          Sat, 24 Aug 2019 20:26:01 +0800
 */
#include <bits/stdc++.h>
#define xxx(x) cerr<<(#x)<<": "<<x<<endl;
#define iosfast ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
typedef long long ll;
using namespace std;
int M, D;
int main() {
  cin >> M >> D;
  int cnt = 0;
  for (int m = 1; m <= M; m++) {
    for (int d = 1; d <= D; d++) {
      int ten = d/10, one = d%10;
      if (one >= 2 && ten >= 2 && one*ten == m) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Maxn 2007
using namespace std;
int a[Maxn][Maxn];
int m,n,k;
inline int get(int x) 
{ 
	while (x<0) x+=m;
	return x%m;
}

int main() 
{
	n=1407,k=38,m=37;
	int now=0;
	for (int i=0;i<n-1;i+=m)
	{
		for (int j=0;j<m;++j) 
			a[now][i+j]=1;
		a[now][n-1]=1;
		++now;
	}
	for (int i=0;i<m;++i)
	{
		for (int s=0;s<m;++s) 
		{
			int p=s;
			for (int j=m;j<n-1;j+=m) 
			{
				a[now][j+p]=1;
				p=get(p+i);
			}
			a[now][i]=1;
			++now;
		}
	}
	printf("%d %d\n",n,k);
	for (int i=0;i<n;++i)
	{
		for (int j=0;j<n;++j)
			if (a[i][j]>0) printf("%d ",j+1);
		printf("\n");
	}
	return 0;
}

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

int main() {
	int n,m, a[100],max=0,min=1000000000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		if (max < a[i])max = a[i];
		if (min > a[i])min = a[i];
	}
	m = max - min;
	cout << m << endl;
}

Measured memory_bytes: 256
dp = [0] * 31
dp[0] = 1
dp[1] = 1
dp[2] = 2

for i in range(3, 31):
    dp[i] = dp[i-1]+dp[i-2]+dp[i-3]

while(1):
    n = int(input())
    if not n:
        break
    print((dp[n]-1)//3650+1)


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

int main() {
    bool is_prime[1000001];
    for (int i = 0 ; i < 1000001; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= 1000000 / 2; i++) {
        if (is_prime[i])
            for (int j = 2; j * i <= 1000000; j++) {
                is_prime[i*j] = false;
            }
    }
    int N;
    while (cin >> N, N) {
        int count = 0;

        for (int i = 0; i <= N / 2; i++) {
            if (is_prime[i] && is_prime[N-i]) {
                count++;
            }
        }

        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 4044
main :: IO()
main = do
    [x,y] <- map read . words <$> getLine
    putStrLn $ if (getsolve x == getsolve y) then "Yes" else "No"

getsolve :: Int -> Int
getsolve num
    | num == 1		= 1
    | num == 2		= 3
    | num == 3		= 1
    | num == 4		= 2
    | num == 5		= 1
    | num == 6		= 2
    | num == 7		= 1
    | num == 8		= 1
    | num == 9		= 2
    | num == 10		= 1
    | num == 11		= 2
    | num == 12		= 1

Measured memory_bytes: 508
import java.util.Scanner;

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

		sc.close();

		if((x-t)>0){
			System.out.print(x-t);
		}else if((x-t)<=0){
			System.out.print(0);
		}
	}
}

Measured memory_bytes: 21972
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  string S;
  get(S);
  if (S.size() == 3)
    reverse(ALL(S));
  print(S);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		long sum = 0;
		for (int i = 0; i < n; i++) {
			int a = scan.nextInt();
			if(a > max) {
				max = a;
			}
			if(a < min) {
				min = a;
			}
			sum += a;
		}
		System.out.println(min + " " + max + " " + sum);
	}

}

Measured memory_bytes: 41684
#include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    typedef long long ll;
    ll n, m, c[1000000];
    int main() {
        vector<ll> v, v1;
        cin >> n >> m;
        for(ll i = 2; i < 1000000; ++i)
            if(!c[i])
                for(ll j = i * 2; j < 1000000; j += i)
                    c[j] = 1;
        v.push_back(1);
        ll g = __gcd(n, m);
        for(ll i = 2; i < 1000000 && g != 1; ++i) 
            if(!c[i] && g % i == 0)
                g /= i, v.push_back(i), --i;
        if(g > 1)
            v.push_back(g);
        v.resize(unique(v.begin(), v.end()) - v.begin());
        cout << v.size() << endl;
        return 0;
    }

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

const int N=1000000005;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        int n;
        cin>>n;
        int ac=0,wa=0,tle=0,re=0;
        for(int i=0;i<n;i++)
        {
            string s;
            cin>>s;
            if(s=="AC")
                ac++;
            else if(s=="TLE")
                tle++;
            else if(s=="WA")
                wa++;
            else if(s=="RE")
                re++;
        }
        cout<<"AC x "<<ac<<endl;
        cout<<"WA x "<<wa<<endl;
        cout<<"TLE x "<<tle<<endl;
        cout<<"RE x "<<re<<endl;
    }
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int dp[101][4][4][4];

int main(){
  long long mod = 1000000007;
  int N;
  scanf("%d",&N);
  std::vector<long long > baisuu(N+1);
  baisuu[0]=1;
  for (int i=1; i<=N; i++){
    baisuu[i] = baisuu[i-1]*4;
    baisuu[i]%=mod;
  }

  dp[0][3][3][3]=1;
  for (int i=1; i<=N; i++){
    for (int c1=0; c1<4; c1++){
      for (int c2=0; c2<4; c2++){
        for (int c3=0; c3<4; c3++){
          for (int a=0; a<4; a++){
            if (a==2 && c1==1 && c2==0) continue;
            if (a==2 && c1==0 && c2==1) continue;
            if (a==1 && c1==2 && c2==0) continue;
            if (a==2 && c1==1 && c3==0) continue;
            if (a==2 && c2==1 && c3==0) continue;
            dp[i][a][c1][c2] += dp[i-1][c1][c2][c3];
            dp[i][a][c1][c2] %= mod;
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int c1=0; c1<4; c1++){
    for (int c2=0; c2<4; c2++){
      for (int c3=0; c3<4; c3++){
        ans += dp[N][c1][c2][c3];
        ans %= mod;
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 256
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

ll MOD = 1000000007;

ll modpow(ll a, int n) {
    if (n == 0) return 1LL;
    if (n % 2 == 1) return a * modpow(a, n-1) % MOD;
    ll h = modpow(a, n/2);
    return h * h % MOD;
}

ll modinv(ll a) { return modpow(a, MOD-2); }

ll fact[201010], facti[201010];

ll comb(int n, int k) {
    if (n == 0) return 1LL;
    return (fact[n] * facti[k] % MOD) * facti[n-k] % MOD;
}

ll N, A, B, C;

ll p[202010];

void init() {
    fact[0] = 1;
    facti[0] = modinv(fact[0]);
    for (int i = 1; i < 201010; ++i) {
        fact[i] = i * fact[i-1] % MOD;
        facti[i] = modinv(fact[i]);
    }
    fill(p, p+201010, 0);
}

int main() {
    init();
    cin >> N >> A >> B >> C;

    ll ap = A * modinv(A+B) % MOD;
    ll bp = B * modinv(A+B) % MOD;
    ll ce = C * modinv(100 - C) % MOD;

    ll ans = 0;
    for (int b = 0; b < N; ++b) {
        if (B == 0 && b > 0) break;
        ll inc =
            modpow(ap, N) * modpow(bp, b) % MOD
            * comb(N+b-1, N-1) % MOD;
        ans = (ans + (N+b) * inc % MOD) % MOD;

        p[N+b] = (p[N+b] + inc) % MOD;
    }

    for (int a = 0; a < N; ++a) {
        if (A == 0 && a > 0) break;
        ll inc =
            modpow(ap, a) * modpow(bp, N) % MOD
            * comb(N+a-1, N-1) % MOD;
        ans = (ans + (N+a) * inc % MOD) % MOD;

        p[N+a] = (p[N+a] + inc) % MOD;
    }

    for (int i = N; i < 2*N; ++i) {
        ans = (ans + i * p[i] % MOD * ce % MOD) % MOD;
    }

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


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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}


int n,m;

int main()
{
    cin>>n>>m;
    vec<int> h(n,0);
    rep(i,n){cin>>h[i];}
    vec<int> v(n);
    iota(v.begin(), v.end(), 0); //1からはじめるm要素の列
    set<int> s;

    int a,b;
    rep(i,m){
        cin>>a>>b;
        a--;
        b--;

        if(h[a]>=h[b]){
            s.insert(b);
        }
        
        if(h[b]>=h[a]){
            s.insert(a);
        }
    }
    int ans=n-s.size();
    // for(auto e:s){
    //     cout<<e+1<<" ";
    // }
    // cout<<endl;

    cout<<ans<<endl;

    return 0;

}




Measured memory_bytes: 6700
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int n,d;
  cin>>n>>d;
  int pos[10][10]={};
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin>>pos[i][j];
    }
  }
  
  int result=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int dist_pow=0;
      for(int k=0;k<d;k++){
        dist_pow+=(pos[i][k]-pos[j][k])*(pos[i][k]-pos[j][k]);
      }
      for(int l=1;l*l<=20000;l++){
        if(dist_pow==l*l){
          result++;
          break;
        }
      }
    }
  }
  
  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1
typedef pair<ll, ll> P;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
    ll H, N, A, sum = 0;

    cin >> H >> N;
    rep(i, N) {
        cin >> A;
        sum += A;
    }
    if(sum >= H){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - 1e8;
const ll INFLL = numeric_limits<ll>::max() - 1e17;

signed main() {
    int N;
    cin >> N;
    vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(2, vector<ll>(3, -INFLL)));
    dp[0][1][0] = 0;
    for (int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        for (int j = 0; j <= 1; j++) for (int k = 0; k <= 2; k++) {
            if (j + k < 3) dp[i + 1][1][j + k] = max(dp[i + 1][1][j + k], dp[i][j][k]);
            if (j == 1) dp[i + 1][0][k] = max(dp[i + 1][0][k], dp[i][j][k] + A);
        }
    }
    if (N % 2 == 0) cout << max(dp[N][1][0], dp[N][0][1]) << endl;
    else cout << max(dp[N][0][2], dp[N][1][1]) << endl;
}


Measured memory_bytes: 33044
#include<bits/stdc++.h>
using namespace std;
typedef pair<double,double> P;
int main(){
  int n;
  while(cin>>n,n){
    vector<P> v;
    double x,y,mx1,mx2,my1,my2,p,q,a,b,c;
    int ans=1;
    int i,j,k,l;
    for(i=0;i<n;i++){
      cin >> x >> y;
      v.push_back(P(x,y));
    }
    for(i=0;i<n;i++){
      for(j=i+1;j<n;j++){
        mx1=v[i].first;my1=v[i].second;
	mx2=v[j].first;my2=v[j].second;
	//cout << (mx1-mx2)*(mx1-mx2)+(my1-my2)*(my1-my2) << endl;
	if((mx1-mx2)*(mx1-mx2)+(my1-my2)*(my1-my2)>2.0*2.0) continue;
	p=(my1-my2)/(mx2-mx1);
	q=((mx1+mx2)-p*(my1+my2))/2;
	//cout << p << ":" << q << endl;
	a=p*p+1;b=2*p*q-2*my1-2*mx1*p;c=q*q-2*mx1*q+mx1*mx1+my1*my1-1.0;
	//cout << a << ":" << b << ":" << c << endl;
	l=0;
	//cout << b*b-4*a*c << "/";
	y=(-b+sqrt(b*b-4*a*c))/(2*a);x=p*y+q;
	//cout << x << ":" << y << endl;
	for(k=0;k<n;k++){
	  if((v[k].first-x)*(v[k].first-x)
	     +(v[k].second-y)*(v[k].second-y)<=1.0001) l++;
	}
	l=0;
	y=(-b-sqrt(b*b-4*a*c))/(2*a);x=p*y+q;
	for(k=0;k<n;k++){
	  if((v[k].first-x)*(v[k].first-x)
	     +(v[k].second-y)*(v[k].second-y)<=1.0001) l++;
	}
	ans=max(ans,l);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1260
using System;

namespace AtCoder
{
    class Program
    {
        static IO io = new IO();

        static void Main(string[] args)
        {
            //入力
            io.ReadSplit();
            string[] s = io.String(3);

            //計算
            string output = s[0].Substring(0, 1).ToUpper() + s[1].Substring(0, 1).ToUpper() + s[2].Substring(0, 1).ToUpper();

            //出力
            io.WriteLine(output);
        }
    }
    class IO
    {
        private string[] _Inputs;
        private int _Index;
        public void Read()
        {
            _Inputs = new string[1];
            _Inputs[0] = Console.ReadLine();
            _Index = 0;
        }
        public void ReadSplit()
        {
            _Inputs = Console.ReadLine().Split(' ');
            _Index = 0;
        }
        public string String()
        {
            return _Inputs[_Index++];
        }
        public string[] String(int xCount)
        {
            string[] rv = new string[xCount];
            Array.Copy(_Inputs, _Index, rv, 0, xCount);
            _Index += xCount;
            return rv;
        }
        public int Int()
        {
            return int.Parse(_Inputs[_Index++]);
        }
        public int[] Int(int xCount)
        {
            int[] rv = new int[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = int.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public long Long()
        {
            return long.Parse(_Inputs[_Index++]);
        }
        public long[] Long(int xCount)
        {
            long[] rv = new long[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = long.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public void Write(string xStr)
        {
            Console.Write(xStr);
        }
        public void WriteLine(string xStr)
        {
            Console.WriteLine(xStr);
        }
    }
}

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

int main(void){
    double n, res= 0;
    
    cin >> n;
    
    vector<double> a(n);
    
    rep(i, n){
        cin >> a.at(i);
        res += 1/a.at(i);
    }

    res = 1 / res;

    printf("%.6lf", res);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int h[N];

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

    int cnt = 0;
    for (int i = 0; i < N; i++){
        if (h[i] >= K){
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> a(m);
  rep(i,m) cin >> a[i];
  
  int sum = 0;
  rep(i,m) sum+=a[i];
  
  if(n > sum) cout << n - sum << endl;
  else if(n==sum) cout << 0 << endl;
  else cout << "-1" << endl;
}

Measured memory_bytes: 3652
import itertools

n = int(input())
a = [int(input()) for i in range(n)]

max_list = [0] + list(itertools.accumulate(a, func=max))
max_list_r = ([0] +list(itertools.accumulate(reversed(a), func=max)))[::-1]
for i in range(n):
    print(max(max_list[i], max_list_r[i + 1]))


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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            WriteLine((IO_ShortCut.ReadInt + 1) / 2);
        }
    }

    public class IO_ShortCut
    {
        #region Input
        public static string ReadString => ReadLine();
        public static int ReadInt => int.Parse(ReadLine());
        public static long ReadLong => long.Parse(ReadLine());
        public static double ReadDouble => double.Parse(ReadLine());

        public static List<string> ReadSplitString => ReadLine().Split().ToList();
        public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
        public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
        public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

        #endregion
    }

    /// <summary>
    /// 正の数の四則演算のみ対応
    /// </summary>
    public class Mod
    {
        // 割る数の定義
        private readonly static long M = 1000000007;

        // 足し算
        public static long Add(long a, long b) => (a * b) % M;
        // 引き算
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        // 掛け算
        public static long Multi(long a, long b) => (a * b) % M;
    }

    public class MathLib
    {
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;

// 片方を無視したときにstartからgoalまで到達できるか
bool isOK (int start, int goal,string &S) {
    int cur = 0;
    for(int i = start; i <= goal; ++i) {
        if(S[i] == '.') cur = 0;
        else cur++;
        if(cur == 2) return false;// "##"があるとき到達できない
    }
    return true;
}
// startからgoalまでに飛び越せる場所つまり"..."があるか
bool swapOK (int start, int goal,string &S) {
    for(int i = start; i <= goal; ++i) {
        if(S[i] == '.' && S[i-1] == '.' && S[i+1] == '.') return true;
    }
    return false;
}

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

int N,A,B,C,D;
cin >> N >> A >> B >> C >> D;
A--;B--;C--;D--;
string S;
cin >> S;

if(C < D) {
    if(isOK(A, C, S) && isOK(B, D, S)) cout << "Yes" << endl;
    else cout << "No" << endl;
}
else {
    if(isOK(A, C, S) && isOK(B, D, S) && swapOK(B, D, S)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

return 0;
}

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

class HeavyLightDecomposition{
private:
	struct edge{int to,cost;};
	int n;
	vector<vector<edge>> g;
	vector<int> sub;//部分木のサイズ
	vector<int> par,depth;
	vector<int> head;//自分の所属するheavyパスの先頭
	vector<int> idx;//オイラーツアーの番号
	void dfs(int now){
		sub[now] = 1;
		int ma = 0;
		for(auto& e: g[now])if(e.to != par[now]){
			par[e.to] = now;
			depth[e.to] = depth[now] + 1;
			dfs(e.to);
			sub[now] += sub[e.to];
			if(sub[g[now][0].to] < sub[e.to])swap(g[now][0],e);//g[now][0]に部分木が最大であるようなものが来る
		}
	}
	int et = 0;
	void dfs2(int now){
		idx[now] = et;
		et++;
		rep(i,g[now].size())if(g[now][i].to != par[now]){
			edge e = g[now][i];
			if(i){
				head[e.to] = e.to;
			}else{
				head[e.to] = head[now];
			}
			dfs2(e.to);
		}
	}
public:
	HeavyLightDecomposition(int sz){
		n = sz;
		g.resize(n);
		sub.resize(n);
		par.resize(n);
		head.resize(n);
		depth.resize(n);
		idx.resize(n);
	}
	void add_edge(int a, int b, int c){
		g[a].push_back({b,c});
		g[b].push_back({a,c});
	}
	void build(int root){
		par[root] = -1;
		depth[root] = 1;
		dfs(root);
		head[root] = root;
		dfs2(root);
	}
	int lca(int u, int v){
		if(idx[u] > idx[v])swap(u,v);
		// u < v
		if(head[u] == head[v])return u;
		return lca(u,par[head[v]]);
	}
	/*
	int query_sum(int u, int v){
		int x = lca(u,v);


	}
	void add(int v, int x){

	}
	*/
};

void grl5c(){
	int n;
	cin >> n;
	HeavyLightDecomposition hld(n);
	rep(i,n){
		int k;
		cin >> k;
		rep(_,k){
			int t;
			cin >> t;
			hld.add_edge(i,t,1);
		}
	}
	hld.build(0);
	int q;
	cin >> q;
	while(q--){
		int u,v;
		cin >> u >> v;
		cout << hld.lca(u,v) << endl;
	}
}

int main(){
	grl5c();
}



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

int main(){
	int64_t A, B, AB_Max, AB_Min, N = 1;

	cin >> A >> B;	

	AB_Max = max(A,B);
	AB_Min = min(A,B);
//	cout << AB_Max << endl;
	
	
	while((AB_Min*N)%AB_Max != 0){
		N++;
	}
	
	cout << AB_Min*N << endl;
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

bool isPalindrome(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  return s == t;
}

int main(){
  string s;
  cin >> s;
  int n = s.length();
  bool ans = true;
  if(!isPalindrome(s)) ans = false;
  if(!isPalindrome(s.substr(0, n / 2))) ans = false;
  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a==b)ans=2*a;
    else ans=2*max(a,b)-1;
    OUT(ans);
    return 0;
}

Measured memory_bytes: 256
import sys, math
from collections import deque

readline = sys.stdin.readline

A = int(readline())

n = math.floor(math.log10(A)) + 1

count = 0
for i in range(1, n, 2):
    count += 9 * 10 ** (i - 1)

if n % 2 == 1:
    count += A - 10 ** (n - 1) + 1

print(count)

Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;

namespace ForATCODER
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int[] nm = S2Iarray(Console.ReadLine().Split(' '));
            int[] an = S2Iarray(Console.ReadLine().Split(' '));
            int sum = 0;
            int max = 0;
            for(int i = 0; i< nm[0];i++)
            {
                sum += an[i];
                if (max < an[i]) max = an[i];
            }
            int count = 0;
            double low =sum * ( 1.0f / (4 * nm[1]));
            for (int i = 0; i < nm[0]; i++)
            {
                if (an[i] >= low) count++;
                if (count >= nm[1]) { RESULT("Yes"); return; };
            }
            RESULT("No");

        }
        public static bool swap(int x, int y, ref int[] array)
        {

            // check for out of range
            if (array.Length <= y || array.Length <= x) return false;


            // swap index x and y
            var buffer = array[x];
            array[x] = array[y];
            array[y] = buffer;


            return true;
        }
        static int arser(int[] ar ,int search, int[] except)
        {
            for(int i  = 0;i < ar.Length;i++)
            {
                if(ar[i] == search)
                {
                    if (Array.IndexOf(except, i) >= 0) continue;
                    return i;
                }
            }
            return -1;
        }

        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static void RESULT(double res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(long res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(ulong res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(int res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(String res)
        {
            Console.WriteLine(res);
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine();
            }
            return res;
        }

        static int[] S2Iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 13268
using System;
using System.Collections.Generic;

namespace AtCoderBegginerContest121
{
    class Program
    {
        static void Main(string[] args)
        {
            var inptNM = Console.ReadLine().Split(' ');
            int N = int.Parse(inptNM[0]);
            int M = int.Parse(inptNM[1]);

            List<EneDri> EneDriList= new List<EneDri> { };

            for(int i = 0; i < N; i++)
            {
                var inpt = Console.ReadLine().Split(' ');
                EneDriList.Add(new EneDri(Int64.Parse(inpt[0]), Int64.Parse(inpt[1])));
            }
            EneDriList.Sort((a,b) => (int)(a.Price - b.Price));

            long stockSum = 0;
            long priceSum = 0;

            foreach(EneDri enedri in EneDriList)
            {
                if (stockSum + enedri.Stock < M)
                {
                    priceSum = priceSum + enedri.Price * enedri.Stock;
                    stockSum = stockSum + enedri.Stock;
                }
                else{
                    priceSum = priceSum + enedri.Price * (M - stockSum);
                    break;
                }
            }
            Console.Write(priceSum);
        }
    }
    class EneDri { 
        public long Price { get; set; }
        public long Stock { get; set; }
        public EneDri(long price,long stock)
        {
            this.Price = price;
            this.Stock = stock;
        }
    }
}


Measured memory_bytes: 24128
h,w = map(int,input().split())
field = [list(input()) for i in range(h)]

tmp=0
for i in range(h):
    for j in range(w):
        if field[i][j]=='#':
            tmp+=1
if (h+w-1)==tmp:
    print('Possible')
else:
    print('Impossible')

Measured memory_bytes: 3060