akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int n; long long a[109];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	long long g = a[0];
	for (int i = 1; i < n; i++) g = g / gcd(g, a[i]) * a[i];
	cout << g << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
p = input()
for i in range(len(s)):
    if i + len(p) <= len(s):
        t = s[i:i + len(p)]
    else:
        t = s[i:] + s[:i + len(p) - len(s)]
    if t == p:
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 7460
#include<stdio.h>
#include<math.h>
int main()
{
	int A,B,C,D,E,F;
	scanf("%d %d",&A,&B);
	C=A+B;
	D=A-B;
	E=A*B;
	if(C<D)
	{
		C=D;
	}
	if(C<E)
	{
		C=E;
	}
	printf("%d\n",C);
	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

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

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];
    sort(all(a));
    cout << a[n - 1] << " ";
    int x = 0;
    for(int i = 0; i < n - 1; i++) {
        if(fabs(a[n - 1] / 2.0 - a[i]) < abs(a[n - 1] / 2.0 - x)) x = a[i];
    }
    cout << x << endl;
    return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
#define N 25
#define M 1000000007
#define ll long long
#define inf 1000000000000000000
ll n, arr[N][N], dp[N][3000000];


ll cal(int i, int mask)
{
    if(i > n) return 1;
    if(dp[i][mask] != -1) return dp[i][mask];
    //cout << i <<" " << mask << endl;
    dp[i][mask] = 0;
    for(int j = 1; j <= n; j++) if(arr[i][j] && !((mask >> (j - 1)) & 1)) dp[i][mask] =(dp[i][mask] + cal(i + 1, mask | (1 << (j - 1)))) % M;
    return dp[i][mask];
}

int main()
{
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for(int i = 1; i <= n; i++) for(int j = 1;j <= n; j++) cin >>arr[i][j];
    cout << cal(1, 0);
}





Measured memory_bytes: 586240
import math
n = int(input())
count = 0
for i in range(n):
    t = int(input())
    a = int(t ** (1 / 2))
    end = 0
    for j in range(2, a + 1):
        if t % j == 0:
            end = 1
            break
    if end == 0:
        count += 1
print(count)


