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

int main(){
  int flag=0,i,j,H,W,count=0;
  cin >> H >> W;
  char A[H][W];
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      cin >> A[i][j];
      if(A[i][j]=='#'){count++;}
    }
  }
  i=0;j=0;
  while(i<H || j<W){
  	if(i==H-1 && j==W-1){break;}
    if(A[i+1][j]=='#' && A[i][j+1]=='#'){
      flag=1;break;
    }else if(A[i+1][j]=='#'){
      i++;
    }else if(A[i][j+1]=='#'){
      j++;
    }else{
      flag=1;break;
    }
  }
  if(flag==0 && count==H+W-1){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
num, a ,b = map(int,input().split())
s = input()
a_cnt = 0
b_cnt = 0
for i in range(num):
    if s[i] == "a" and a_cnt + b_cnt < a + b:
        print("Yes")
        a_cnt += 1
    elif s[i] == "b" and a_cnt + b_cnt < a + b and b_cnt < b:
        print("Yes")
        b_cnt += 1
    else:
        print("No")



Measured memory_bytes: 9304
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, P = map(int, input().split())
f = [1]*(N+1)
for i in range(1, N):
    f[i+1] = f[i]*(i+1)

A = list(map(lambda x: int(x) % 2, input().split()))

odd = A.count(1)
even = N-odd

ans = 0

even_sum = 2**even
odd_sum_even = sum([f[odd]//(f[v]*f[odd-v]) for v in range(0, odd+1, 2)])
odd_sum_odd = sum([f[odd]//(f[v]*f[odd-v]) for v in range(1, odd+1, 2)])
if P == 0:
    ans = even_sum*odd_sum_even if even_sum * \
        odd_sum_even != 0 else max(even_sum, odd_sum_even)
else:
    if odd_sum_odd == 0:
        ans = 0
    else:
        ans = even_sum*odd_sum_odd if even_sum * \
            odd_sum_odd != 0 else max(even_sum, odd_sum_odd)

print(ans)


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    ll sum = 0;
    rep(i, M){cin >> A.at(i); sum += A.at(i);}
    if (sum <= N){
        cout << N - sum << endl;
    } else {
        cout << -1 << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define int long long
using namespace std;

int size;
vector<int> val;
vector<int> lazy;
vector<int> width;

void lazy_propagate(int p) {
    if (lazy[p] > 0) {
        val[p] += lazy[p] * width[p];
        if (p < size-1) {
            lazy[p*2+1] += lazy[p];
            lazy[p*2+2] += lazy[p];
        }
        lazy[p] = 0;
    }
}

void add(int wishl, int wishr, int watchl, int watchr, int k, int x) {
    if (wishr <= watchl || watchr <= wishl) {
        lazy_propagate(k);
        return;
    }
    if (wishl <= watchl && watchr <= wishr) {
        lazy[k] += x;
        lazy_propagate(k);
        return;
    }
    int mid = (watchl+watchr)/2;
    lazy_propagate(k);
    add(wishl, wishr, watchl, mid, k*2+1, x);
    add(wishl, wishr, mid, watchr, k*2+2, x);
    val[k] = val[k*2+1] + val[k*2+2];
}
void add(int wishl, int wishr, int x) {
    add(wishl, wishr, 0, size, 0, x);
}

int getsum(int wishl, int wishr, int watchl, int watchr, int k) {
    if (wishr <= watchl || watchr <= wishl) {
        return 0;
    }
    if (wishl <= watchl && watchr <= wishr) {
        lazy_propagate(k);
        return val[k];
    }
    int mid = (watchl+watchr)/2;
    lazy_propagate(k);
    int sl = getsum(wishl, wishr, watchl, mid, k*2+1);
    int sr = getsum(wishl, wishr, mid, watchr, k*2+2);
    return sl + sr;
}
int getsum(int wishl, int wishr) {
    return getsum(wishl, wishr, 0, size, 0);
}

signed main() {
    int n, q;
    cin >> n >> q;
    size = 1;
    while (size < n) size <<= 1;
    val = vector<int>(size*2, 0);
    lazy = vector<int>(size*2, 0);
    width = vector<int>(size*2, 1);

    for (int i = size-2; i >= 0; i--) {
        width[i] = width[i*2+1] + width[i*2+2];
    }

    while (q--) {
        int type, l, r;
        cin >> type >> l >> r;
        if(type == 0) {
            int x;
            cin >> x;
            add(l-1, r, x);
        } else {
            cout << getsum(l-1, r) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 8908
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d, e,ans;
	cin >> a >> b >> c >> d >> e;
	ans = (c - a) * 60 + d - b-e;
	if (ans <= 0)cout << "0";
	else cout << ans;
	return 0;
}

Measured memory_bytes: 3592
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<pint,lint> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
#define N 131072
lint dat[N*2+10];
lint inf=12345678901234567LL;
//[a,b)の最小値
//外からは(a,b,0,0,n)として呼ぶ
lint query(int a,int b,int k=0,int l=0,int r=N){
	if(r<=a || b<=l) return inf;
	if(a<=l && r<=b) return dat[k];
	lint vl=query(a,b,k*2+1,l,(l+r)/2);
	lint vr=query(a,b,k*2+2,(l+r)/2,r);
	return min(vl,vr);
}
void update(int k,lint a){
	//cout<<k<<' '<<a<<endl;
	k+=N-1;
	dat[k]=min(dat[k],a);
	while(k>0){
		k=(k-1)/2;
		dat[k]=min(dat[k*2+1],dat[k*2+2]);
	}
	return;
}
vector<tint> v;
int main()
{
	int n,m,x,y,z;
	cin>>n>>m;
	rep(i,m){
		cin>>x>>y>>z;v.pb(mp(mp(x,y),z));
	}
	sort(All(v));
	rep(i,N*2+5) dat[i]=inf;update(1,0);
	rep(i,m){
		lint now=query(v[i].fi.fi,n+10);
		//cout<<v[i].fi.fi<<' '<<v[i].fi.se<<' '<<v[i].se<<' '<<now<<endl;
		update(v[i].fi.se,now+v[i].se);
	}
	lint out=query(n,n+10);
	if(out>=inf) cout<<-1<<endl;
	else cout<<out<<endl;
}


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

using namespace std;

int ctoi(char c){
    if(c >= '0' && c <= '9'){
        return c - '0';
    }
    return 0;
}

int main(){
    string N, A, B;
    int min = 55, sum = 0;
    cin >> N;
    for(int i = 1; i < stoi(N); i++){
        A = to_string(i);
        B = to_string(stoi(N)-i);
        for(int j = 0; j < A.size(); j++){
            sum += ctoi(A[j]);
        }
        for(int j = 0; j < B.size(); j++){
            sum += ctoi(B[j]);
        }
        if(sum < min){
            min = sum;
        }
        sum = 0;
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
#define mod 1000000007
long long fpow(long long x,long long y){//x^y mod 1e9+7
	if(y==0)
		return 1LL;
	long long res=1LL;
	while(y){
		if(y&1){
			res=(res*x)%mod;
		}
		x=(x*x)%mod;
		y>>=1;
	}
	return res;
}
long long h,w,t,gh,gw,rx,ry;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w>>t;
	gh=__gcd(h,t);
	gw=__gcd(w,t);
	rx=h/gh;
	ry=w/gw;
	cout<<fpow(((fpow(2,rx)+fpow(2,ry))%mod+fpow(2,__gcd(rx,ry))+mod-3)%mod,gh*gw)%mod;
	return 0;
}


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

using namespace std;

int main(void){

  int n;
  string s;
  while(cin >> n, n){
    int m[1000] = {0}, cnt = 0, ba = 0;
    cin >> s;

    for(int i = 0 ; i < 100 ; i++){

      if(cnt == n){
	//cout << cnt << endl;
	cnt = 0;
      }

      if(s[i] == 'M'){ // テァツ板キ
	m[cnt]++;
      }else if(s[i] == 'S'){ // テ・ツ敖甘、ツクツサ
	ba += m[cnt] + 1;
	m[cnt] = 0;
      }else if(s[i] == 'L'){ // テ・ツァツォ
	m[cnt] += ba + 1;
	ba = 0;
      }
      cnt++;
    }
    sort(m, m + n);
    for(int i = 0 ; i < n ; i++){
      cout << m[i] << " ";
    }
    cout << ba << endl;


  }
  return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;

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

    int x = sc.nextInt();
    int y = sc.nextInt();

    if (y > x * 4 || y < x * 2) {
      System.out.println("No");
      return;
    }

    if (y % 2 == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35876
var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

var hills = [];
rl.on('line', function(line) {
    hills.push(parseInt(line.trim()));
}).on('close', function() {
    var top3 = hills.sort(function(a, b) {
        return a - b;
    }).reverse().slice(0, 3);
    for (i=0; i<top3.length; i++) {
        console.log(top3[i]);
    }
});

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

void push(int);
int pop(void);

char input[100];
int stack[100];

int top=-1,x,y;

int main(){
 

  while(scanf("%s",input)!= EOF){
    int i=0;
    if(input[i]=='+'){
      x=pop();
      y=pop();
      push(x+y);
    }
    
    else if(input[i]=='-'){
      x=pop();
      y=pop();
      push(y-x); 
    }
    
    else if(input[i]=='*'){
      x=pop();
      y=pop();
      push(x*y);
    }
    
    else{
      x=atoi(&input[i]);
      push(x);
    }
    
    i++;
  }
  
  printf("%d\n",stack[top]);
  return 0;
}

void push(int num){
  top++;
  stack[top]=num;
}

int pop(){
  top--;
  return stack[top+1];
}



Measured memory_bytes: 2108
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
 
#include <cstdio>
 
//using namespace std;
 
using int64 = long long;
 
class Combination {
 public:
  constexpr Combination() { Build(); }
  static constexpr int mod_ = 1000000007;
  static constexpr int n_ = 700000;
  class LookupTable {
   public:
    int64 factorial_[n_];
    int64 inverse_[n_];
    int64 finverse_[n_];
  };
  LookupTable lt{};
  // return nCk
  constexpr int64 Get(int n, int k) const noexcept {
    if (n < k || n < 0 || k < 0) return 0;
    return lt.factorial_[n] * (lt.finverse_[k] * lt.finverse_[n - k] % mod_) %
           mod_;
  }
 
 private:
  constexpr void Build() noexcept {
    lt.factorial_[0] = 1;
    lt.factorial_[1] = 1;
    lt.finverse_[0] = 1;
    lt.finverse_[1] = 1;
    lt.inverse_[1] = 1;
    for (int i = 2; i < n_; ++i) {
      lt.factorial_[i] = lt.factorial_[i - 1] * i % mod_;
      lt.inverse_[i] = mod_ - lt.inverse_[mod_ % i] * (mod_ / i) % mod_;
      lt.finverse_[i] = lt.finverse_[i - 1] * lt.inverse_[i] % mod_;
    }
  }
};
 
template<typename T> inline void fastin(T &num) {
  T c;
  num = 0;
  c = getchar_unlocked();
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
}
 
Combination com;
 
int main() {
  int x, y; fastin(x); fastin(y);
 
  if ((x + y) % 3 != 0) {
    printf("%d", 0);
    return 0;
  }
 
  int nn = (x + y) / 3;
  int r = x - nn;
 
  int64 ans = com.Get(nn, r);
  printf("%lld", ans);
 
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(){
  int n,cnt,box[30];
  char s[50];
  scanf("%d",&n);
  for(int i=0;i<26;i++)
    box[i]=50;
  for(int i=0;i<n;i++){
    scanf("%s",s);
    for(int j=0;j<26;j++){
      cnt=0;
      for(int k=0;k<strlen(s);k++)
        if(s[k]=='a'+j)
          cnt++;
      if(box[j]>cnt)
        box[j]=cnt;
    }
  }
  for(int i=0;i<26;i++)
    for(int j=0;j<box[i];j++)
      printf("%c",'a'+i);
  printf("\n");
}

Measured memory_bytes: 128
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
INF = float('inf')

A,B = inpl()

ans =A-2*B

if ans <0:
    ans =0

print(ans)

Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

priority_queue<ll>a;
int main() {
	ll n,k;
	cin>>n>>k;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		a.push(x);
	}
	for(ll i=0;i<k;i++){
		ll now=a.top();
		a.pop();
		now/=2;
		a.push(now);
	}
	ll ans=0;
	while(a.size()!=0){
		ans+=a.top();
		a.pop();
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int main(){
  int ans=0;
  int n,d;
  cin >> n;
  int i,j,k;
  for(i=0;i<n;i++){
    cin >> d;
    k=1;
    for(j=2;j*j<=d;j++){
      if(d%j==0){
	k=0;
	break;
      }
    }
    ans+=k;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<stack>

using namespace std;

int main(){
  int n, x, cnt=0;
  stack<int> st;
  cin >> n;
  for(int i=0; i<n; ++i){
    cin >> x;
    if(st.empty() || x>st.top()) st.push(x);
    else if(x<st.top()){
      while(!st.empty()){
	if(x==st.top()) break;
	if(x>st.top()){ st.push(x); break; }
	st.pop(), cnt++;
      }
      if(st.empty()) st.push(x);
    }
  }
  cout << cnt+st.size() << endl;
  return 0;
}

Measured memory_bytes: 1800
n, k = list(map(int, input().split()))
l = [0 for i in range(k)]
ans = 0
M = 10**9 + 7

# def dev(n):
#     dl = []
#     for i in range(1, int(n**0.5)+1):
#         if n % i == 0:
#             dl.append(i)
#             if i != n // i:
#                 dl.append(n//i)
#     dl.sort()
#     return dl

for i in range(k, 0, -1):
#     a=k//i
#     b=a**n%M
    b=pow(k//i, n, M)
    for j in range(i*2, k+1, i):
        b -= l[j-1]
    l[i-1] = b%M

for i in range(1, k+1):
    ans+=i*l[i-1]

print(ans%M)


Measured memory_bytes: 11364
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class Main {
	private static final String VOWEL = "aeiou";

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

		while (true) {
			int n = Integer.parseInt(br.readLine());
			if (n == 0)
				break;

			int max = 0;

			ArrayList<String> list = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				String str = br.readLine();
				max = Math.max(str.length(), max);
				list.add(str);
			}
			int ans = 0;
			Set<String> set;
			while (++ans <= max) {
				set = new HashSet<>();
				for (String str : list) {
					set.add(trim(str, ans));
				}
				if (set.size() == n) {
					break;
				}
			}

			System.out.println(ans > max ? -1 : ans);
		}
	}

	static String trim(String str, int len) {
		StringBuilder sb = new StringBuilder();
		boolean flg = true;
		for (char elm : str.toCharArray()) {
			if (flg) {
				sb.append(elm);
				flg = false;
			}
			if (VOWEL.indexOf(elm) >= 0) {
				flg = true;
			}
		}
		return sb.toString().substring(0, Math.min(len, sb.length()));
	}
}



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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 100000002;

int main(){
	int r; cin >> r;
	double pi = 3.14159265358979323846;
	cout << pi * r * 2 << endl;
}

Measured memory_bytes: 3780
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s;
    cin >> s;
    string ans;
    if (s == "Sunny") ans = "Cloudy";
    else if (s == "Cloudy") ans = "Rainy";
    else ans = "Sunny";
    cout << ans << endl;

    return 0;
}


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

int main(void){
  int ticket, A, B, C, D;
  cin >> ticket;
  D = ticket%10, ticket = ticket/10;
  C = ticket%10, ticket = ticket/10;
  B = ticket%10, ticket = ticket/10;
  A = ticket%10, ticket = ticket/10;
  if(A + B + C + D == 7) cout << A << "+" << B << "+" << C << "+" << D << "=" << 7 << endl;
  else if(A + B + C - D == 7) cout << A << "+" << B << "+" << C << "-" << D << "=" << 7 << endl;
  else if(A + B - C + D == 7) cout << A << "+" << B << "-" << C << "+" << D << "=" << 7 << endl;
  else if(A + B - C - D == 7) cout << A << "+" << B << "-" << C << "-" << D << "=" << 7 << endl;
  else if(A - B + C + D == 7) cout << A << "-" << B << "+" << C << "+" << D << "=" << 7 << endl;
  else if(A - B + C - D == 7) cout << A << "-" << B << "+" << C << "-" << D << "=" << 7 << endl;
  else if(A - B - C + D == 7) cout << A << "-" << B << "-" << C << "+" << D << "=" << 7 << endl;
  else if(A - B - C - D == 7) cout << A << "-" << B << "-" << C << "-" << D << "=" << 7 << endl;
  return 0;
}


Measured memory_bytes: 256
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
s = sum((l2))/(4*l1[1])
c=0
for i in range(l1[0]):
    if l2[i]>=s:
        c +=1
if c>=l1[1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
N=int(input())
A1=list(map(int, input().split()))
A2=list(map(int, input().split()))
ans=0
for i in range(N):
  s1=sum(A1[:i+1])
  s2=sum(A2[i:])
  ans=max(ans,s1+s2)
print(ans)

Measured memory_bytes: 62840
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=4e5+10;
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
char S[maxn],Ci;
int Q,Fi;

int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        //freopen("1.out","w",stdout);
    #endif
    
    string a;
    int pos=2e5,left=pos,right=pos-1;
    bool flag=true;
    cin>>a>>Q;
    for(unsigned int i=0;i<a.size();i++)
        S[++right]=a[i];

    while(Q--)
    {
        // for(int i=left;i<=right;i++)
        //     cout<<S[i];
        // cout<<endl;
        // cout<<flag<<endl;
        int type;
        cin>>type;
        if(type==1)
        {
            flag=!flag;
        }
        else if(type==2)
        {
            cin>>Fi>>Ci;
            if(Fi==1)
            {
                if(flag)
                    S[--left]=Ci;
                else
                    S[++right]=Ci;
            }
            else if(Fi==2)
            {
                if(!flag)
                    S[--left]=Ci;
                else
                    S[++right]=Ci;
            }
        }
    }
    if(flag)
    {
        for(int i=left;i<=right;i++)
            cout<<S[i];
        cout<<endl;
    }    
    else
    {
        for(int i=right;i>=left;i--)
            cout<<S[i];
        cout<<endl;
    }
    return 0;
}

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

using namespace std;

int main (void)
{
  int a[5];
  for (int i = 0; i < 5; i++)
    cin >> a[i];
  int k;
  cin >> k;
  bool flg = false;
  for (int i = 0; i < 5; i++)
  {
    for (int j = i+1; j < 5; j++)
    {
      if((a[j] - a[i]) > k)
      {
        flg = true;
      }
    }
  }
  if (flg == true)
    cout << ":(";
  else
    cout << "Yay!";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;
 
int main() {
    ll a, b, y;
    double x;
    cin>>a>>b;
    y = (a+b)/2;
    x = (a+b)/2.0;
    if(x>y){
        y++;
    }
    cout<<y<<endl;
}

Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

D,G = map(int, input().split())
Q = []
for i in range(D):
    p,c = map(int, input().split())
    Q.append(tuple([p,c,100*(i+1)*p+c]))

ans = 1000
for i in range(1<<D):
    point = 0
    comp = 0
    l_index = -1
    for j in range(D):
        if (i>>j)&1:
            comp += Q[j][0]
            point += Q[j][2]
        else:
            l_index = j
    
    if point >= G:
        ans = min(ans,comp)
    else:
        if l_index >= 0:
            for i in range(Q[l_index][0]):
                if point+(l_index+1)*100*i >= G:
                    ans = min(ans,comp+i)
                    break

print(ans)

Measured memory_bytes: 12188
a = list(map(int, input().split()))
l = []
ans = 0
for i in range(a[0]):
    l.extend(list(map(int, input().split()))[1:])

for i in range(a[1]):
    if l.count(i + 1) == a[0]:
        ans = ans + 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
#include <set>
#include <functional>

using namespace std;


int main() {
    char b;
    cin >> b;

    if (b == 'A') cout << 'T' << endl;
    if (b == 'C') cout << 'G' << endl;
    if (b == 'G') cout << 'C' << endl;
    if (b == 'T') cout << 'A' << endl;

    return 0;
}



Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<map>
#include<set>
#include<vector>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<string>
#include<tuple>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
long A,B;
inline void solve(void){
  in(A,B);
  if(A<=5)out(0);
  else if(A>=13)out(B);
  else out(B/2);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=1e5+7;
int cnt[maxn][2];
int main()
{
    int n;
    cin>>n;
    vi a(n/2),b(n/2);
    for(int i=0;i<n;i++)
    {
        if(i&1) cin>>b[i/2];
        else cin>>a[i/2];
    }
    int mxa=0,mxb=0;
    for(int i=0;i<n/2;i++)
    {
        cnt[a[i]][0]++;
        cnt[b[i]][1]++;
        if(cnt[a[i]][0]>cnt[mxa][0]) mxa=a[i];
        if(cnt[b[i]][1]>cnt[mxb][1]) mxb=b[i];
    }
    if(mxa==mxb)
    {
        int mxxa=0,mxxb=0;
        for(int i=0;i<n/2;i++)
        {
            if(a[i]!=mxa)
            {
                if(cnt[a[i]][0]>cnt[mxxa][0]) mxxa=a[i];
            }
            if(b[i]!=mxb)
            {
                if(cnt[b[i]][1]>cnt[mxxb][1]) mxxb=b[i];
            }
        }
        int ans=min(n/2-cnt[mxa][0]+n/2-cnt[mxxb][1],n/2-cnt[mxxa][0]+n/2-cnt[mxb][1]);
        print(ans);
    }
    else{
        print(n/2-cnt[mxa][0]+n/2-cnt[mxb][1]);
    }

}

Measured memory_bytes: 1408
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    struct P { int x, y; }
    int N; 
    P[][] F;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        F = new P[][](N, N);
        foreach (i; 0 .. N) {
            foreach (j; 0 .. N) {
                P p; scanf("%d %d", &p.x, &p.y);
                F[i][j] = p;
            }
        }
        return true;
    }

    void solve() {
        auto used = new bool[][](N, N);
        auto loop = new bool[][](N, N);
        bool dfs(int oy, int ox, int y, int x) {
            if (y == oy && x == ox) return true;
            if (used[y][x]) return false;
            if (loop[y][x]) return false;
            used[y][x] = true;
            return dfs(oy, ox, F[y][x].y, F[y][x].x);
        }
        void fillLoop(int y, int x) {
            if (loop[y][x]) return;
            loop[y][x] = true;
            fillLoop(F[y][x].y, F[y][x].x);
        }
        int C = 0;
        foreach (i; 0 .. N) {
            foreach (j; 0 .. N) {
                foreach (k; 0 .. N) used[k][] = false;
                if (dfs(i, j, F[i][j].y, F[i][j].x)) {
                    C++;
                    fillLoop(i, j);
                }
            }
        }
        writeln(C);
    }

    while (input) solve;
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N;
  int p[4],t[4];
  int temp=100000000;

  cin>>N;
  for(int i=0;i<4;i++){
    cin>>p[i];
  }
  for(int i=0;i<4;i++){
    cin>>t[i];
  }

  for(int i=0;i<=N;i++){
    for(int j=0;j<=N;j++){
      for(int k=0;k<=N;k++){
        for(int l=0;l<=N;l++){
          if(i*t[0]+j*t[1]+k*t[2]+l*t[3] >= N)
            temp = min(temp, i*p[0]+j*p[1]+k*p[2]+l*p[3]);
        }
      }
    }
  }

  cout<<temp<<endl;

  return 0;
}



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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

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

  int ans=0;
  int tmp=0;
  rep(i,s.size()){
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
      tmp++;
    } else {
      tmp=0;
    }
    chmax(ans, tmp);
  }

  prt(ans);
}


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

int main()
{
    int a,b,c;
    cin>>a>>b >> c; int k;
    cin>>k;
    if(b>a && c>b) {
	cout<<"Yes"<<endl;
	return 0;
}
    	while(a>=b && k>0){
    		b=b*2;
    		k--;
		}
		while(b>=c && k>0){
			c=c*2;
			k--;
		}
		//cout<<a<<" "<<b<<" "<<c<<endl;
		if(a<b && c>b) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	
   
}

/// A L H A M D U L I L L A H

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
const int nmax=2000005;
ll fac[nmax],finv[nmax],inv[nmax];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}

ll com(int n,int k){
  if(n<k||n<0||k<0){
    return 0;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

// 繰り返し二乗法 n*nが64bitにおさまる必要
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;  
  }
  return res;
}

// 逆元
ll mod_inverse(ll a, ll m)
{
	return pow_mod(a,m-2,m);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k;cin >> k;
    string s;cin >> s;
    ll n=s.size();
    COMinit();
    ll ans=0;
    REP(i,k+1){
        (ans+=com(n-1+k-i,n-1)*pow_mod(25,k-i,mod)%mod*pow_mod(26,i,mod)%mod)%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 51236
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let (n, k): (usize, usize) = parse_line().unwrap();

    let mut ret = k;
    for _ in 0..(n - 1) {
        ret *= k - 1;
    }
    println!("{}", ret);
}


Measured memory_bytes: 2180
n = gets.chomp.to_i
p = gets.chomp.split.map(&:to_i)
count = 0
for i in 1..n-2
  count += 1 if (p[i-1] > p[i] && p[i] > p[i+1])
  count += 1 if (p[i-1] < p[i] && p[i] < p[i+1])
end
puts count

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

using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
const int N=1e9+5;///1e18+5

void solve()
{
    int n;
    cin>>n;
    ll a[n];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int cnt=0;
    for(int i=0; i<n-2; i++)
    {
        for(int j=i+1; j<n-1; j++)
        {
            if(a[i]==a[j])
            {
                continue;
            }
            for(int k=j+1; k<n; k++)
            {
                if(a[j]==a[k])
                {
                    continue;
                }
                if(a[i]+a[j]>a[k])
                {
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;

}


int main()
{
    //freopen("input.txt","r",stdin);
    IO;
    int tc=1;
    //cin>>tc;
    while(tc--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
#define dbg(x) cerr << #x << ": " << x << endl

int main() {
  string S;
  ll K;
  cin >> S >> K;
  ll i = 0;
  while(1) {
    if(S[i] == '1')
      K--;
    else
      break;
    if(K <= 0) break;
    i++;
  }
  cout << S[i] << endl;
  return 0;
}

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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n, k;
vi arr;
vi dig;

void in(){
    cin >> n >> k;
    rep(i,0,n){
        arr.push_back(input());
    }

    rep(i,0,50){
        dig.push_back(k % 2);
        k /= 2;
    }
    reverse(all(dig));

}

int score[50][2];

int dp[50][2];

int dfs(int i, bool flag){

    if(i == 50) return 0;

    if(dp[i][flag] > -1) return dp[i][flag];

    int ans = 0;

    if(flag){
        rep(j,0,dig[i] + 1){
            chmax(ans, score[i][j] + dfs(i + 1, dig[i] == j));
        }
    }else{
        chmax(ans, score[i][0] + dfs(i + 1, false));
        chmax(ans, score[i][1] + dfs(i + 1, false));
    }

    return dp[i][flag] = ans;


}


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


    rep(i,0,50){
        int cnt = 0;
        rep(j,0,n) cnt += arr[j] & (1LL << i);
        score[49 - i][0] = cnt;
        score[49 - i][1] = (1LL << i) * n - cnt;

    }


    print(dfs(0, true));




}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int m1, d1;
  cin >> m1 >> d1;
  
  int m2, d2;
  cin >> m2 >> d2;
  
  if(m1!=m2){
    cout << 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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 int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N, M;
	cin >> N >> M;
	vector<int>ans(N), a(M), b(M);
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		ans[a[i] - 1]++;
		ans[b[i] - 1]++;
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 256
N,M = gets.split.map &:to_i
INF = 10**15
ds = (0...N).map{ Array.new(N, INF) }
es = (0...N).map{ (0...N).map{ [] } }
M.times {
  a,b,c = gets.split.map &:to_i
  a -= 1; b -= 1
  ds[a][b] = ds[b][a] = c
  es[a][b] = [b]; es[b][a] = [a]
}

(0...N).each{ |k|
  dsk = ds[k]
  esk = es[k]
  (0...N).each{ |i|
    next if i == k
    dsi = ds[i]
    esi = es[i]
    (0...N).each{ |j|
      next if i == j
      next if k == j
      v = dsi[k] + dsk[j]
      if v < dsi[j]
        dsi[j] = v
        esi[j] = esi[k] + esk[j]
      end
    }
  }
}

used = {}
(0...N).each{ |i|
  dsi = ds[i]
  esi = es[i]
  (0...N).each{ |j|
    next if dsi[j] == INF
    arr = [i] + esi[j]
    (0...arr.size-1).each{ |a|
      used[arr[a]*N+arr[a+1]] = 1
    }
  }
}
p M - used.size/2



Measured memory_bytes: 8700
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#t = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))

l = [[] for i in range(n)]

for i in range(m):
    a, b = map(int, sys.stdin.readline().split())
    l[a-1].append(b-1)
    l[b-1].append(a-1)

ans = [None for i in range(n)]
q = deque([0])
while q:
    u = q.popleft()
    for i in l[u]:
        if ans[i] is None:
            ans[i] = u
            q.append(i)

print("Yes")
for i in range(1,len(ans)):
    print(ans[i]+1)





            


        


Measured memory_bytes: 34684
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

constexpr ll mod = mod998;

int main() {
	ll n, x, m;
	cin >> n >> x >> m;
	vector<bool> used(m);
	vector<ll> a;
	ll ans = 0;
	while (n--) {
		if (used[x]) {
			n++;
			break;
		}
		used[x] = true;
		ans += x;
		a.pb(x);
		x *= x; x %= m;
	}
	if (n > 0) {
		vector<ll> p; bool flag = false;
		for (int i : a) {
			if (i == x) flag = true;
			if (flag) p.pb(i);
		}
		int sz = p.size();
		ll sum = accumulate(all(p), 0ll);
		ans += sum * (n / sz);
		n %= sz;
		rep(i, n) ans += p[i];
	}
	cout << ans << '\n';
}

Measured memory_bytes: 4288
import java.util.*;

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

        long divide = (long) N/(A+B);
        long ans = 0;
        ans += divide * A;

        if(N%(A+B) >= A){
            ans += A;
        }else{
            ans += N%(A+B);
        }

        System.out.println(ans);

    }

}


Measured memory_bytes: 23124
A, B = map(int, input().split())
if B > 0:
    if A * B > (A + B):
        val = A * B
    else:
        val = A + B
else:
    if A * B > (A - B):
        val = A * B
    else:
        val = A - B
        
print("%d"%val)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  bool fi = true;
  while(true){
  int a, b;
  cin >> a >> b;
  bool f = false;
  if(a == 0 && b == 0) break;

  if(fi) fi = false;
  else
    cout << endl;

  FOR(i,a,b+1){
    if(i % 4 == 0){
      if(i % 100 == 0){
        if(i % 400 == 0){
          cout << i << endl;
          f = true;
        }
        
      }else{
        cout << i << endl;
        f = true;
      }
    }
  }

  if(!f){
    cout << "NA" << endl;
  }
  }
  return 0;
}




Measured memory_bytes: 3080
package main

import (
	"fmt"
)

func main(){
	var n int
	fmt.Scan(&n)
	var a float64
	var u string 
	ans := 0.0
	for i := 0; i < n; i++ {
		fmt.Scan(&a,&u)
		if u == "BTC" {
			a = a * 380000.0
		}
		ans = ans + a
	}
	fmt.Println(ans)
}

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

int main()
{
 
  int a , x = 1 , total = 0 , total1 = 0;;
  char b;

  while( scanf("%c",&b) != EOF ){

 

   
    if( b == '0'){

      if( x != 1 ) total = total * 10 ;
      else   total = total + 0;
      x++;

    }
    
    
    else  if( b == '1'){

      if( x != 1 )  total = total * 10 + 1 ;
      else   total = total + 1;
      x++;
    }
    
    else  if( b == '2'){
      
      if( x != 1 )  total = total * 10 + 2 ;
      else   total = total + 2;
      x++;
    }
    
    else  if( b == '3'){
      
      
      if( x != 1 ) total = total * 10 + 3 ;
      else   total = total + 3;
      x++;
    }
    
    else  if( b == '4'){

      if( x != 1 ) total = total * 10 + 4 ;
      else   total = total + 4;
      x++;
    }
    
    else  if( b == '5'){
      
      if( x != 1 )  total = total * 10 + 5 ;
      else   total = total + 5;
      x++;
    }
    
    else  if( b == '6'){
      
      if( x != 1 ) total = total * 10 + 6 ;
      else   total = total + 6;
      x++;
    }
    
    else  if( b == '7'){
      
      if( x != 1 ) total = total * 10 + 7 ;
      else   total = total + 7;
      x++;
    }
    
    else  if( b == '8'){
      
      if( x != 1 ) total = total * 10 + 8 ;
      else   total = total + 8;
      x++;
    }
    
    else  if( b == '9'){
      
      if( x != 1 )  total = total * 10 + 9 ;
      else   total = total + 9;
      x++;
    }
    
    else  {

      x = 1;
      total1 = total1 + total;

      total = 0;
    
    }

  }

  cout << total1 << endl;;

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string.h>
using namespace std;
typedef long long int llint;
int main() {
	llint n;
	cin >> n;
	llint x;
	vector<llint>a(n + 2);
	a[0] = 0;
	a[n + 1] = 1000000010;
	llint ans = 0;
	for (int i = 1;i <= n;i++) {
		cin >> x;
		if (i == 0) {
			a[i] = x;
		}
		else {
			a[i] = a[i - 1] + x;
		}
	}
	sort(a.begin(), a.end());
	llint cnt;
	for (int i = 1;i < n + 1;i++) {
		if (a[i - 1] == a[i]) {
			cnt = 2;
			while (a[i] == a[i + 1]) {
				cnt++;
				i++;
			}
			ans += cnt*(cnt - 1) / 2;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    
    if ((A < C && C < B) || (B < C && C < A)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256