akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#define IF_DEBUG 0
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 105;

int n, m, nb, a[maxn], odd, ra[maxn], b[maxn];
bool used[maxn];

int main()
{
	sf("%d%d",&n,&m);
	fo(i,1,m) sf("%d",&a[i]), odd += (a[i]&1);
	if(odd > 2) return 0*pf("Impossible");
	if(m == 1)
	{
		if(a[1] == 1) pf("1\n1\n1\n");
		else pf("%d\n2\n%d %d\n",a[1],a[1]-1,1);
		return 0;
	}
	fo(i,1,m) if(a[i]%2==1)
	{
		if(!ra[1]) ra[1] = a[i];
		else ra[m] = a[i];
		used[i] = true;
	}
	int cnt = 1;
	fo(i,1,m) if(!used[i]) 
	{
		while(cnt <= m && ra[cnt]) ++ cnt;
		ra[cnt] = a[i];
	}
	if(ra[1] == ra[m] && ra[1] == 1)
	{
		b[1] = 2;
		fo(i,2,m-1) b[i] = ra[i];
		fo(i,1,m) pf("%d ",ra[i]); pf("\n");
		pf("%d\n",m-1);
		fo(i,1,m-1) pf("%d ",b[i]);
		return 0;
	}
	else if(ra[1] == 1) 
	{
		swap(ra[1], ra[m]);
		fo(i,1,m) 
		{
			if(i==1) b[i] = ra[i]-1;
			else if(i==m) b[i] = ra[i]+1;
			else b[i] = ra[i];
		}
		b[m] = 2;
		fo(i,1,m) pf("%d ",ra[i]); pf("\n");
		pf("%d\n",m);
		fo(i,1,m) pf("%d ",b[i]);
		return 0;
	}
	fo(i,1,m) 
	{
		if(i==1) b[i] = ra[i]-1;
		else if(i==m) b[i] = ra[i]+1;
		else b[i] = ra[i];
	}
	if(ra[m] == 1) b[m] ++;
	fo(i,1,m) pf("%d ",ra[i]); pf("\n");
	pf("%d\n",m);
	fo(i,1,m) pf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 256
cylinders = []
n = gets.to_i
gets.split.map(&:to_i).each do |r1|
  if cylinders.empty?
    cylinders << [r1, r1]
  else
    x1 = [cylinders.map {|x2, r2| x2 + 2 * Math.sqrt(r1 * r2) }.max, r1].max
    cylinders << [x1, r1]
  end
end
p cylinders.map {|x, r| x + r }.max


Measured memory_bytes: 7876
#include <stdio.h>
#include <string.h>
int rev(char str[])
{
    int i,le;
    char t;
    le=strlen(str);
    for(i=0; i<le/2; i++)
    {
        t=str[i];
        str[i]=str[le-1-i];
        str[le-1-i]=t;
    }
}
int main()
{
    int lo;
    char str[21];
    gets(str);
    lo=strlen(str);
    if(lo>0&&lo<=20)
    {
        rev(str);
        puts(str);
    }
    return 0;
}

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

int main() {
	int n, k;
	cin>>n;
	vector<vector<int>> mat;
	for(int i = 0; i<n; i++){
	    vector<int> arr(3);
	    for(int i = 0l; i < 3; i++){
	        cin>>arr[i];
	    }
	    mat.push_back(arr);
	}
	
	vector<vector<int>> dp(n, vector<int>(3,0));
	dp[0][0] = mat[0][0];
	dp[0][1] = mat[0][1];
	dp[0][2] = mat[0][2];
	
	for(int i = 1; i < n; i++){
	    for(int j = 0; j < 3; j++){
	        dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + mat[i][j];
	    }
	}
	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
	return 0;
}


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    vector<int> v(5);

    rep(i, 5){
        cin >> v[i];

        if(v[i] == 0){
            cout << i + 1 << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>


int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    char S[a+b+1];
    for(int i=0;i<a+b+1;i++){
        S[i]='X';
    }
    scanf("%s",S);
    for(int i=0;i<a;i++){
        if(S[i]<'0' || S[i]>'9'){
            printf("No");
            exit(0);
        }
    }
    if(S[a]!='-'){
        printf("No");
        exit(0);
    }
    for(int i=a+1;i<a+b+1;i++){
        if(S[i]<'0' || S[i]>'9'){
            printf("No");
            exit(0);
        }
    }
            printf("Yes");
    return 0;
}

Measured memory_bytes: 128
A, B, K = map(int, input().split())

if A-K <= 0:
    K2 = K-A
    A_ans = 0
    if B-K2 <= 0:
        B_ans = 0
    else:
        B_ans = B-K2
else:
    A_ans = A-K
    B_ans = B
    
print(A_ans, B_ans)      

Measured memory_bytes: 9000
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;

#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 _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T>
inline void chmax(T &a, const T &b) {
    if ((a) < (b)) (a) = (b);
}
template <class T>
inline void chmin(T &a, const T &b) {
    if ((a) > (b)) (a) = (b);
}

#define divceil(a, b) ((a) + (b)-1) / (b)
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x)    \
    sort(all(x)); \
    x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
    }
} fast;
void check_input() {
    assert(cin.eof() == 0);
    int tmp;
    cin >> tmp;
    assert(cin.eof() == 1);
}

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;


