akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = int(1e9)+7;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M; cin >> N >> M;
	ll ans = 1;
	for (int i = 1; i <= N; i++) ans *= i, ans %= MOD;
	for (int i = 1; i <= M; i++) ans *= i, ans %= MOD;
	if (N == M) {
		ans *= 2;
	} else if (abs(N - M) == 1) {
		ans *= 1;
	} else {
		ans *= 0;
	}
	ans %= MOD;
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n);
    for(int i = 0; i < m; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].emplace_back(v);
    }
    int s, t;
    cin >> s >> t;
    --s, --t;
    vector<vector<int>> dist(n, vector<int>(3, INF));
    dist[s][0] = 0;
    queue<P> que;
    que.push(P(s, 0));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int from = p.first, state = p.second;
        for(int to : graph[from]){
            int nextstate = (state + 1) % 3;
            if(dist[to][nextstate] > dist[from][state] + 1){
                dist[to][nextstate] = dist[from][state] + 1;
                que.push(P(to, nextstate));
            }
        }
    }
    int ans = dist[t][0];
    if(ans == INF)  ans = -1;
    else    ans /= 3;
    cout << ans << endl;   
}

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

const int MOD=1e9+7;

int main(){
  int n;cin>>n;
  long long a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  long long pre[n];
  pre[0]=a[0];
  long long ans=0;
  for(int i=1;i<n;i++) pre[i]=pre[i-1]+a[i];
  for(int i=n-1;i>=1;i--){
    ans=(ans+(a[i]%MOD)*(pre[i-1]% MOD))%MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 6748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll mod=1e9+7;
#define w(x) int x;cin>>x;while(x--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vll vector<ll>
#define ppi pair<Sint,int>
#define ppl pair<ll,ll>
#define F first
#define S second 
#define LB lower_bound
#define UB upper_bound
#define mset multiset
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll binpow(ll x, ll y, ll p){  ll res = 1;x = x % p;if (x == 0)return 0;while (y > 0)  { if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p;}return res;}  
ll gcd(ll a, ll b){ if (b == 0) return a; return gcd(b, a % b); } 
bool parity(ll x,ll y){ bool f = ((x ^ y) < 0);return !f;}


int main()
{
    IOS

    int n,k;
    cin>>n>>k;
    vi v(n);
    vector<bool> dp(k+1);
    
    for(int i=0;i<n;i++)
        cin>>v[i];

    for(int i=0;i<=k;i++)
    {
        for(int x: v)
        {
            if(i>=x && !dp[i-x])
                dp[i]=true;
        }
    }
    if(dp[k])
        cout<<"First";
    else
        cout<<"Second";

    return 0;
}

Measured memory_bytes: 256
S = input()
if len(S) == 1:
    print('YES')
    exit()
if len(set(list(S))) == 1 or (len(set(list(S))) == 2 and len(S) != 2):
    print('NO')
    exit()
cnt = [S.count('a'),S.count('b'),S.count('c')]
if max(cnt)-min(cnt) <= 1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 71632
#include <stdio.h>

int main (){
	
	int h1, h2, m1, m2, k;
	
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
	
	int sum1 = 0;
	int sum2 = 0;
	int sum3 = 0;
	int sum4 = 0;

	
	sum4 = m2 - m1;

	
	
	sum1 = h2 - h1;
	sum2 = sum1 * 60;
	sum3 = sum2 + sum4 -k;
	
	printf("%d", sum3);
	
	
	return 0;
}


Measured memory_bytes: 1668
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

void dout() { cerr << '\n'; }

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

#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = (1 << 17);
int p[N];

int cut(int n, int k) {
    int l = (n >> (k + 1)) << k;
    int r = n & ((1 << k) - 1);
    return l | r;
}

int glue(int n, int k, int val) {
    int l = (n >> k) << (k + 1);
    int r = n & ((1 << k) - 1);
    int res = l | r;
    if (val) {
        res |= (1 << k);
    }
    return res;
}

void solve(int n, int a, int b, int pos) {
    if (n == 1) {
        p[pos] = a;
        p[pos + 1] = b;
        return;
    }
    int k = -1;
    for (int i = 0; i < n; i++) {
        if ((a ^ b) >> i & 1) {
            k = i;
            break;
        }
    }
    assert(k != -1);
    int c = cut(a, k) ^ 1;
    solve(n - 1, cut(a, k), c, pos);
    solve(n - 1, c, cut(b, k), pos + (1 << (n - 1)));
    for (int i = pos; i < pos + (1 << (n - 1)); i++) {
        p[i] = glue(p[i], k, (a >> k & 1));
    }
    for (int i = pos + (1 << (n - 1)); i < pos + (1 << n); i++) {
        p[i] = glue(p[i], k, (b >> k & 1));
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif

    int n, a, b;
    cin >> n >> a >> b;
    if (__builtin_popcount(a ^ b) % 2 == 0) {
        cout << "NO";
        return 0;
    }
    cout << "YES\n";
    solve(n, a, b, 0);
    for (int i = 0; i < (1 << n); i++) {
        cout << p[i] << ' ';
    }
}


Measured memory_bytes: 1664
n=int(input())
a=input().split()

sum=int(a[0])
for i in range(n-2):
    if int(a[i])<int(a[i+1]):
        sum=sum+int(a[i])
    else:
        sum=sum+int(a[i+1])
sum=sum+int(a[n-2])
print(sum)
        

Measured memory_bytes: 2940
#include <iostream>
#include <cstring>

using namespace std;

using ll = long long;

int main() {
    char s[51];
    char t[51];
    char p[102]{};
    cin >> s >> t;
    int len1 = strlen(s);
    int len2 = strlen(t);
    int cnt = 0;
    if (len1 > len2) {
        for (int i = 0; i < len2; i++) {
            p[cnt++] = s[i];
            p[cnt++] = t[i];
        }
        for (int i = len2; i < len1; i++) {
            p[cnt++] = s[i];
        }
    } else {
        for (int i = 0; i < len1; i++) {
            p[cnt++] = s[i];
            p[cnt++] = t[i];
        }
        for (int i = len1; i < len2; i++) {
            p[cnt++] = t[i];
        }
    }
    p[cnt] = '\0';
    for (int i = 0; p[i]; i++) {
        cout << p[i];
    }
    return 0;
}


Measured memory_bytes: 256
a = [[0] * 3 for x in range(3)]
s = [[0] * 3 for x in range(3)]
for i in range(3):
  a[i] = [int(x) for x in input().split()]
n = int(input())
b = []
for i in range(n):
  b.append(int(input()))
for i in range(n):
  for j in range(3):
    for k in range(3):
      if b[i] == a[j][k]:
        s[j][k] = 1
res = "No"
if s[0][0] == 1 and s[0][1] == 1 and s[0][2] == 1:
  res = "Yes"
if s[1][0] == 1 and s[1][1] == 1 and s[1][2] == 1:
  res = "Yes"
if s[2][0] == 1 and s[2][1] == 1 and s[2][2] == 1:
  res = "Yes"
if s[0][0] == 1 and s[1][0] == 1 and s[2][0] == 1:
  res = "Yes"
if s[0][1] == 1 and s[1][1] == 1 and s[2][1] == 1:
  res = "Yes"
if s[0][2] == 1 and s[1][2] == 1 and s[2][2] == 1:
  res = "Yes"
if s[0][0] == 1 and s[1][1] == 1 and s[2][2] == 1:
  res = "Yes"
if s[2][0] == 1 and s[1][1] == 1 and s[0][2] == 1:
  res = "Yes"
print(res)

Measured memory_bytes: 9316
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int a;
  cin >> a;
  pr(48-a);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> umami(N);
  for(int n=0;n<N;n++){
    cin >> umami.at(n);
    }
  int sum=0;
  for(int x=0; x<N;x++){
    for(int y=0; y<N;y++){
      if(x<y) sum+=umami.at(x)*umami.at(y);
    }
  }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N;
        int[] a = new int[100000];
        int friend=0;
        
        N = sc.nextInt();

        for(int i=0;i<N;i++){
        	a[i] = sc.nextInt();
        }
        
        for(int i=0;i<N;i++){
        	int test = a[a[i]-1];
        	if(i+1==a[a[i]-1])friend++;
        }
        
        System.out.println(friend/2);
    }
}

Measured memory_bytes: 32568
#include<iostream>
    #include<string>
    #include<vector>
    #include<math.h>
    #include<cmath>
    #include<stack>
    #include <algorithm>
    #include <functional>
    //#include<stdlib.h>
    using namespace std;
    int main() {
    	long long int n, k, t,l=0; int s[40] = { 0 };
    	cin >> n >> k;
     
    	for (int i = 0; i < n; i++)
    	{
    		cin >> t;
    		for (int j = 0; j < 40; j++)
    		{
    			s[j] +=( t & 1);
    			t =( t >> 1);
    		}
    	}
    	t = 0;
    	for (int j = 39; j > -1; j--)
    	{
    		if ((s[j] < n - s[j])&&((k&((long long int)1<<j))== ((long long int)1 << j) ||l>0))
    		{
    			s[j] = n - s[j];
    		}
    		else { l += (k&((long long int)1 << j)); }
    	}
    	t = 0;
    	for (int j = 39; j >-1; j--)
    	{
    		t =( t << 1);
    		t+=s[j];
    	}
     
    	cout << t;
    	return 0;
    }

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

int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int sum=0;
    int ans=1e9;
    for(int i=0;i<=max(x,y);i++){
        sum=2*c*i+a*(max(x-i,0))+b*(max(0,y-i));
        if(ans>sum) ans=sum;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def main(Hitpoint,Attack):
  count_num = 0
  while True:
    Hitpoint -= Attack
    count_num += 1
    if Hitpoint <= 0:
      break
  return count_num
 
if __name__ == "__main__":
    inp=input().split()
    hitpoint = int(inp[0])
    attack = int(inp[1])
    print(main(hitpoint,attack))

Measured memory_bytes: 2940
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = (ll)1e9+7;
//}}}

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  while(a != b || b != c){
    if(a > b) swap(a, b);
    if(a > c) swap(a, c);
    if(b > c) swap(b, c);
    ans++;
    if(a == b){
      a++;
      b++;
    }else{
      a+=2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
height = list(map(int, input().split()))
bridge = [1]*N

for i in range(M):
    X, Y = map(int, input().split())
    if height[X-1] >= height[Y-1]:
        bridge[Y-1] =0
    if height[Y-1] >= height[X-1]:
        bridge[X-1] =0

print(bridge.count(1))


Measured memory_bytes: 85076
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for i in range(N)]

ct = 0
for i in A:
    if sum([j * k for j, k in zip(i, B)]) + C > 0:
        ct += 1

print(ct)


Measured memory_bytes: 3316
import java.util.*;


class Main{
	static int[] isPrimeFlag ;
	static int[] cntAccumlasion2017LikeNumbers;
	
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		int[] l = new int[ N ];
		int[] h = new int[ N ];
		
		
		createIsPrimeTable(100000);
		createCntAccumlasion2017LikeNumbers(100000);
		
		
		
		for(int i = 0 ; i < N ; i ++){
			l[i] = sc.nextInt();
			h[i] = sc.nextInt();
			
			int L = l[i] == 1 ? 0 :  l[i] - 1 - 1  ;
				
			System.out.println( cntAccumlasion2017LikeNumbers[ h[i] - 1  ] - cntAccumlasion2017LikeNumbers[ L ] );
		}
	}
	
	static void createIsPrimeTable(int N){
		
		isPrimeFlag = new int[N];
		isPrimeFlag[0] = -1;
		int cursor = 0;
		
		//isPrimeFlag = 0 なる数を探す
		for(int i = 1; i < N ; i++){
			if(isPrimeFlag[i] == 0){
				cursor = i;
				
				for(int j = cursor ; j < N ; j =  j + cursor + 1 ){
					isPrimeFlag[ j ] = j == cursor ? 1 : -1;
				}
			}
		}
	}
	
	
	/**
	*@param num 1以上
	*/
	static boolean is2017LikeNumber(int num){
		boolean result = false;
		if( num % 2 != 0  && isPrimeFlag[num - 1] == 1  ){
			result = isPrimeFlag[ ( num  + 1 )/2 - 1 ] == 1 ? true : false ;
		}
		return result;
	}
	
	static void createCntAccumlasion2017LikeNumbers(int N){
		
		cntAccumlasion2017LikeNumbers = new int[N];
		cntAccumlasion2017LikeNumbers[0] = 0;
		
		for(int i = 1 ; i < N  ; i ++){
			cntAccumlasion2017LikeNumbers[ i ] = 
			is2017LikeNumber(i + 1) ? cntAccumlasion2017LikeNumbers[ i - 1] + 1 :
				                      cntAccumlasion2017LikeNumbers[ i - 1]   ;
		}
	}
}


Measured memory_bytes: 63908
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    string s;
    cin >> s;
    int h=0;
    for(int i=0;i<s.size();i++){
        if(i==A){
            if(s.at(i)!='-')h++;
        }
        else{
        if((s.at(i)>='0')&&(s.at(i)<='9'))continue;
        h++;
        }
    }
    if(h!=0)cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX_H = 100;
static const int MAX_W = 100;
static const int MOD = 100000;

int w, h;
int memo[3][3][MAX_H + 1][MAX_W + 1];

int main(){
	for(;;){
		cin >> w >> h;
		if(w == 0 && h == 0) break;
		w++; h++;

		fill(memo[0][0][0], memo[3][0][0], 0);

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(i == 0 && j == 0) memo[2][2][i][j] = 1;
				else if(i == 1 && j == 0) memo[2][0][i][j] = 1;
				else if(i == 0 && j == 1) memo[2][1][i][j] = 1;
				else if(j == 0){
					memo[0][0][i][j] += memo[0][0][i - 1][j];
				}else if(i == 0){
					memo[1][1][i][j] += memo[1][1][i][j - 1];
				}else{
					for(int k = 0; k < 3; k++){
						for(int l = 0; l < 2; l++){
							if(k != 0 || l != 1){
								memo[l][0][i][j] += memo[k][l][i - 1][j];
								memo[l][0][i][j] %= MOD;
							}
							if(k != 1 || l != 0){
								memo[l][1][i][j] += memo[k][l][i][j - 1];
								memo[l][1][i][j] %= MOD;
							}
						}
					}
				}
			}
		}

		int res = 0;
		for(int i = 0; i < 2; i++){
			for(int j = 0; j < 2; j++){
				res += memo[i][j][h - 1][w - 1];
				res %= MOD;
			}
		}
		cout << res << endl;
	}
	return 0;
}



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

