akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	string s;
	cin>>s;
	int mx=0;
	for(int i=0;i<s.size();i++){
		int cnt=0;
		for(int j=i;j<s.size();j++){
			if(s[j]=='A'||s[j]=='C'||s[j]=='G'||s[j]=='T')cnt++;
			else break;
		}
		mx=max(mx,cnt);
	}
	cout<<mx<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<map> 
#include<string>
#define int long long
using namespace std;
int n,ans;
double d,x[200005],y[200005];
signed main()
{
	cin>>n>>d;
	for(int i=1;i<=n;i++)
	{
		scanf("%lf %lf",&x[i],&y[i]);
		if(sqrt(x[i]*x[i]+y[i]*y[i])<=d)
		{
			ans++;
		}
	}
	cout<<ans;
	
 } 

Measured memory_bytes: 7024
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll l,r,d;sc(l);sc(r);sc(d);
 ans=0;
 rep(i,l,r+1){
 if(i%d==0)ans++;}
 pr(ans);
return 0;}

Measured memory_bytes: 3624
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    K=I()
    x=LI()
    ans=0
    for i in range(N):
        ans+=min(x[i],abs(K-x[i]))
    print(ans*2)

main()


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

int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    ll mn;
    if(a % x != 0) mn = a + x - a%x;
    else mn = a;
    ll mx = b - b%x;
    if(mx < mn){
        cout << 0 << endl;
    }else{
        cout << (mx-mn)/x + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifndef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

lint readL(){
  lint res;
#ifdef ONLINE_JUDGE
  scanf("%I64d",&res);
#else
  scanf("%lld",&res);
#endif
  return res;
}
void printL(lint res){
#ifdef ONLINE_JUDGE
  printf("%I64d",res);
#else
  printf("%lld",res);
#endif
}

//const int INF=5e8;
int h,w;
string s;
string ans="snuke";
int main(){
  cin>>h>>w;
  REP(i,h) REP(j,w){
    string t;cin>>t;
    if(t==ans){
      printf("%c%d\n",j+'A',i+1);
      return 0;
    }
  }
  return 0;
}





Measured memory_bytes: 384
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [0] * N
    for i in range(N):
        S[i] = readline().strip()

    ans = 0
    d = defaultdict(int)
    for s in S:
        s = ''.join(sorted(s))
        if s in d:
            ans += d[s]
        d[s] += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 29520
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int n, m;
	int ans;
	int A[100][100], b[100];

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> A[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		ans = 0;
		for (int j = 0; j < m; j++) {
			ans += A[i][j] * b[j];
		}
		cout << ans << endl;
	}

	return (0);
}

Measured memory_bytes: 1200
s = input()
t = [a for a in s if a!="x"]
u = []
tmp = 0
for a in s:
    if a == "x":
        tmp += 1
    else:
        u.append(tmp)
        tmp = 0
u.append(tmp)

if t != t[::-1]:
    print(-1)
else:
    ans = 0
    for i in range(len(u)//2):
        ans += abs(u[i] - u[-i-1])
    print(ans)

Measured memory_bytes: 5620
#include<iostream>
using namespace std;
long dp[1111][1111],mod=1e9+7;
main()
{
	int n,k;cin>>n>>k;
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;j++)
		{
			dp[i][j]=(dp[i-1][j-1]+dp[i-1][j]*j)%mod;
		}
	}
	cout<<dp[n][k]<<endl;
}



Measured memory_bytes: 11784
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    string s;
    cin >> s;
    int count = 0;
    int result = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
            count++;
        }
        else{
            result = max(count, result);
            count = 0;
        }
    }
    cout << max(result, count) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n, d[50], ans = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> d[i];
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
}


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

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e15+7;

