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

int main() {
    int K, A, B; cin >> K >> A >> B;
    bool can = false;
    int num = K;
    while (num <= B) {
        if (num >= A) {
            can = true;
            break;
        }
        num += K;
    }
    if (can) cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3644
#include<cstdio>
using namespace std;

int main() {
  int sum=0,count=0,tsum=0,t,s;
  double avg;
  while(~scanf("%d,%d", &t, &s)) {
    sum += t*s;
    tsum += s;
    count++;
  }
  avg = (double)tsum/count;
  avg += 0.5;
  printf("%d\n%.0f\n", sum, avg);
}

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

using namespace std;

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

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

Measured memory_bytes: 256
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        String[] input = br.readLine().split(" ");
        int N = Integer.parseInt(input[0]);
        int K = Integer.parseInt(input[1]);

        bw.write(String.format("%d\n", (N - 1) / (K - 1) + ((N - 1) % (K - 1) > 0 ? 1 : 0)));
        bw.flush();
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define mod 1000000007
using namespace std;

int main(){
    int n,ans=0;
    cin >> n;
    vector<int> d(n);
    rep(i,0,n-1)cin >> d[i];
    rep(i,0,n-1){
        rep(j,0,n-1){
            if(i>j){
                ans += d[i]*d[j];
            }
        }
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

# n_C_rの最大化
# nは出来るだけ大きい方が良く、rは出来るだけn/2に近い方が良い

# n>rという条件があるので、サンプル２では(100,100)は許されない
#
x = max(a)
y = float("inf")
for ai in a:
    if abs(x / 2 - ai) < abs(x / 2 - y) and ai < x:
        y = ai
print(x, y)


Measured memory_bytes: 84920
using System;

class Test
{
 static void Main(string[] args){
   string[] tmp = Console.ReadLine().Split(' ');
   int r = int.Parse(tmp[0]);
   int g = int.Parse(tmp[1]);
   int b = int.Parse(tmp[2]);
   int calc = 100 * r + 10 * g + b;
   if(calc%4 == 0){
     Console.WriteLine("YES");
   }else{
     Console.WriteLine("NO");
   }
 }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX_N = 110;

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

int Sum1[MAX_N], Sum2[MAX_N];

int main(){
    int n;
    cin >> n;
    
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        Sum1[i + 1] = Sum1[i] + x;
    }
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        Sum2[i + 1] = Sum2[i] + x;
    }

    int ans = 0;
    for (int i = 1; i <= n; i++){
        ans = max(ans, Sum1[i] + Sum2[n] - Sum2[i - 1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<functional>
#include<vector>
#include<math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0;i<(n);i++)
int inf = 1000000000;
ll INF = 1000000000000000000;
int n, ma, mb, a[50], b[50], c[50];
int dp[50][1000][1000];
int main() {
	cin >> n >> ma >> mb;
	rep(i, 50) {
		rep(j, 1000) {
			rep(k, 1000)dp[i][j][k] = inf;
		}
	}
	rep(i, n)cin >> a[i] >> b[i] >> c[i];
	dp[0][0][0] = 0;
	for (int i = 1; i <= n; i++) {
		rep(j, 1000) {
			rep(k, 1000) {
				if (j < a[i - 1] || k < b[i - 1])dp[i][j][k] = dp[i - 1][j][k];
				else dp[i][j][k] = min(dp[i - 1][j][k], dp[i - 1][j - a[i - 1]][k - b[i - 1]] + c[i - 1]);
			}
		}
	}
	int ans = inf;
	for (int i = 1; ma*i < 1000 && mb*i < 1000; i++) {
		int z = ans;
		ans = min(ans, dp[n][ma * i][mb * i]);
	}
	if (ans == inf)cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 195584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

vector<ll> sieve;
void sieve_init(int n) {
    sieve = vector<ll>(n + 1, 1);
    sieve.at(0) = sieve.at(1) = 1;
    for (int i = 2; i <= n; i++) {
        if (sieve.at(i) == 1) {
            sieve.at(i)++;
            for (int mul = i * 2; mul <= n; mul += i) {
                int j = mul, cnt = 0;
                while (j % i == 0) {
                    j /= i;
                    cnt++;
                }
                sieve.at(mul) *= (cnt + 1);
            }
        }
    }
}

int n;

int main() {
    cin >> n;
    sieve_init(n);
    ll ans = 0;
    reps(i, n) { ans += i * sieve.at(i); }
    cout << ans << endl;
    return 0;
}

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

typedef long long int ll;

int main()
{

    ll n, a, b;

    cin>>n>>a>>b;
    ll mn1,mn2;

    if(abs(a-b)%2==0)
    {
        ll val = abs(a-b)/2;
        cout<<val;
    }
    else
    {
        ll val1,val2;
        mn1 =  n - max(a,b);
        val1 = min(a,b)+mn1+1;
        mn1 += (n-val1)/2;
        mn1+=1;

        mn2 =  min(a,b)-1;
        val2 = max(a,b)-mn2-1;
        mn2+= (val2-1)/2;
        mn2+=1;
        ll val = min(mn1,mn2);
        cout<<val; 
    }

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func solve() {
	n, k := getInt(), getInt()

	ans := 0.0
	for i := 1; i <= n; i++ {
		x := i
		cnt := 0.0
		for {
			if x >= k {
				break
			}
			x *= 2
			cnt++
		}
		ans += (1.0 / float64(n)) * math.Pow(0.5, cnt)
	}
	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 640
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=2020,M=4004000;
int i,j,k,n,m,ch;
int a[N],z[N];
vector<int> A[N],ans;
void R(int &x) {
	x=0;ch=getchar();
	while (ch<'0' || '9'<ch) ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
}
int gcd(int a,int b) {
	if (!b) return a;
	return gcd(b,a%b);
}
vector<int> merge(vector<int> a,vector<int> b) {
	vector<int> c;
	int i=0,j=0;
	while (i<a.size() && j<b.size()) {
		if (a[i]>b[j]) c.push_back(a[i]),i++;
		else c.push_back(b[j]),j++;
	}
	while (i<a.size()) c.push_back(a[i]),i++;
	while (j<b.size()) c.push_back(b[j]),j++;
	return c;
}
vector<int> add(vector<int> a,int b) {
	vector<int> c;
	c.push_back(b);
	for (int i=0;i<a.size();i++) c.push_back(a[i]);
	return c;
}
vector<int> dfs(int x) {
	z[x]=1;
	vector<int> t;
	for (int i=1;i<=n;i++) if (!z[i] && gcd(a[x],a[i])>1) t=merge(t,dfs(i));
	t=add(t,a[x]);
	return t;
}
int main() {
	R(n);
	for (i=1;i<=n;i++) R(a[i]);
	sort(a+1,a+n+1);
	for (i=1;i<=n;i++) if (!z[i]) ans=merge(ans,dfs(i));
	for (i=0;i<ans.size();i++) printf("%d ",ans[i]);
	puts("");
}

Measured memory_bytes: 768
def gcd(a,b):
    if b==0:return a
    else:return gcd(b,a%b)

def lcm(a,b):
    return a*b//gcd(a,b)

N = int(input())

ans = 1
for i in range(N):
    a = int(input())
    ans = lcm(ans,a)
    
print(ans)

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

using namespace std;

struct test{
    int x;
    int y;
    int z;
};

int main()
{
    int n;
    cin>>n;
    vector<test> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i].x>>v[i].y>>v[i].z;
    }
    int dp[n][3];
    
    dp[0][0]=v[0].x;
    dp[0][1]=v[0].y;
    dp[0][2]=v[0].z;
    
    for(int i=1;i<n;i++){
        dp[i][0]=v[i].x+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=v[i].y+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=v[i].z+max(dp[i-1][0],dp[i-1][1]);
    }
    int ans=0;
    
    ans=max(dp[n-1][0],dp[n-1][1]);
    ans=max(ans,dp[n-1][2]);
    
    cout<<ans;
  
   return 0;
}

Measured memory_bytes: 5624
// Believe in yourself
#include<bits/stdc++.h>

using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Pair vector<pair<ll,ll>>
#define vec vector <ll> 
#define all(a) a.begin(),a.end()
#define mo 1000000007
#define decimal(i,n) fixed << setprecision(i) << n
#define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl;
#define show_nl(a) for(auto xyz:a)cout<<xyz<<endl;


void eea(ll a,ll b,ll &x,ll &y)
{
    if (a == 1)
    {
        x = 1; y = 0;
        return;
    }
    ll x1, y1;
    eea(b%a,a,x1,y1);
    x=y1-(b/a)*x1;
    y=x1;
}
ll mi(ll a,ll m)
{
    ll x,y;
    eea(a,m,x,y);
    x= (x%m+m)%m;
    return x;
}

/*
Enter the test case


Some helpful points
1.) Calm yourself
2.) check for semicolon or data type mismatch
*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);    
    ll t=1;
    // cin>>t;
    while(t--)
    {
       ll n;
       cin>>n;
       int a[n],s=0;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
           s^=a[i];
       }
       for(int i=0;i<n;i++)
       {
           cout<<(s^a[i])<<" ";
       }
    }
}



Measured memory_bytes: 4424
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;

//
//initialization here
vi g[10];
int n, m;
//initialization finish
//

//
// your function is here



int dfs(int to, int from, int idx[])
{
	int sum = 0;
	rep(i, n) sum += idx[i];
	if (sum == n) return 1;

	int ans = 0;
	for (auto i : g[to])
	{
		if (idx[i] == 0)
		{
			idx[i] ++;
			ans += dfs(i, to, idx);
			idx[i]--;
		}
	}

	return ans;
	
}

// your function finished
//


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

	// your code is here
	cin >> n >> m;

	
	int a, b;
	rep(i, m)
	{
		cin >> a >> b;
		a--, b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	int idx[10];
	memset(idx, 0, sizeof idx);
	idx[0]++;
	int ans = dfs(0, -1, idx);

	Print(ans);
	// your code finished
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;

// 10^6 * log(10^6)
int main(){
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    
    for(int i = 0; i < x; i++)  cin >> a[i];
    for(int i = 0; i < y; i++)  cin >> b[i];
    vector<ll> xy(x*y);
    for(int i = 0; i < x; i++){
        for(int j = 0; j < y; j++){
            xy[i*x+j] = (ll)a[i]+b[j];
        }
    }
    sort(xy.rbegin(), xy.rend());

    for(int i = 0; i < z; i++)  cin >> c[i];

    priority_queue<pair<ll, pair<int,int>>> pq;
    for(int i = 0; i < z; i++)  pq.push({xy[0]+c[i], {i, 0}});

    for(int i = 0; i < k; i++){
        pair<ll, pair<int,int>> p = pq.top();  pq.pop();
        cout << p.first << endl;
        int ni = p.second.first, nj = p.second.second+1;
        if(nj < x*y)    pq.push({(xy[nj]+c[ni]), {ni, nj}});
    }
    return 0;
}

Measured memory_bytes: 8192
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int N = sc.nextInt();
      int A = sc.nextInt();
      int B = sc.nextInt();

      int min = 1000;

      min = Math.min(N*A,B);

      System.out.println(min); 
                   }
      }

Measured memory_bytes: 21844
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;

int D, N;
int T[202];
int A[202], B[202], C[202];
int dp[202][202]; //[テ、ツスツ陛ヲツ猟・テァツ崢ョ][テ・ツ可催ヲツ猟・テァツ敖?」ツ?淌ヲツ慊江

bool check(int day, int ai){
  if(A[ai] <= T[day] && T[day] <= B[ai]){
    return true;
  }
  return false;
}

void solve(){
  memset(dp, -1, sizeof(dp));

  for(int j = 0; j < N; j++){
    if(check(0, j)){
      dp[0][j] = 0;
    }
  }

  for(int i = 0; i < D - 1; i++){
    for(int j = 0; j < N; j++){
      if(dp[i][j] == -1) continue;

      for(int k = 0; k < N; k++){
        if(!check(i + 1, k)) continue;
        dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abs(C[j] - C[k]));
      }
    }
  }

  int ans = 0;
  for(int j = 0; j < N; j++){
    ans = max(ans, dp[D - 1][j]);
  }
  cout << ans << endl;
}

int main(){
  while(cin >> D >> N){
    for(int i = 0; i < D; i++){
      cin >> T[i];
    }
    for(int i = 0; i < N; i++){
      cin >> A[i] >> B[i] >> C[i];
    }
    solve();
  }
}

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

#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

const int N = 300005;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;
    long double res = 0;
    for (int i = 1; i <= n; i++) {
        int x = i;
        long double cur = 1.0 / n;
        while(x < k) {
            x *= 2;
            cur /= 2.0;
        }
        res += cur;
    }
    cout << fixed << setprecision(16) << res << endl;
    return 0;
}


Measured memory_bytes: 256
from math import factorial
def gcd(a, b):
     while b:
     	a, b = b, a % b
     return a
def lcm(a, b):
     return a * b // gcd (a, b)

a,b,c,d=map(int, input().split())

upper=b//c+b//d-b//lcm(c,d)
lower=(a-1)//c+(a-1)//d-(a-1)//lcm(c,d)

#print(upper)
#print(lower)
print(b-a+1-(upper-lower))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <math.h>

using namespace std;

int main(void) {
int h, w;
cin >> h >> w;

string board[50];

for (int i = 0; i < h; ++i) cin >> board[i];

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

for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
if (board[i][j] == '#') continue;

int num = 0;
for (int d = 0; d < 8; ++ d) {
const int ni = i + dy[d];
const int nj = j + dx[d];

if (ni < 0 or h <= ni) continue;
if (nj < 0 or w <= nj) continue;
if (board[ni][nj] == '#') num++;
}

board[i][j] = char(num + '0');

}
}

for (int i = 0; i < h; ++i) cout << board[i] << endl;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<numeric>
#include<set>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long li;
#define minimize(a,b) (a>(b)?a=(b),1:0)
#define maximize(a,b) (a<(b)?a=(b),1:0)
#define ceil(a,b) (((a)+(b)-1)/(b))
#define yn(i) ((i)?"Yes":"No")
#define chmin(a,b) (a>(b)?a=(b),1:0)
#define abs(n) max((n),-(n))
#define dist(a,b) max((a)-(b),(b)-(a))
#define chmax(a,b) (a<(b)?a=(b),1:0)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define MOD 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)

#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}




string key="keyence";

void add(char m,string s,set<string> st){
  int n=s.size();
  rep(i,n){
    if(s[i]!=m) continue;
    string t;
    repa(j,i,n){
      t.push_back(s[j]);
      st.insert(t);
    }
  }
}

int gcd(int a,int b){
  return b?gcd(b,a%b):a;
}

int main(){
  int n; li k; cin >>n >>k;
  map<int,li> mp;
  rep(i,n){
    li a,b; cin >>a >>b;
    mp[a]+=b;
  } 
  li s=0;
  auto itr=mp.begin();
  while(s<k){
    s+=itr->second;
    itr++;
  }
  itr--;
  print(itr->first);
}





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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define eb emplace_back

int main()
{
    ll N, K;
    cin >> N >> K;

    if(K > (N-1)*(N-2)/2) PR(-1);
    else {
        vector<pair<ll,ll>> E;
        ll cnt = 0, M = N * (N-1) / 2 - K;
        bool f = false;
        PR(M);
        REP(i,1,N) {
            REP(j,i+1,N+1) {
                PS(i); PR(j);
                ++cnt;
                if(cnt == M) {
                    f = true;
                    break;
                }
            }
            if(f) break;
        }
    }

    return 0;
}

/*



*/

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
//#include <bits/stdc++.h>

#define ll unsigned long long int
#define pb push_back
#define llu unsigned long long int
#define fo(i,n) for(int i=0;i<n;i++)
#define eb emplace_back
#define M 1000000007
#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int,int>
#define mp make_pair
#define mapi map<int,int>

using namespace std;
int min(int x,int y)
{
	if(x<y)
		return x;
	return y;
}
int max(int x,int y)
{
	if(x>y)
		return x;
	return y;
}
bool compare_float(double x, double y, double epsilon = 0.0000001f){
   if(fabs(x - y) < epsilon)
      return true; //they are same
      return false; //they are not same
}
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    cin.ignore(numeric_limits<streamsize>::max(),'\n');
    ll ac=0,wa=0,tle=0,re=0;
    while(n--)
    {
    	string s;
    	getline(cin,s);
    	//cin.ignore(numeric_limits<streamsize>::max(),'\n');
    	if(s=="AC")	ac++;
    	else if(s=="WA") wa++;
    	else if(s=="RE") re++;
    	else if(s=="TLE") tle++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
    //const unsigned ll M=1000000007;
    
	//cout << lol;
    return 0;
}



Measured memory_bytes: 3236
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<cstdio>
#include<sstream>
#include<cmath>
#include<set>
#include<algorithm>
#include<map>
#include<ctime>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const double eps = 1e-8;
const int maxn = 200009;
const int inf = 100000009;
const int mod = 10007;
pii op[19][20];
int pq[19], vis[19], hj[19];
int dfs(int p) {
	vis[p] = 1;
	int tmp = 1;
	for (int i = 0; i < pq[p]; ++i) {
		pii e = op[p][i];
		if (e.second&&vis[e.first] == 0) {
			int kl = dfs(e.first);
			if (!kl) return 0;
			else tmp += kl;
		}
		else if (e.second&&vis[e.first] == -1) return 0;
		else if (!e.second&&vis[e.first] == 1) 	return 0;
		else if (!e.second&&vis[e.first] == 0) vis[e.first] = -1;
	}
	return tmp;
}
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> pq[i];
		for (int j = 0; j<pq[i]; ++j) {
			cin >> op[i][j].first >> op[i][j].second;
		}
	}
	int num = 0;
	for (int i = 1; i <= n; ++i) {
		mst(vis, 0); mst(hj, 0);
		int yu = dfs(i);
		if (yu) {
			for (int j = 1; j <= n; ++j) {
				if (vis[j] != 0) hj[j] = 1;
			}
			for (int j = 1; j <= n; ++j) {
				if (vis[j]==0) {
					int jk = dfs(j);
					if (!jk) {
						for (int k = 1; k <= n; ++k) {
							if (!hj[k] && vis[k] != 0) vis[k] = 0;
						}
					}
					else {
						yu += jk;
						for (int k = 1; k <= n; ++k) {
							if (!hj[k] && vis[k] != 0) hj[k] = 1;
						}
					}
				}
			}
		}
		num = max(num, yu);
	}
	cout << num;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Control.Monad


readInt = fst . fromJust . BS.readInteger
getInt = readInt <$> BS.getLine

primeFactrization :: Integer -> Integer -> [Integer]
primeFactrization n i
                  | n < i = []
                  | isDivisor = [i] ++ primeFactrization n (i + 1)
                  | not isDivisor  = primeFactrization n (i + 1)
                  | otherwise = []
                  where
                      isDivisor = if n `mod` i == 0 then True else False

hyakugo :: Integer -> [Integer]
hyakugo n
        | n < 1 = []
        | muchLen && isOdd  = [n] ++ hyakugo (n - 1)
        | otherwise = hyakugo (n - 1)
        where
            numPF = length (primeFactrization n 1)
            isOdd = if n `mod` 2 == 0 then False else True
            muchLen = if numPF == 8 then True else False
            
main = do
     n <- getInt
     print $ length (hyakugo n)

Measured memory_bytes: 4376
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll inf = 1000000000;
typedef pair<ll, ll> P;
ll a[100005];
int main() {
	int n, k, s;
	cin >> n >> k >> s;
	if (s != inf) {
		for (int i = 0; i <k; i++) {
			cout <<s<<" ";
		}
		for (int i = 0; i < n - k; i++) {
			cout << s + 1 <<" ";
		}
		cout << endl;
		return 0;
	}
	else {
		for (int i = 0; i < k; i++) {
			cout << inf << " ";
		}
		for (int i = 0; i < n - k; i++) {
			cout << "1" << " ";
		}
		cout << endl;
		return 0;
	}
}


Measured memory_bytes: 1280
def read_input():
    a, b, c = map(int, input().split())
    return a, b, c

def submit():
    a, b, c = read_input()

    candies = [a, b, c]
    candies.sort(reverse=True)

    if candies[0] == sum(candies[1:]):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    submit()


Measured memory_bytes: 38512
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

constexpr long double PI = 3.14159265358979323846264338327950L;

int main() {
	int a, b, h, m;
	cin >> a >> b >> h >> m;
	long double z, x, y;
	x = (static_cast<long double>(60) * h + m) / 720 * 2 * PI;
	y = static_cast<long double>(m) / 60 * 2 * PI;
	x -= y;
	z = sqrt(static_cast<long double>(a * a + b * b) - static_cast<long double>(a * b * 2) * cos(x));
	cout << fixed << setprecision(10) << z << endl;
}

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

int main(int argc , char **argv)
{
	(void)argc;
	(void)argv;

	char a[101][101] = {};

	int H,W;
	cin >> H >> W;
	for(int i=0;i<H;i++){
		cin >> a[i];
	}

	for(int i=0;i<W+2;i++){printf("#");}
	printf("\n");

	for(int i=0; i<H; i++){printf("#%s#\n",a[i]);}

	for(int i=0;i<W+2;i++){printf("#");}
	printf("\n");

	return 0;
}


Measured memory_bytes: 256
N=gets.to_i
# dp[len][char(len-3)][char(len-2)][char(len-1)]
dp=Array.new(N+1){Array.new(4){Array.new(4){Array.new(4,0)}}}
dp[0][3][3][3]=1
MOD=10**9+7

# blacklist A=0 C=1 G=2 T=3
# ACG
# GAC
# AXGC
# AGXC
N.times do |i|
    dpi=dp[i]
    dpip=dp[i+1]
    4.times do |c1|
        dpi1=dpi[c1]
        4.times do |c2|
            dpi12=dpi1[c2]
            dpip2=dpip[c2]
            4.times do |c3|
                dpi123=dpi12[c3]
                dpip23=dpip2[c3]
                4.times do |c4|
                    next if c4==2 && c3==1 && c2==0
                    next if c4==1 && (
                        (c3==2 && c2==0) || (c3==0 && c2==2) || (c1==0 && (c2==2 || c3==2))
                    )
                    dpip23[c4]+=dpi123
                    dpip23[c4]%=MOD
                end
            end
        end
    end
end

ans=0
4.times do |i|
    4.times do |j|
        4.times do |k|
            ans+=dp[N][i][j][k]
            ans%=MOD
        end
    end
end

p ans

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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

int main() {
	
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	
	int d = (h2 - h1) * 60 + (m2 - m1);
	
	printf("%d\n", d - k);
}

Measured memory_bytes: 3692
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;
import java.lang.Object;
 
public class Main {
    Scanner sc = new Scanner(System.in);
   
    public static void main(String[] args) {
        new Main(); 
    }
   
    public Main() {
        new aoj1232().doIt();
    }
    class aoj1232{
    	ArrayList<Integer> prime = new ArrayList<Integer>();
    	void eratos(){ int MAX = 1000000;
    		boolean [] isprime = new boolean[MAX + 1];
    		Arrays.fill(isprime, true);
    		isprime[0] = false;
    		isprime[1] = false;
    		for(int i = 0; i * i <= MAX; i++){
    			if(isprime[i]){
    				for(int j = i * 2; j <= MAX; j+= i){
    					isprime[j] = false;
    				}
    			}
    		}
    		for(int i = 0; i <= 10000; i++){
    			if(isprime[i])prime.add(i);
    		}
    	}
    	void doIt(){
    		eratos();
    		while(true){
    			double n = sc.nextDouble();
    			double a = sc.nextDouble();
    			double b = sc.nextDouble();
    			if(n+a+b == 0)break;
    			double sum = a/b;
    			double max = 0;
    			int numa = 0,numb = 0;
    			for(int i = 0;i < prime.size();i++){
    				for(int j = i;j < prime.size();j++){
    					double num = prime.get(i)*1.0/prime.get(j);
    					if(num < sum || prime.get(i)*prime.get(j) > n)break;
    					if(max < prime.get(i)*prime.get(j)){
    						max = prime.get(i)*prime.get(j);
    						numa = prime.get(i);
    						numb = prime.get(j);
    					}
    				}
    			}
    			System.out.println(numa+" "+numb);
    		}
    	}
    }
}

Measured memory_bytes: 50872
N = int(input())
h = list(map(int, input().split()))

dp = [float('inf')]*(10**5 + 10)
dp[0] = 0

for i in range(1,N):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

print(dp[N-1])

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

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.size()<=k){
        cout << s << endl;
        return 0;
    }
    rep(i,k){
        cout << s.at(i);
    }
    cout << "..." << endl;
    return 0;
}

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

const ll mod = 1000000007;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	int a, b; cin >> a >> b;
	bool ok = false;
	for(int i = a; i <= b; i++){
		if(i % n == 0) ok = true;
	}
	if(ok) cout << "OK" << endl;
	else cout << "NG" << endl;
}


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

#define loop(i,a,b) for(ll i=a; i<b; i++)
#define rloop(i,a,b) for(ll i=a; i>b; i--)
#define all(var) var.begin(), var.end()
#define eloop(var) for(auto elem : var)
#define debug(x) cerr<<#x<<" ----> "<<x<<endl;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define TC ll _t; cin>>_t; while(_t--)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define MOD 1000000007
#define MAX 100005
#define sz(var) (ll)var.size()
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<pair<ll, ll> > vpl;

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

    // TC
    {
        ll n, d;
        cin>>n>>d;
        ll cnt=0;
        // set<pair<ld,ld>> st;
        while(n--) {
            ld x,y;
            cin>>x>>y;
            if(sqrt(x*x+y*y)<=d)
                cnt++;
        }
        cout<<cnt<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3864
s = gets.chomp.chars

ans_a = ans_b = 0

s.size.times do |i|
  c = s[i].to_i
  ans_a += 1 if i.even? && c == 0 || i.odd? && c == 1
end

s.size.times do |i|
  c = s[i].to_i
  ans_b += 1 if i.even? && c == 1 || i.odd? && c == 0
end

puts [ans_a, ans_b].min


Measured memory_bytes: 6908
#include <iostream>

using namespace std;
int main()
{
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if(x + r <= w && y + r <= h && x - r >= 0 && y - r >= 0)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}
}

Measured memory_bytes: 3100
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int x,y;
  scanf("%d \n%d",&x,&y);
  if((x==1&&y==2)||(x==2&&y==1))
  {
    printf("3");
  }
  else if((x==2&&y==3)||(x==3&&y==2))
  {
    printf("1");
  }
  else
  {
    printf("2");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,ans;
    string s;
    cin >> n >> s;
    vector<int> c(n+1);
    c.at(0)=0;
    for(int i=0;i<n;i++){
        c.at(i+1)=c.at(i);
        if(s.at(i)=='W')
            c.at(i+1)++;
    }
    ans = n;
    for(int i=1;i<=n;i++)
        ans = min(ans,c.at(i-1) + (n-i) - (c.at(n) - c.at(i)));
    cout << ans << endl;
}

Measured memory_bytes: 1796
#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 sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
   int h,w;cin>>h>>w;
   char c[h][w];
   rep(i,h)rep(j,w)cin>>c[i][j];
   vector<vector<ll>> vu(h,vector<ll>(w,0)),vd(h,vector<ll>(w,0)),vr(h,vector<ll>(w,0)),vl(h,vector<ll>(w,0));
   rep(i,h){
       rep(j,w){
           if(c[i][j]=='.'){
               vu[i][j]++;
               vd[i][j]++;
               vr[i][j]++;
               vl[i][j]++;
           }
       }
   }
   rep(i,h){
       rep(j,w-1){
           if(c[i][j+1]=='.')vl[i][j+1]+=vl[i][j];
       }
       for(int j=w-1;j>0;j--){
           if(c[i][j-1]=='.')vr[i][j-1]+=vr[i][j];
       }
   }
   rep(j,w){
       rep(i,h-1){
           if(c[i+1][j]=='.')vd[i+1][j]+=vd[i][j];
       }
       for(int i=h-1;i>0;i--){
           if(c[i-1][j]=='.')vu[i-1][j]+=vu[i][j];
       }
   }
   ll res=0;
   rep(i,h){
       rep(j,w){
           ll buf=vu[i][j]+vd[i][j]+vr[i][j]+vl[i][j];
           if(c[i][j]=='.')buf-=3;
           chmax(res,buf);
       }
   }
   
   cout<<res<<endl;
}

Measured memory_bytes: 132612
N = int(input())
A = [int(input()) for _ in range(N)]

m1=0
m2=0
for a in A:
  if a>=m1:
    m1,m2 = a,m1
  elif m1>a>=m2:
    m1,m2 = m1,a

ans = [m1 if a!=m1 else m2 for a in A]
for a in ans:
  print(a)


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

using namespace std;

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


	int repeat = 0;
	for (int i = 0; i < 3; i++)
	{
		for (int j = i + 1; j < 4; j++)
		{
			if (S[i] == S[j])
			{
				repeat += 1;
			}
		}
	}

	string res = repeat == 2 ? "Yes" : "No";
	cout << res << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();
		System.out.println(Math.min(Math.min(p + q, q + r), r + p));
	}
}


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