int main(){
  int n; cin >> n;
  int ans = 0;
  vector<int> a(n), c(n-1);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  for(int i = 0; i < n; i++){
    int b; cin >> b;
    ans += b;
  }
  for(int i = 0; i < n- 1; i++){
    cin >> c.at(i);
  }
  for(int i = 0; i < n - 1; i++){
    if(a.at(i) + 1 == a.at(i + 1)) ans += c.at(a.at(i) - 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC109.A
{
    class Program
    {
        static void Main()
        {
            var sc = new Scanner();
            var a = sc.Nextint();
            var b = sc.Nextint();
            Console.WriteLine(a % 2 != 0 && b % 2 != 0 ? "Yes" : "No");
        }
    }
    class Scanner
    {
        string[] s;
        long i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public int Nextint()
        {
            return int.Parse(Next());
        }
        public int[] Arrayint(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = Nextint() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }

        public double[] ArrayDouble(long N, double add = 0)
        {
            double[] Array = new double[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }

        public decimal NextDecimal()
        {
            return decimal.Parse(Next());
        }

        public decimal[] ArrayDecimal(long N, decimal add = 0)
        {
            decimal[] Array = new decimal[N];
            for (long i = 0; i < N; i++)
            {
                Array[i] = NextDecimal();
            }
            return Array;
        }
    }
}


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

string S;
string T;

int numS = 0;
int numT = 0;


int main() {
    cin >> S >> T;

    numS = S.length();
    numT = T.length();

    if(T.substr(0,numT-1) == S){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

  
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x);1
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair	
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef long double ld;	
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
 
const ll MAX = 10000000;
const ll inf = 5e18-1;

int main() {
	fastio;
	ll r;
	cin>>r;
	cout<<r*r<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

int main()
{
	while ( true )
	{
		int h, w;
		cin >> h >> w;
		cin.ignore( 1 );

		if ( h == 0 && w == 0 )
		{
			break;
		}

		vector<string> field;

		REP( i, 0, h )
		{
			string buffer;
			cin >> buffer;
			field.PB( buffer );
		}

		pair<int,int> current = MP( 0, 0 );
		set< pair<int,int> > visited;

		while ( true )
		{
			if ( field[ current.fst ][ current.snd ] == '.' )
			{
				cout << current.snd << ' ' << current.fst << endl;
				break;
			}

			if ( visited.find( current ) != visited.end() )
			{
				cout << "LOOP" << endl;
				break;
			}

			visited.insert( current );

			switch ( field[ current.fst ][ current.snd ] )
			{
			case '>':
				current.snd++;
				break;
			case '<':
				current.snd--;
				break;
			case '^':
				current.fst--;
				break;
			case 'v':
				current.fst++;
				break;
			}

		}
	}

	return 0;
}

Measured memory_bytes: 0
N = int(input())
A = list(map(int, input().split()))
newA = []
count = 0
ans = 0

for i in range(N):
    if A[i]%2 ==0:
        newA.append(A[i])
        count += 1

for j in range(count):
    if newA[j]%3 == 0 or newA[j]%5== 0:
        ans += 1

if ans == count:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 9140
#include <iostream>

int main()
{
	int n, b, f, r, v;
	int c[4][3][10] {};
	std::cin >> n;
	for (int i=0; i!=n; ++i) {
		std::cin >> b >> f >> r >> v;
		c[b-1][f-1][r-1] += v;
	}
	for (int i=0; i!=4; ++i) {
		for (int j=0; j!=3; ++j) {
			for (int k=0; k!=10; ++k) {
				std::cout << ' ' << c[i][j][k];
			}
			std::cout << '\n';
		}
		if (i!=3) std::cout << "####################\n";
	}
}

Measured memory_bytes: 3080
#include<iostream>
#include<string>
#include<set>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

    int N;
    long long int A;
    set<long long int> st={};
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A;
        if(st.find(A)==st.end()) st.insert(A);
        else st.erase(A);
    }
        
	cout << st.size() << "\n";
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;

int main(){
     
    int a,b;
    
    cin>>a>>b;
    
    if(a==1)a=14;
    if(b==1)b=14;
    if(a>b)cout<<"Alice"<<endl;
    else if(a<b)cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
     
    return 0;
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pll pair<ll,ll>
#define vll vector<ll,ll>
#define all(a) (a).begin(),(a).end()
#define ff first
#define ss second
#define sz(x) (ll)x.size()
#define hell 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>b;i--)
#define lbnd lower_bound
#define ubnd upper_bound
#define bs binary_search
#define gcd(a,b) __gcd((a),(b))
#define EPS 1e-12
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define sqrt sqrtl
#define cbrt cbrtl
using namespace std;
ll n;
vector<ll> a;
vector<ll> b;

int main()
{
	cin>>n;
	ll i,x;
	for(i=0;i<n;i++)
	{
		cin>>x;
		a.pb(x);
	}
	for(i=0;i<n;i++)
	{
		cin>>x;
		b.pb(x);
	}
	ll sum1=0,sum2=0;
	for(i=0;i<n;i++)
		if(a[i]>b[i])
		{
			sum1+=a[i];
			sum2+=b[i];
		}
		cout<<sum1-sum2;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

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

    vector<ll> A(N);
    rep (i, N) { cin >> A[i]; }

    vector<ll> B(N/2);

    rep (i, N/2)
    {
        B[i] = A[i*2] ^ A[i*2+1];
    }

    ll lhs = 0, rhs = 0;
    rep (i, (N/2)-1) { rhs ^= B[i+1]; }

    rep (i, N/2)
    {
        const auto prev = (A[i*2+0] ^ lhs) ^ rhs;
        const auto next = (A[i*2+1] ^ lhs) ^ rhs;

        cout << next << endl;
        cout << prev << endl;
        if (i+1 == N/2) { break; }

        rhs = rhs ^ B[i + 1];
        lhs = lhs ^ B[i];
    }

    return 0;
}


Measured memory_bytes: 5548
#include "bits/stdc++.h"
using namespace std;
void InsertionSort(int N, vector<int>& A) {
	for (int i = 1; i < N; i++) {
		if (A.at(i - 1) > A.at(i)) {
			int tmp = A.at(i);
			int j = i - 1;
			while (j >= 0) {
				if (A.at(j) <= tmp) break;
				A.at(j + 1) = A.at(j);
				j--;
			}
			A.at(j) = tmp;
		}
		for (int k = 0; k < N; k++) {
			cout << A.at(k);
			if (k != N - 1) cout << ' ';
		}
		cout << endl;
	}
}
long long GCD(long long A, long long B) {
	if (B == 0) return A;
	else return GCD(B, A % B);
}
int main() {
	long long A, B;
	cin >> A >> B;
	cout << GCD(A, B) << endl;
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
  pr(b);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int a, b;
  cin >> a >> b;
  pr(a + b / 2);
  return 0;
}


Measured memory_bytes: 3492
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 0
constexpr int kMod = 1000000007;
typedef long long LL;

struct Info {
  int hcnt = 0;
  int wcnt = 0;
};

int main() {
  int H, W; std::cin >> H >> W;
  bool space[2002][2002];
  static Info info[2002][2002];

  for (int i = 0; i < H; ++i) {
    space[i][0] = false;
    space[i][W+1] = false;
  }
  for (int j = 0; j < W; ++j) {
    space[0][j] = false;
    space[H+1][j] = false;
  }

  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      char c; std::cin >> c;
      if (c == '#') space[i][j] = false;
      else          space[i][j] = true;
    }
  }
#if DEBUG
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      std::cout << space[i][j];
    }
    std::cout << std::endl;
  }
#endif

  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (!space[i][j]) continue;

      int hcnt = 0, wcnt = 0;
      // Vertical direction count.
      if (space[i-1][j]) {
        hcnt = info[i-1][j].hcnt;
      } else {
        for (int k = i+1; k <= H; ++k) {
          if (!space[k][j]) break;
          ++hcnt;
        }
      }

      // Horizontal direction count.
      if (space[i][j-1]) {
        wcnt = info[i][j-1].wcnt;
      } else {
        for (int k = j+1; k <= W; ++k) {
          if (!space[i][k]) break;
          ++wcnt;
        }
      }

      info[i][j].hcnt = hcnt; info[i][j].wcnt = wcnt;
//      std::cout << "(" << hcnt << "," << wcnt << ")";
    }
//    std::cout << std::endl;
  }

  LL vmax = 0;
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (!space[i][j]) continue;
      LL v = (LL)info[i][j].hcnt + (LL)info[i][j].wcnt + 1LL;
      vmax = std::max(vmax, v);
    }
  }
  std::cout << vmax << std::endl;
}