signed main(){
	string s;
	cin >> s;
	int a = stoi(s.substr(0, 4));
	int b = stoi(s.substr(5, 2));
	int c = stoi(s.substr(8, 2));
	bool flag = false;
	if(a < 2019)
		flag = 1;
	if(a == 2019 && b < 4)
		flag = 1;
	if(a == 2019 && b == 4 && c <= 30)
		flag = 1;
	cout << (flag ? "Heisei" : "TBD") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  // 標準入力高速化のおまじない
  // scanfとの同期を切る。以降紛らわしいのでscanf使用不可。
  ios::sync_with_stdio(false);
  // // cin前の自動flashをやめる
  cin.tie(nullptr);
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N,vector<int>(M));
  for(int i=0; i<N; i++){
    cin >> C[i];
    for(int j=0; j<M; j++){
      cin >> A[i][j];
    }
  }
  ll result = -1;
  // vector<vector<int>> conb;  // 組み合わせ（デバッグ用）
  // ビット全検索
  // 縦方向に{0},{0,1},{0,2}{0,1,2}とすべての組み合わせを試す
  for(int mask=0; mask < 1<<N; mask++){
    ll sum_cost = 0;
    vector<int> level(M);  // アルゴリズム理解度
    // vector<int> temp_conb; // デバッグ用
    for(int i=0; i<N; i++){
      if(!((mask>>i)&1)) continue;
      // temp_conb.push_back(i);
      sum_cost += C[i];
      for(int j=0; j<M; j++){
        level[j] += A[i][j];
      }
    }
    // if(!temp_conb.empty()){
    //   conb.push_back(temp_conb);
    // }

    // 目標のアルゴリズム理解度に到達しているか
    bool understood = true;
    for(int j=0;j<M;j++){
      if(level[j] < X){
        understood = false;
      }
    }
    if(understood && (result == -1 || result > sum_cost )){
      result = sum_cost;
    }

  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<set>
using namespace std;
int main () {
  int N;
  cin >> N;
  set<int>A;
  for (int i = 0; i < N; i ++) {
    int a;
    cin >> a;
    A.insert(a);
  }
  int kj = N - A.size();
  kj = ((kj + 1) / 2) * 2;
  cout << N - kj << endl;
}

Measured memory_bytes: 4992
n = int(input())
s = [input() for i in range(n)]
m,a,r,c,h = 0,0,0,0,0

for name in s:
    if name[0] == "M":
        m += 1
    if name[0] == "A":
        a += 1
    if name[0] == "R":
        r += 1
    if name[0] == "C":
        c += 1
    if name[0] == "H":
        h += 1
        
print(m*a*r
    +m*a*c
    +m*a*h
    +m*r*c
    +m*r*h
    +m*c*h
    +a*r*c
    +a*r*h
    +a*c*h
    +r*c*h
    )

Measured memory_bytes: 9772
N = int(input())
lis = [0,0,0,0]
for i in range(N):
    s = input()
    if s == 'AC':
        lis[0] += 1
    elif s == 'WA':
        lis[1] += 1
    elif s == 'TLE':
        lis[2] += 1
    else:
        lis[3] += 1
print('AC x '+str(lis[0]))
print('WA x '+str(lis[1]))
print('TLE x '+str(lis[2]))
print('RE x '+str(lis[3]))

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

int main()
{
  ll n;
  cin >> n;
  set<ll> st;
  string ret = "YES";
  rep(x, n){
    ll t;
    cin >> t;
  	if(st.find(t) != st.end())
    {
      ret = "NO";
      break;
    }
    st.insert(t);
  }
  cout << ret << endl;
	return 0;
}

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

const int MAX_N = 333;
int N;
int a[MAX_N], b[MAX_N];
int c[MAX_N], d[MAX_N];
vector<int> G[MAX_N];
int match[MAX_N];
bool used[MAX_N];

bool ok(int i, int j)
{
    return (a[i]<c[j]) && (b[i]<d[j]);
}

void add_edge(int from, int to)
{
	G[from].push_back(to);
	G[to].push_back(from);
}

bool dfs(int u)
{
	used[u] = true;
	for(int v : G[u]){
		int w=match[v];
		if(w<0 || (!used[w]&&dfs(w))){
			match[v]=u;
			match[u]=v;
			return true;
		}
	}
	return false;
}

int bipartite_matching()
{
	memset(match,-1,sizeof(match));
	int res = 0;
	for(int i=0;i<N;++i)if(match[i]<0){
		memset(used,false,sizeof(used));
		if(dfs(i)) res++;
	}
	return res;
}

void solve()
{
	for(int i=0;i<N;++i)for(int j=0;j<N;++j){
		if(ok(i,j)) add_edge(i, j+N);
	}
	cout << bipartite_matching() << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i) cin >> a[i] >> b[i];
	for(int i=0;i<N;++i) cin >> c[i] >> d[i];
	solve();
	return 0;
}

Measured memory_bytes: 3708
#include<stdio.h>

int main()
{
int a, min = 1000000, max = -1000000, n, i;
long long sum = 0;
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a);
sum += (long long)a;
if (a < min)
min = a;
if (a > max)
max = a;
}
printf("%d %d %ld\n", min, max, sum);

return 0;
}


Measured memory_bytes: 2128
#include <iostream>

using namespace std;

/** Problem0022 : Maximum Sum Sequence **/

int main()
{
	int n, num[5001]={0}, s;
	int maxNum;
	
	while (1) {
		cin >> n;
		if (n==0) break;
		for (int i=0; i<n; i++) {
			cin >> num[i];
		}
		
		maxNum = num[0];
		for (int i=0; i<n; i++) {
			s=0;
			for (int j=i; j<n; j++) {
				s+=num[j];
				if (s>maxNum)
					maxNum=s;
			}
		}
		cout << maxNum << endl;
	}
}

Measured memory_bytes: 1184
a, b, c = [int(x) for x in input().split()]
k = int(input())

count = 0
while b <= a:
    b *= 2
    count += 1
while c <= b:
    c *= 2
    count += 1
# print(a, b, c, count)
if count <= k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61832
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <numeric>

long int Euclid(long int A, long int B){
  if(A<B) return Euclid(B, A);
  while(B!=0){
    long int R = A%B;
    A = B; B = R;
  }
  return A;
}