Measured memory_bytes: 5744
/**

サイコロの各面には図のとおりに 1 から 6 のラベルが割りあてられています。

入力としてサイコロの各面のラベルに対応する数字と、転がす命令の列が与えられるので、サイコロの上面の数字を出力してください。シミュレーションの初期状態は、図のとおりのラベルの位置でサイコロが置かれているものとします。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);
		// 6桁の数字を受け取る配列diceを作る
		int[] dice = new int[6];
		// 6個入力された数字を受け取る
		for (int i = 0; i < 6; i++) {
			dice[i] = sc.nextInt();
		}
		// 命令の文字列を受け取る
		String mei = sc.next();
		// 受け取った文字列をcharの配列に入れていく
		char[] Roll = mei.toCharArray();
		//受け取った文字列の長さの回数処理を繰り返す
		for (int i = 0; i < mei.length(); i++) {
			//数字入れ替え用の変数
			int irekae = 0;
			//文字列がSだった場合
			if (Roll[i] == 'S') {
				irekae = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = irekae;
			//文字列がNだった場合
			} else if (Roll[i] == 'N') {
				irekae = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = irekae;
			//文字列がWだった場合
			} else if (Roll[i] == 'W') {
				irekae = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = irekae;
			//文字列がEだった場合
			} else if (Roll[i] == 'E') {
				irekae = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = irekae;

			}

		}
		//表示
		System.out.println(dice[0]);
	}
}

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

const int N = 3050;
int dp[N][N];
string s,t;

int solve(int idx1 , int idx2)
{
    if(idx1 == s.length() || idx2 == t.length())
        return 0;
    int &ret = dp[idx1][idx2];
    if(ret != -1)
        return ret;
    if(s[idx1] == t[idx2])
        return ret = 1 + solve(idx1+1,idx2+1);
    return ret = max(solve(idx1+1,idx2),solve(idx1,idx2+1));
}

void f(int idx1 , int idx2)
{
    if(idx1 == s.length() || idx2 == t.length())
        return ;
    if(s[idx1] == t[idx2])
    {
        cout << s[idx1];
        return f(idx1+1,idx2+1);
    }
    if(solve(idx1+1,idx2) > solve(idx1,idx2+1))
        return f(idx1+1,idx2);
    else
        return f(idx1,idx2+1);
}

int main()
{
    ios :: sync_with_stdio();
    cin.tie(0);
    cin >> s >> t;
    memset(dp,-1,sizeof dp);
    solve(0,0);
    f(0,0);
    return 0;
}


Measured memory_bytes: 36864
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lli;
lli n,k;
vector<lli> a;
lli ans = 0;
int main(){
    cin >> n >> k;
    a = vector<lli> (n);
    for(lli i = 0;i < n;i++) cin >> a[i];
    lli t = 0,s;
    for(lli i = 0;i < n;i++){
        if(a[i] > 0) t += a[i];
    }
    s = t;
    for(lli i = 0;i < k;i++){
        if(a[i] > 0) t -= a[i];
        else s += a[i];
    }
    ans = max(ans,s);
    ans = max(ans,t);
    for(lli i = k,j = 0;i < n;i++,j++){
        if(a[j] > 0) t += a[j];
        else s -= a[j];
        if(a[i] > 0) t -= a[i];
        else s += a[i];
        ans = max(ans,s);
        ans = max(ans,t);        
    }
    cout << ans << endl;
    return 0;
}

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

int digit_sum(int n){
  int sum = 0;
  while (n > 0){
    sum += n%10;
    n /= 10;
  }
  return sum;
}

void string_solve(){
  int n; cin >> n;
  string t = to_string(n);
  int sum = 0;
  for(int i=0;i<(int)t.size(); i++){
    sum += t[i]-'0';
  }
  if(n % sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

void num_solve(){
  int n; cin >> n;
  int sum = digit_sum(n);
  if(n % sum == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

int main(){
  string_solve();
}

  


Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
int main() {
	long long int a, b, c; std::cin >> a >> b >> c;
	std::cout << std::min(a + b + 1, c) + b << std::endl;
}

Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())

stations = []
for _ in range(N-1):
    c, s, f = map(int, sys.stdin.readline().split())
    stations.append((c, s, f))

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        c, s, f = stations[j]
        if t <= s:
            t = s + c
        else:
            tmp = t - s
            t = s + f * ((tmp - 1) // f + 1) + c

    print(t)
print(0)

Measured memory_bytes: 9136
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

string S;
int K;

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

    if(S.size()<=K){
        cout<<S<<endl;
    }else{
        rep(i,K) cout<<S[i];
        cout<<"..."<<endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>

int main(void){
  
  using namespace std;
  int A,B,C,D;
  
  cin >> A >> B >> C >> D;
  
  if(A+B > C+D){
    cout << "Left" << endl;
  } else if(A+B == C+D) {
    cout << "Balanced" << endl;
  } else if (A+B < C+D) {
    cout << "Right" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,m= map(int, sys.stdin.readline().split(' '))
    a=list(map(int,sys.stdin.readline().split(' ')))
    if(sum(a)>n):
        print(-1)
    else:
        print(n-sum(a))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

Measured memory_bytes: 10024
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
	int num;
	cin >> num;
	int i = 1;
	long long cur = 0;
	while (i <= num) {
		if (i % 3 != 0 && i % 5 != 0) {
			cur += i;
		}
		i++;
	}
	cout << cur << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
int sum , i;
char k[1000];
while(1){
scanf("%s",k);
if(k[0]=='0')break;
for(sum=0,i=0; k[i]!='\0'; i++) {
sum+=(k[i]-'0');
}
printf("%d\n",sum);
}
return 0;
}

Measured memory_bytes: 536
import bisect
S = input()
T = input()

dic = {chr(s): [] for s in range(ord("a"), ord("z") + 1)}
for i, s in enumerate(S):
    dic[s].append(i + 1)

out = 0
cnt = -1
V = [0] * len(T)
for i, t in enumerate(T):
    if dic[t]:
        """
        for l in dic[t]:
            if cnt < l:
                V[i] = l
                cnt = l
                break
        else:
            cnt = dic[t][0]
        """

        idx = bisect.bisect(dic[t], cnt)
        if idx == len(dic[t]):
            V[i] = dic[t][0]
            cnt = dic[t][0]
        else:
            V[i] = dic[t][idx]
            cnt = dic[t][idx]

    else:
        out = 1
        break
if out == 1:
    print(-1)
else:
    cnt = 0
    for i in range(len(V)-1):
        if V[i+1] <= V[i]:
            cnt += 1
    if cnt == 0:
        print(V[-1])
    elif V[-1] == len(S):
        print(len(S) * (cnt + 1))
    else:
        print(len(S) * cnt + V[-1])
a = 0

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

using namespace std;
#define int long long
int MOD = 1000000007;

signed main(){
    int N;
    string A,B,C;
    cin >> N >> A >> B >> C;
    
    
    int ans = 0;
    for(int i=0;i<N;i++){
        if(A[i]==B[i] && B[i]==C[i]) ans += 0;
        else if(A[i]==B[i]||B[i]==C[i]||A[i]==C[i]) ans++;
        else ans += 2;
        
    }
    
    cout << ans << endl;
    
    return 0;
}


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

 using namespace std;

 int main() {
 int N; cin >> N;
 
 vector<int> A(N);
 for (int i = 0; i < N; ++i) {
 cin >> A[i];
 --A[i];
 }
 vector<int> B(N);
 for (int i = 0; i < N; ++i) {
 cin >> B[i];
 }
 vector<int> C(N-1);
 for (int i = 0; i < N; ++i) {
 cin >> C[i];
 }
 
 int ans = 0;
 for (int i = 0; i < N; ++i) {
 ans += B[A[i]];
 if (i > 0 && A[i] == A[i-1]+1) {
 ans += C[A[i-1]];
 }
 }
 cout << ans << endl;
 }


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



int main(){

  int n;
  cin >>n;
  int a[3000];
  long sum=0;
  for(int i=0; i<n; i++){
    cin >>a[i];
    sum+=a[i];
  }
  
  cout << sum-n << endl;
  
}

Measured memory_bytes: 256
def prime(n):
    res =set()
    while n% 2==0:
        res.add(2)
        n //= 2
    i  = 3
    while i*i <= n:
        if n % i==0:
            res.add(i)
            n //= i
        else:
            i += 2
    if n != 1:
        res.add(n)
    return res
a,b = map(int,input().split())
a = prime(a)
b = prime(b)
print(len(a&b)+1)

Measured memory_bytes: 38384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on
int N;

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

  cout << "ABC" + to_string(N) << endl;
  return 0;
}


Measured memory_bytes: 384
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main() {
	string s;
	cin >> s;
	if (s[1] == s[2] && (s[0] == s[1] || s[2] == s[3])) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int d[n];
  map<int,int> mp;
  for(int i=0;i<n;i++){
    cin>>d[i];
    mp[d[i]]++;
  }
  int m;cin>>m;
  for(int i=0;i<m;i++){
    int u;cin>>u;
    if(mp[u]==0){
      cout<<"NO"<<endl;
      return 0;
    }
    mp[u]--;
  }
  cout<<"YES"<<endl;
}
  

Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
int main() {
	cin >> X;
	ll P = 100;
	for (i = 1; i <= 10000; i++) {
		P *= 1.01;
		if (P >= X) {
			cout << i;
			exit(0);
		}
	}
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int N,M;
    cin>>N;
    vector<pair<int,int>> P;
    rep(i,N){
        int h,m;cin>>h>>m;
        P.pb(MP(h,m));
    }
    cin>>M;
    rep(i,M){
        int h,m;cin>>h>>m;
        P.pb(MP(h,m));
    }

    sort(all(P));
    P.erase(unique(all(P)),P.end());

    rep(i,P.size()){
        cout<<P[i].first;
        cout<<":";
        if(!(P[i].second/10)) cout<<0;
        cout<<P[i].second;
        cout<<(i!=P.size()-1?" ":"\n");
    }

}


Measured memory_bytes: 3112
n=int(input())
ans=[]
if(n==0):
    ans+=[0]
while(n!=0):
    if(n%(-2)==0):
        ans+=[0]
        n=n//-2
    else:
        ans+=[1]
        n=(n-1)//-2

ans.reverse()
ans=''.join(map(str,ans))
print(ans)

Measured memory_bytes: 3064
n, m = map(int, input().split())
s = input()
t = input()

cnt = 1
ns = 1
nt = 1
ss = 0
tt = 0
fail = False


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


ll = (n * m) // gcd(n, m)
l = ll

while l <= n * m:
    fail = False
    while not(ns > l or nt > l):
        while not(ns <= nt):
            nt += l / m
            tt += 1

        if(ns == nt) and (s[ss] != t[tt]):
            fail = True
            break

        ns += l / n
        ss += 1
    if not(fail):
        break
    cnt += 1
    l = ll * cnt

if(fail):
    print(-1)
else:
    print(l)


Measured memory_bytes: 3316
import sys
x, y = map(int, input().split())

if y%2==1:
  print("No")
  sys.exit()
if y//2-x < 0:
  print("No")
  sys.exit()
if 0 <= 2*x-y//2 <= x and 0<= y//2-x <= x:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9136
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 201000
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 1000000000000000000
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

vector<int> adj[N];
int vis[N]={};
int dp[N]={};
int dfs(int a)
{
    vis[a]=1;
    fn(i,adj[a].size()) 
    {
        if(!vis[adj[a][i]]) dfs(adj[a][i]);
        dp[a]=max(dp[a],1+dp[adj[a][i]]);
    }
    return dp[a];
}
signed main() 
{
    speed;
    //freopen("input.tXt","r",stdin);
    //freopen("output.tXt","w",stdout);

    int n,m;
    cin>>n>>m;

    fn(i,m)
    {
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
    }
    int ans=0;
    rep(i,1,n) if(!vis[i]) ans=max(ans,dfs(i));
    cout<<ans;
}   

Measured memory_bytes: 12544
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll count = 0;
    ll r=0,g=0,b=0;
    rep(i,n){
        if(s[i]=='R') r++;
        if(s[i]=='G') g++;
        if(s[i]=='B') b++;
    }
    count = r*g*b;
    ll ex=0;
    rep1(j,1,n){
        rep(i,n){
            if((i+j)>=n || (i+j*2)>=n) continue;
            if(s[i]!=s[i+j] && s[i+j]!=s[i+j*2] && s[i]!=s[i+j*2]) ex++;
        }
    }

    ll ans = count-ex;

    cout << ans <<endl;
    return 0;
    

}

Measured memory_bytes: 3608
/*input
7 4
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, k; cin >> n >> k;
    cout << min(n % k, k - (n % k));

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[35];
int main(){
	int n,m,k;
	string s;cin>>s;
	for(int i=0;i<s.size();i++) a[s[i]-'a']=1;
	for(k=0;k<26;k++)if(!a[k])break;
	if(k==26)cout<<"None";
	else printf("%c",k+'a');
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define REP(i, n) for (LL i = 0; i < (LL)(n); i++)
#define REP2(i, n) for (LL i = 1; i <= (LL)(n); i++)
#define FOR(i, m, n) for (LL i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RSORT(x) sort(x.begin(), x.end(),greater<int>())
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define SUM(x) accumulate(x.begin(), x.end(),0)
#define VLL(v,n) vector<LL> v(n); REP(i,n)cin>>v[i];
#define VSTR(v,n) vector<string> v(n); REP(i,n)REP(i,n)cin>>v[i];
LL INF = 1e9 + 1;
LL MOD = 1e9+7;
  LL a,b,c,d,e,n,m,l,r,x,y,z,ans=100000000,ans2=0,cnt=0;
string s,S,t;
bool flag=false;
int main() {
  LL t;
ios_base::sync_with_stdio(false);
cin>>n>>t>>a;
REP2(i,n){
  cin>>x;
  LL A=(t*1000-x*6)-a *1000;
 if(A<0)A=-A;
  if(ans>A){
    ans=A;
 ans2=i;
   }
}
cout << ans2<<endl;
}


Measured memory_bytes: 3568
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let d: i64 = input();
    let x: i64 = input();
    let a: Vec<i64> = (0..n).map(|_| input()).collect();

    let mut ans = 0;
    for i in 0..n {
        let mut t = 1;
        while t <= d {
            ans += 1;
            t += a[i];
        }
    }
    println!("{}", x + ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

void solve() {
    string s;
    cin >> s;
    if (s == "ABC") {
        cout << "ARC" << endl;
    }
    else {
        cout << "ABC" << endl;
    }
}

void querySolve() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    solve();
    //querySolve();
}


Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll w,h,n,sum=0,minx=0,miny=0;
	cin >> w>> h>> n;
	ll maxx = w, maxy = h;
	vector<ll>x(n),y(n),a(n);
	for (ll i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> a[i];
		if (a[i] == 1) {
			minx = max(x[i],minx);
		}
		else if (a[i] == 2) {
			maxx = min(x[i], maxx);
		}
		else if (a[i] == 3) {
			miny=max(y[i],miny);
		}
		else {
			maxy=min(y[i],maxy);
		}

	}
	if (maxx > minx&&maxy > miny) {
		cout << (maxx - minx)*(maxy - miny) << endl;
		//cout << minx <<" "<< maxx << " " << miny << " " << maxy << endl;
	}
	else {
		cout << '0' << endl;
	}


}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

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

	pair<int, int> p[N];
	for (int i = 0; i < N; i++){
		cin >> p[i].second >> p[i].first;
	}
	sort(p, p + N);

	for (int i = 0, sum = 0; i < N; i++){
		sum += p[i].second;
		if (sum > p[i].first){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 1792
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mp make_pair
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


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

  ll ans = 0;
  int rcount = 0;
  rep(i, n){
    if(s[i]=='R') rcount++;
  }
  for(int i = rcount; i < n; i++){
    if(s[i]=='R') ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3748
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d,e,f;cin >> a>>b >>c >>d >>e >>f;
    if(a+ b*5 + c*10+d*50+e*100+f*500 >= 1000) cout << 1 << endl;
    else cout <<0 << endl;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)

signed main() {
	int N, M, K; cin >> N >> M >> K;
	vector<int> A(N);
	vector<int> v(N + 1);
	rep(i, N) {
		cin >> A[i];
		int minv = 1ll << 60, maxv = -1;
		int ans = 1ll << 60;
		rep(j, M * (i - j >= 0)) {
			int a = A[i - j];
			minv = min(minv, a);
			maxv = max(maxv, a);
			ans = min(ans, K + (j + 1) * (maxv - minv) + v[i - j]);
		}
		v[i + 1] = ans;
	}
	cout << v[N] << endl;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    priority_queue<double,vector<double>,greater<double>> v;
    rep(i,n){
      double a;
      cin>>a;
      v.push(a);
    }
    rep(i,n-1){
      double a,b;
      a=v.top();
      v.pop();
      b=v.top();
      v.pop();
      v.push((a+b)/2);
    }
    cout<<v.top()<<endl;
}

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	string s;
	ll k;
	cin >> s >> k;
	REP(i, s.size()) {
		if(s[i] - '1'){
			cout << s[i] << "\n";
			break;
		} else if(i == k - 1){
			cout << s[k - 1] << "\n";
			break;
		} 
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

void solve1();
int score1();
int change(int, int, int);
vector<int> changeT(vector<int>);

int ti;
int D;
int sumC;
int k = 26;
int score;
vector<int> c(k), t, tz;
vector<vector<int>> s;

int main() {
	srand((unsigned)time(NULL));
	cin >> D;
	s.resize(D);

	rep(i, k) {
		cin >> c[i];
		sumC += c[i];
	}
	rep(i, D) {
		s[i].resize(k);
		rep(j, k) {
			cin >> s[i][j];
		}
	}
	t.resize(D);

	rep(i, D) {
		t[i] = rand() % 26;
	}
	score = score1();

	solve1();

	//cout << score << endl;
	//score = score1();
	//cout << score << endl;


	rep(i, D) {
		cout << t[i] + 1 << endl;
	}

}

void solve1() {

	ti = clock();
	int count = 0;

	while (1) {
		count++;
		double time = (double)(clock() - ti) / CLOCKS_PER_SEC;
		if (time > 1.9) {
			break;
		}

		int no = rand() % 20;
		int sz = score;
		tz = t;
		//vector<P> temp;
		rep(i, no) {
			int d = rand() % D;
			int q = rand() % k;
			sz = change(sz, d, q);
			//temp.push_back(mp(d, q));
		}

		if (sz > score) {
			score = sz;
			t = tz;
		}
		
	}

	//cout << count << endl;
}

vector<int> changeT(vector<int> t) {
	int no = rand() % 15;
	rep(i, no) {
		int d = rand() % D;
		int q = rand() % k;
		t[d] = q;
	}
	return t;
}

int score1() {
	//最後にコンテストが行われた日
	vector<int> last(k, -1);
	int ans = 0;

	rep(i, D) {
		ans += s[i][t[i]];
		last[t[i]] = i;
		rep(j, k) {
			ans -= c[j] * (i - last[j]);
		}
		//cout << ans << endl;
	}
	return ans;
}

int change(int score, int d, int q) {
	score += s[d][q] - s[d][tz[d]];
	int x = d + 1;
	while (x != D && tz[x] != q) {
		x++;
	}
	int y = d - 1;
	while (y >= 0 && tz[y] != q) {
		y--;
	}
	score += c[q] * (d - y) * (x - d);

	x = d + 1;
	while (x != D && tz[x] != tz[d]) {
		x++;
	}
	y = d - 1;
	while (y >= 0 && tz[y] != tz[d]) {
		y--;
	}
	score -= c[tz[d]] * (d - y) * (x - d);

	tz[d] = q;
	return score;
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5,M=3;
ll dp[N][M],a[N][M];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=1;i<=n;i++)for(ll j=0;j<M;j++)cin>>a[i][j];
    for(ll i=1;i<=n;i++){
        for(ll j=0;j<M;j++){
            for(ll k=0;k<M;k++){
                if(j==k)continue;
                dp[i][j]=max(dp[i][j] , dp[i-1][k]+a[i][j]);
            }
        }
    }
    cout<<max({dp[n][0],dp[n][1],dp[n][2]});
}

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

int cnt[100007];
int main(){
   int n,ans=0;
   cin>>n;
   vector<int> a(n);
   for(int i=0;i<n;i++)
       cin>>a[i];
   sort(a.begin(),a.end());
   cnt[a[0]]++;
   vector<int> diff;
   for(int i=1;i<=n;i++){
      if(i<n) cnt[a[i]]++;
      if(i==n or cnt[a[i]]==1)
         diff.emplace_back(cnt[a[i-1]]);
   }
   int l=0,r=1;
   while(r<diff.size()){
     if(diff[l]>1 and diff[l]%2==0){
        if(r==n-1 or (diff[r]>1 and diff[r]%2==0)){
           ans+=1+((diff[r]&1)?0:1);
           l=r+1,r=l+1;
         }
         else{
           ans++;
           r++;  
         }  
     }
     else{
       ans++;
       l++;
       r++;
     }
   }
   if(l<n and diff[l]&1) ans++;
   if(ans==0) ans=1;
   cout<<ans<<"\n";
} 


Measured memory_bytes: 1532
n = int(input())
total = 0
for i in range(1,n+1):
    if i % 2 ==0:continue
    count = 0
    for j in range(1,n+1):
        if count >8:
            total -= 1
            continue
        if i % j == 0:
            count +=1
    if count == 8 :
        total += 1
print(total)

Measured memory_bytes: 3060
import math
a, b, x = map(int, input().split())
men = x / a
if a * b / 2 <= men:
    h = (((a * b) - men) * 2) / a
    theta = math.degrees(math.atan(h/a))
    print(theta)
    exit()
a_dash = men * 2 / b
theta = math.degrees(math.atan(a_dash / b))
print(90 - theta)

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

struct era{
    string name;
    int end, year;
};

int main(){
    int n, q;
    while( cin >> n >> q, n ){
        vector<era> eras(n);
        //vector<int> list(1<<9);
        //rep(i, list.size()) list[i] = i;
        rep(i, n){
            //string name;
            //int end, year;
            cin >> eras[i].name >> eras[i].end >> eras[i].year;
        }
        rep(i, q){
            int query;
            cin >> query;
            int ans = 0;
            rep(j, n){
                if( eras[j].year - eras[j].end < query && query <= eras[j].year ){
                    ans = query - eras[j].year + eras[j].end;
                    cout << eras[j].name << ' ' << ans << endl;
                    break;
                }
            }
            if( ans == 0 ) cout << "Unknown" << endl;
        }
    }
}

Measured memory_bytes: 1284
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;


#define MAX 500000
#define SENTINEL 2000000000
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2


int main(){
  int n;
  cin >> n;
  if (n == 1) cout << "Hello World" << endl;
  else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}

Measured memory_bytes: 256
// Problem : F - Intervals on Tree
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z)                                                       \
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define dbp(x) \
  cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define dbv(v)                         \
  {                                    \
    cout << #v << " : ";               \
    for (auto x : v) cout << x << ' '; \
    cout << endl;                      \
  }
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define die(x) return cout << x << '\n', 0;

using namespace std;

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

int32_t main() {
  fastio;
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
  int testcases;
  testcases = 1;
  // cin>>testcases;

  while (testcases--) {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      ans = ans + i * (n - i + 1);
    }
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      if (u > v) swap(u, v);
      ans = ans - u * (n - v + 1);
    }
    cout << ans << '\n';
  }

  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pk(x) cout<<(x)<<" ";
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a,b,c,d,n,m,x[100001],y[100001],z,h,w,k,sum,mi=inf,ma=-inf,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;

ll dp[10010];
ll al[]={2,5,5,4,5,6,3,7,6};

int main(void){
    cin>>n>>m;
    rep(i,n+1)dp[i]=-inf;
    VL v(m);
    rep(i,m)cin>>v[i];
    dp[0]=0;
    rep(i,n+1){
        for(ll x: v){
            if(i-al[x-1]<0)continue;
            dp[i]=max(dp[i],dp[i-al[x-1]]+1);
        }
    }
    sort(all(v));
    string ans;
    int i=0;
    n++;
    rep(tmp,dp[n-1]){
        rep(j,m){
            if(dp[n-1-i-al[v[m-1-j]-1]]<0 || n-1-i-al[v[m-1-j]-1]<0)continue;
            if(dp[n-1-i]==dp[n-1-i-al[v[m-1-j]-1]]+1){
                ans+=to_string(v[m-1-j]);
                i+=al[v[m-1-j]-1];
                break;
            }
        }
    }
    p(ans);
    return 0;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.Arrays;
class Main{
    public static void main(String[] args) throws IOException {
        int i,ans;
        String str;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        for(;;){
            str = in.readLine();
            if(str.equals("0")) break;
            char[] c = str.toCharArray();
            ans=0;
            for(i=0;i<str.length();i++){
                ans+=Integer.parseInt(String.valueOf(c[i]));
            }
            System.out.println(ans);
        }
        System.out.flush();
    }
}

Measured memory_bytes: 24636
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)    for(int (i) = 0;   (i) < (n); ++(i))
#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))

int N;
vector<int> A;

void extend(vector<pair<int, int>> &v, int sz) {
    if (v.size() == 0) v.emplace_back(0, sz);
    else if (v.back().first == 0) v.back().second += sz;
    else v.emplace_back(0, sz);
}

void connect(vector<pair<int, int>> &v, pair<int, int> p) {
    if (v.size() == 0) v.emplace_back(p);
    else {
        if (v.back().first == p.first) v.back().second += p.second;
        else v.emplace_back(p);
    }
}

bool increment(int mid, vector<pair<int, int>> &v) {
    if ((int)v.size() == 1) {
        if (v[0].first == mid - 1) return false;
        if (v[0].second == 1) v[0].first++;
        else {
            pair<int, int> nw = {v[0].first + 1, 1};
            v[0].second--;
            connect(v, nw);
        }
        return true;
    }
    if (v.back().first == mid - 1) {
        pair<int, int>    bck = v.back();   v.pop_back();   bck.first = 0;
        pair<int, int> bckbck = v.back();   v.pop_back();
        if (bckbck.second == 1) {
            bckbck.first++;
            connect(v, bckbck);
        } else {
            pair<int, int> nw = {bckbck.first + 1, 1};
            bckbck.second--;
            connect(v, bckbck);
            connect(v, nw);
        }
        connect(v, bck);
    } else {
        if (v.back().second == 1) {
            pair<int, int> nw = v.back();   v.pop_back();
            nw.first++;
            connect(v, nw);
        } else {
            pair<int, int> nw = {v.back().first + 1, 1};
            v.back().second--;
            connect(v, nw);
        }
    }
    return true;
}

void cut(vector<pair<int, int>> &v, int bef, int aft) {
    while (bef > aft) {
        if (bef - aft >= v.back().second) {
            bef -= v.back().second;
            v.pop_back();
        } else {
            int sz = bef - aft;
            v.back().second -= sz;
            bef -= sz;
        }
    }
}

/*
    ランレングス圧縮した状態で操作を行う
    文字数を増やすときは, 最後に0をその個数分つなげる
    文字数が同じときは, 最後の要素をインクリメントする
    文字数を減らすときは, その文字数まで減らしてからインクリメントする
*/
bool check(int mid) {
    vector<pair<int, int>> arr;
    extend(arr, A[0]);
    FOR(i, 1, N) {
        int bef = A[i - 1];
        int aft = A[i];
        if (bef < aft) {
            extend(arr, aft - bef);
        } else if (bef == aft) {
            if (not increment(mid, arr)) return false;
        } else {
            cut(arr, bef, aft);
            if (not increment(mid, arr)) return false;
        }
    }
    return true;
}