int main(){
	string s,t;
	cin >> s>>t;
	sort( s.begin(), s.end() );
	sort( t.begin(), t.end() );
	reverse( t.begin(), t.end());


	if (s < t) {
	cout << "Yes" << endl;
	}
	else {
	cout << "No" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define ll          long long
#define pii         pair<int, int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int, int>
#define mii         map<pii, int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rev(i,a,b)  for(int i=a;i>=b;i--)
#define lb          lower_bound
#define ub          upper_bound

#define bg(i)       i.begin()
#define fset(it,s)   for(auto it = s.begin(); it != s.end(); it++)
 
#define track(x)                 cerr<<#x<<": "<<x<<endl
#define track2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define track3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define track4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
 
#define ed(i)       i.end()
#define mem(a)	    memset(a, 0, sizeof(a))

#define MOD         1000000007
int mult(int a,int b, int p=MOD){return ((a%p)*(b%p))%p;}
int add(int a, int b, int p=MOD){return (a + b + p)%p;}
int fpow(int n, int k, int p = MOD) {int r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
void self_max(int &a, int b) {a = max(a, b); }
void self_min(int &a, int b) {a = min(a, b); }
void self_add(int &a, int b, int p = MOD) { a += b; if(a >= p) a -= p;}
void self_sub(int &a, int b, int p = MOD) { a -= b; if(a < 0) a += p;}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
const int INF = 1e9 + 5;
#define N	    	400001

void solve(){
    int n, m;
    cin>>n>>m;
    vi in(m);
    int mat[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    char st[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    rep(i, 0, m)
        cin>>in[i];
    string s[n+1];
    rep(i, 1, n+1) {
        for(int no : in) {
            if(i >= mat[no]) {
                string tmp = s[i-mat[no]] + st[no];
                if(i-mat[no] != 0 && sz(s[i-mat[no]]) == 0)
                        continue;
                sort(all(tmp)); reverse(all(tmp));
                if(sz(tmp) > sz(s[i]))
                    s[i] = tmp;
                else if(sz(tmp) == sz(s[i])) {
                    if(tmp > s[i])
                        s[i] = tmp;
                }
            }
        }
    }
    cout<<s[n]<<endl;
}
int main() {
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin>>t;
	while(t--){
		solve();
	}
}


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

using namespace std;

vector<int> blue,red,redpair,v;
vector<vector<int> >c;

int m=0,n=0;

int gcd(int x,int y){
    if(x%y==0){return y;}
    return gcd(y,x%y);
}

bool match(int x){
    if(x==-1){
        return 1;
    }
    for(int i=0;i<n;i++){
        if(c[x][i]==1 && v[i]==0){
			v[i]=1;
			if(match(redpair[i])){
				redpair[i]=x;
				return 1;
			}
		}
	}
	return 0;
}


int main(){
    while(cin >> m >> n){
        if(m == 0 && n == 0){
            break;
        }
        blue.clear();
        red.clear();
        redpair.clear();
        v.clear();
        c.clear();
        for(int i = 0;i < m;i++){
            int tmp = 0;
            cin >> tmp;
            blue.push_back(tmp);
        }
        for(int i = 0;i < n;i++){
            int tmp = 0;
            cin >> tmp;
            red.push_back(tmp);
            redpair.push_back(-1);//-1??§?????¢??????????????¶????????¨???
            v.push_back(0);
        }
        for(int i = 0;i < m;i++){
            c.push_back(vector<int>());
            for(int j = 0;j < n;j++){
                c[i].push_back(gcd(blue[i],red[j]) != 1);
            }
        }
        int ans = 0;
        for(int i = 0;i < m;i++){
            for(int j = 0;j < n;j++){
                v[j] = 0;
            }
            if(match(i)){ans++;}
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2156
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
using namespace std;
long long MOD = 1e9 + 7;

int N;

int main() {
	cin >> N;
	for (int d = 0; d <= 25; d++) {
		int left = N - 4 * d;
		if (left < 0)continue;
		if (left % 7 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
S = input()

if (S[0]==S[1] and S[2]==S[3] and S[0]!=S[2]) or \
(S[0]==S[2] and S[1]==S[3] and S[0]!=S[1]) or \
(S[0]==S[3] and S[1]==S[2] and S[0]!=S[2]):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
def main():
    s = []
    l = list(raw_input())
    for c in l:
        if c == '0':
            s.append(c)  
        elif c == '1':
            s.append(c)
        elif c == 'B':
            if 0 < len(s):
                s.pop()
                
        else:
            pass
        
    print "".join(map(str,s))

if __name__ == '__main__':
    main()
    

Measured memory_bytes: 2568
#include "bits/stdc++.h"

using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    size_t N; string s;
    cin >> N >> s;
    s.erase(unique(s.begin(), s.end()), s.end());
    cout << s.length() << "\n";
    return 0;
}


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

using namespace std;

int n, k, h[200010];

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &h[i]);
	}
	sort(h + 1,  h + n + 1);
	long long ans = 0;
	for (int i = 1; i <= n - k; ++i) {
		ans += h[i];
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1024
//
// Created by yamunaku on 2019/10/19.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans=n;
    repl(i,1,n){
        if(s[i]==s[i-1]) ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <utility>

using namespace std;

int main(void) {
	int n,a[100],cnt=0;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++) {
		int minj = i;
		for(int j = i;j < n;j++) 
			if(a[j]<a[minj]) 
				minj = j;
		swap(a[i],a[minj]);
		if(i != minj)
			cnt++;
	}
	for(int i = 0;i < n-1;i++) cout << a[i] << " ";
	cout << a[n-1] << endl << cnt << endl;
}



Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main()
{ 
     int n , j=1, k=0;
     cin>>n;
     char s[n] , t[n] , r[2*n] ;
     for(int i=0 ; i<n; i++)
     { 
          cin>>s[i];
     } 
     for(int i=0 ;i<n;i++)
     { 
         cin>>t[i];
     } 
     for(int i=0 ; i<=n; i++)
      {  
          r[i+k] = s[i];
          r[i+j] =t[i];
          j++;
        k++;
      }
      
     for(int i=0 ; i<2*n; i++)
     { 
          cout<<r[i];
     }
      return 0;
}

     

Measured memory_bytes: 3584
<?php

$a = intval(fgets(STDIN));
$b = intval(fgets(STDIN));
$c = intval(fgets(STDIN));
$x = intval(fgets(STDIN));

$sumCount = 0;
for ($i=0; $i <= $a; $i++) {
    for ($j=0; $j <= $b; $j++) {
        for ($k=0; $k <= $c; $k++) {
            $result = 500*$i + 100*$j + 50*$k;
            if ($result === $x) {
                $sumCount++;
            }
        }
    }
}

echo $sumCount;

Measured memory_bytes: 4604
N=int(input())
S=input()
ans=0
a=0
b=0
c=0
for i in S:
	if i=='A':
		a=1
		b=c=0
	elif i=='B' and a==1:
		if b==0:
			b=1
		else:
			a=0
			b=0
	elif i=='C' and a==1 and b==1:
		c=1
		ans+=c
		a=b=c=0
	else:
		a=b=c=0
print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

n = int(input())

a = []

for i in range(n):
    a_list = list(map(int, input().split()))
    a_dict = {i:e for i,e in enumerate(a_list[:i])}
    a.append(a_dict)

if n == 1:
    print("-1")
    exit()

elif n == 2:
    print(a[1][0])
    exit()

# Minimam total path length
min_total = 0

for i in range(n):
    dim = i+1
    if dim == 1:
        continue
    elif dim == 2:
        min_total += a[1][0]
        continue

    paths_to_subgraph = []
    a_sorted = sorted(a[i].items(), key=lambda e:e[1])

    dest, path = a_sorted.pop(0)
    paths_to_subgraph.append((dest, path))
    min_total += path

    for dest, path in a_sorted:
        create_path = True
        for detour in paths_to_subgraph:
            detour_path = detour[1] + a[max([dest,detour[0]])][min([dest,detour[0]])]
            if path > detour_path:
                print("-1")
                exit()
            elif path == detour_path:
                create_path = False

        if create_path:
            for detour in paths_to_subgraph:
                detour_path = detour[1] + path
                minpath = a[max([dest,detour[0]])][min([dest,detour[0]])]
                if minpath > detour_path:
                    print("-1")
                    exit()
                elif minpath == detour_path:
                  # Delete path
                  min_total -= minpath
            paths_to_subgraph.append((dest, path))
            min_total += path

print(min_total)


Measured memory_bytes: 49244
#include <iostream>
#include <tuple>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;
void init();
#define REP(var, num) for(sll var = 0; var < num; var++)
typedef signed long long sll;
typedef unsigned long long ull;
/*
numeric_limits<sll>::max()
*/

bool memo[1000000];
int main() {
    init();
    sll s;
    cin >> s;

    REP(i, 1000000) { memo[i] = false; }
    sll a = s;
    sll i = 2;
    memo[s] = true;
    for (;; i++) {
        a = (a % 2 == 0) ? a/2 : 3 *a + 1;
        if (memo[a])
            break;
        memo[a] = true;
    }

    cout << i << endl;
    return 0;
}

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

Measured memory_bytes: 1280
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    S = input()

    l = len(S) // 2
    l2 = len(S)
    ans = 0

    for i in range(l):
        if not S[i] == S[l2 - i - 1]:
            ans += 1

    print(ans)


if __name__ == '__main__':

    solve()


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

int n,m,k;
ll mod = 998244353;

ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mod, factr[i]=factr[i-1]*inv[i]%mod;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mod*factr[N_-C_]%mod;
}

ll modpow(ll a, ll n=mod-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mod,a=a*a%mod,n>>=1;
	return r;
}

int main(){
    cin>>n>>m>>k;
    ll ans = 0;
    rep(i,0,k+1){
        ans += comb(n-1,i)*m%mod*modpow(m-1,n-i-1)%mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 13012
using System;

namespace aoj1d
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string[] array = str.Split(' ');        //WW ???HH???xx???yy???r
            int W = int.Parse(array[0]);
            int H = int.Parse(array[1]);
            int x = int.Parse(array[2]);
            int y = int.Parse(array[3]);
            int r = int.Parse(array[4]);

            if ( ((x-r) >= 0)  && ( (x+r) <= W ) && ( (y-r) >= 0 ) && ( (y+r) <= H ) )
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

int main()
{

        char c;
        cin >> c;

        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
                cout << "vowel" << endl;
        }
        else {
                cout << "consonant" << endl;
        }


}


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

int main()
{
    int a,b,s,m,x;
    cin>>a>>b;
    s = a+b;
    m = a-b;
    x = a*b;

    int t;

    if(s>= m && s>=x )
        t =s;
    if (m>=s && m>=x)
        t=m;
    if(x>=s && x>=m)
        t=x;

    cout<<t<<endl;
}


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

int main() {
  int X, Y;
  cin >> X >> Y;
  bool result = false;
  for (int i = 0; i <= X; i++) {
    if(2 * i + 4 * (X - i) == Y) {
      result = true;
      break;
    }
  }
  if (result) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3556
from decimal import Decimal,getcontext
from math import ceil
getcontext().prec = 1000
N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(Decimal(takahashi)/Decimal(a)),ceil(Decimal(aoki)/Decimal(b)))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

Measured memory_bytes: 5076