akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author OmarYasser
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public static int gcd(int a, int b) {
            return b == 0 ? a : gcd(b, a % b);
        }

        public void solve(int testNumber, Scanner sc, PrintWriter out) {
            int n = sc.nextInt(), k = sc.nextInt();
            int gcd = sc.nextInt(), max = gcd;
            for (int i = 1; i < n; i++) {
                int x;
                gcd = gcd(gcd, x = sc.nextInt());
                max = Math.max(max, x);
            }
            if (k <= max && k % gcd == 0) out.println("POSSIBLE");
            else out.println("IMPOSSIBLE");
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader f) {
            br = new BufferedReader(f);
        }

        public String next() {
            while (st == null || !st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using ll = long long;

int N;

void solve(){
    vector<vector<int>> dp(9 + 1, vector<int>(9 + 1, 0));
    for(int i = 1; i <= N; ++i){
        int msd = i;
        while(msd >= 10) msd /= 10;
        int lsd = i % 10;
        dp[msd][lsd]++;
    }
    ll ans = 0;
    for(int i = 1; i <= 9; ++i){
        for(int j = 1; j <= 9; ++j){
            ans += dp[i][j] * dp[j][i];
        }
    }
    cout << ans;
}

int main(){
    cin >> N;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define NMAX 100000

#define D(x,y) (pos[(x)]-pos[(y)])

long long A[NMAX];
long long pos[NMAX*2];
int N;
long long L;

long long solve() {
    long long ret = 1;
    int p0 = 0, p1 = 0, p2 = 0;
    while (p0 < N) {
        if (p1 <= p0) p1 = p0 + 1;
        while (p1 - p0 < N && D(p1, p0) <= ret) p1++;
        if (D(p1, p0) <= ret) goto L1;

        if (p2 <= p1) p2 = p1 + 1;
        while (p2 - p0 < N && D(p2,p1) < D(p1, p0)) p2++;
        if (D(p2, p1) < D(p1, p0)) goto L1;

        if (L - D(p2, p0) >= D(p1, p0)) {
            ret = D(p1, p0);
            if (ret >= L/3) return ret;
            continue;
        }
L1:
        p0 += 1;
        while (p2 > p1 && D(p2, p1) > D(p1, p0)) p2--;
    }
    return ret;
}

int main(void) {
    int i;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
        L += A[i];
    }
    for (i = 0; i < 2*N; i++) {
        pos[i] = pos[i-1] + A[(i-1)%N];
    }
    printf("%lld\n", solve());
    return 0;
}

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  ll N,K;
  cin>>N>>K;
  cout << min(N%K,K-N%K) << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long num1,num2,g,l,i,j,min,temp1,temp2;
    while(scanf("%lld %lld",&num1,&num2) != EOF)
    {
        temp1=num1;
        temp2=num2;
        while (temp1 != 0)
        {
            g=temp1;
            temp1=temp2 % temp1;
            temp2=g;
        }
        l=(num1*num2)/g;
        printf("%lld %lld\n",g,l);
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i, start, end) for(ll i=(ll)start; i<(ll)end; i++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(i,0,len) cout << a[i] << " ";

int main(){
  ll n, k;
  string s;
  cin >> n >> k;
  cin >> s;
  
  s[k-1] = tolower(s[k-1]);
  print(s);
  
  return 0;
}


Measured memory_bytes: 256
# 累積和
N, Q = map(int, input().split())
S = input()
cs = [0] * N
for i in range(1, N):
  if S[i - 1:i + 1] == 'AC':
    cs[i] = 1
for i in range(1, N):
  cs[i] += cs[i - 1]
for _ in range(Q):
  l, r = map(int, input().split())
  t = cs[r - 1]
  if l != 1:
    t -= cs[l - 2]
    if S[l - 2:l] == 'AC':
      t -= 1
  print(t)


Measured memory_bytes: 9588
import scala.annotation.tailrec
import io.StdIn

object Main extends App {
  val n = StdIn.readInt
  val seq = StdIn.readLine.split(" ").map(_.toInt % 3)
  val a = for(i <- 0 until 3) yield seq.count(_ == i)

  @tailrec
  def rec(acc:Int, hasMany:Int, c0:Int, c1:Int, c2:Int):Int = {
    if(hasMany == 0) acc
    else {
      if(hasMany == 1) {
        if(c0 != 0) rec(acc+1, 1, c0-1, c1, c2)
        else if(c1 != 0) rec(acc+1, 2, 0, c1-1, c2)
        else if(c2 != 0) rec(acc+1, 0, c0, c1, c2-1)
        else acc
      }
      else {
        if(c0 != 0) rec(acc+1, 2, c0-1, c1 ,c2)
        else if(c2 != 0) rec(acc+1, 1, c0, c1, c2-1)
        else if(c1 != 0) rec(acc+1, 0, c0, c1-1, c2)
        else acc
      }
    }
  }

  val res1 = if(a(1) == 0) 0 else rec(0,1,a(0),a(1)-1,a(2)) + 1
  val res2 = if(a(2) == 0) 0 else rec(0,2,a(0),a(1),a(2)-1) + 1
  val ans = if(a.drop(1).sum == 0) 1 else math.max(res1,res2)
  println(ans)
}



Measured memory_bytes: 88160
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

int main() {
	ll n;
	cin >> n;
	ll a, b;
	ll bA, bB;
	cin >> a >> b;
	bA = a;
	bB = b;

	for(ll i = 1;i < n;i++){
		cin >> a >> b;
		ll aa = bA / a;
		if(bA % a != 0) aa++;
		ll bb = bB / b;
		if(bB % b != 0) bb++;

		ll ret = max(aa, bb);

		bA = a * ret;
		bB = b * ret;
	}

	cout << bA + bB << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <functional>
using namespace std;

typedef long long ll;
const ll InF = 1e15;
const int IntInf = 1e5;

int main() {
  int N,K;
  cin>>N>>K;
  vector<ll> h(N);
  for (int i = 0; i < N; i++) cin>>h[i];
  sort(h.begin(),h.end());
  ll ans = InF;
  for (int i = K; i <= N; i++) {
    ll res;
    res = h[i-1] - h[i-K];
    ans = min(ans,res);
    if (ans==0) break;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <algorithm>
#include <iterator>
#include <cstring>
#include <math.h>
#include <vector>
#include <ctime>
#include <map>
using namespace std;
typedef long long int ll;

int main()
{
	ll  n;
	cin >> n;
	vector <double> v(n);
	for(ll i=0;i<n;i++)
	{
		cin >> v[i];
	}
	sort(v.begin(),v.end());
	double ans=v[0];
	for(ll i=1;i<n;i++)
	{
		ans=(ans+v[i])/2;
	}
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int main( void )
{
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  ll a[55];
  for( int i=0; i<N; i++ ){
    cin >> a[i];
  }
  ll ret = 0;
  while( 1 ){
    ll d = 0;
    for( int i=0; i<N; i++ ){
      d += a[i] / N;
      a[i] = (a[i] % N) - (a[i]/N);
    }
    int f = 1;
    for( int i=0; i<N; i++ ){
      a[i] += d;
      if( a[i] >= N ) f = 0;
    }
    ret += d;
    if( f ) break;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = [input() for _ in range(h)]
ans = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            ans[i][j] = '#'
        else:
            left = max(0, j-1)
            right = min(w-1, j+1)
            top = max(0, i-1)
            bottom = min(h-1, i+1)
            for k in range(top, bottom+1):
                ans[i][j] += s[k][left:right+1].count('#')
for i in range(h):
    for j in range(w):
        print(ans[i][j], end='')
    print()


Measured memory_bytes: 3572
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int GCD(int a, int b)
{
    if (a < b) swap(a, b);

    if (b == 0) return a;

    int p = b, q = a % b;
    return GCD(p, q);
}

int main()
{
    int N, K;
    cin >> N >> K;
    int A[100005], mx_A = 0, mn_A = 1000000000;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
        mx_A = max(mx_A, A[i]);
        mn_A = min(mn_A, A[i]);
    }

    if (K > mx_A)
    {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    int gcd = A[1];
    for (int i = 2; i <= N; i++)
    {
        gcd = GCD(gcd, A[i]);
    }

    int start = mn_A % gcd;

    if ((K - start) % gcd == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#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, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    ll k;
    cin >> s >> k;
    
    int n = size(s), len = 1;
    vector<int> v;

    REP(i, n-1){
        if(s[i] == s[i+1]){
            len++;
        }else{
            v.push_back(len);
            len = 1;
        }
    }
    v.push_back(len);

    ll ans = 0;

    if(size(v) == 1){
        ans = (v[0] * k) / 2;
    }else{
        for(auto i : v){
            ans += i / 2;
        }
        ans *= k;
        if(s.front() == s.back() && v[0]%2 == 1 && v.back()%2 == 1){
            ans += k - 1;
        }
    }
    

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
l = list(map(int, input().split()))
num = l[0]
k = l[1]
baro=[]
ans=[]
for j in range(1,num+1):
    for i in range (100000):
        if j * 2 **i >= k:
            baro.append(i) 
            break
for m in baro:
    ans.append((1/num)*(1/2)**m)

print(sum(ans))

Measured memory_bytes: 7064
#include <iostream>

int main(){
    int a = 0;
    int b = 0;
    int sum = 1;
    int number = 0;

    std::cin >> a >> b;

    while(b - (sum - 1 + a) >= 0){
        sum = sum - 1 + a;
        number++;
    }
    if(b - sum > 0){
        number++;
    }

    std::cout << number << std::endl;
    return 0;
}

Measured memory_bytes: 256
# B - Good Distance

N, D = map(int, input().split())
X = [[int(x) for x in input().split()] for _ in range(N)]

cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        dist = 0
        for k in range(D):
            dist += (abs(X[i][k] - X[j][k])) ** 2
        if (dist ** (1 / 2)).is_integer():
            cnt += 1

print(cnt)


Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))

border_4 = n//2
border_2 = n

cnt_4=0
cnt_2=0

for i in range(n):
    if a[i]%4==0:
        cnt_4+=1
    elif a[i]%4!=0 and a[i]%2==0:
        cnt_2+=1
    else:
        continue


if cnt_4>=border_4:
    print('Yes')
elif n-cnt_4*2<=cnt_2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
#include<iostream>
#include<set>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
 char S[100];
 cin>>S;
 bool flag1 = true;
 for(int i = 0;i < 100;i++){
     if(i%2 != 0){
         if(S[i] == 'R')flag1 = false;
     }
    else{
        if(S[i] == 'L')flag1 = false;
    }
    if(flag1 == false)break;
 }
 if(flag1)cout<<"Yes";
 else cout<<"No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int n,m;
const int max_size_n=50050;
const int max_size_m=22;
int d[max_size_m]={0};
int t[max_size_n];
int INF = (1<<30)-1;
int main()
{
	cin >> n >> m;
	for(int i=0;i<m;i++)
		cin >> d[i];
	for(int j=0;j<=n;j++)
	{
		t[j]=INF;
	}
	t[0]=0;
	for(int i=0;i<m;i++)
	for(int j=d[i];j<=n;j++){
		t[j]=min(t[j],t[j-d[i]]+1);
	}
	cout << t[n] <<endl;
	return 0;
}


Measured memory_bytes: 3300
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    string ans="";
    for(int i=0;i<s.size();i++)
    {
        ans+=t[i];
    }
    if(s==ans && s.size()+1==t.size())
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3596
// D - Maze Master
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
using vi = vector<int>;
using vvi = vector<vi>;
using VC = vector<char>;
using VVC = vector<VC>;

// BFS (幅優先探索)
// 文字列迷路SをS[sh][sw]から各マスまでの最短コストをdist[h][w]に求める
#define HMAX 20
#define WMAX 20
VVC S(HMAX+2, VC(WMAX+2, '#'));//外周を壁で囲む
vvi dist(HMAX+1, vi(WMAX+1, -1));
void bfs(int sh, int sw){
	int dx[4]={0,-1,0,1}, dy[4]={-1,0,1,0};
	dist[sh][sw] = 0;//最短コスト設定
	S[sh][sw] = '_';//訪問済みフラグ on
	queue<int> qh, qw;
	qh.push(sh), qw.push(sw);
	while(!qh.empty()){
		int ph = qh.front(); qh.pop();
		int pw = qw.front(); qw.pop();
		rp(k, 0, 4){//四方向処理
			int h = ph + dy[k], w = pw + dx[k];
			if(S[h][w] != '.') continue;//壁・訪問済みはパス
			S[h][w] = '_';//訪問済みフラグ on
			dist[h][w] = dist[ph][pw] + 1;//最短コスト設定
			qh.push(h);
			qw.push(w);
		}
	}
}

int main(){
	int H,W; cin>>H>>W;

	rp(h, 1, H+1){
		string s; cin>>s;
		rp(w, 1, W+1) if(s[w-1]=='.') S[h][w] = '.';
	}

	VVC S_temp = S;
	vvi dist_temp = dist;

	int ans = 0;
	rp(h, 1, H+1){
		rp(w, 1, W+1){
			S = S_temp;
			if(S[h][w]=='.'){
				dist = dist_temp;
				bfs(h,w);
				for(vi v:dist)for(int d:v) ans = max(ans, d);
			}
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
int a[N], b[N], tot;
int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 0; i < n; ++ i){
		cin >> a[i];
	}
	for(int i = n-1; i >= 0; i -= 2){
		b[tot ++] = a[i];
	}
	for(int i = n&1; i < n; i += 2){
		b[tot ++] = a[i];
	}
	for(int i = 0; i < n; ++ i){
		printf("%d%c", b[i], i == n-1 ? '\n' : ' ');
	}
}


Measured memory_bytes: 3712
#include<iostream>
#include<string>
using namespace std;
int main()
{  int n;
 cin>>n;
 int count1=0,count2=0,count3=0,count4=0;
 while(n--)
 {  string s;
   cin>>s;
  if(s.compare("AC")==0)
      count1++;
  if(s.compare("WA")==0)
      count2++;
  if(s.compare("TLE")==0)
      count3++;
  if(s.compare("RE")==0)
      count4++;
  
 }
 cout<<"AC x "<<count1<<endl;
 cout<<"WA x "<<count2<<endl;
 cout<<"TLE x "<<count3<<endl;
 cout<<"RE x "<<count4;
}

Measured memory_bytes: 3640
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

		String line1 = sc.nextLine();

		List<String> lines1 = Arrays.asList(line1.split(" "));
		/*
				Integer a = Integer.parseInt(lines1.get(0));
				Integer b = Integer.parseInt(lines1.get(1));
		*/

		String a = lines1.get(0);
		String b = lines1.get(1);
		StringBuilder buff = new StringBuilder();
		buff.append(a);
		buff.append(b);

		Double c = Double.parseDouble(buff.toString());
		// 平方根
		double d = Math.sqrt(c);
		int e =(int)d;

		if ((d - e == 0)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 21972
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    int H1, M1, H2, M2, K;
    cin>>H1>>M1>>H2>>M2>>K;
    int A, B;
    A = H1*60 + M1;
    B = H2*60 + M2;
    cout<<max(0, B-A-K)<<endl;
}



Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

Int gcd(Int a, Int b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

int main() {

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

	Int N;
	cin >> N;

	vector<Int> x(N + 1);
	for (Int i = 0; i < N+1; i++) {
		cin >> x[i];
	}

	sort(x.begin(), x.end());

	vector<Int> dis(N);
	for (Int i = 0; i < N; i++) {
		dis[i] = x[i + 1] - x[i];
	}

	vector<Int> G(N);
	G[0] = dis[0];

	for (Int i = 0; i < N-1; i++) {
		G[i+1]=gcd(G[i], dis[i + 1]);
	}
	cout << G[N - 1] << endl;
}

Measured memory_bytes: 2560
n = int(input())
a = list(map(int, input().split()))

def bubbleSort(A, N):
    flag = 1 #逆の隣接要素が存在する
    cnt = 0
    while flag:
        flag = 0
        for j in range(n-1, 0, -1):#が N-1 から 1 まで:
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
                flag = 1
    print(*A)
    print(cnt)
    
bubbleSort(a, n)


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

void solve() {
	string s; cin >> s;
	for (char c: s) {
		printf("%c", c==','?' ':c);
	}
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int main() {
    int N; cin >> N;
    vector<int> A(N); rep(i, N) cin >> A[i];
    int M; cin >> M;
    vector<int> B(M); rep(i, M) cin >> B[i];

    map<int, int> m;
    rep(i, N) m[A[i]]++;

    rep(i, M) {
        if (m[B[i]] > 0) {
            m[B[i]]--;
        } else {
            cout << "NO" << endl;
            exit(0);
        }
    }

    cout << "YES" << endl;
}


Measured memory_bytes: 11264
n = int(input())

a = [1]
b = [1]

while True:
    d = a[-1] * 9
    if d > n:
        break
    a.append(d)

while True:
    d = b[-1] * 6
    if d > n:
        break
    b.append(d)

dp = [n] * (2 * n)
dp[0] = 0

for i in range(n):
    for j, a_ in enumerate(a):
        dp[i+a_] = min(dp[i+a_], dp[i]+1)
    for j, b_ in enumerate(b):
        dp[i+b_] = min(dp[i+b_], dp[i]+1)

print(dp[n])

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

int main() {
  int N, K,C;
  cin >> N >> K;
  C=0;
  
  for(int i=0;i<N;i++){
    int B;
    cin >> B;
    C += min(2*B,2*K-2*B);
  }
  
  cout << C << endl;
}


Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

template <typename T>
std::vector<int> sort_indexes(const std::vector<T> &v) {
  std::vector<int> idx(v.size());
  std::iota(idx.begin(), idx.end(), 0);
  std::sort(idx.begin(), idx.end(), [&v](int i1, int i2) {return v[i1] > v[i2];});
  return idx;
}


signed main() {
	int n;
	std::cin >> n;
	std::vector<int> p(n);
	rep(i,n) std::cin >> p[i];
	auto idx = sort_indexes(p);
	std::set<int> set;
	int sum = 0;
	for(auto i:idx) {
		auto it = set.emplace(i).first;
		int a,b,c,d;
		if(it==set.begin()) {
			a=0;b=*it+1;
		} else {
			auto itb = std::prev(it);
			b = *it - *itb;
			if(itb == set.begin()) {
				a = *itb+1;
			} else {
				auto ita = std::prev(itb);
				a = *itb - *ita;
			}
		}
		auto itc = std::next(it);
		if(itc==set.end()) {
			d=0;c=n-*it;
		} else {
			auto itd = std::next(itc);
			c = *itc - *it;
			if(itd==set.end()) {
				d=n-*itc;
			} else {
				d=*itd-*itc;
			}
		}
		sum+=p[*it]*(a*c+b*d);
	}
	print(sum);
	return 0;
}


Measured memory_bytes: 6528
a, b, c, k = map(int, input().split())
if k % 2 == 0:
    if abs(a - b) >= 10 ** 18:
        print('Unfair')
    else:
        print(a - b)
else:
    if abs(a - b) >= 10 ** 18:
        print('Unfair')
    else:
        print(b - a)


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

using Graph = vector<vector<int> >;

vector<int> color;

bool dfs(Graph &G, int v, int cur = 0){
    color[v] = cur;
    for(auto nv : G[v]){
        if(color[nv]!=-1){
            if(color[nv] == cur) return false;
            continue;
        }

        if(!(dfs(G,nv,1-cur) ) )  return false;
    }
    return true;
}

int main(){
    ll N,M; cin >> N >> M;
    Graph G(N+1);
    rep(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    color.assign(N+1,-1);
    bool is_bipartite = true;
    rep(v,N){
        if(color[v]!=-1) continue;
        if(!(dfs(G,v)) ) is_bipartite = false;
    }

    ll res = 0;
    if(is_bipartite){
        ll B=0,W=0;
        rep(v,N){
            if(color[v]) W++;
            else B++;
        }
        res = B*W-M;
    }else{
        res = N*(N-1)/2 - M;
    }

    cout << res << endl;
}

Measured memory_bytes: 9524
nums = [int(num) for num in input().split()]
a = nums[0]
b = nums[1]
c = nums[2]
maxi = max(a,b)
maxi = max(maxi,c)
if maxi == a:
    ans = a*10 +b+c
elif maxi == b:
    ans = b*10+a+c
else:
    ans = c*10+a+b    
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] n = sc.next().split("");

		for (int i = 0; i < n.length; i++) {
			if (n[i].equals("1")) {
				n[i] = "9";
			} else if (n[i].equals("9")){
				n[i] = "1";
			}
			System.out.print(n[i]);
		}

	}
}

Measured memory_bytes: 23124
#!/usr/bin/env python3
#ABC140 A

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
print(n**3)


Measured memory_bytes: 38384
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  int n; cin>>n;
  if(n%2==0) cout<<n/2<<endl;
  else cout<<n/2+1<<endl;
  return 0;
}  

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

int main() {
  ll n;cin>>n;
  string s;
  while(n){
    n--;
    s+=(char)('a'+n%26);
    n/=26;
  }
  reverse(all(s));
  cout<<s<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

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

    int k, x;
    cin >> k >> x;
    if (500 * k >= x) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}   


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int N[4];
  for (int i = 0; i < 4; i++)
    cin >> N[i];
  sort(N, N + 4);
  string ans = "NO";
  if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9)
    ans = "YES";
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  string s,t;
  cin>>s>>t;
  sort(ALL(s));sort(ALL(t));reverse(ALL(t));
  cout<<((s<t)?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;


int main() {
    int a, p;
    cin >> a >> p;

    cout << ( (a*3+p)/2 ) << endl;
        

    return 0;
}


Measured memory_bytes: 256
H,W=map(int, input().split())
C=["0" for k in range(H)]
for k in range(H):
    C[k]=input()
D=["0"for k in range(2*H)]
for k in range(H):
    D[2*k]=C[k]
    D[2*k+1]=C[k]
for k in range(2*H):
    print(D[k])

Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {


        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var vals = Console.ReadLine().Split(' ').
                Select(x => int.Parse(x)).ToList();
            var K = vals[1];
            var A = Console.ReadLine().Split(' ').
                Select(x => int.Parse(x)).ToList();
            A.Sort();
            var ans = A.Take(K).Sum();


            Console.WriteLine(ans);
            Console.Out.Flush();
        }




    }
}




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rep3(i, m, n) for(ll i=m;i<=(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000
#define LLINF 1000000000000000000

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; }

// union by size + path having
class UnionFind {
public:
	vector <ll> par; // 各元の親を表す配列
	vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};

void solve_abc_d() {
	ll n, m;
	ll l_ans = 0;

	cin >> n >> m;

	V a(m), b(m);
	UnionFind uf(n + 1);
	rep(i, m) {
		cin >> a[i] >> b[i];
		uf.merge(a[i], b[i]);
	}

	rep(i, uf.siz.size()) {
		chmax(l_ans, uf.siz[i]);
	}

	cout << l_ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed;
	cout << setprecision(15);

	solve_abc_d();

	return 0;
}


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

int main() {
    int n,m,k,r,c,maxic,maxir;
    cin>>n>>m>>k;
    vector<int>row(300001,0);
    vector<int>col(300001,0);
    map<pair<int,int>,int> chk;
    for(int i=0;i<k;i++) {
        cin>>r>>c;
        row[r-1]++;
        col[c-1]++;
        chk[{r-1,c-1}]=1;
    }
    int ans=0;
    int maxi = -1;
    
    r = 0;
    c = 0;
    maxic =-1;
    maxir =-1;
    for(int i=0;i<max(m,n);i++) {
        if(row[i]>maxir) {
            maxir=row[i];
            r=i;
        }
        else if(row[i]==maxir && chk[{i,c}]==0) {
            maxir=row[i];
            r=i;
        }

        if(col[i]>maxic) {
            maxic=col[i];
            c=i;
        }
        else if(col[i]==maxic && chk[{r,i}]==0) {
            maxic=col[i];
            c=i;
        }
    }

    if(chk[{r,c}]==1) ans=maxir+maxic-1;
    else ans=maxir+maxic;
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  for (int i = 0; i < k; i++) {
    cout << s;
    if (i < n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  if (s < 1000000000) {
    for (int i = k; i < n; i++) {
      cout << 1000000000;
      if (i < n - 1) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  } else {
    for (int i = k; i < n; i++) {
      cout << 1;
      if (i < n - 1) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 1280
import numpy as np

N, M = map(int, input().split())
X_list = list(map(int, input().split()))
X_list.sort()

if M <= N:
    print(0)
elif N == 1:
    print(X_list[-1] - X_list[0])
else:
    diff = np.diff(X_list)
    ans = max(X_list) - min(X_list) - np.sum((-np.sort(-diff))[:N-1])
    print(ans)


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

int main() {
  string s;
  cin >> s;
  if (s == "RRR") cout << 3 << endl;
  else if (s == "RRS" || s == "SRR") cout << 2 << endl;
  else if (s == "SSS") cout << 0 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    string s;
    int K;
    cin >> s >> K;
//    方針
//    unique_charを持つヤツの次の連中で一番小さいヤツを探す
//    綺麗に書くには再帰か，幅優先探索か，いや，ダイクストラか
//    ダイクストラ法っぽいな．
//    初期化：全部の文字を単品で入れる
//    iteration: 一番小さいヤツを取り出す．
//    set<string>に取り出したヤツを入れる．
//    取り出したヤツに次の文字を加えたやつをpqに入れる（なければ何もしない）
//    終了条件：set<string>の大きさがKになること

    priority_queue<pair<string, string::iterator>, vector<pair<string, string::iterator>>, greater<>> pq{};
    for (string::iterator itr = s.begin(); itr != s.end(); itr++){
        pq.push(make_pair(string(itr, itr+1), itr));
    }
    set<string> memory{};
    while(!pq.empty()){
        string str;
        string::iterator itr;
        tie(str, itr)= pq.top();
        pq.pop();
//        cout << str << " " << *itr << endl;

        bool inserted;
        tie(ignore, inserted) = memory.insert(str);
        if (inserted && memory.size() == K){
            cout << str;
            return 0;
        }
        if (itr + 1 != s.end()){
            pq.push(make_pair(str + string(itr+1, itr+2), itr+1));
        }
    }
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan =new Scanner(System.in);
		String s=scan.next();

		
		if(s.equals("ABC")) {
			System.out.println("ARC");
		}
		else {
			System.out.println("ABC");
		}
		
	}
}


Measured memory_bytes: 35460
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,temp,sum=0,count=0,f=1;
    cin>>n>>m;
    ll heights[n+1] = {0};
    vector<ll> adj[n+1];
    for(i=1;i<=n;i++){
        cin>>heights[i];
    }
    set<pair<ll, ll>> s;
    for(i=0;i<m;i++){
        cin>>x>>y;
        s.insert({x, y});      
        s.insert({y, x}); 
    }
    for(auto i: s){
        x = i.first;
        y = i.second;
        // cout<<x<<" "<<y<<"\n";
        adj[x].pb(y);

    }
    for(i=1;i<=n;i++){
        f = 0;
        for(j=0;j<adj[i].size();j++){
            ll node = adj[i][j];
            if(heights[node] >= heights[i]){
                f = 1;
                break;
            }
        }
        if(f == 0){
            // cout<<i<<"-\n";
            count++;
        }
    }
    cout<<count;
}    
    

Measured memory_bytes: 22540
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u32,
        i: u32
    }
    println!("{}", n-i+1);
}


Measured memory_bytes: 4352
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;


class C755 {
public:
    int a[3] = { 3, 5, 7 };
    ll N;
    ll ans = 0;

    void solve(std::istream& in, std::ostream& out) {
        in >> N; dfs(0, 0);
        COUT(ans);
    }

    void dfs(ll n, int b) {
        if (n > N) return;
        if (b == 7) ans++;
        REP(i, 3) dfs(10 * n + a[i], b | 1 << i);
    }
};


int main() {
    C755 solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s] = 1;
    }
    cout << mp.size();
}


Measured memory_bytes: 19224
#include<stdio.h>
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main(void){
    long long int tmp,ans,i;
    string x;
    while(1){
        ans=0;
        getline(cin,x);
        if(x[0]=='0') break;
        for(i=0;i<x.size();i++){
            ans+=x[i]-'0';
        }
        cout << ans << endl;

    }
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    
    vector<string> s(N);
    for(int i = 0; i < N; i++){
        cin >> s.at(i);
    }
    
    int M;
    
    cin >> M;
    
    vector<string> t(M);
    for(int i = 0; i < M; i++){
        cin >> t.at(i);
    }
    
    vector<int> ans(N, 0);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(s.at(i) == s.at(j)){
                ans.at(i)++;
            }
        }
//        cout << "i:" << i << ", ans:" << ans.at(i) << endl; 
    }
    
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            if(s.at(i) == t.at(j)){
                ans.at(i)--;
            }
        }
//        cout << "i:" << i << ", ans:" << ans.at(i) << endl; 
    }
    
    int maxans = 0;
    for(int i = 0; i < N; i++){
        if(ans.at(i) > maxans){
            maxans = ans.at(i);
        }
    }
    
    cout << maxans << endl;
    
}


Measured memory_bytes: 256
from fractions import gcd
from math import sqrt
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from itertools import accumulate,permutations
from bisect import bisect_left,bisect_right

S = input()

flag = False
for sta in range(len(S)):
    for end in range(sta,len(S)):
        if S[:sta] + S[end:] == "keyence":
            flag = True

if flag:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}
 
ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}


void solve(long long N, std::vector<long long> a){

}

int main(){
    long long N;
    cin >> N;
    ll ans = 0;
    for(int i = 0 ; i < N ; i++){
        ll tmp;
        cin >> tmp;
        while(tmp % 2 == 0){
            tmp /= 2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int res = 60*(H2-H1) + (M2-M1) - K;
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int main()
  {
  ios_base::sync_with_stdio(0); 
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  }


Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <queue>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

ll L[100005];
vector< pair<int, int> > E[100005];
bool U[100005];

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

	REP(i, N - 1)
	{
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		E[a].push_back(pair<int, int>(b, c));
		E[b].push_back(pair<int, int>(a, c));
	}

	int Q, K;
	cin >> Q >> K;
	K--;
	queue<int> q;
	q.push(K);
	while (!q.empty())
	{
		int i = q.front();
		q.pop();
		U[i] = true;
		REP(j, E[i].size())
		{
			auto e = E[i][j];
			if (!U[e.first])
			{
				L[e.first] = L[i] + (ll)e.second;
				q.push(e.first);
			}
		}
	}
	REP(i, Q)
	{
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << L[x] + L[y] << endl;
	}
	return 0;
}

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

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


# r < g < b
r, g, b = map(int, input().split())
k = int(input())


def is_valid(r, g, b, comb):
    for c in comb:
        if c == 'r':
            r *= 2
        elif c == 'g':
            g *= 2
        else:
            b *= 2
    if r < g < b:
        return True
    return False


l = ['r', 'g', 'b']
flag = False
for i in range(k+1):
    if i == 0:
        if is_valid(r, g, b, []):
            flag = True

    combs = list(itertools.combinations_with_replacement(l, i))
    for comb in combs:
        if flag:
            break
        if is_valid(r, g, b, comb):
            flag = True

if flag:
    print('Yes')
else:
    print('No')


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

long double D, T, S;

int main(){
	// int T; cin >> T;
	// while (T --){
		cin >> D >> T >> S;
		long double R = D / S;
		cout << (R <= T ? "Yes" : "No") << "\n";
	// }
}

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

using namespace std;

int main() {
    double a,b,x; cin>>a>>b>>x;

    double n;
    if (a*a*b/2.0 <= x) {
        n = atan(2.0*(a*a*b-x)/(a*a*a));
    } else {
        n = M_PI/2.0 - atan(2.0*x/(a*b*b));
    }
    cout << setprecision(10) << n * (180.0 / M_PI) << endl;

    return 0;
}

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

int n, m, q;
int a[50];
int b[50];
int c[50];
int64_t d[50];
int ans = 0;

void calc(std::vector<int> A)
{
  if (A.size() == n + 1)
  {
    int now = 0;
    for (int i = 0; i < q; ++i)
    {
      if (A[b[i]] - A[a[i]] == c[i])
      {
        now += d[i];
      }
    }
    ans = std::max(ans, now);
    return;
  }

  A.push_back(A.back());
  while (A.back() <= m)
  {
    calc(A);
    A.back()++;
  }
}

int main()
{
  std::cin >> n >> m >> q;
  for (int i = 0; i < q; ++i)
  {
    std::cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  std::vector<int> A(1,1);
  calc(A);
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3556