int main(){
  long int N;
  std::cin>>N;
  std::vector<int> A(N);
  std::copy_n(std::istream_iterator<int>(std::cin),N,A.begin());
  std::vector<long int> gcd_front(N+1);
  std::vector<long int>  gcd_back(N+1);
  gcd_front[1]=A[0];
  gcd_back[1] =A[N-1];
  long int gcd_f = A[0]; long int gcd_b = A[N-1];
  for(int i = 1 ; i < N ; i++ ){
    gcd_front[i+1]=Euclid(gcd_f, A[i]);
    gcd_back[i+1] =Euclid(gcd_b, A[N-i-1]);
    gcd_f = gcd_front[i+1];
    gcd_b = gcd_back[i+1];
  }
  long int gcd = 0;
  long int max_gcd = gcd_back[N-1];
  for(int i = 2 ; i < N ; i++ ){
    gcd = Euclid(gcd_front[i-1],gcd_back[N-i]);
    if(max_gcd<=gcd) max_gcd = gcd;
  }
  gcd = gcd_front[N-1];
  if(max_gcd<=gcd) max_gcd = gcd;
  std::cout<<max_gcd<<std::endl;
  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N = 0;
  string S;
  cin >> N ;
  for (int i = 0; i < N; i++){
  	cin >> S;
  	if (S=="Y"){
    	cout << "Four" <<endl;
      	break;
    }
  	if (i==N-1){
      	cout << "Three" <<endl;
    }
  	S = "";
  }
}