Measured memory_bytes: 35456
# ABC 081: B – Shift only
n = int(input())
a = [int(s) for s in input().split()]
can_divided = True
number_of_operations = 0

while can_divided:
    for i in range(len(a)):
        if a[i] % 2 != 0:
            can_divided = False
            break
        else:
            a[i] //= 2
    else:
        number_of_operations += 1

print(number_of_operations)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    
    int i,a,b,c,d,e;
    
    while(scanf("%d", &a)!= EOF) {
    b=600/a;
    
    int sum=0;
           for(i=1;i<b;i++){
           e=i*a;
           d=e*e;
           c=a*d;
           sum+=c;
           
       }
       
       printf("%d\n",sum);
       if(a == 0) {
    break;
    }
       }
       
    return 0;
    }


Measured memory_bytes: 2036
x1,y1,x2,y2 = map(int,input().split())

dx = x2-x1
dy = y2-y1
x3 = x2-dy
y3 = y2+dx
x4 = x1-dy
y4 = y1+dx
print('{} {} {} {}'.format(x3,y3,x4,y4))

Measured memory_bytes: 3060
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	double x;

	cin >> x;

	double num = x / 3;

	double num2 = num * num*num;

	cout <<fixed<< num2 << endl;


	return 0;
}

Measured memory_bytes: 256
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

