akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    int n,m;
    cin >> n >> m; 

    int a[n][m];
    int s;

    

    for (int i=0;i<n;i++){
        cin >> s;
        for(int j=0;j<m;j++){
            if(j<s)cin >> a[i][j];
            else a[i][j]=0;
        }
    }

    int ans=0;
    for (int k=1;k<=m;k++){
        int num=0;
        for (int i=0;i<n;i++){
            int local=0;
            for(int j=0;j<m;j++){
                if(a[i][j]==k){local++;break;}
            }
            if(local!=0)num++;
        }
        if(num==n){ans++;}
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 

int main(void) {
  string s, t;cin>>s>>t;
  reverse(s.begin(), s.end()), reverse(t.begin(), t.end());
  bool can = false;
  int i;
  for(i = 0; i < s.size(); i++) {
    if(s[i] == t[0] || s[i] == '?'){
      can = true;
      Fr(j, t.size()-1) {
        if(i+j >=s.size()) {
          can = false;
          break;
        }
        if(s[i+j] != t[j] && s[i+j] != '?') can = false; 
      }
    }
    if(can) break;
  }
  if(can) {
  for(int j = 0; j < t.size(); j++) s[j+i] = t[j];
  for(int j = 0; j < s.size(); j++) if(s[j] == '?')s[j] = 'a';
  reverse(s.begin(), s.end());
  cout << s << endl;
  } else cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
require 'prime'

loop do
  m, a, b = gets.split.map(&:to_i)
  break if m == 0
  ans = [0, 0]
  prod = 0
  Prime.each.lazy.take_while{ |p| p <= Math.sqrt(100000).to_i }.each do |p|
    q = Prime.each.lazy.take_while{ |q| p * q <= m }
                   .drop_while{ |q| q < p  }
                   .take_while{ |q| a * q <= b * p }.to_a.last
    if q && prod < p * q
      ans = [p, q]
      prod = p * q
    end
  end
  puts ans * ' '
end

Measured memory_bytes: 9872
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,q,t[N<<2],lev[N];
char s[N];
void update(int k)
{
    t[k]=t[k<<1]|t[k<<1|1];
}
void build(int l,int r,int k)
{
    if(l==r)
    {
        lev[l]=k;
        t[k]=1<<(s[l]-'a');return;
    }
    int m=l+r>>1;
    build(l,m,k<<1);build(m+1,r,k<<1|1);
    update(k);
}
void fix(int x,char c)
{
    if(s[x]==c) return;
    s[x]=c;
    x=lev[x];
    t[x]=1<<(c-'a');
    while(x>>=1) update(x);
}
int query(int l,int r,int k,int x,int y)
{
    if(r<x||l>y) return 0;
    if(l>=x&&r<=y) return t[k];
    int m=l+r>>1;
    return query(l,m,k<<1,x,y)|query(m+1,r,k<<1|1,x,y);
}
int main()
{
    scanf("%d%s",&n,s+1);
    build(1,n,1);
    scanf("%d",&q);
    while(q--)
    {
        int opt;scanf("%d",&opt);
        if(opt==1)
        {
            int x;char c;
            scanf("%d %c",&x,&c);
            fix(x,c);
        }
        else
        {
            int l,r;scanf("%d%d",&l,&r);
            printf("%d\n",__builtin_popcount(query(1,n,1,l,r)));
        }
    }
}


Measured memory_bytes: 8448
using System;
using System.IO;

namespace AizuOnline
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var x = Convert.ToInt32(Console.ReadLine());

            for (int i = 1; i <= x; i++)
            {
                if (i % 3 == 0)
                {
                    Console.Write(" " + i);
                    continue;
                }

                var p = i;
                while (true)
                {
                    if (p % 10 == 3)
                    {
                        Console.Write(" " + i);
                        break;
                    }

                    p /= 10;
                    if (p == 0)
                    {
                        break;
                    }
                }
            }
            Console.WriteLine();
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9408
#!/usr/bin/env python3

def main():
    n, x = map(int, input().split())
    xn = list(map(int, input().split()))
    di = [abs(xi - x) for xi in xn]
    res = di[0]
    for i in range(1, n):
        res = gcd(res, di[i])
    print(res)

def gcd(x, y):
    if x < y:
        x, y = y, x  # x >= y
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

main()


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

int main() {
  string n;
  cin >> n;
  bool nine = true;
  for (int i = 1; i < n.size(); ++i) {
    if (n[i] != '9') {
      nine = false;
    }
  }
  int ans = n[0] - '0' + 9 * (n.size() - 1);
  if (!nine) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
#include "bits/stdc++.h"
using namespace std;

int main() {
    
	int n;
	cin >> n;
	
	int mx = 1;
	
	for (int base=2; base<=n; base++) {
		int curr = base;
		while (curr * base <= n) {
			curr = curr * base;
		} 
		if (curr == base) continue;
		mx = max(mx, curr);
	}
	
	cout << mx << endl;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>
#define pL3 pair<pL, ll>

const int MX=1000010;
const ll inf=1e18;
const ll mod=1e9+7;


ll dp[MX][2][2], n;

ll cal(int p, int f, int f2)
{

    if(p>=n) return (f==1 && f2==1);
    if(~dp[p][f][f2]) return dp[p][f][f2];

    ll ret=0;
    for(int i=0; i<10; i++)
    {
        ret+=cal(p+1, f|(i==0), f2|(i==9));
        ret%=mod;
    }
    return dp[p][f][f2]=ret;
}

int main()
{
    FasterIO;

//    int tc, cs=1; cin>>tc;
//    while(tc--)
    {

        cin>>n;

        mem(dp, -1);

        ll ans=cal(0, 0, 0);

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


Measured memory_bytes: 112904
#include<iostream>
using namespace std;
typedef long long ll;
ll n,m,a;
int main(){
  cin >> n >> m;
  a=1ll*((n&1)*n)^(((m&1)^1)*m)^((n^m)&1)^(((n^m)&2)>>1);
  cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <forward_list>
#include <map>
#include <unordered_map>
#include <utility>

#define MAXN 100000

using namespace std;

int pre[MAXN] = {-1};
int st[MAXN];

vector<pair<int,int>> vp;
vector<forward_list<int>> query;
map<pair<int,int>,int> mans;

struct pair_hash {
    template <class T1, class T2>
    size_t operator () (const pair<T1, T2> &p)const {
        auto h1 = hash<T1>{}(p.first);
        auto h2 = hash<T2>{}(p.second);
        return h1 + h2;
    }
};

unordered_map<pair<int,int>,int,pair_hash> seek;

void swap(int &i,int &j){
    int t = i;
    i = j;
    j = t;
}


class Edge{
public:
    int s;
    int t;
    Edge(int si,int ti):s(si),t(ti){;}
};

class Graph{
public:
    int V;
    vector<forward_list<int>> adj;
    Graph(int v):V(v){
        adj.resize(v);
        query.resize(v);
        for(int i = 0; i < V;i++) {st[i] = i;pre[i] = -1;}
        }
    void addEdge(int i,int j){adj[i].push_front(j);}
    void tarjanR(Edge e);
};

int root(int v){
    while(st[v] != v) v = st[v];
    return v;
}

void Graph::tarjanR(Edge e){
    int t = e.t;
    int s = e.s;
    pre[t] = 0;

    for(auto a = adj[t].begin();a != adj[t].end();++a){
        int v = *a;
        if(pre[v] == -1){
            tarjanR(Edge(t,v));
        }
    }
    for(auto k = query[t].begin(); k != query[t].end();++k){
        int mi = *k,ma = t;
        if(mi > ma) swap(mi,ma);
        pair<int,int> p = make_pair(mi,ma);
        if(pre[*k] != -1 && seek.find(p)!=seek.end() && seek[p] == -1){
            seek[p] = root(*k);
        }
    }
    st[t] = s;
}


int main()
{
    int V,j,q,tt;
    scanf("%d",&V);
    Graph G(V);
    for(int i = 0; i < V; i++){
        scanf("%d",&j);
        for(int k = 0; k < j;k++)
        {
            scanf("%d",&tt);
            G.addEdge(i,tt);
        }
    }

    int s,t;

    scanf("%d",&q);
    for(int i = 0; i < q;i++){
        scanf("%d %d",&s,&t);
        if(s > t){swap(s,t);}
        vp.push_back(make_pair(s,t));
        seek[make_pair(s,t)] = -1;
        query[s].push_front(t);
        query[t].push_front(s);
    }

    G.tarjanR(Edge(0,0));

    for(int i = 0; i < q;i++){
        printf("%d\n",seek[vp[i]]);
    }

    return 0;
}


Measured memory_bytes: 28708
n,m = map(int, raw_input().split(' '))
def intersection(A,B):
	a,b  = max(A[0],B[0]), min(A[1],B[1])
	return [a,b] if a <= b else []

r = [1,n+1]
for _ in range(m):
	a,b = map(int, raw_input().split(' '))
	r = intersection(r, [a,b])
	if len(r) == 0: break
print (r[1] - r[0] + 1) if r else 0


Measured memory_bytes: 33256
K = int(input())

num_table = [
	[1, 2, 3, 4, 5, 6, 7, 8, 9]
]

while True:
	if K < len(num_table[-1]):
#		for nums in num_table:
#			for n in nums:
#				print(n)
		print(num_table[-1][K - 1])
		break
	K -= len(num_table[-1])
	

	d = 1
	d2 = 10 ** len(num_table)
	new_num_table = set((d2,))
	for i in range(0, len(num_table) - 1):
		for num in num_table[i]:
			if num // d == 1:
				new_num_table.add(d2 + num)
		d *= 10
	
	for num in num_table[-1]:
		top = num // d
		if top > 1:
			new_num_table.add((top - 1) * d2 + num)
		if top > 0:
			new_num_table.add(top * d2 + num)
		if top < 9:
			new_num_table.add((top + 1) * d2 + num)
	
	new_num_table = list(new_num_table)
	new_num_table.sort()
	
	num_table.append(new_num_table)


Measured memory_bytes: 17764
from collections import Counter
s=str(input())
ss=s
a=Counter(s)
a=sorted(a.items(), key=lambda x: x[1])
a=a[::-1]
#print(list(a))

ans=float('inf')
for j in range(len(a)):
    s=ss
    ans1=0
    while len(set(s))!=1:
        t=''
        for i in range(len(s)-1):
            if s[i]==a[j][0] or s[i+1]==a[j][0]:
                t+=a[j][0]
            else:
                t+=s[i]
        s=t
        #print(s)
        ans1+=1
    ans=min(ans,ans1)
print(ans)

Measured memory_bytes: 3316
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] v = new int[n];
		int[] c = new int[n];
		for(i=0; i<n; i++) {
			v[i] = Integer.parseInt(sc.next());
		}
		int sum=0;
		int xy;
		for(i=0; i<n; i++) {
			xy = v[i] - Integer.parseInt(sc.next());
			if(xy>0)sum+=xy;
		}
		sc.close();
		sc = null;
		System.out.println(sum);
	}
}


Measured memory_bytes: 23124
import java.util.Scanner;

//20180509
//01

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

		int count = scanner.nextInt();
		int[][][] nums = new int[4][3][10];

		for(int i = 0;i < count;i++) {
			int b =  scanner.nextInt();
			int f =  scanner.nextInt();
			int r = scanner.nextInt();
			int v = scanner.nextInt();

			nums[b-1][f-1][r-1] += v;
		}
		scanner.close();
		for(int z = 0;z < 4;z++) {
			for(int y = 0;y < 3;y++) {
				for(int x = 0;x < 10;x++) {
					System.out.printf(" %d",nums[z][y][x]);
				}
				System.out.println();
			}
			if(z != 3) {
				for(int i= 0;i < 20;i++) {
					System.out.print("#");
				}
				System.out.println();
			}
		}
    }
}


Measured memory_bytes: 31052
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    char str[105]={0};
    scanf("%s", str);
    int len=strlen(str);
    int flag=0;
    int i;
    for(i=0; i<len; i++) {
        if(str[i]=='C') flag=1;
        else if(str[i]=='F' && flag) {
            printf("Yes\n"); return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const ll INF = 1e18 + 5;

void solve(){
    int n; cin>>n;
    vii deadl_leng(n);
    for(int i = 0; i < n; i++){
        int length,deadline;
        cin>>length>>deadline;
        deadl_leng[i] ={deadline,length};
    }
    sort(all(deadl_leng));
    //for(auto it:deadl_leng) cout<<it.F<<" "<<it.S<<endl;
    int cur=0;
    for(int i = 0; i < n; i++){
        cur+=deadl_leng[i].S;
        if(cur>deadl_leng[i].F){
            cout<<"No";
            return;
        }
    }
    cout<<"Yes";
}
int main(){
    int T=1;        //! COMMENT IF THERE IS NO TEST CASES
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 1792
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        var k = int.Parse(Console.ReadLine().Trim());
        getAns(a, b, c, k);
    }
    static void getAns(int a, int b, int c, int k)
    {
        var count = 0;
        while (b <= a)
        {
            b *= 2;
            count++;
            if (count > k) { Console.WriteLine("No"); return; }
        }
        while (c <= b)
        {
            c *= 2;
            count++;
            if (count > k) { Console.WriteLine("No"); return; }
        }
        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 27484
#include<iostream>
#include<vector>

using namespace std;

int N, M;

int main() {
    cin >> N;
    long long sum = 0;
    vector<long long> problems(N);
    for (int i = 0; i < N; i++) {
        cin >> problems[i];
        sum += problems[i];
    }
    cin >> M;
    int num;
    long long time;
    vector<long long> record;
    while (M--) {
        cin >> num >> time;
        record.push_back(sum - (problems[num - 1] - time));
    }
    for (auto res : record)
        cout << res << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(void)
{
	int w,h,c,x,a,b;
	scanf("%d %d %d",&w,&h,&c);
	if(w>h){
		x=h;
	}
	if(w<h){
		x=w;
	}
	while(1){
		if(w%x==0&&h%x==0){
			break;
		}
		x=x-1;
	}
	a=(w/x)*(h/x);
	b=a*c;
	printf("%d\n",b);
	return 0;
}


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

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

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

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


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

LL powm(LL x, LL y, LL m){
  if(y == 0) return 1;
  return powm(x*x%m, y/2, m) * (y%2==0?1:x) % m;
}

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

  int N;
  cin >> N;
  string S[2];
  REP(i,2) cin >> S[i];

  LL ans = 1, prv = -1;
  for(int i=0;i<N;){
	if(S[0][i] == S[1][i]){
	  if(prv == 1) (ans *= 2) %= MOD;
	  else if(prv == -1) ans *= 3;
	  prv = 1;
	  ++i;
	}
	else{
	  if(prv == 1) (ans *= 2) %= MOD;
	  else if(prv == -1) ans *= 6;
	  else (ans *= 3) %= MOD;
	  prv = 0;
	  i += 2;
	}
  }
  
  cout << ans << endl;

  return 0;
}


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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define scn(var)         cin >> var;
#define pYes()           prt("Yes")
#define pNo()            prt("No")
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

//----------------------------------------------------
int a, b, ans;
int main(){
    cin >> a >> b;
    for(int i = 0; i < 2; i++){
        if(a > b) {
            ans += a;
            a--;
        }else{
            ans += b;
            b--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();
        int[] c = new int[4];

        for(int i = 0; i < n; i++){
            switch(sc.next()){
                case "AC":
                    c[0]++;
                    break;
                case "WA":
                    c[1]++;
                    break;
                case "TLE":
                    c[2]++;
                    break;
                case "RE":
                    c[3]++;
                    break;
            }
        }

        System.out.println("AC x " + c[0]);
        System.out.println("WA x " + c[1]);
        System.out.println("TLE x " + c[2]);
        System.out.println("RE x " + c[3]);

    }
}


Measured memory_bytes: 58140
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it before "scanf" and other c input!

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    double  r;
    scanf("%lf",&r);
    printf("%.20f\n",2 * pi * r);
    return 0;
}

Measured memory_bytes: 3236
k = (int)(input())
if k % 360 == 0:
  print(1)
elif k % 180 == 0:
  print(2)
elif k % 120 == 0:
  print(3)
elif k % 90 == 0:
  print(4)
elif k % 72 == 0:
  print(5)
elif k % 60 == 0:
  print(6)
elif k % 45 == 0:
  print(8)
elif k % 40 == 0:
  print(9)
elif k % 36 == 0:
  print(10)
elif k % 30 == 0:
  print(12)
elif k % 24 == 0:
  print(15)
elif k % 20 == 0:
  print(18)
elif k % 18 == 0:
  print(20)
elif k % 15 == 0:
  print(24)
elif k % 12 == 0:
  print(30)
elif k % 10 == 0:
  print(36)
elif k % 9 == 0:
  print(40)
elif k % 8 == 0:
  print(45)
elif k % 6 == 0:
  print(60)
elif k % 5 == 0:
  print(72)
elif k % 4 == 0:
  print(90)
elif k % 3 == 0:
  print(120)
elif k % 2 == 0:
  print(180)
else:
  print(360)

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }

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

	for(int n; cin >> n && n;) {
		unordered_map<int, vector<int>> a;

		for(int i = 0; i < n; ++i) {
			int in;
			cin >> in;

			for(int j = 1;; j <<= 1, in >>= 1) {
				if(in & 1) {
					a[in].emplace_back(j);
					break;
				}
			}
		}

		int ans = 0;
		for(const auto &p : a) {
			const auto &vec = p.second;

			const int sum = accumulate(begin(vec), end(vec), 0);
			vector<int> dp(sum + 1, -1);
			dp[0] = 0;

			dump(vec);

			for(const auto &e : vec) {
				for(int i = sum - (sum % e); i > 0; i -= e) {
					if(dp[i - e] != -1) chmax(dp[i], dp[i - e] + 1);
				}
			}

			for(int i = 1; i <= sum; i <<= 1) {
				chmax(ans, dp[i]);
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1768
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10 ** 7)


def solve(N: int, V: "List[int]", C: "List[int]"):
    ans = 0
    for i in range(len(V)):
        ans += max(V[i] - C[i], 0)
    print(ans)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, V, C)


if __name__ == '__main__':
    main()


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

const ll INF = 1LL << 60;

ll N;
int dist[310][310];
int input[310][310];

int main() {
    cin >> N;

    rep(i, N)rep(j, N) cin >> input[i][j];

    rep(i, N)rep(j, N) dist[i][j] = input[i][j];

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                // if (i != j && dist[i][j] == dist[i][k] + dist[k][j]) {
                //     cout << i << " " << k << " " << j << endl;
                //     // 減らす
                // }
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    // 表が一致するかどうか
    // rep(i, N) {
    //     rep(j, N) {
    //         cout << dist[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    rep(i, N)rep(j, N) {
        if (input[i][j] != dist[i][j]) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            // 中継点
            bool judge = true;
            for (int k = 0; k < N; k++) {
                if (k == i) continue;
                if (k == j) continue;

                if (dist[i][k] + dist[k][j] == dist[i][j]) {
                    judge = false;
                }
            }
            if (judge) {
                ans += dist[i][j];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;






int main(){
    vector<ll> a(3);
    for(int i=0;i<3;i++){cin>>a[i];}
    sort(a.begin(),a.end());
    cout<<a[2]*10+a[1]+a[0]<<endl;
    
    
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200001];
	scanf("%s", s);
	int i,j,l=strlen(s);
	for(i=0; i<l; i++)
		if(s[i]=='A')
			break;
	for(j=l-1; j>0; j--)
		if(s[j]=='Z')
			break;
	printf("%d\n", j-i+1);
	return 0;
}

Measured memory_bytes: 512
#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+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n)cin >> p.at(i);
    int ans = 0;
    int m = -1*INF;
    rep(i,n){
        if(m>=p[i])++ans;
        m = min(m,p[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a == (b + c) || b == (a + c) || c == (a + b)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
n, d = gets.chomp.split.map(&:to_i)
x = n.times.map{gets.chomp.split.map(&:to_i)}#.transpose
combo = (0..(n - 1)).to_a.combination(2).to_a
sum = 0
cnt = 0
result = 0
combo.each do |a, b|
    d.times do |block|
        sum += (x[a][cnt] - x[b][cnt]) ** 2
        cnt += 1
    end
    result += 1 if Math.sqrt(sum) % 1 == 0.0
    cnt = 0
    sum = 0
end

puts result



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n, k;
    while(cin>>n>>k){
        ll ans=0;
        while(n>0){
        	n/=k;
        	++ans;
        }
        cout<<ans<<endl;
    }
  return 0;
}




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

int main(){
  int n;cin>>n;
  vector<int> h(n);
  for(int i=0;i<n;i++)cin>>h[i];
  
  vector<int> ans(n);
  ans[0]=0;ans[1]=abs(h[0]-h[1]);
  for(int i=2;i<n;i++){
    ans[i]=min(abs(h[i]-h[i-1])+ans[i-1],abs(h[i]-h[i-2])+ans[i-2]);
  }
  
  cout<<ans[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int t[9];
int merry[3] = {1,2,4};

int main(){
  t[0] = 1;
  REPR(i,9)t[i]=t[i-1]*3;
  int _p;
  while(~scanf("%d",&_p)){
    int p[8];
    p[0] = _p;
    REPR(i,8)cin>>p[i];
    int _[8] = {1,2,1,2,1,4,1,4};
    vi merry(_,_+8);
    string merrystr = "12121414";
    int minscore = 1145141919;
    string minid = "999999999";
    vi ret;
    REP(i,8){
      // calc
      int score = 0;
      REP(j,8) score += max(0,p[j]-merry[j]);
      if(score < minscore){
        minid = merrystr;
        ret = merry;
        minscore = score;
      }else if(score==minscore && merrystr < minid){
        minid = merrystr;
        ret = merry;
        minscore = score;
      }
      // loop
      int head = merry[0]; merry.erase(merry.begin()); merry.push_back(head);
      merrystr = merrystr.substr(1) + merrystr[0];
    }
    cout<<ret[0];
    REPR(i,8)cout<<" "<<ret[i];
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1284
X, K, D = map(int,input().split()) 
n = abs(X)//D
if n >= K:
  print(abs(X)-(K*D))
else:
  if (K-n) % 2 == 0:
    print(abs(X)%D)
  else:
    print(abs(abs(X)%D-D))

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

typedef tuple<int, int, int> triple;

int n, m;
map<pii, vector<triple>> g;
map<pii, ll> dist;

int main()
{
  cin >> n >> m;
  rep(i, m){
    int p, q, c;
    cin >> p >> q >> c;
    p--; q--;

    g[mp(p, c)].pb(mt(q, c, 0));
    g[mp(q, c)].pb(mt(p, c, 0));
    g[mp(p, c)].pb(mt(q, -1, 0));
    g[mp(q, c)].pb(mt(p, -1, 0));
    g[mp(p, -1)].pb(mt(q, c, 1));
    g[mp(q, -1)].pb(mt(p, c, 1));

    dist[mp(p, c)] = linf;
    dist[mp(q, c)] = linf;
    dist[mp(p, -1)] = linf;
    dist[mp(q, -1)] = linf;
  }
  
  rep(i, n) dist[mp(i, -1)] = linf;

  priority_queue<triple, vector<triple>, greater<triple>> que;
  que.push(mt(0, 0, -1));
  dist[mp(0, -1)] = 0;

  while(!que.empty()){
    int d, v, c;
    tie(d, v, c) = que.top();
    que.pop();

    if(dist[mp(v, c)] < d) continue;
    for(auto e : g[mp(v, c)]){
      int to, cc, dd;
      tie(to, cc, dd) = e;
      if(dist[mp(to, cc)] > dist[mp(v, c)] + dd){
        dist[mp(to, cc)] = dist[mp(v, c)] + dd;
        que.push(mt(dist[mp(to, cc)], to, cc));
      }
    }
  }
  
  ll ans = dist[mp(n-1, -1)];
  if(ans == linf) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 92152
#include <iostream>

using namespace std;

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


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
G = [[] for i in range(N)]

for m in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)

visited = set()
ans1, ans2 = [], []


def dfs(n, ans):
    ans.append(str(n+1))
    visited.add(n)
    for ni in G[n]:
        if ni not in visited:
            dfs(ni, ans)
            break


dfs(0, ans1)
for ni in G[0]:
    if ni not in visited:
        dfs(ni, ans2)
        break

print(len(ans1) + len(ans2))
print(" ".join(ans2[::-1] + ans1))

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

inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}

inline void writeln(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
     puts("");
}

signed main(){
    string s,t;
    cin>>s>>t;
    
    int ans=0;
    
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i])
            ans++;
    }
    
    writeln(ans);
    return 0;
}

Measured memory_bytes: 3920
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

        String[] str = s.split("");

        Arrays.sort(str, Comparator.reverseOrder());

        long ans = 0;

        for (int i = 0; i < s.length(); i++) {
            if (str[i].equals("B")) {
                ans += i;
            }
        }

        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'B') {
                ans -= i;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 54764
#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 srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200105
int word[200105];
const int len = 200005;
 
int main() {
    int n; cin >> n;

    int a[n] = {};
    rep(i,n)cin >> a[i];

    int sakujo = 0;
    int f[n] = {};
    srep(i,1,n-1){
        if(a[i-1]<a[i] && a[i]<a[i+1] && 200 < a[i-1]){
            f[i] = 1;
            sakujo++;
        }else if(a[i+1] < a[i] && a[i] < a[i-1] && 200 < a[i+1]){
            f[i] = 1;
            sakujo++;
        }
    }

    int ccc = 0;
    rep(i,n){
        if(f[i]==0){
            a[ccc] = a[i];
            ccc++;
        }
    }
    n = n - sakujo;

    srep(i,1,n-1){
        if(a[i-1]>a[i] && a[i]<a[i+1] && a[i]>250){
            a[i] = 250;
        }
    }

    srep(i,1,n-1){
        if(a[i-1]<a[i] && a[i]<a[i+1] && a[i-1] <= 260 && 270 <= a[i+1]){
            a[i] = 265;
        }
    }

    srep(i,1,n-1){
        if(a[i-1]>a[i] && a[i]>a[i+1] && a[i+1] <= 260 && 270 <= a[i-1]){
            a[i] = 265;
        }
    }

    srep(i,1,n-1){
        if(a[i-1]<a[i] && a[i]>a[i+1] && 270 <= a[i]){
            a[i] = 270;
        }
    }
    

    // 1種類でいけるかの判定
    if(n == 1){
        cout << '1' << endl;
        return 0;
    }
    srep(i, 1, n){
        if(a[i] <= a[i-1]){
            break;
        }
        if(i == n-1){
            cout << '1' << endl;
            return 0;
        }
    }

    // 文字の種類数
    int count = 2;

    int l = 2;
    int r = n;

    while(true){
        int count = (l+r)/2;
        int burst = 0; //フラグ
        rep(i,len)word[i] = 0;
        rep(i, n){
            if(i == 0){ // 初期条件（例：a[0]=5の時、あああああ）
                rep(j, min(a[0],len)){
                    word[j] = 1;
                }
                continue;
            }else if(a[i] > a[i-1]){
                if(a[i-1]<len){
                    srep(j,a[i-1],min(a[i],len)){
                        word[j] = 1;
                    }
                }
                continue;
            }

            drep(j,min(a[i],len)){
                if(j==(min(a[i],len) - 1)){
                    word[j]++;
                }
                if(word[j]==count + 1){
                    if(j==0){
                        burst = 1;
                        break;
                    }
                    word[j] = 1;
                    word[j-1]++;
                }
            }
            if(burst==1)break;
            srep(j,a[i],min(a[i-1],len)){
                word[j] = 0;
            }
        }
        if(burst == 1){
            l = count + 1;
        }else{
            r = count;
        }
        if(l==r)break;
    }

    cout << r << endl;
    return 0;
}
 


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];
  vector<ll> dp(N + 5, 1e15);
  dp[0] = 0;
  for (ll i = 0; i < N; i++) {
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(A[i + 1] - A[i]));
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(A[i + 2] - A[i]));
  }
  cout << dp[N - 1] << '\n';
  return 0;
}

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

long n,onea=1,oneb=-1,xla=0,xlb=0;
string x;
vector<long> a(200050);
vector<long> b(200050);
vector<long> ans(200050);
long keisan(long x,long y) {
  if(x==0) return y;
  long aaa=0;
  for(long i=1;i<=x;i*=2) if(x/i%2==1) aaa++;
  return keisan(x%aaa,y+1);
}
int main() {
  cin >> n >> x;
  for(long i=0;i<n;i++) if(x[i]=='1') onea++,oneb++;
  a[0]=1%onea;
  if(oneb>0) b[0]=1%oneb;
  for(long i=1;i<n;i++) {
    a[i]=a[i-1]*2%onea;
    if(oneb>0) b[i]=b[i-1]*2%oneb;
  }
  for(long i=0;i<n;i++) {
    if(x[n-i-1]=='1')xla=(xla+a[i])%onea;
    if(x[n-i-1]=='1'&&oneb>0)xlb=(xlb+b[i])%oneb;
  }
  
  for(long i=0;i<n;i++) {
    if(x[i]=='0') {
      long asdf=(xla+a[n-i-1])%onea;
      ans[i]=keisan(asdf,1);
    } else {
      if(oneb==0) ans[i]=0;
      else {
        long asdf=(xlb+oneb-b[n-i-1])%oneb;
        ans[i]=keisan(asdf,1);
      }
    }
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 8296
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;

int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

string alpha="abcdefghijklmnopqrstuvwxyz";

int A,B;



int main(){
	cin>>A>>B;
	if((A%3)==0||(B%3)==0||((A+B)%3)==0){
		cout<<"Possible"<<endl;
	}
	else cout<<"Impossible"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int n; scanf("%d", &n);
	int j = 1;
	while ((j + 1)*j / 2 < n)j++;
	while (n&&j>0&&n - j >= 0) {
		cout << j << endl;
		n -= j;
		j--;
	}
	if (n)cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int n, p, a[] = {3, 5, 7}, b[9];
int dp[9][2][2][2][2];

int f(int k, int s, int d1, int d2, int d3)
{
    if (k == 9)
        return d1 && d2 && d3;
    if (dp[k][s][d1][d2][d3] != -1)
        return dp[k][s][d1][d2][d3];
    
    int sol = 0;
    if (!d1 && !d2 && !d3)
        sol += f(k + 1, 1, 0, 0, 0);

    for (int i = 0; i < 3; ++i)
    {
        if (s == 1 || a[i] <= b[k])
        {
            int z = (s == 1 || a[i] < b[k]) ? 1 : 0;
            sol += f(k + 1, z, d1 || i == 0, d2 || i == 1, d3 || i == 2);
        }
    }

    return dp[k][s][d1][d2][d3] = sol;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < 9; ++i)
        b[9 - i - 1] = n % 10, n /= 10;

    int s = 0;
    while (b[s] == 0)
        s++;

    memset(dp, -1, sizeof dp);
    cout << f(s, 0, 0, 0, 0);
}


Measured memory_bytes: 256
//
//  main.cpp
//  ALDS1_7_A
//
//  Created by ptyuan on 2018/11/3.
//  Copyright © 2018 YY. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;

struct Node {
    int parent = - 1;
    int left;
    int right;
};

const int kCount = 100000;
const int kNil = -1;
Node tree[kCount];
int D[kCount];
int n = 0;

void depth(int u, int p) {
    D[u] = p;
    if (tree[u].right != kNil) { depth(tree[u].right, p); }
    if (tree[u].left != kNil) { depth(tree[u].left, p + 1); }
}

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << tree[u].parent << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if (kNil == tree[u].parent) {
        cout << "root, ";
    } else if (kNil == tree[u].left) {
        cout << "leaf, ";
    } else {
        cout << "internal node, ";
    }
    
    cout << "[";
    int c = 0;
    for (int i = 0, c = tree[u].left; c != kNil; c = tree[c].right, i++) {
        if (i > 0) cout << ", ";
        cout << c;
    }
    
    cout << "]" << endl;
}

int main(int argc, const char * argv[]) {
    
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        Node temp;
        temp.parent = temp.left = temp.right = kNil;
        tree[i] = temp;
    }
    int ll = 0;
    for (int i = 0; i < n; ++i) {
        int nodeIndex = kNil;
        scanf("%d", &nodeIndex);
        
        int depth = 0;
        scanf("%d", &depth);
        int parentNode = nodeIndex;
        for (int j = 0; j < depth; j++) {
            int subNodeIndex = kNil;
            scanf("%d", &subNodeIndex);
            
            if (0 == j) {
                tree[parentNode].left = subNodeIndex;
            } else {
                tree[ll].right = subNodeIndex;
            }
            ll = subNodeIndex;
            tree[subNodeIndex].parent = parentNode;
        }
    }
    
    int root = kNil;
    for (int i = 0; i < n; i++) {
        if (tree[i].parent == kNil) {
            root = i;
        }
    }
    
    depth(root, 0);
    
    for (int i = 0; i < n; i++) {
        print(i);
    }
    return 0;
}



Measured memory_bytes: 7848
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int h = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int r = sc.nextInt();
    if((r>x)||(r>y)||(r>w-x)||(r>h-y)){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 26260
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define N 100005
#define pb push_back
int main()
{
	int n,count=0,i;
	cin>>n;
	string s;
	cin>>s;
	for(i=0;i<n;i++)
	{
		if(s.substr(i,3)=="ABC")
			count++;
	}
	cout<<count;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
cnt = 0
target = 10**10
sum_A = 0
for a in A:
	if a < 0:
		cnt+=1
		sum_A+=-a
	else:
		sum_A+=a
		
	if target > abs(a):
		target = abs(a)

if cnt%2==0:
	print(sum_A)
else:
	print(sum_A - 2*target)

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int q;cin >> q;
    vector<int> b(q);
    vector<int> e(q);
    rep(i, q) {
        cin >> b.at(i) >> e.at(i);
    }
    rep(i, q) {
        reverse(a.begin()+b.at(i), a.begin()+e.at(i));
    }
    rep(i, n) {
        cout << a.at(i);
        if (i < n -1) cout << " ";
    }
    cout << endl;
}



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

int main() {
	int A1 ,A2,A3;
	cin >> A1 >> A2>>A3;
	if (A1+A2+A3 >=22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3512
/**
 *    author:  Mohamad Milhem
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(5)
int h,n;
long long yes[1003], no[1003];
long long dp[20005];



long long calc(int now){
	if (now <= 0)return 0;

	if (dp[now] != -1)return dp[now];


	long long ans = 2e9;

	for (int i = 0 ; i < n ; i++){
		ans = min(ans, calc(now - yes[i]) + no[i]);
	}

	return dp[now] = ans;
}








void solve(){

	cin >> h >> n;

	for (int i = 0 ; i < n ; i++){
		cin >> yes[i] >> no[i];
	}

	


	for (int i = 0 ; i <= 20000 ; i++){
		dp[i] = 1e17;
	}


	dp[0] = 0;


	for (int i = 0 ; i < n ; i++){
		for (int j = yes[i] ; j <= 20000 ; j++){
			dp[j] = min(dp[j] , dp[j - yes[i]] + no[i]);
		}

	}

	

	long long ans = 1e17;

	for (int i = h ; i <= 20000 ; i++){
		ans = min(ans, dp[i]);
	}

	cout << ans << endl;

}



int main()
{
    FAST;
    int t;
    t = 1;

    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3712
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d", $n, $m);

echo (($n - 1) * ($m - 1)) . PHP_EOL;

Measured memory_bytes: 4604
N,W = map(int, input().split())
dp = [0]*(W+1)
temp = [0]*(W+1)

for i in range(1,N+1):
    v,w = map(int,input().split())
    for j in range(1, W+1):
        if w <= j and v + temp[j-w] > temp[j]:
            dp[j] = temp[j-w]+v
    temp[0:W+1] = dp[0:W+1]

print(dp[W])

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

const int INF = 1001001001;
vector<int> to[100005];

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n, INF);
    vector<int> pre(n, -1);

    dist[0] = 0;
    q.push(0);

    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int u : to[v]) {
            if (dist[u] != INF) continue;
            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    rep(i, n) {
        if (i == 0) continue;
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 10708
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
   
 #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif
 
// -------------------------------------Code starts here---------------------------------------------------------------------     

   string s;
   cin>>s;
   if(s[2]==s[3]&&s[4]==s[5])
      cout<<"Yes";
   else
      cout<<"No";

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }
 

Measured memory_bytes: 256
#include <cstdio>
#include <set>
#include <algorithm>

using namespace std;

#define MAX_N 200005
#define MAX_A 1000005

int N;
int A[MAX_N];

void solve() {
  sort(A, A+N);
  set<int> ng;

  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (ng.count(A[i]) > 0) continue;
    int loop = 0;
    for (int j = A[i]; j < MAX_A; j+= A[i]) {
      ng.insert(j); loop++;
    }
    // printf("A[i] = %d, loop = %d\n", A[i], loop);
    if ((i > 0 && A[i-1] == A[i]) || (i < N-1 && A[i] == A[i+1])) continue;
    ans++;
  }

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

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", A+i);
  }
  solve();
}


Measured memory_bytes: 50944