int solve() {
    ll L,R;cin>>L>>R;

    vec<ll> p;
    rep(x, L, min(L+4041, R+1)){
        p.pb(x%2019);
    }

    ll ans = INF;
    rep(i, sz(p)){
        rep(j, i+1, sz(p)){
            chmin(ans, (p[i]*p[j])%2019);
        }
    }
    cout << ans << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb push_back
#define sz(s) ( (int)s.size() )
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 1e5 + 5;

int n, m, ar[N], cur[N], ans, mx[N], cnt, sum;

vector <int> g[N], V;

vector <pair <int, int> > vec;

main ()
{
    cin >> n >> m;
    for (int i = 1; i <=n; i++)
    {
        scanf("%d", &ar[i]), cur[ ar[i] % m ]++;

        g[ ar[i] % m ].pb( ar[i] );
    }

    ans = cur[0] >> 1;

    for (int i = 1; i < (m + 1) / 2; i++)
    {
        if (cur[i] >= cur[m - i])
        {
            ans += cur[m - i];
            vec.pb( mk( cur[i] - cur[m - i], i ) );
        }
        else
        {
            ans += cur[i];
            vec.pb( mk( cur[m - i] - cur[i], m - i ) );
        }
    }
    if (m % 2 == 0)
        ans += cur[m / 2] >> 1;

    for (auto x : vec)
    {
//        V.clear();

        sum = 0;
        cnt = 1;

        int v = x.sc, col = x.fr;

        sort(all(g[v]));

        for (int j = 1; j < sz(g[v]); j++)
        {
            if ( g[v][j] == g[v][j - 1] )
                cnt++;
            else
            {
                sum += (cnt - (cnt % 2));
//                V.pb(cnt - (cnt % 2) );
                cnt = 1;
            }
        }
        sum += (cnt - (cnt % 2));
//        V.pb( cnt - (cnt % 2) );
//        sort( all(V), greater<int>() );
        ans += min( sum, col ) / 2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 7164
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int n = sc.nextInt();
        String s = sc.next();
        int ans = 1;
        for (int i = 1; i<n; i++){
            if (s.charAt(i) != s.charAt(i-1)){
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 39376
#include<iostream>
#include<cmath>
#include<complex>
using namespace std;

complex<double> p[300];

complex<double> core(int a,int b){
  complex<double> res,mid,norm;

  mid = (p[a]+p[b]) / 2.0;

  norm = (p[a] - p[b]) * complex<double>(0,1);
  norm = norm / abs(norm);
  norm = norm * sqrt(1.0 - abs(mid-p[a])*abs(mid-p[a]));

  res = norm + mid;
  return res;
}
  

int main(){
  int n;
  complex<double> o,r;
  int max,tmp;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++)cin >> p[i].real() >> p[i].imag();

    max = 1;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	r = p[i]-p[j];
	if(i!=j && r.real()*r.real() + r.imag()*r.imag() < 4.0){
	  o = core(i,j);
	  tmp = 2;
	  for(int k=0;k<n;k++){
	    if(k!=i && k!=j){
	      r = o-p[k];
	      if( r.real()*r.real() + r.imag()*r.imag() <1.0)tmp++;
	    }
	  }
	  if(max < tmp)max = tmp;
	}
      }
    }
    cout << max << endl;
  }
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define rep1(i,n) for (int i=1; i<=(int)(n); i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fst first
#define scd second
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll n, k; cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans = 0, M = 1e9+7;
  ll km = ((k*(k-1)) % M * (M/2+1)) % M;
  rep(i,n) {
    ll ac = 0, c = 0;
    rep(j,n) {
      if (a[i] > a[j]) {
        if (j > i) c++;
        ac++;
      }
    }
    ll rt = (c * k) % M;
    ll mt = (ac * km) % M;
    ans = (ans + (rt + mt) % M) % M;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

const int N = 44;
const int K = 4;
const int INF = 1000000000;
int n;
int p[N];
int t[N];

bool input(){
  cin>>n;
  if(n==0)return false;
  n++;
  p[0] = 0;
  t[0] = 0;
  reps(i,1,n){
    cin>>p[i]>>t[i];
  }
}



void solve(){
  int dp[N][K];
  rep(i,N)rep(j,K)dp[i][j]=INF;

  dp[0][0]=0;

  reps(i,1,n){
    rep(has,K){

      int dist = abs(p[i]-p[i-1]);
      int time = t[i]-t[i-1];
      //direct
      if(has!=K-1 && (has+1)*dist<=time){
	dp[i][has+1] = min(dp[i][has+1], dp[i-1][has]+dist);
      }
      //back
      if((has+1)*p[i-1] + p[i]<=time){
	dp[i][1] = min(dp[i][1], dp[i-1][has]+p[i-1]+p[i]);
      }
    }

    bool ok = false;
    rep(has,K){
      if(dp[i][has]<INF)ok=true;
    }
    if(!ok){
      printf("NG %d\n",i);
      return;
    }
  }

  int ans = INF;

  rep(j,K){
    ans = min(ans, dp[n-1][j]+p[n-1]);
  }

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

int main(){
  while(input())solve();
}

Measured memory_bytes: 1136
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {
	
    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
        	String s = sc.next();
        	
        	int sum1 = 0;
        	int sum2 = 0;
        	for ( int i = 0; i < s.length(); i++ ) {
        		// 010101.. ptn
        		if(Character.getNumericValue(s.charAt(i)) != i % 2) {
        			sum1++;
        		} else {
        			sum2++;
        		}
        	}
        	
            System.out.println(sum1 < sum2 ? sum1 : sum2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 24660
let m, c, (n, h) = ref 0, ref 0, Scanf.scanf " %d %d" @@ fun a b -> a, ref b
let bs = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> m := max !m a; b
let _ = Array.(sort (fun x y -> y - x) bs; iter (fun b -> if b > !m then (if !h > 0 then (incr c; h := !h - b))) bs); Printf.printf "%d\n" @@ !c + (max 0 !h + !m - 1) / !m

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

int main(void){
    int n;
    cin >> n;
    
    int p;
    int sum = 0;
    int max = 0;
    for(int i = 1; i <= n; i++){
        cin >> p;
        if(p > max){
            max = p;
        }
        sum += p;
    }
    
    sum -= max / 2;
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var O = ReadLine();
            var E = ReadLine();
            var pass = new char[O.Length + E.Length];
            for (var i = 0; i < O.Length; ++i)
                pass[i * 2 ] = O[i];
            for (var i = 0; i < E.Length; ++i)
                pass[i * 2 + 1] = E[i];
            WriteLine(pass);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 11092
import copy
import sys
import math

def main():
	n,a,b = map(int,input().split())
	x = list(map(int,input().split()))
	ans = 0
	for i in range(1,n):
		renji = x[i] - x[i-1]
		if(renji * a > b):
			ans += b
		else:
			ans += renji * a
	print(ans)


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()



Measured memory_bytes: 64364
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 9223372036854775807
#define MOD 1000000007
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;

int n,m1,m2;
int a[1111],b[1111],c[1111];
int m[44][1111][1111];

int dp(int i,int ak,int bk){
	if(ak!=0 && bk!=0 && ak*m2==bk*m1/*ak%m1==0 && bk%m2==0 && ak/m1==bk/m2*/){
		DEB(ak)END DEB(bk)END
		return 0;
	}
	if(i==n){
		//DEB(ak)END DEB(bk)END
		return INF;
	}
	if(m[i][ak][bk]!=-1){
		DEB(ak)END DEB(bk)END
		return m[i][ak][bk];
	}
	
	int sum1,sum2;
	
	//else{
		//DEB(ak)END DEB(bk)END
		sum1=dp(i+1,ak+a[i],bk+b[i])+c[i];
		sum2=dp(i+1,ak,bk);
	//}
	DEB(sum1)END DEB(sum2)END
	return m[i][ak][bk]=min(sum1,sum2);
}

signed main(){
	cin>>n>>m1>>m2;
	rep(i,n){
		rep(j,1111){
			rep(k,1111){
				m[i][j][k]=-1;
			}
		}
	}
	
	rep(i,n)cin>>a[i]>>b[i]>>c[i];
	int ans=dp(0,0,0);
	if(ans==INF)cout<<-1<<endl;
	else cout<<ans<<endl;
	

}

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

int main() {
	int n; cin >> n;
	long long a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] == 0LL) {
			cout << "0" << endl;
			return 0;
		}
	}

	long long res = 1;
	for (int i = 0; i < n; i++)
	{
		if((1000000000000000000) / res < a[i] ) {
			cout << "-1" << endl;
			return 0;
		}
		else res *= a[i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 4412
n = int(input())
x,y = map(int,input().split())

for i in range(n-1):
    t,a = map(int,input().split())
    if x%t == 0:
        x1 = x
        y1 = (x//t)*a
    else:
        x1 = (x//t+1)*t
        y1 = (x//t+1)*a
    
    if y % a == 0:
        x2 = (y//a)*t
        y2 = y
    else:
        x2 = (y//a+1)*t
        y2 = (y//a+1)*a
    
    if y1 < y:
        x1 = y1 = float("inf")
    if x2 < x:
        x2 = y2 = float("inf")
    
    if x1 + y1 >= x2 + y2:
        x = x2
        y = y2
    else:
        x = x1
        y = y1

print(x+y)


Measured memory_bytes: 3064
//https://atcoder.jp/contests/dp/tasks/dp_f#include <bits/stdc++.h>
#include<bits/stdc++.h>
#include <sstream> 
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define pi 2*acos(0.0)
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repe(i,a,b) for(ll i=a;i<=b;++i)
#define CPrint(c)  for(auto i:(c)) { cout<<i<<" "; } nl 
#define eb   emplace_back
#define ef   emplace_front
#define pb   push_back
#define pf   push_front
#define popb pop_back
#define popf pop_front
#define mp   make_pair
#define sz(a) int((a).size())
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
//Allows to traverse any type of macro
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
//debuggers
#define trace2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define trace3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define trace4(w,x,y,z) cout<<#w<<"="<<w<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair<ll,ll> pll;
const int INF = 1e9+5;
template <typename T> void max_self(T& a,T b)
{
	a = max(a,b);
}
int main()
{
	string s,t;
	FAST_IO;
	cin >> s;
	cin >> t;
//	string s="";
	//find longest string which is subsequence of s and t both
	ll m = s.length(),n = t.length();
	//ll i =0,j=0;
	vector<vector<ll>>dp(m+1,vector<ll>(n+1,0));
	repe(i,0,m)
	{
		repe(j,0,n)
		{
			if(i==0 || j==0)
			{
				dp[i][j]=0;
			}
			else if (s[i-1]==t[j-1])
			{
				dp[i][j] = dp[i-1][j-1]+1;
			}
			else
			{
				dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
			}
		}
	}

/*	repe(i,0,m)
	{
		repe(j,0,n)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	ll ans = 0;
	for(int i=0;i<=m;i++)
	{
		for(int j=0;j<=n;j++)
		{
		/*	if(dp[i][j]!=0)
				cout << dp[i][j] << " ";*/
			ans = max(ans,dp[i][j]);
		}
	}
	string x="";
	ll i = m,j=n;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			x +=t[j-1]; 
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
		{
			i--;
		}
		else
		{
			j--;
		}

	}
	//cout << ans << endl;
	reverse(x.begin(),x.end());
	cout << x << endl;
}

Measured memory_bytes: 70784
s=str(input())
a=0
k=s.count('K')
u=s.count('U')
p=s.count('P')
c=s.count('C')
while True:
    if k==0 or u==0 or p==0 or c==0:
        break
    else:
        a+=1; k-=1; u-=1; p-=1; c-=1
print(a)



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

int main(){
    int D;
    cin >> D;
    if(D==25){
        cout << "Christmas" << endl;
    }else if(D==24){
        cout << "Christmas Eve" << endl;
    }else if(D==23){
        cout << "Christmas Eve Eve" << endl;
    }else if(D==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int n,m,tot,c[N],a[N],head[N],nex[N],to[N],id[N];
void add(int u,int v,int i){to[++tot]=v;nex[tot]=head[u];head[u]=tot;id[tot]=i;}
bool vis[N];
int dis[N];
int ans;
struct node
{
    int u,x;
    node(int u=0,int x=0):u(u),x(x){}
    bool operator<(const node&o)const
    {
        return x<o.x;
    }
};
priority_queue<node>q;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    bool flag=false;
    for(int i=1;i<=m;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        add(u,v,i);add(v,u,i);
        if(a[u]==a[v]&&!vis[u]&&!vis[v])
        {
            q.push(node(u,a[u]));
            q.push(node(v,a[v]));
            c[u]=1;c[v]=0;
            vis[u]=vis[v]=true;
            ans+=2;
            dis[i]=a[u];
            flag=true;
        }
    }
    if(!flag){printf("-1\n");return 0;}
    while(!q.empty())
    {
        node now=q.top();q.pop();
        for(int i=head[now.u];i;i=nex[i])
        {
            int v=to[i];if(vis[v]||a[v]<now.x) continue;
            vis[v]=true;ans++;
            dis[id[i]]=a[v];
            c[v]=c[now.u]^1;
            q.push(node(v,a[v]));
        }
    }
    if(ans!=n){printf("-1\n");return 0;}
    for(int i=1;i<=n;i++)
        putchar(c[i]?'B':'W');
    putchar('\n');
    for(int i=1;i<=m;i++)
        printf("%d\n",!dis[i]?1000000000:dis[i]);
}



Measured memory_bytes: 14456
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    vector<pair<int,int>> R(n);
    vector<pair<int,int>> B(n);

    for(int i=0;i<n;i++){
        cin >> R[i].first >> R[i].second;
    }
    for(int i=0;i<n;i++){
        cin >> B[i].first >> B[i].second;
    }
    sort(B.begin(),B.end());
    sort(R.begin(),R.end());

    int res=0;
    for(int i=0;i<B.size();i++) {
        int ry=-1;
        int ri=-1;
        for(int j=0;j<R.size();j++){
            if(R[j].first<B[i].first && R[j].second<B[i].second){
                if(ry<R[j].second) {
                    ry=R[j].second;ri=j;
                }
            }
        }
        if(ri!=-1){
            res++;
            R.erase(R.begin()+ri);
        }
    }
    p(res)
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
#define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi       acos(-1)
#define mp make_pair
#define pb push_back
#define int long long ////////////
#define MOD 1000000007    ////////
#define POD 998244353 ////////
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define F first
#define S second
#define ppb pop_back
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) (m*n)/GCD(m,n)
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define initarr(a,n,x) for (int i=0;i<n;++i) a[i]=x
#define rep(i,a,n)  for(int i=a ; i<n ; i++)
#define repe(i,a,n) for(int i=a;i<=n;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
//define ll long long
#define ld long double 
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pii > vpii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef map<char,int> mci;
 
#define itv for(auto it= v.begin(); it != v.end(); ++it )
 
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(ALL(container),element) != container.end())
//#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
//#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.insert(tmp);commands}
//#define trav(a, x) for(auto& a : x)
//#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
 
 
#define bs binary_search
#define  lb(v,val)  lower_bound(ALL(v), val); 
 
#define dbg1(a) cout<<" *"<<a<<" ";
#define dbg2(a,b) cout<<" *"<<a<<" **"<<b<<" "     /////
#define dbg cout<<"hi"
#define nl "\n";
#define sz(s)         (int)((s).size())
#define coutsp(k)   cout<<setprecision(k)  //set precision (total length k icluding decimal and non decimal)
#define coutfsp(k)   cout<<fixed<<setprecision(k)  //fixed set precision(after decimal fixing)
#define  INF   (int)2e18 
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define vin(v,n)   vi v(n); rep(i,0,n)  cin>>v[i];
//#define siz  (int)1e8
#define N 300000



void quickly_quickly_kro()
{
   int n,w; cin>>n>>w;

   vi wt(n+1),v(n+1);

   rep(i,1,n+1)
   {
    cin>>wt[i]>>v[i];
   }


   int dp[n+1][w+1];
   
   rep(i,0,w+1)
   dp[0][i]=0;

   rep(i,0,n+1)
   dp[i][0]=0;



  
   rep(i,1,n+1)
   { 

    rep(j,1,w+1)
    {
          if(wt[i]<=j)
       dp[i][j]=max(dp[i-1][j-wt[i]]+v[i],dp[i-1][j]);
      else
        dp[i][j]=dp[i-1][j];


    }


   }

   cout<<dp[n][w];

 }
 
 
 
 
signed main()
{
 
    
 
 
   FAST
   
   int t; 
      t=1;              
  // cin>>t;
    while(t--)
    {
    
      quickly_quickly_kro();
      cout<<nl;
          
}
 
 
 
 
 
   return 0;
}

Measured memory_bytes: 79232
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const arr = input.split(/\n/);
let stack = "";
arr.forEach(item => {
  const rectangle = item.split(" ").map(Number);
  const h = rectangle[0];
  const w = rectangle[1];
  if(h === 0 && w === 0) return;
  let row = "";
  for(let i = 0; i < w; i++) row += "#";
  for(let j = 0; j < h; j++) stack += row + "\n";
  stack += "\n";
})
console.log(stack.trim() + "\n");


Measured memory_bytes: 16032
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>

using namespace std;

int main () {
    string S;
    cin >> S;
    int N = S.length();
    int ans01 = 0;
    int ans10 = 0;
    int ans;
    char S01[N], S10[N];
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0)
        {
            S01[i] = '0';
            S10[i] = '1';
        } else {
            S01[i] = '1';
            S10[i] = '0';
        }
    }
    for (int i = 0; i < N; i++)
    {
        if (S[i] != S01[i])
        {
            ans01++;
        }
        if (S[i] != S10[i])
        {
            ans10++;
        }
    }
    ans = min(ans01, ans10);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ins insert
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vll vector<ll>
#define sz(a) (ll)((a).size())
#define matrix vector<vector<ll>>
#define rep(i,a,b) for(ll i = a; i < b; i++)
#define repd(i,a,b) for(ll i = a; i >= b; i--)
#define tr(container,it) for(typeof(container.begin())it=container.begin();it!=container.end();it++)
#define set_bits(n) __builtin_popcount (n)
const ll MOD = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double Pi = 3.141592653589793116, EPS = 1e-9;
const ll dx[4] = {0, 1, 0, -1};
const ll dy[4] = {1, 0, -1, 0};


int main()
{
    ll r;cin>>r;
    cout<<3*r*r<<"\n";
    return 0;
}



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

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   int p[N], A[N], B[N];
   int M = 30000;
   for (int i = 0; i < N; i++) {
      cin >> p[i];
      int id = p[i] - 1;
      A[id] = id * M + 1 + i;
      B[id] = (N - id) * M + 1;
   } 
   for (int i = 0; i < N; i++) {
      cout << A[i] << " ";
   }
   cout << endl;
   for (int i = 0; i < N; i++) {
      cout << B[i] << " ";
   }
   cout << endl;
   return 0;
}


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

#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>
#include <sstream>

using namespace std;

class arc089_c {
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        long long x = 0, y = 0, t = 0;
        for (int i = 0; i < N; ++i) {
            long long nt, nx, ny;
            in >> nt >> nx >> ny;
            long long dist = abs(x - nx) + abs(y - ny);
            if (dist > nt - t || ((nt - t) - dist) % 2 != 0) {
                out << "No\n";
                return;
            }
        }
        out << "Yes\n";
    }
};


int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc089_c solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp

ss = s.split("")

rs = []
gs = []
bs = []
ss.each.with_index(1) do |rgb, i|
 if rgb == "R"
  rs << i
 elsif rgb == "G"
  gs << i
 else
  bs << i
 end
end

ans = 0
rs.each do |r|
  gs.each do |g|
    rg = (r - g).abs
    max = [r, g].max
    min = [r, g].min
    ans += bs.length
    if max + rg - 1 < ss.length && ss[max + rg - 1] == 'B'
      ans -= 1
    end
    if rg % 2 == 0 && ss[max - rg/2 - 1] == 'B'
      ans -= 1
    end
    if min - rg - 1 > 0 && ss[min - rg - 1] == 'B'
      ans -= 1
    end
  end
end
p ans

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

int n,m;
map<string,int> mp;



int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
       string s;
       cin>>s;
       mp[s]++;
    }
    scanf("%d",&m);
    for (int i=1;i<=m;i++)
    {
        string s;
        cin>>s;
        mp[s]--;
    }
    int ans=0;
    for (map<string,int>::iterator it=mp.begin();it!=mp.end();it++)
        ans=max(ans,it->second);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int main(){
	int n,x,t,ans;
	cin>>n>>x>>t;
	if(n%x==0){
		ans=n/x*t;
	}
	else{
		ans=n/x*t+t;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;
const int N = 1e6+5;
ll dp[3001][3001][3], arr[3001][3001];
int main()
{
	sync;
	ll R, C, K;
	cin >> R >> C >> K;
	//memset(dp, 0, sizeof(dp));
	for(ll i = 0; i < K ; i++)
	{
		ll x, y, z;
		cin >> x >> y >> z;
		arr[x][y] = z;	
	}	
	for(ll i = 1; i <= R; i++)
	{
		for(ll j = 1; j <= C; j++)
		{
			dp[i][j][0] = max(dp[i][j - 1][0], max(dp[i - 1][j][0], max(dp[i - 1][j][1], dp[i - 1][j][2])) + arr[i][j]);
			dp[i][j][1] = max(dp[i][j - 1][0] + arr[i][j], dp[i][j - 1][1]);
			dp[i][j][2] = max(dp[i][j - 1][1] + arr[i][j], dp[i][j - 1][2]);
		}
	}
	cout << max(dp[R][C][0], max(dp[R][C][1], dp[R][C][2]));
}

Measured memory_bytes: 284900
#include<stdio.h>
#include<string.h>
#include<math.h>

int ke[100][100],ki[50][50],tki[50][50],x,y,tx,ty;

int main(){
	int i,j,k,s,t,n,m;
	
	while(0<=scanf("%d%d",&n,&m)){
		if(n==0 && m==0)break;
		
		//iFÆØê[ÌüÍ
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&ke[j][i]);
			}
		}
		
		for(i=0;i<m;i++){
			for(j=0;j<m;j++){
				scanf("%d",&ki[j][i]);
			}
		}
		
		//ÀWðú»
		x=y=tx=ty=n;
		
		//½d[vEopÌtO
		int flag=1;
		
		//4ñ]Ì[v
		for(i=0;i<4;i++){
			
			//®SÉdÈéªÌTõ
			for(j=0;j<n-m+1;j++){
				for(k=0;k<n-m+1;k++){
					//±±ÜÅØê[ÌÚ®
					
					//±±©çØê[ÆiFÌÆ
					flag=1;
					for(s=0;s<m;s++){
						for(t=0;t<m;t++){
							if(ki[t][s]==-1)continue;
							
							if(ki[t][s]!=ke[k+t][j+s]){
								flag=0;
								break;
							}
						}
						if(flag==0)break;
					}
					if(flag==1){
						for(s=0;s<m*m;s++){
							if(ki[s%m][s/m]!=-1)break;
						}
						tx=s%m+k;
						ty=s/m+j;
					}
					if(flag)break;
				}
				if(flag)break;
			}
			
			//©Â©Á½ÀWªOñ©Â©Á½Æ±ëæèã¤Å¶¤Èçãü
			if(ty<=y){
				if(ty<y){
					x=tx;
					y=ty;
					//if(x!=n)printf("%d %d %d\n",i,x,y);
				}else if(tx<x){
					x=tx;
					y=ty;
					//if(x!=n)printf("%d %d %d\n",i,x,y);
				}
			}
			
			
			//ñ]
			for(j=0;j<m;j++){
				for(k=0;k<m;k++){
					//printf("%d ",ki[k][j]);
					tki[k][j]=ki[m-j-1][k];
				}
				//printf("\n");
			}
			//printf("\n");
			memcpy(ki,tki,sizeof(ki));
		}
		
		//¦oÍ
		if(x==n)printf("NA\n");
		else printf("%d %d\n",x+1,y+1);
	}
	return 0;
}

Measured memory_bytes: 828
N,M,K=map(int,input().split())
MOD = 998244353

fact = [0]*(N+1)
ifact = [0]*(N+1)
inv = [0]*(N+1)

def combination(n,fact,ifact):
    fact[0] = 1
    fact[1] = 1
    ifact[0] = 1
    ifact[1] = 1
    inv[1] = 1
    for i in range(2,n+1):
        fact[i] = (fact[i-1]*i)%MOD
        inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
        ifact[i] = (ifact[i-1]*inv[i])%MOD
def op(n,k):
    if k<0 or k>n or n<0:
        return 0
    return (fact[n]*ifact[k]*ifact[n-k])%MOD
combination(N,fact,ifact)

res = 0
for k in range(K+1):
    res = (res + op(N-1,k)*M*pow(M-1,N-1-k,MOD) )%MOD
print(res)



Measured memory_bytes: 32476
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  string S, ans="yes";
  cin>>S;
  vector <int> s(26);
  int i=0;
  for(char t='a';t<='z';t++){
    if(S.rfind(t)!=S.find(t)){
      ans="no";
    }
  }
  cout<< ans <<endl;
}


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

int n,a[500105],m;
long long inf=2e9;
void Merge( int left , int mid , int rigth ){
	int n1=mid-left, n2=rigth-mid;
	int l[n1],r[n2];
	for(int i=0 ; i<n1 ; i++){
		l[i]=a[left+i];
	}
	for(int i=0 ; i<n2 ; i++){
		r[i]=a[mid+i];
	}
	l[n1]=inf;
	r[n2]=inf;
	int x=0,y=0;
	for(int i=left ; i<rigth ; i++){
		if(l[x]>r[y]){
			a[i]=r[y];
			y++;
		}
		else{
			a[i]=l[x];
			x++;
		}
	
		m++;
	}
}

void mergesort( int l, int r ){
	if( l+1<r ){
		int mid=(l+r)/2;
		mergesort( l , mid );
		mergesort( mid , r );
		Merge( l , mid , r );
	}
}

int main(){
	
	cin >> n;
	for(int i=0 ; i<n ; i++){
		cin >> a[i];
	}
	
	mergesort( 0 , n );
	
	for(int i=0 ; i<n ; i++){
		cout << a[i];
		if(i!=n-1) printf(" ");
	}
	cout << endl;
	cout << m << endl;
}


/*

*/


Measured memory_bytes: 6884
import sys

N = int(input())
A = list(map(int, input().split()))
answer = 1

if 0 in A:
    print(0)
    sys.exit()

for i in range(N):
    answer = answer * A[i]
    if answer > 10**18:
        print(-1)
        sys.exit()
        
print(answer)

Measured memory_bytes: 21672
import sys


def PeriodCount(a, mod):
    x = a % mod
    count = 1

    while x != 1:
        x = a * x % mod
        count += 1

    return count


def GreatestCommonDiviser(num1, num2):
    while num2 != 0:
        num1, num2 = num2, num1 % num2

    return num1


def LeastCommonMultiple(num1, num2):
    return num1 * num2 / GreatestCommonDiviser(num1, num2)


for line in sys.stdin:
    line = line[:-1]

    if line == "0 0 0 0 0 0":
        break

    inputNum = [int(item) for item in line.split(" ")]
    counts = [PeriodCount(inputNum[lp * 2], inputNum[lp * 2 + 1])
              for lp in range(3)]

    lcm = LeastCommonMultiple(counts[0], counts[1])
    lcm = LeastCommonMultiple(lcm, counts[2])

    print(int(lcm))



Measured memory_bytes: 5612
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        string s;
        cin >> s;
        vector<int> val(n);
        int cur = 0, ba = 0;
        for (auto &&i : s) {
            if(i == 'M') val[cur]++;
            else if(i == 'S') ba += val[cur]+1, val[cur] = 0;
            else if(i == 'L') val[cur] += ba+1, ba = 0;
            cur = (cur+1)%n;
        }
        sort(val.begin(),val.end());
        for (int i = 0; i < n; ++i) {
            printf("%d ", val[i]);
        }
        cout << ba << "\n";
    }
    return 0;
}


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

using namespace std;

void read(){
    freopen("in.txt", "r", stdin);
}

int main(){
    //read();
    int n; cin >> n;
    vector<vector<int>>grid(n, vector<int>(3));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            cin >> grid[i][j];
        }
    }

    vector<vector<int>>dp(n, vector<int>(3, INT_MIN));
    //cout << dp[0].size();
    dp[0][0] = grid[0][0];
    dp[0][1] = grid[0][1];
    dp[0][2] = grid[0][2];
    for(int i = 1; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j == 0){
                  dp[i][j] = grid[i][j] + max(dp[i - 1][1], dp[i - 1][2]);
            }
            if(j == 1){
                  dp[i][j] = grid[i][j] + max(dp[i - 1][0], dp[i - 1][2]);
            }
            if(j == 2){
                  dp[i][j] = grid[i][j] + max(dp[i - 1][1], dp[i - 1][0]);
            }
        }
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
    return 0;
}



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