int solve(int n,vector<int> odd, vector<int> even){

    int m1 = *max_element(odd.begin(), odd.end());
    int m2 = *max_element(even.begin(), even.end());

    vector<int> sum1(m1+1);
    vector<int> sum2(m2+1);

    for (int i = 0; i < odd.size(); i++){
       sum1[odd[i]]++; 
    }

    auto Iter1 = max_element(sum1.begin(), sum1.end());
    int index = distance(sum1.begin(), Iter1);
    int ans = n/2 - *Iter1;

    for (int i = 0; i < even.size(); i++){
        sum2[even[i]]++;
    }

    vector<int>::iterator Iter2;

    bool t = false;
    while(t == false){
        Iter2 = max_element(sum2.begin(), sum2.end());
        int index2 = distance(sum2.begin(), Iter2);

        if (index != index2){
            t = true;
        } else {
            sum2[index2] = 0;
        }
    }

    ans += n/2 - *Iter2;

    return ans;

}
int main(){
    //input section

    int n;
    int ans = 0;

    cin >> n;
    vector<int> v;

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

    //vの分割seciton

    vector<int> odd,even;
    for (int i = 0; i < n; i+=2){
        odd.push_back(v[i]);
    }
    for (int i = 1; i < n; i+=2){
        even.push_back(v[i]);
    }

    int ans1 = solve(n, odd, even);
    int ans2 = solve(n, even, odd);
    /*
    //こっから
    //最大値を求めて最瀕値を求めるsection
    int m = *max_element(odd.begin(), odd.end());
    int m2 = *max_element(even.begin(), even.end());

    vector<int> sum(m+1);
    vector<int> sum2(m2+1);

    for (int i = 0; i < odd.size(); i++){
       sum[odd[i]]++; 
    }

    auto Iter1 = max_element(sum.begin(), sum.end());
    int index = distance(sum.begin(), Iter1);
    ans = n/2 - *Iter1;

    for (int i = 0; i < even.size(); i++){
        sum2[even[i]]++;
    }

    vector<int>::iterator Iter2;

    bool t = false;
    while(t == false){
        Iter2 = max_element(sum2.begin(), sum2.end());
        int index2 = distance(sum2.begin(), Iter2);

        if (index != index2){
            t = true;
        } else {
            sum2[index2] = 0;
        }
    }

    ans += n/2 - *Iter2;
    */
    //ここまでを関数化

    //cout << ans << endl;
    /*

    int ans2 = 0;
    vector<int> sum3(m2+1);
    vector<int> sum4(m+1);

    for (int i = 0; i < even.size(); i++){
       sum3[even[i]]++; 
    }
    Iter1 = max_element(sum3.begin(), sum3.end());
    index = distance(sum3.begin(), Iter1);
    ans2 = n/2 - *Iter1;

    for (int i = 0; i < odd.size(); i++){
        sum4[odd[i]]++;
    }

    //vector<int>::iterator Iter2;

    t = false;
    while(t == false){
        Iter2 = max_element(sum4.begin(), sum4.end());
        int index2 = distance(sum4.begin(), Iter2);

        if (index != index2){
            t = true;
        } else {
            sum4[index2] = 0;
        }
    }
    ans2 += n/2 - *Iter2;
    */

    if (ans1 < ans2) {
        cout << ans1 << endl;
    } else {
        cout << ans2 << endl;
    }

}