Measured memory_bytes: 256
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        public int N, P;
        public int[] A;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                P = line[1];
                A = Input.ReadIntArray();
            }

            int[] mods = new int[2];
            for (int i = 0; i < N; i++)
            {
                mods[A[i] % 2]++;
            }

            // corner case
            if (P == 1 && mods[1] == 0)
            {
                Console.WriteLine(0);
                return;
            }

            int c = mods[0] + Math.Max(mods[1] - 1, 0);
            long ret = Power2(2, c);
            Console.WriteLine(ret);
        }

        public long Power(long x, long n)
        {
            long tmp = 1;

            if (n > 0)
            {
                tmp = Power(x, n / 2);
                if (n % 2 == 0) tmp = tmp * tmp;
                else tmp = tmp * tmp * x;
            }

            return tmp;
        }

        public long Power2(long x, long n)
        {
            long tmp = 1;
            for (int i = 0; i < n; i++)
            {
                tmp *= 2;
            }
            return tmp;
        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13268
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for (int i = 0; i < n; i++) {
			double[] xy = new double[8];
			for (int j = 0; j < 8; j++) {
				xy[j] = stdIn.nextDouble();
			}
			double m = (xy[2] - xy[0]) * (xy[7] - xy[5]) - (xy[3] - xy[1]) * (xy[6] - xy[4]);
			if(Math.abs(m) < 1e-10){
				System.out.println("YES");
			}
			else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 23228
import math
a=int(input())
b=[]
for i in range(2,11):
    if math.ceil(a**(1/i))>=2:
        b.append((math.ceil(a**(1/i))**i if math.ceil(a**(1/i))**i<=a else math.floor(a**(1/i))**i))
print(max(b)if a>3else 1)

Measured memory_bytes: 3060
import sys
import os

def file_input():
    f = open('ABC116/input.txt', 'r')
    sys.stdin = f

def minusmin(a):
    # print(a)
    if len(a)==1:
        # print('end:'+str(a[0]))
        return a[0]
    else:
        a_min=min(a)
        # print('min:'+str(a_min))
        # print(a_min)
        j=0
        out=a_min
        for i in range(len(a)):
            a[i]-=a_min
            if a[i]==0:
                # print("j="+str(j)+" i="+str(i))
                if i!=j:
                    out+=minusmin(a[j:i])
                j=i+1
            elif i==len(a)-1 and a[i]!=0:
                out+=minusmin(a[j:i+1])
        return out

def main():
    #file_input()
    N=int(input())
    h_li=list(map(int, input().split()))

    print(minusmin(h_li))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int a,b;
	cin>>a>>b;
	cout<<max(a,b)+max(max(a,b)-1,min(a,b))<<endl;
	return 0;
}

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

int main()
{
  while(true)
  {
    int h,w;
    cin >> h >> w;
    if ( h == 0 && w == 0 ) break;
    char **room = new char*[h];
    for (int i=0; i<h; i++)
    {
      room[i] = new char[w];
    }

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

    int x = 0;
    int y = 0;
    bool flag = true;
    while(flag)
    {
      switch (room[y][x])
      {
      case '>':
        room[y][x] = 'x';
        x++;
        break;
      case '<':
        room[y][x] = 'x';
        x--;
        break;
      case '^':
        room[y][x] = 'x';
        y--;
        break;
      case 'v':
        room[y][x] = 'x';
        y++;
        break;
      case '.':
        cout << x << ' ' << y << endl;
        flag = false;
        break;
      case 'x':
        cout << "LOOP" << endl;
        flag = false;
        break;
      }
    } //おへや

    for (int i=0; i<h; i++)
    {
      delete[] room[i];
    }
    delete[] room;
  } //  データセット
}

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#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, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



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

	LL N, M; cin >> N >> M;
	vector<PLL>a(M);
	FOR(i, 0, M) {
		cin >> a[i].first >> a[i].second;
	}
	sort(ALL(a), [](const PLL&a, const PLL&b) {
		if (a.second != b.second) {
			return a.second < b.second;
		}
		else {
			return a.first < b.first;
		}
	});
	LL s = 0; LL ans = 0;
	FOR(i, 0, M) {
		if (s <= a[i].first) {
			s = a[i].second;
			ans++;
		}
	}

	std::cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;

int main() {
	int r, d, x;
	cin >> r >> d >> x;
	ll ans=x;
	for (int i = 0; i < 10; i++) {
		ans = r * ans - d;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int i,j,n,m;
    int a[100][100]={};
    int b[100]={};
    int c[100]={};
    
    scanf("%d%d",&n,&m);
    
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            scanf("%d",&a[i][j]);//ai+1j+1
    
    for(i=0;i<m;i++)
        scanf("%d",&b[i]);//bi-1
    
    for(i=0;i<n;i++)
        //c[i]=a[i][0]*b[0]+a[i][1]*b[1]+...a[i][m-1]*b[m-1]
        for(j=0;j<m;j++)
            c[i]+=a[i][j]*b[j];
    
    for(i=0;i<n;i++)
        printf("%d\n",c[i]);




}



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

using namespace std;

#define ll long long
#define ar array

struct Node{
    int Num;
    int length = 0;
    set<Node*> reach;
};


int N,M,A,B;
Node a[100001];
int r[100001];

void solve(){

    cin >> N >> M;
    

    for (int i = 0; i < N; i++)
    {
        a[i].Num = i;
        r[i] = 0;
    }
    
    for (int i = 0; i < M; i++)
    {
        cin >> A >> B;
        A--;
        B--;

        a[A].reach.insert(&a[B]);
        a[B].reach.insert(&a[A]);
    }
    

    vector<Node*> queue;
    vector<Node*> nextqueue;
    queue.push_back(&a[0]);
    r[0] =1;

    int cur = 1;
    while (!queue.empty())
    {
        for (auto q : queue)
        {
            //cout << "in Queue " << q->Num << endl;
            for (auto rea : q->reach)
            {
                if(r[rea->Num] == 0){
                    rea->length = q->Num+1;
                    r[rea->Num] = 1;
                    nextqueue.push_back(rea);
                }
            }
            
        }
        
        cur++;
        queue = nextqueue;
        nextqueue.clear();
    }
    


    bool flag = false;
    for (int i = 0; i < N; i++)
    {
        if(r[i] ==0) flag == true;
    }
    
    if(flag){
        cout << "No"<< endl;
    }
    else{
        cout << "Yes" << endl;
        for (int i = 1; i < N; i++)
        {
            cout << a[i].length << endl;
        }
        
    }

}





int main(){

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

    solve();

}

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

typedef long long int ll;

#define MAX 1000005
vector<int> primes;
bool isprime[MAX];


void sieve(int n){
	memset(isprime, true, sizeof(isprime));
	isprime[0] = isprime[1] = false;
	int p;
	for( p=2; p*p<=n; p++){
		if(isprime[p]){
			primes.push_back(p);
			for(int i=p*2; i<=n;i+=p){
				isprime[i] = false;
			}
		}
	}
	for(int i=p; i<=n;i++){
		if(isprime[i]) primes.push_back(i);
	}
}



typedef long long int ll;

int main(){
	sieve(MAX);
	ll n; cin>>n;
	int ans = 0;
	for(auto x: primes){
		int v =x;
		int p = 1;
		while(n%(int)(pow(v,p))==0){
			n/=(int)pow(v,p);
			p+=1;
			ans+=1;
		}
		while(n%v==0){
			n/=v;
		}
	}
	if (n>1000000) ans++;
	printf("%d",ans);
}


Measured memory_bytes: 5264
#include <iostream>

int main()
{
	std::string str;
	std::size_t a_pos, z_pos;

	std::cin >> str;
	for (a_pos = 0; str.at(a_pos) != 'A'; a_pos++) {}
	for (z_pos = str.size() - 1; str.at(z_pos) != 'Z'; z_pos--) {}

	std::cout << (z_pos - a_pos + 1) << std::endl;

	return 0;
}

Measured memory_bytes: 640
#https://atcoder.jp/contests/abc136/tasks/abc136_c

n = int(input())
h = [int(i) for i in input().split()]

flag = 'Yes'
for i in reversed(range(n - 1)):
    if h[i+1] - h[i] < 0 and h[i+1] - h[i] > -2:
        h[i] -= 1
    elif h[i+1] - h[i] <= -2:
        flag = 'No'
        break
print(flag)

Measured memory_bytes: 14252
//キューというデータ構造を定義
#include <stdio.h>
#include <string.h>
#define LEN 100005

//プロセスを表す構造体
typedef struct pp{
    char name[100];
    int t;
} P;//Pという名前で扱う(C++でいうクラス定義みたいなもの)

P Q[LEN];
int head, tail, n;

void enqueue(P x){//要素の追加
    Q[tail] = x;
    tail = (tail + 1)%LEN; //ただ単にtailをインクリメントしたら困るので、LENの値まで増えたら0になるようにする
}

P dequeue(){//中身を取り出す//Pは構造体の名前
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b){ return a < b? a : b;} //最小値を返す

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q); //プロセス数を表すn, クオンタムを表す整数q

    //全てのプロセスをキューに順番に追加する
    for(i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }

    head = 1; tail = n + 1;

    //シミュレーション
    while(head != tail){
        u = dequeue();//先頭の要素（headが指している要素）を取り出してuに代入

        c = min(q, u.t); //qまたはプロセスに必要な時間u.tだけ処理を行う

        u.t -= c; //経過時間を計算（プロセスに必要時間がクオンタムより小さいならばu.tは0になる（処理が完了する））

        elaps += c; //経過時間を加算

        if(u.t > 0)
            enqueue(u);//処理が完了していなけらばキューに追加
        else{
            printf("%s %d\n", u.name, elaps);//処理が終わったプロセスから表示していく
        }
    }
    return 0;
}