signed main() {

    cin >> N;

    A.resize(N);
    REP(i, N) cin >> A[i];

    int ok = (int)1e9 + 10, ng = 0;
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) >> 1;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }

    cout << ok << endl;

}


Measured memory_bytes: 1152
/*
  AtCoder Beginner Contest 100
  D - Patisserie ABC
*/

#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

long long N, M;

long long getVal(vector<long long>& vec, long long M) {
  long long val = 0;
  sort(vec.begin(), vec.end(), greater<long long>());
  for (long long i = 0; i < M; ++i) {
    val += vec[i];
  }
  return val;
}

int main() {
  scanf("%lld%lld", &N, &M);

  vector<long long> ppp(N), npp(N), pnp(N), ppn(N), nnp(N), npn(N), pnn(N), nnn(N);
  long long x, y, z;
  for (long long i = 0; i < N; ++i) {
    cin >> x >> y >> z;
    ppp[i] = +x +y +z;
    npp[i] = -x +y +z;
    pnp[i] = +x -y +z;
    ppn[i] = +x +y -z;
    nnp[i] = -x -y +z;
    npn[i] = -x +y -z;
    pnn[i] = +x -y -z;
    nnn[i] = -x -y -z;
  }

  long long maxval = 0, val;
  
  val = getVal(ppp, M);
  if (maxval < val) maxval = val;
  val = getVal(npp, M);
  if (maxval < val) maxval = val;
  val = getVal(pnp, M);
  if (maxval < val) maxval = val;
  val = getVal(ppn, M);
  if (maxval < val) maxval = val;
  val = getVal(nnp, M);
  if (maxval < val) maxval = val;
  val = getVal(npn, M);
  if (maxval < val) maxval = val;
  val = getVal(pnn, M);
  if (maxval < val) maxval = val;
  val = getVal(nnn, M);
  if (maxval < val) maxval = val;

  printf("%lld\n", maxval);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n, l; cin >> n >> l;
	vector<int> taste(n);
	for( int i = 0; i < n; ++i ) taste[i] = l+i;
	int sum = accumulate( taste.begin(), taste.end(), 0 );
	int m = inf;
	for( int i = 0; i < n; ++i ) m = min( m, abs(taste[i]) );
	int k = -1;
	for( int i = 0; i < n; ++i ){
		if( m == abs(taste[i]) ){
			k = i;
			break;
		}
	}
	cout << sum - taste[k] << endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())