Measured memory_bytes: 2296
def dfs(n, s, types):
    if(n==1):
        for i in range(types):
            c = chr(97+i)
            print(s+c)
    else:
        for i in range(types):
            c = chr(97+i)
            if(i==types-1):
                dfs(n-1, s+c, types+1)
            else:
                dfs(n-1, s+c, types)

N = int(input())
dfs(N, '', 1)


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

int ans(int &a, int &b){
    int p=2018;
    a=a%2019;
    b=b%2019;
    for(int i=a; i<b ;i++){
        for(int h =a+1; h<=b ; h++){
            if((i*h)%2019<p){
                p=i*h%2019;
            }
        }
    }
    return p;
}
    
int main(){
    int l,r;
    cin >> l >> r;
    if(r-l>673){cout << 0 << endl;}
    else{
        cout << ans(l,r) << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

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

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
int h[maxn],dp[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&h[i]);
    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    printf("%d\n",dp[n]);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long gcd = gcd(Math.max(A, B), Math.min(A, B));
    // count(prime <= gcd && gcd % prime == 0);
    int ans = 1; // include '1'.
    boolean[] isPrime = new boolean[1000_001 + 1];
    Arrays.fill(isPrime, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i < isPrime.length; i++) {
      if (isPrime[i] && gcd % i == 0) {
        while(gcd % i == 0) {
          gcd /= i; // Assure uniqueness. e.g. 4=2*2*1
        }
        ans++;
      }
      for (int j = i; j < isPrime.length; j += i) {
        isPrime[j] = false;
      }
    }
    if (gcd > 1) ans++; // ?
    System.out.println(ans);
  }

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


Measured memory_bytes: 26068
#include<bits/stdc++.h>
using namespace std;
 
const int MAX_n = 1e5 + 5;
int n,mingcd;
int num[MAX_n];
int gcd_b[MAX_n];
int gcd_a[MAX_n];
 
int main()
{
	scanf("%d",&n);
	for ( int i = 0 ; i < n ; i++ )
		scanf("%d",&num[i]);
	gcd_b[0] = num[0];
	for ( int i = 0+1 ; i <= n-1 ; i++ )
		gcd_b[i] = __gcd(gcd_b[i-1],num[i]);
	gcd_a[n-1] = num[n-1];
	for ( int i = n-1-1 ; i >= 0 ; i-- )
		gcd_a[i] = __gcd(gcd_a[i+1],num[i]);
	mingcd = gcd_a[0+1];
	for ( int i = 0+1 ; i <= n-1-1 ; i++ )
		mingcd = max(mingcd,__gcd(gcd_b[i-1],gcd_a[i+1]));
	mingcd = max(mingcd,gcd_b[n-1-1]);
	printf("%d",mingcd);
	printf("\n");
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int a[N], b[N], c[N];
    rep(i , N){
        cin >> a[i] >> b[i] >> c[i];
    }

    int dp[N][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    
    for(int i=1;i<N;i++){
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
        dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b[i];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
    }
    int MAX=0;
    rep(i, 3){
        MAX = max(MAX, dp[N-1][i]);
    }
    printf("%d\n", MAX);
    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#define MAX 1000
static int INFTY = (1<<21);

int M[MAX][MAX],d[MAX],f[MAX],Q[MAX*2];
int color[MAX];
int head,tail,n;

void initialize(){
  head = tail = 1;
}

void enqueue(int x){
  Q[tail++] = x;
}

int empty(){
  return head == tail;
}

int dequeue(){
  int x = Q[head++];
  return x;
}

void bfs(int s){
  int i,u,v;
  
  initialize();
  enqueue(s);
  for(i = 0;i < n;i++ ){
    d[i] = INFTY;
  }
  d[s] = 0;
  
  while(!empty()){
    u = dequeue();
    
    for(v = 0;v < n;v++){
      if(M[u][v] == 0)continue;
      if(d[v] != INFTY)continue;
      d[v] = d[u] + 1;
      enqueue(v);
    }
  }
  for(i = 0;i < n;i++){
    printf("%d %d\n", i+1,((d[i]==INFTY)?(-1):d[i]));
  }
}

int main(){
  int i,j,a,b,c;
  
  scanf("%d",&n);

  for(i = 0;i <n;i++){
    for(j = 0;j <n;j++)M[i][j] = 0;
  }
  
  for(i = 0;i < n;i++){
    scanf("%d %d",&a,&b);
    a--;
    
    for(j = 0;j < b;j++){
      scanf("%d",&c);
      c--;
      M[a][c] = 1;
    }
    
  }
  
  bfs(0);

  return 0;
}



Measured memory_bytes: 2124
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

long long mod = 1e9 + 7;

long long maxi(long long x, long long n) {
	return x * n - x * (x - 1) / 2;
}

long long mini(long long x) {
	return x * (x - 1) / 2;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin >> n >> k;

	long long ans = 0;
	for (int i = k; i <= n + 1; ++i) {
		ans += (maxi(i, n) - mini(i) + 1) % mod;
	}

	cout << ans % mod << "\n";

	return 0;

}

Measured memory_bytes: 3636
#include<stdio.h>


int L[500010],time=0;
int temp[500000];
void merge_me(int L[],int L1,int R1,int L2,int R2){
	int i=L1,j=L2,index=0;
	for( ;i<=R1&&j<=R2;)
		if(L[i]<=L[j]) {temp[index++]=L[i++];time++;}
		else {temp[index++]=L[j++];time++;}
	while(i<=R1) {temp[index++]=L[i++];time++;}
	while(j<=R2) {temp[index++]=L[j++];time++;}//完成合并
	for(i=0,j=L1;i<index;++i)//{
		L[j++]=temp[i];
		//printf("%d ",temp[i]);}
} 
void mergesort_me(int L[],int L0,int R0){
	if(L0<R0){
		int t=(L0+R0)/2;
		mergesort_me(L,L0,t); //在这里犯了低级错误，以为L0和R0没有改变，果然还是没理解递归
		mergesort_me(L,t+1,R0); //其实把它当做左右子树处理来理解很清晰
		merge_me(L,L0,t,t+1,R0);}
} 

int main(){
	int n,l,r;
	scanf("%d",&n);
	if(n>5.e5) n=5.e5;
	for(int i=0;i<n;++i)
		scanf("%d",L+i);
	l=0,r=n-1;
	mergesort_me(L,l,r);
	for(int i=0;i<n;++i)
		if(i) printf(" %d",L[i]);
		else printf("%d",L[i]);
	printf("\n%d\n",time);

	return 0;
}


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

int main () {
  long long n, k;
  cin >> n >> k;
  
  long long d;
  
  d = n % k;
  
  if (d > k - d) {
    cout << k - d << endl;
  } else {
    cout << d << endl;
  }
}

Measured memory_bytes: 256
n,y = gets.split.map &:to_i
ans = [-1, -1, -1]
for i in 0..n
  for j in 0..n-i
    k = n-i-j
    sum = i*10000 + j*5000 + k*1000
    ans = [i, j, k] if y == sum
  end
end

puts ans*' '

Measured memory_bytes: 2044
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
    exit()
tmp=h*w
tmp_2=h*w
tmp_3=h*w
tmp_4=h*w
for i in range(1,h):
    half_h=h-i
    area_1=i*w
    area_2=half_h//2*w
    area_3=(half_h-(half_h//2))*w
    ans=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans<tmp:
        tmp=ans
for j in range(1,w):
    half_w=w-j
    area_1=h*j
    area_2=(half_w//2)*h
    area_3=(half_w-half_w//2)*h
    ans_2=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_2<tmp_2:
        tmp_2=ans_2
for i in range(1,h):
    half_w=w//2
    area_1=i*half_w
    area_2=i*(w-half_w)
    area_3=(h-i)*w
    ans_3=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_3<tmp_3:
        tmp_3=ans_3
for j in range(1,w):
    half_h=h//2
    area_1=h*j
    area_2=(w-j)*half_h
    area_3=(w-j)*(h-half_h)
    ans_4=max(area_1,area_2,area_3)-min(area_1,area_2,area_3)
    if ans_4<tmp_4:
        tmp_4=ans_4
print(min(tmp,tmp_2,tmp_3,tmp_4))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, y;
    cin >> n >> y;
    y /= 1000;
    rep(i, 0, 2001){
        rep(j, 0, 2001){
            int tmp = 10 * i + 5 * j;
            if(tmp < 0) continue;
            int k = y - tmp;
            if(k < 0) continue;
            if(i + j + k == n){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	long long int n, m;
	cin >> n >> m;
	vector<long long int>as;
	vector<long long int>bs;
	vector<long long int>cs;
	vector<long long int>ds;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		as.push_back(a);
		bs.push_back(b);
	}
	for (int i = 0; i < m; i++) {
		long long int c, d;
		cin >> c >> d;
		cs.push_back(c);
		ds.push_back(d);
	}
	for (int i = 0; i < n; i++) {
		long long int ans = 1000000000000;
		long long int ansnumber = 0;
		for (long long int j = 0; j < m; j++) {
			if (ans > abs(as[i] - cs[j]) + abs(bs[i] - ds[j])) {
				ans = abs(as[i] - cs[j]) + abs(bs[i] - ds[j]);
				ansnumber = j + 1;
			}
		}
		cout << ansnumber << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[100005];

ll func(ll a[],ll n, ll k)
{
    if(k==0)
    {
     return 0;
    }
    if(k<0)
    return 1;

    if(dp[k]!=-1)
    return dp[k];
    for(ll i=0;i<n;i++)
    {
        if(func(a,n,k-a[i])==0)
         return dp[k]=1;
    }
   return dp[k]=0;
}
 
int main() {
   
   ll n,i,k;
   cin>>n>>k;
   ll a[n];
   for(i=0;i<n;i++)
    cin>>a[i];
    memset(dp,-1,sizeof(dp));
    if(func(a,n,k))
    cout<<"First"<<endl;
    else
      cout<<"Second"<<endl;

}

Measured memory_bytes: 9072