Measured memory_bytes: 11904
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val c = sc.next()
    println(problem049a(c))
}

fun problem049a(c: String): String {
    return when (c) {
        "a", "i", "u", "e", "o" -> "vowel"
        else -> "consonant"
    }
}

Measured memory_bytes: 29468
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60
#define MOD 1000000007

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

template<class T> inline bool chMax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chMin(T& a, T b){ if (a > b) { a = b; return true; } return false; }
template<class T> inline ll gcd(T a, T b){ if (a % b == 0){ return b; } else{ return gcd(b, a%b); } }
template<class T> inline ll lcm(T a, T b){ return a * b / gcd<ll>(a, b); }

int main(){
    ll A, B;
    cin >> A >> B;
    ll ans = lcm<ll>(A, B);

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


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

using namespace std;

int small_x[4] = {-1,  0, 0, 1};
int small_y[4] = { 0, -1, 1, 0};

int medium_x[8] = {-1, -1, -1,  0, 0,  1, 1, 1};
int medium_y[8] = {-1,  0,  1, -1, 1, -1, 0, 1};

int large_x[12] = {-2, -1, -1, -1,  0,  0, 0, 0,  1, 1, 1, 2};
int large_y[12] = { 0, -1,  0,  1, -2, -1, 1, 2, -1, 0, 1, 0};

void solve()
{
	int Field[14][14];
	memset(Field, 0, sizeof(Field));
	int a, b, c;
	while(~scanf("%d,%d,%d", &a, &b, &c))
	{
		++Field[b + 2][a + 2];
		if(c == 1)
		{
			for(int i = 0; i < 4; ++i)
			{
				++Field[b + 2 + small_y[i]][a + 2 + small_x[i]];
			}
		}
		else if(c == 2)
		{
			for(int i = 0; i < 8; ++i)
			{
				++Field[b + 2 + medium_y[i]][a + 2 + medium_x[i]];
			}
		}
		else if(c == 3)
		{
			for(int i = 0; i < 12; ++i)
			{
				++Field[b + 2 + large_y[i]][a + 2 + large_x[i]];
			}
		}
	}
	int count = 0;
	int Max = 0;
	for(int i = 2; i < 12; ++i)
	{
		for(int j = 2; j < 12; ++j)
		{
			if(Field[i][j] == 0)
			{
				++count;
			}
			if(Max < Field[i][j])
			{
				Max = Field[i][j];
			}
		}
	}
	cout << count << endl;
	cout << Max << endl;
}

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

Measured memory_bytes: 0
def bubblesort(a,n):
    exc = 0
    flag = True
    while flag:
        flag = False
        for j in range(n-1,0,-1):
            if a[j] < a[j-1]:
                exc += 1
                tmp = a[j]
                a[j] = a[j-1]
                a[j-1] = tmp
                flag = True
    return exc

n = int(input())
a = list(map(int,input().split()))

exc = bubblesort(a,n)
print(*a)
print(exc)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int a,b;cin>>a>>b;
    vstr grid(100);
    rep(i,50)rep(j,100){
        grid[i]+='#';
    }
    rep(i,50)rep(j,100){
        grid[i+50]+='.';
    }
    int res=0;
    for(int i=0;i<50;i+=2){
        for(int j=0;j<100;j+=2){
            if(res==a-1)break;
            grid[i][j]='.';
            res++;
        }
        if(res==a-1)break;
    }
    res=0;
    for(int i=51;i<100;i+=2){
        for(int j=0;j<100;j+=2){
            if(res==b-1)break;
            grid[i][j]='#';
            res++;
        }
        if(res==b-1)break;
    }
    cout<<100<<" "<<100<<endl;
    rep(i,100)cout<<grid[i]<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  float x1,y1,x2,y2,x3,y3,xp,yp;
  float a,b,c,d,e,f,s1,s2,t1,t2;
  while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
    t2 = 0;
    a = sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
    b = sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
    c = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    s1 = (a+b+c)/2.0; // 3辺を頂点とする三角形の面積
    t1 = sqrt(s1*(s1-a)*(s1-b)*(s1-c));
    d = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
    e = sqrt((x3-xp)*(x3-xp)+(y3-yp)*(y3-yp));
    f = sqrt((x2-xp)*(x2-xp)+(y2-yp)*(y2-yp));
    s2 = (a+e+f)/2; 
    t2 += sqrt(s2*(s2-a)*(s2-e)*(s2-f));
    s2 = (b+d+e)/2; 
    t2 += sqrt(s2*(s2-b)*(s2-d)*(s2-e));
    s2 = (c+d+f)/2; 
    t2 += sqrt(s2*(s2-c)*(s2-d)*(s2-f));
    if( (t1 + 0.00001) >= t2){
      cout << "YES" << endl;
    }else {
      cout << "NO" << endl;
    }
  }
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl;
using namespace std;