S= list(input())
W_count=S.count('W')
R_count=S.count('R')
count=0
if((W_count==0) or (R_count==0)):
    print(0)
else:
    list_test=['R']*R_count+['W']*W_count
    for i,j in zip(S,list_test):
        if(i!=j):
            count+=1
    print(count//2)

Measured memory_bytes: 13408
#coding utf-8
A,B,C,D=map(int,input().split())

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        return gcd(x%y,y)

if A%C==0:
  ac=A//C-1
else:
  ac=A//C
bc=B//C

if A%D==0:
  ad=A//D-1
else:
  ad=A//D
bd=B//D

CD=C*D//gcd(C,D)

if A%CD==0:
  acd=A//CD-1
else:
  acd=A//CD
bcd=B//CD

print(B-A+1-(bc-ac)-(bd-ad)+(bcd-acd))

Measured memory_bytes: 3064
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int N,M,A,i;
    int answer=0;
    scanf("%d %d",&N,&M);
    for(i=0;i<M;i++){
        scanf("%d",&A);
        if(A>M)
            answer++;
    }
    printf("%d\n",answer);
    return 0;
}



Measured memory_bytes: 2104
input_line1 = input()
N = int(input_line1)
input_line2 = input()
numbers = input_line2.split()
num_sum = 1
 