int main() {
    int N; cin >> N;
    vector<int> d(N);
    for(int &x : d)
    { cin >> x;
    }
    sort(d.begin(), d.end());
    int x = d[N/2];
    int z = d[N/2 - 1];
    int cnt=0;
    while (x > z)
    {
        cnt++;
        x--;
    }
    
    cout << cnt << endl;
    
    //else cout << 0 << endl;
    return 0;
}



Measured memory_bytes: 640
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(S: int, K: int):
    ret = 1
    for i, s in enumerate(str(S)):
        if i == (K - 1):
            ret = s
            break
        if s != '1':
            ret = s
            break
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(S, K)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5396
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		/*<考察>
		 * (1,1)→(1,2)へ進むには奇数回必要(奇数回であれば絶対到達可能）
		 * ※(1,1)→(1,6)は5回以上の奇数回であれば到達可能であることを意味する
		 * 
		 * (1,1)→(1,1)に戻ったり(1,1)→(1,3)に行くには偶数回必要
		*/
		
		int n = stdIn.nextInt();
		
		int[] t = new int[n+1];
		int[] x = new int[n+1];
		int[] y = new int[n+1];
		
		t[0] = 0;
		x[0] = 0;
		y[0] = 0;
		
		for(int i = 1; i < n+1; i++) {
			 t[i] = stdIn.nextInt();
			 x[i] = stdIn.nextInt();
			 y[i] = stdIn.nextInt();
			
			
			int time = t[i] - t[i-1];
			int X = Math.abs(x[i] - x[i-1]);
			int Y = Math.abs(y[i] - y[i-1]);
			
			if(X+Y > time) { //到達不能条件
				System.out.println("No");
				return;
			}else if((X+Y) % 2 == 0) {
				if(time % 2 != 0) {
					System.out.println("No");
					return;
				}
				
				
			}else if((X+Y) % 2 != 0) {
				if(time% 2 == 0) {
					System.out.println("No");
					return;
				}
			}else {
				continue;
			}
		
			
		}
		
		System.out.println("Yes");
		
		
		
	}

}