int main(){
    int ans=0;
    int K; cin>>K;
    for(int a=1; a<=K; a++){
        for(int b=1; b<=K; b++){
            for(int c=1; c<=K; c++){
                ans+=__gcd(a, (__gcd(b, c)));
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3544
local n, k, c = io.read("*n", "*n", "*n", "*l")
local s = io.read()
local t = {}
local okday = {}
for i = 1, n do
  t[i] = s:sub(i, i) == "o"
  if t[i] then
    table.insert(okday, i)
  end
end
local score = {}
for i = 1, #okday do
  score[i] = 1
end
local dayleft, dayright = {}, {}
for i = 1, k do
  dayleft[i], dayright[i] = 0, 0
end
local curscore, curday = 1, okday[1]
dayleft[1] = 1
for i = 2, #okday do
  if curday + c < okday[i] then
    curscore = curscore + 1
    if curscore == k + 1 then break end
    dayleft[curscore] = okday[i]
    curday = okday[i]
  end
end

curscore, curday = k, okday[#okday]
dayright[k] = curday
for i = #okday - 1, 1, -1 do
  if okday[i] + c < curday then
    curscore = curscore - 1
    if curscore == 0 then break end
    dayright[curscore] = okday[i]
    curday = okday[i]
  end
end
for i = 1, k do
  if 0 < dayleft[i] * dayright[i]
  and dayleft[i] == dayright[i] then
    print(dayleft[i])
  end
end


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

int main(){
  int n,l; cin >> n >> l;
  int sum = l*n + n*(n+1)/2 - n;
  if(l>0) cout << sum-l << endl;
  else if(l+n-1<0) cout << sum-(l+n-1) << endl;
  else cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    string s; cin >> s;
    ll r=0,g=0,b=0;
    ll rg=0,rb=0,gb=0,gr=0,br=0,bg=0;
    ll ans=0;
    rep(i,n){
        if(s[i]=='R'){
            ans+=gb+bg;
            r++;
            gr+=g;
            br+=b;
        }else if(s[i]=='G'){
            ans+=rb+br;
            g++;
            bg+=b;
            rg+=r;
        }else{
            ans+=rg+gr;
            b++;
            rb+=r;
            gb+=g;
        }
    }
    rep(i,n){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j]||n-1<2*j-i) continue;
            int k=2*j-i;
            if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i]) ans--;
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3632
def rectangle(length, breadth):
    return str(length*breadth) + " " + str(2*length + 2*breadth)

if __name__ == "__main__":
    param = input()
    param = param.split(" ")
    length = int(param[0])
    breadth = int(param[1])
    print(rectangle(length, breadth))



Measured memory_bytes: 5596
//============================================================================
// Name        : abc104.cpp
// Author      : sep
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>

using namespace std;

inline void main104A() {

	long int n;

	cin >> n;

	if (n < 1200) {
		cout << "ABC";
	} else if (n < 2800) {
		cout << "ARC";
	} else {
		cout << "AGC";
	}

}

int main() {

#ifdef TEST
	struct timespec startTime, endTime;
	while (1) {
		clock_gettime(CLOCK_REALTIME, &startTime);
#endif

		main104A();

#ifdef TEST
		cout << flush;
		cerr << flush;
		cerr << endl << "Elapsed Time:";
		clock_gettime(CLOCK_REALTIME, &endTime);
		if (endTime.tv_nsec < startTime.tv_nsec) {
			cerr << endTime.tv_sec - startTime.tv_sec - 1 << "."
					<< endTime.tv_nsec + 1000000000 - startTime.tv_nsec << "s"
					<< endl;
		} else {
			cerr << endTime.tv_sec - startTime.tv_sec << "."
					<< endTime.tv_nsec - startTime.tv_nsec << "s" << endl;
		}

		cerr << endl;
	}
#endif

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1234567890


string z,o;
ll zl,ol;
ll n;

P type(ll x){
    if(x<n) return P(0,x);
    else if(x<n+zl) return P(1,x-n);
    else if(x<n+zl+n) return P(0,x-n-zl);
    else return P(2,x-n-zl-n);
}

ll ba(P p){
    if(p.fi==1) return z[p.se]-'a';
    else return o[p.se]-'a';
}


struct UnionFind {
    int n, cnt;
    vector<int> par, rank, sz;

    UnionFind(int n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) {
        iota(par.begin(), par.end(), 0);
    }

    int find(int x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sz[find(x)];
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        } else {
            par[y] = x;
            sz[x] += sz[y];
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        cnt--;
    }
};


int main(){
    ll i,j;
    cin>>z>>o>>n;
    zl=z.size();
    ol=o.size();
    ll cnt=0;

    if(n>101010){
        cnt+=(n-ol+1)/2;
        n=ol;
    }

    ll L=2*n+zl+ol;


    UnionFind uf(n+28);

    for(i=0;i<L;i++){
        j=L-1-i;
        P p1=type(i);
        P p2=type(j);
        if(p1.fi==0&&p2.fi==0){
            uf.unite(p1.se,p2.se);
        }
        else if(p1.fi==0&&p2.fi!=0){
            uf.unite(p1.se,n+ba(p2));
            
        }
        else if(p1.fi!=0&&p2.fi==0){
            uf.unite(n+ba(p1),p2.se);
        }
        else{
            uf.unite(n+ba(p1),n+ba(p2));
        }
    }

    for(i=0;i<26;i++){
        for(j=i+1;j<26;j++){
            if(uf.same(n+i,n+j)) {
                cout<<0<<endl;
                return 0;
            }
        }
    }

    ll  decided=0;
    for(i=0;i<26;i++){
        if(uf.size(n+i)>1) decided++;
    }

    ll fre=0;
    vector<ll> used(n,0);
    for(i=0;i<n;i++){
        if(used[uf.find(i)]==0) {
            fre++;
            used[uf.find(i)]=1;
        }
    }

    cnt+=fre-decided;
    ll ans=1;
    ll ki=26;

    for(i=0;i<63;i++){
        if((cnt>>i)&1==1) ans*=ki;
        ans%=Mod;
        ki=ki*ki;
        ki%=Mod;
    }

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


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (2000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int n;
  cin >> n;
  cout << (n-2)*180;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
N, M, *L = map(int, open(0).read().split())
dic = defaultdict(list)
par =  [0]*N
cnt = [0]*(N+1)
for a,b in zip(*[iter(L)]*2):
  dic[a] += [b]
  cnt[b] += 1

for i in range(1,N+1):
  if cnt[i]==0:
    q = deque([i])
    par[i-1] = '0'
    break
  
while q:
  m = q.popleft()
  for c in dic[m]:
    cnt[c] -= 1
    if cnt[c]==0:
      par[c-1] = str(m)
      q += [c]

ans = '\n'.join(par)
print(ans)

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

const int maxn = 1e4+10;
bitset<maxn> cookie[10];

int main(){
	int R,C;
	while(cin>>R>>C && (R||C)){
		int i,j;
		for(int i=0; i<R; i++)
			for(int j=0; j<C; j++){
				bool upward;
				cin >> upward;
				cookie[i][j] = upward;
			}

		int r = 1<<R;
		int res = 0;
		for(int i=0; i<r; i++){
			for(int j=0; j<R; j++){
				if(i & (1<<j)) 
					cookie[j].flip();
			}

			int ans = 0;
			for(int j=0; j<C; j++){
				int up = 0;
				for(int k=0; k<R; k++){
					if(cookie[k][j])
						up++;
				}
				ans += max(up,R-up);
			}

			res = max(ans,res);

			for(int j=0; j<R; j++){
				if(i & (1<<j)) 
					cookie[j].flip();
			}
		}
		printf("%d\n",res);
	}

}

Measured memory_bytes: 3140
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <queue>

using namespace std;

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

  map<string, int64_t> str_cnt;
  int64_t mx = 0;
  for (int64_t n = 0; n < N; ++n) {
    string S;
    cin >> S;
    ++str_cnt[S];
    mx = max(mx, str_cnt[S]);
  }
  priority_queue<string, vector<string>, greater<string>> q;
  for (auto &p : str_cnt) {
	if (p.second == mx) {
      q.push(p.first);
    }
  }
  while (!q.empty()) {
    cout << q.top() << endl;
    q.pop();
  }
  return 0;
}


Measured memory_bytes: 26868
N,K = map(int,input().split())
A =list(map(int,input().split()))

num = [0]*(N+1)

for i in range(N):
    num[A[i]] +=1

V = N+1 - num.count(0)

if V <=K:
    print(0)
else:
    num.sort()
    num.reverse()
    print(sum(num[K:]))

Measured memory_bytes: 25644
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


//***********************************
//mintを定義
//***********************************
const int mod = 1000000007;
struct mint {
  int x;
  mint(int x=0):x(x%mod){}   //メンバ変数xをx%modで初期化
  int get() const { return (int)x; }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;           //thisは暗黙的に左辺のポインタ
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }

  //累乗
  mint mpow(int t) const {
    if (!t) return 1;
    mint a = mpow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  //除算
  mint minv() const {
    return mpow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.minv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

//標準出力
ostream& operator<<(ostream& st, const mint a) 
{ st << a.get(); return st; };
//--------------------------------------------------

//***********************************
//場合の数の計算
//***********************************
const int MAX = 200010;
mint fac[MAX], finv[MAX];

//前計算
inline void INIT_F(){
    fac[0] = finv[0] = 1;
    for(int i=1; i<MAX-1; i++) {
        fac[i] = (fac[i-1]*mint(i));
        finv[i] = (finv[i-1]/mint(i));
    }
}

//nCk
mint mcomb(int n, int k) {
    if(n<k || k<0) return 0;
    else return ((fac[n]*finv[k])*finv[n-k]);
}

//nHk
mint mhcomb(int n, int k) {
  return mcomb(n+k-1, k);
}
//--------------------------------------------------

signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    INIT_F();

    mint res;
    mint t = 2;
    res = t.mpow(n) - 1;
    //cout << res << endl;

    
    mint aa = 1, bb = 1;
    rep(i, a) {
        aa *= n-i;
    }
    rep(i, b) {
        bb *= n-i;
    }
    //cout << aa << " " << fac[a] << endl;
    //cout << bb << " " << fac[b] << endl;
    aa /= fac[a]; bb /= fac[b];
    

    res -= aa;
    res -= bb;

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3328
import math
from collections import deque


def main():
    n, k, s = map(int, input().split())
    ans = []

    for i in range(n):
        if i < k:
            ans.append(s)
        else:
            if k == n:
                ans.append(s)
            else:
                if s == 2 or s == 1:
                    ans.append(3)
                else:
                    ans.append(s-1)

    # if s % 2 == 0:
    #     for i in range(k + 1):
    #         ans.append(s // 2)
    #     for i in range(n - k - 1):
    #         if s == 2:
    #             ans.append(3)
    #         else:
    #             ans.append(s-1)
    # else:
    #     for i in range(k):
    #         ans.append(s)
    #     for i in range(n - k):
    #         ans.append(s + 1)
    print(" ".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 21148
#include <cstdio>
#include <map>
#include <vector>
using namespace std;

typedef long long LL;

void func(int n, map<int,int> &ret){
	vector<int> h(n + 1);
	int x;
	for(int i = 1; i <= n; ++i){
		scanf("%d", &x);
		h[i] = h[i-1] + x;
	}

	map<int,int> mp;
	for(int i = 0; i < n; ++i)
	for(int j = i + 1; j <= n; ++j){
		++mp[h[j] - h[i]];
	}
	
	ret.swap(mp);
}

int main(){
	int n, m;
	map<int,int>::iterator it1, it2;
	map<int,int> mp1, mp2;

	while( scanf("%d%d", &n, &m), n != 0 ){
		func(n, mp1);
		func(m, mp2);

		LL ans = 0;
		it1 = mp1.begin();
		it2 = mp2.begin();
		while(it1 != mp1.end() && it2 != mp2.end()){
			if(it1->first == it2->first){
				ans += (LL)it1->second * it2->second;
				++it1;
				++it2;
			}
			else if(it1->first < it2->first){
				++it1;
			}
			else{
				++it2;
			}
		}
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 27668
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
#define Sort(X) sort(X.begin(), X.end())
#define RSort(X, T) sort(X.begin(), X.end(), greater<T>())
//#define MOD 998244353
#define MAX 100000

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

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

	ll N;
	cin >> N;

	ll out = (N - 1) * N / 2;

	cout << out << endl;

	return 0;
}



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

/*ll modpow(ll a,ll b){
	ll c=1;
	while(b>0){if (b%2==0){b/=2;a=(a*a)%mod;}else {b--;c=(c*a)%mod;}}
	return c;
}*/

void up(int p){
	for (int c=0;c<p;c++){cout<<"U";}
		return ;
}
void down(int p){
	for (int c=0;c<p;c++){cout<<"D";}
		return ;
}
void right(int p){
	for (int c=0;c<p;c++){cout<<"R";}
		return ;
}
void left(int p){
	for (int c=0;c<p;c++){cout<<"L";}
		return ;
}

int main()
{
	//freopen("input16.txt","r",stdin);freopen("output16.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	up(ty-sy);right(tx-sx);down(ty-sy);left(tx-sx+1);up(ty-sy+1);right(tx-sx+1);down(1);right(1);down(ty-sy+1);left(tx-sx+1);up(1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int,int>;
const int INF = 1e9+7;

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

  ll sum = 0;
  for (int i = 1; i <= n; i++) {
    ll k = n/i;
    sum += k * (k+1) / 2 * i;
  }

  cout << sum << endl;
}


Measured memory_bytes: 3596