if '0' in numbers:
    print(0)

else:
    for i in range(N):
        num_sum *= int(numbers[i])
        if num_sum > 10 ** 18:
            num_sum = -1
            break
 
    print(num_sum)

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



using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;



int main() {

	string s, t;
	string ans = "";
	int n;
	cin >> n;
	cin >> s >> t;

	REP(i, n) {
		ans += s[i];
		ans += t[i];
	}
	cout << ans << endl;





}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1000000000
#define rep(i,a,b) for(int i =(a);i<(b);i++)
#define fs first
#define ss second
inline int Scan() {
    int x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

template<typename T, typename U>
static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}

// call by reference is used in x
template<typename T, typename U>
static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
//////////////////////////////////////end of template//////////////////////////////////////

int main(){

 ll N,W;
 cin >> N >> W;
 
 ll w[N+1];
 ll V[N+1];
 
 ll sumv =0;
 
 rep(i,1,N+1) {
	 cin >> w[i] >> V[i];
   sumv+= V[i];
 }
 
 
 vector<ll> dp(sumv+1,INF);
 
 
 dp[0] = 0;
 
 for(ll i=1;i<=N;i++){
	for(ll j = sumv;j>=V[i];j--){ 
	    amin(dp[j],dp[j-V[i]] + w[i]);
     }
 }
 
 
 ll ans= 0;
 for(int i =0;i<=sumv;i++){
	 if( dp[i] <= W) ans = max(ans,(ll)i);
 }
  cout << ans <<endl; 
	   
} 





Measured memory_bytes: 1024