Measured memory_bytes: 92404
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
const int N = 222;
int f[2][N][N][N];
int n, m;
char mp[N][N];
int main(){
//	freopen("land.in", "r", stdin);
//	freopen("land.out", "w", stdout);
	cin>>n>>m;
//	memset(f, -1, sizeof(f));
	for(int i = 1;i <= n; i++){
		scanf("%s", mp[i] + 1);
	}
	for(int i = m;i >= 1; i--){
		for(int l = 1;l <= n; l++){
			for(int r = l;r <= n; r++){
				if(mp[l][i] != mp[r][i])break;
				f[0][l][r][i] = i;
				if(mp[l][i+1] == mp[l][i])f[0][l][r][i] = max(f[0][l][r][i+1], i);
			}
		}
	}
	int fl = 0;
	for(int ans = 0;ans <= 20; ans++){
		if(f[fl][1][n][1] == m){
			printf("%d\n", ans);
			return 0;
		}
		for(int i = 1;i <= m; i++){
			for(int l = 1;l <= n; l++){
//				printf("l=%d\n", l);
				int lst = l == n ? n : n - 1;
				for(int r = n;r >= l; r--){
					if(f[fl][l][r][i] == m){
						f[fl^1][l][r][i] = m;
						continue;
					}
					int F = f[fl][l][r][i];
					F = max(F, f[fl][l][r][F+1]);
					int L = l, R = lst, res = l;
//					printf("r=%d\n", r);
//					for(int x = l;x < r; x++){
//						printf("x=%d f=%d\n", x, min(f[fl][l][x][i], f[fl][x+1][r][i]));
//					}
					while(L <= R){
						int mid = (L + R) >> 1;
						if(f[fl][l][mid][i] > f[fl][mid+1][r][i])L = mid + 1, res = mid;
						else R = mid - 1;
					}
//					printf("r=%d res=%d\n", r, res);
					if(res > lst){
						
						printf("ans=%d l=%d r=%d i=%d f=%d res=%d lst=%d\n", ans, l, r, i, F, res, lst);
						exit(0);
					}else lst = res;
					F = max(F, min(f[fl][l][res][i], f[fl][res+1][r][i]));
					if(res + 1 < r)++res, F = max(F, min(f[fl][l][res][i], f[fl][res+1][r][i]));
					f[fl^1][l][r][i] = F;
				}
			}
		}
		fl ^= 1;
	}
	return 0;
}

Measured memory_bytes: 75520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int& x: h) cin >> x;
    vector<ll> dp(n, LLONG_MAX);
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
	for(int j: {i + 1, i + 2}) {
	    if(j < n) {
		dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));
	    }
	}
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4552
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int main()
{
    int N;
    long long a[200005];
    long long height;
    long long ans = 0;
    
    cin >> N;
    for (int i = 0;i < N;i++){
        cin >> a[i];
    }
    
    height = a[0];
    for (int i = 1;i < N;i++){
        if (height < a[i]){
            height = a[i];
        }
        else {
            ans += height - a[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5152
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,x,y;cin>>N;
    vector<pair<int,int> > v;
    REP(i,N){
        cin>>x>>y;
        v.emplace_back(y,x);
    }
    sort(v.begin(),v.end());

    int time = 0;
    REP(i,N){
        time += v[i].second;
        if(time>v[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;

}

Measured memory_bytes: 2420
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
 
	void doIt() {
		int n = sc.nextInt();
		if(n >= 1000 && n <= 9999) {
			n = 909;
		}
		else if(n >= 10 && n <= 99) {
			n = 9;
		}
		else {
			if(n >= 100000) {
				n -= 9091;
			}
			else if(n >= 1000) {
				n -= 9090;
			}
			else if(n >= 10) {
				n-=90;
			}
			
		}
		System.out.println(n);
	}
 
	public static void main(String[] args) {
		new Main().doIt();
	}
}

Measured memory_bytes: 22100