akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
// #define int long long
using namespace std;

map<int, int> prime_factor(int n){
    map<int, int> res;
    for(int i = 2; i*i <= n; i++){
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n]++;
    return res;
}

signed main(){
    int a[2];
    while(1){
        cin >> a[0] >> a[1];
        if(a[0] + a[1] == 0) break;
        map<int, int> mp[2];
        rep(i, 0, 2){
            mp[i] = prime_factor(a[i]);
        }
        int d[2] = {0};
        rep(i, 0, 2){
            int MAX = 0;
            for(auto it = mp[i].begin(); it != mp[i].end(); it++){
                d[i] -= it -> first;
                // cout << it -> first << endl;
                MAX = max(MAX, it -> first);
            }
            d[i] += 2 * MAX;
            // cout << d[i] << endl;
        }
        cout << (d[0] > d[1] ? "a" : "b") << endl;
    } 
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,m;
  cin>>a>>b>>m;
  int mx=INT_MAX;
  int my=INT_MAX;
  int x[a+1],y[b+1];
  for(int i=1;i<=a;i++)
  {
    cin>>x[i];
    mx=min(mx,x[i]);
  }
  for(int i=1;i<=b;i++)
  {
    cin>>y[i];
    my=min(my,y[i]);
  }
  int ans=INT_MAX;
  int p,q,r;
  for(int i=0;i<m;i++)
  {
    cin>>p>>q>>r;
    int h=x[p]+y[q]-r;
    ans=min(ans,h);
  }
  ans=min(ans,mx+my);
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 1024
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  st N;
  ci(N);
  if(N.at(0) == N.at(2)){
    co("Yes");
  }
  else{
    co("No");
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1LL << 62
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i, m) for (int i = 0; i < m; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ALL(v) v.begin(),v.end() 
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  FOR(i, k+1, n+1){
    if(n%i < k) ans += (i-k)*(n/i);
    else ans += (i-k)*(n/i)+(n%i+1-k);
  }
  if(k == 0) cout << n*n << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int,int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

int N;
vector <Pi> E[150010], D[150010];

void dfs(int x, int L){
	if(sz(E[x]) == 0)return;
	Pi A = E[x][0], B = E[x][1];
	dfs(A.Se, L);
	dfs(B.Se, L);
	vector <Pi> v;
	if(sz(D[A.Se]) > sz(D[B.Se]))swap(A, B);
	int L2 = A.Fi + B.Fi;
	for(int i=0, j=0;i<sz(D[A.Se]);i++){
		while(j < sz(D[B.Se]) && D[B.Se][j].Fi + D[A.Se][i].Se + L2 <= L)++j;
		if(j != 0){
			v.emplace_back(D[A.Se][i].Fi + A.Fi, D[B.Se][j-1].Se + B.Fi);
		}
	}
	for(int i=0, j=0;i<sz(D[A.Se]);i++){
		while(j < sz(D[B.Se]) && D[B.Se][j].Se + D[A.Se][i].Fi + L2 > L)++j;
		if(j != sz(D[B.Se])){
			v.emplace_back(D[B.Se][j].Fi + B.Fi, D[A.Se][i].Se + A.Fi);
		}
	}
	sort(all(v));
	int now = ~0u>>1;
	for(int i=0;i<sz(v);i++){
		if(i > 0 && v[i].Fi == v[i-1].Fi)continue;
		if(now > v[i].Se){
			D[x].pb(v[i]);
			now = v[i].Se;
		}
	}
}

int Do(int L){
	for(int i=1;i<=N;i++)if(sz(E[i]) == 0)D[i].emplace_back(0, 0);
	dfs(1, L);
	int save = sz(D[1]);
	for(int i=1;i<=N;i++)D[i].clear();
	return save != 0;
}

void solve(){
	scanf("%d", &N);
	for(int i=2;i<=N;i++){
		int a, v; scanf("%d%d", &a, &v);
		E[a].pb(Pi(v, i));
	}
	
	int low = 0, high = 1e9, res = -1;
	while(low <= high){
		int mid = (low + high) >> 1;
		if(Do(mid))res = mid, high = mid - 1;
		else low = mid + 1;
	 }
	 printf("%d", res);

}

int main(){
	int Tc = 1; //scanf("%d\n", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }



class Shop {
public:
    int price;
    int stock;

    Shop() : price(0), stock(0) {}
    Shop(int price, int stock) : price(price), stock(stock) {}

    bool operator<(Shop const &other) const {
        return price < other.price;
    }
};

ll solve(int N,int M,vi& a,vi& b) {
    vector<Shop> shops(N);
    rep(i,N) {
        shops[i] = Shop(a[i], b[i]);
    }
    sort(ALL(shops));

    int rest = M;
    ll ans = 0;
    for (auto& shop: shops) {
        if (rest == 0) break;
        int price = shop.price, stock = shop.stock;
        int to_buy = min(stock, rest);
        ans += (ll)price * to_buy;
        rest -= to_buy;
    }
    return ans;
}

int main() {
    int N, M; scanf("%d%d", &N, &M);
    vi a(N),b(N);
    rep(i,N) scanf("%d%d", &a[i], &b[i]);
    cout << solve(N,M,a,b) << endl;
    return 0;
}


Measured memory_bytes: 1792
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let s: &str = iter.next().unwrap();

    let result = match s {
        "Sunny" => "Cloudy",
        "Cloudy" => "Rainy",
        "Rainy" => "Sunny",
        _ => "",
    };

    println!("{}", result);
}

Measured memory_bytes: 4352
program main;
var i, n, AC, WA, TLE, RE : integer;
    s : string;
 
begin
  readln(n);
  AC := 0;
  WA := 0;
  TLE := 0;
  RE := 0;
  for i := 1 to n do 
    begin
        readln(s);
        if s = 'AC' 
            then inc(AC)
        else 
            if s = 'WA' 
                then inc(WA)
            else 
                if s = 'TLE' 
                    then inc(TLE)
                else if s = 'RE' 
                    then inc(RE);
  end;
  writeln('AC x ', AC);
  writeln('WA x ', WA);
  writeln('TLE x ', TLE);
  writeln('RE x ', RE);
end.

Measured memory_bytes: 1388
N=int(input())
D =[0]+[int(x) for x in input().split()]
m=D[1]
D.sort()
for i in range(1,N+1):
  D[i]=D[i] if i&1 else 24-D[i]
D.sort()
for i in range(1,N+1):
  m= min(m,D[i]-D[i-1])
print(m)
  


Measured memory_bytes: 3060
use proconio::{input, fastout};
use std::cmp::min;
#[fastout]
fn main() {
  input!{
    mut c: [[i64;3];3]
  }
  for line in 0..3 {
      let mut min_v : i64 = std::i64::MAX;
      for i in 0..3 {
          min_v = min(c[i][line],min_v);
      }
      for i in 0..3 {
          c[i][line] -= min_v;
      }
  }
  for line in 0..3 {
      let mut min_v : i64 = std::i64::MAX;
      for i in 0..3 {
          min_v = min(c[line][i],min_v);
      }
      for i in 0..3 {
          c[line][i] -= min_v;
      }
  }
  let mut ans : bool = true;
  for i in 0..3 {
      for j in 0..3 {
          if c[j][i] != 0 {
            ans = false;
          }
      }
  }
  println!("{}",if ans {"Yes"} else {"No"});
}


Measured memory_bytes: 2168
#include<iostream>
#include<algorithm>
#include<string>
#define all(c) c.begin(),c.end()
using namespace std;
string sum(string a,string b){
	int n=max(a.size(),b.size());
	for(;a.size()!=b.size();){
		if(a.size()<b.size())
		a+='0';
		else
		b+='0';
	}
	string s="";
	int flag=0;
	for(int i=0;i<n;i++){
		int x=(a[i]-'0')+(b[i]-'0')+flag;
		flag=0;
		if(x>=10){
			x-=10;
			flag=1;
		}
		s+='0'+x;
		
	}
	if(flag)
	s+='1';
	return s;
}
bool cal(string a,string b,string c,int x){
	bool flag=false;
	for(int i=0;i<a.size();i++){
		if(a[i]=='X'){
			a[i]='0'+x;
			flag=true;
		}
	}
	for(int i=0;i<b.size();i++){
		if(b[i]=='X'){
			b[i]='0'+x;
			flag=true;
		}
	}for(int i=0;i<c.size();i++){
		if(c[i]=='X'){
			c[i]='0'+x;
			flag=true;
		}
	}
	if(!flag)
	return false;
	if(sum(a,b)==c)
	return true;
	return false;
}
int main(){
	string s;
	while(cin>>s){
		int p,e,n=s.size();
		for(int i=0;i<n;i++){
			if(s[i]=='+'){
				p=i;
			}else if(s[i]=='='){
				e=i;
			}
		}
		string a=s.substr(0,p),b=s.substr(p+1,e-p-1),c=s.substr(e+1);
		int s=0;
		if((a.size()>1&&a[0]=='X')||(b.size()>1&&b[0]=='X')||(c.size()>1&&c[0]=='X')){
			s=1;
		}
		reverse(all(a));reverse(all(b));reverse(all(c));
		int ans=10;
		for(int i=s;i<=9;i++){
			if(cal(a,b,c,i)){
				if(ans!=10){
					ans=10;
					break;
				}else{
					ans=i;
				}
			}
		}
		if(ans==10)
		cout<<"NA"<<endl;
		else
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	double a, b; cin >> a >> b;
	printf("%.20f\n", a*b / 3.305785);
}


Measured memory_bytes: 3176
import sys
from bisect import bisect_left
from bisect import bisect_right

n = int(input())
a = tuple(map(int,sys.stdin.readline().split()))
q = int(input())

l = len(a)
for k in sys.stdin:
    k = int(k.strip())
    if k > a[-1]:print(l, l)
    else:
        print(bisect_left(a,k), bisect_right(a,k))


Measured memory_bytes: 16876
#include <iostream>
using namespace std;
const long long mod = 1e9+7;
 
int main() {
  int n;
  cin >> n;
  long long dp[2001];
  for (int i = 0; i <= 2000; i++) {dp[i] = 0;}
  dp[0] = 1;
  for (int i=1; i<=n; i++) {
    for (int j=0; j <= (i - 3); j++) {
      dp[i] += dp[j];
      dp[i] %= mod;
    } 
  }
  
  cout << dp[n] ;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, i, sum = 0;
  cin >> N;
  
  for (i = 0; i < N; i++){
    int l, r;
    cin >> l >> r;
    sum += r-l;
    sum++;
  }
  cout << sum << endl;
}

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

using namespace std;

const int N = 1000005;
const int mod = 1e9 + 7;

int prd[N];
int inv[N];

int binPow(int x, int y) {
	if (!y) return 1;
	int ret = binPow(x, y >> 1); ret = 1LL * ret * ret % mod;
	if (y & 1) ret = 1LL * ret * x % mod; return ret;
}

inline int C(int n, int k) {
	if (n < k || k < 0) return 0;
	return 1LL * prd[n] * inv[k] % mod * inv[n - k] % mod;
}

int main() {
	int n; cin >> n;
	prd[0] = 1;
	for (int i = 1; i <= n; ++i) prd[i] = 1LL * prd[i - 1] * i % mod; 
	inv[n] = binPow(prd[n], mod - 2);
	for (int i = n; i >= 1; --i) inv[i - 1] = 1LL * inv[i] * i % mod;
	int res = 0, v0 = 0;
	for (int i = n & 1; i <= n - 2; i += 2) {
		int j = (n - 2 - i) / 2;
		int v1 = 1LL * C(i + j, i) * prd[i + j + 1] % mod * prd[n - 2 - i - j] % mod;
		int v2 = v1 - v0; if (v2 < 0) v2 += mod;
		v0 = v1;
		// cout << v2 << ' ' << i << ' ' << j << '\n';
		res = (res + 1LL * v2 * (i + j + 1)) % mod;
	}
	cout << res;
}

Measured memory_bytes: 8064
from itertools import groupby

s = input()
k = int(input())
a = [sum(1 for _ in g) for _, g in groupby(s)]
if len(a) == 1:
    print(len(s) * k // 2)
else:
    r = sum(x // 2 for x in a) * k
    if s[0] == s[-1]:
        r += ((a[0] + a[-1]) // 2 - a[0] // 2 - a[-1] // 2) * (k - 1)
    print(r)


Measured memory_bytes: 3060
fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn read_as_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim()
        .split_whitespace()
        .map(|e| e.trim().parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = read();
    let a: Vec<usize> = read_as_vec();

    let mut ans: Vec<usize> = vec![0; n];
    a.iter().for_each(|i| ans[i - 1] += 1);

    ans.iter().for_each(|e| println!("{}", e));
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, c, k;
  while (cin >> n >> c >> k) {
    int t[n];
    for (int i = 0; i < n; ++i) {
      cin >> t[i];
    }
    sort(t, t + n);
    queue<int> q;
    each (i, t) q.push(i);
    int sum = 0;
    vector<int> v;
    while (q.size()) {
      if (v.size() == c) {
        ++sum;
        v.clear();
        continue;
      }
      if (v.empty()) {
        v.push_back(q.front());
        q.pop();
        continue;
      }
      if (v.front() + k < q.front()) {
        ++sum;
        v.clear();
        continue;
      }
      v.push_back(q.front());
      q.pop();
    }
    cout << sum + (bool)(v.size()) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1024
import 'dart:io';

void main() {
  int n = int.parse(stdin.readLineSync());
  List ta = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  List hn = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();

  List tempList = [];
  tempList.add({"temp": ta[1], "i": n + 1});
  for (int i = 0; i < n; i++) {
    double temp = ta[0] - (hn[i] * 0.006);
    tempList.add({"temp": temp, "i": i + 1});
  }
  List sortTempList = tempList..sort((b, a) => a["temp"].compareTo(b["temp"]));
  var aPlus;
  var aMinus;
  int ans;
  for (int i = 0; i < n; i++) {
    if (sortTempList[i]["temp"] == ta[1]) {
      if (i == 0) {
        ans = sortTempList[i + 1]["i"];
      } else if (i == n - 1) {
        ans = sortTempList[i - 1]["i"];
      } else {
        aPlus = sortTempList[i - 1];
        aMinus = sortTempList[i + 1];
        ans = ((aPlus["temp"] - ta[1]).abs() <= (aMinus["temp"] - ta[1]).abs())
            ? aPlus["i"]
            : aMinus["i"];
      }
    }
  }
  print(ans);
}

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

int main(void){
	int n,m;
	int i;
	long long int h[100000];
	int a,b;
	int com[100000]={0};
	int kazu[100000]={0};
	int ans=0;

	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%lld",&h[i]);
	}
	for(i=0;i<m;i++){
		scanf("%d %d",&a,&b);
		kazu[a-1]=1;
		kazu[b-1]=1;
		if(h[a-1]>h[b-1]){
			com[b-1]=1;
		}else if(h[a-1]==h[b-1]){
			com[b-1]=1;
			com[a-1]=1;
		}else{
			com[a-1]=1;
		}
	}
	for(i=0;i<n;i++){
		if(kazu[i]==0){
			ans++;
			continue;
		}
		if(com[i]==0){
			ans++;
		}
	}
	printf("%d",ans);

	return 0;
}


Measured memory_bytes: 3296
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
    
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}

    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]

        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
        else :
            c=self.u
            self.u=self.s
            self.s=self.d
            self.d=self.n
            self.n=c

import random
u,s,e,w,n,d=map(int,input().split())
dice=Dice(u,w,s,e,n,d)
q=int(input())
for i in range(q):
    a,b=map(int,input().split())
    while True:
        dice.rot(random.randint(0,3))
        if(dice.u==a and dice.s==b):
            print(dice.e)
            break


Measured memory_bytes: 8188
def gcd(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp
    while y > 0:
        r = x % y
        x = y
        y = r

    return print(x)

x_y = input()
tmp = list(map(int, x_y.split()))
x = tmp[0]
y = tmp[1]
gcd(x, y)


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

int main()
{
    string s;
    cin>>s;
    int x = 0,ans = 0;
    rep(i,s.size()){
        if(s[i]=='S')
            x++;
        else
            x--;
        if(x<0){
            ans++;
            x = 0;
        }
    }
    cout << 2 * ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    int x, y;
    cin >> x >> y;
    int ans = 0;
    if (x == 3) ans += 100000;
    if (x == 2) ans += 200000;
    if (x == 1) ans += 300000;
    if (y == 3) ans += 100000;
    if (y == 2) ans += 200000;
    if (y == 1) ans += 300000;
    if ((x == 1) && (y == 1)) ans += 400000;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

minCoin = 0
N = 0
A = 0
B = 0
C = 0
D = 0
memo = []

def main():
    T = int(input())
    for _ in range(T):
        global minCoin,N,A,B,C,D,memo
        N,A,B,C,D  = map(int, input().split()) 
        memo = {}
        minCoin = N*D
        bfs(N,0)
        print(minCoin)

def bfs(tempX,tempC):
    global minCoin,N,A,B,C,D,memo
    if(tempC>=minCoin):
        return
    
    minCoin = min(tempC+(D*tempX),minCoin)

    if(tempX==1):
        return

    if(tempX in memo):
        if tempC < memo[tempX]:
            memo[tempX] = tempC
        else:
            return
    else:
        memo[tempX] = tempC


    if(tempX%2==0):
        bfs(tempX//2,tempC+A)
    else:
        bfs((tempX+1)//2,tempC+A+D)
        bfs((tempX-1)//2,tempC+A+D)
    if(tempX%3==0):
        bfs(tempX//3,tempC+B)
    else:
        mod = tempX%3
        bfs((tempX-mod+3)//3,tempC+B+(D*(3-mod)))
        bfs((tempX-mod)//3,tempC+B+(D*mod))
    if(tempX%5==0):
        bfs(tempX//5,tempC+C)
    else:
        mod = tempX%5
        bfs((tempX-mod+5)//5,tempC+C+(D*(5-mod)))
        bfs((tempX-mod)//5,tempC+C+(D*mod))





if __name__ == '__main__':
    main()


Measured memory_bytes: 93208
use std::io::BufRead;

fn main() {
    let mut input = String::new();
    let stdin = std::io::stdin();
    stdin.lock().read_line(&mut input).unwrap();
    let input: Vec<i32> = input.split_whitespace().map(|s| s.parse::<i32>().unwrap()).collect();
    match (input[0] * input[1]) % 2 == 0 {
        true => println!("Even"),
        false => println!("Odd")
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return abs(a);
    return gcd(b, a % b);
}
int main() {
    int n, k; cin >> n >> k;
    int a; cin >> a;
    int ans = a;
    int m = a;
    rep(i, n - 1) {
        cin >> a;
        ans = gcd(ans, a);
        m = max(m, a);
    }
    //cout << ans << " " << m << endl;
    if (k % ans == 0 && k <= m) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
board = []
for _ in range(3):
    board.append(list(map(int, input().split())))

n = int(input())

nums = [ int(input()) for _ in range(n) ]

# 横方向の判定
for line in board:
    result = True
    for v in line:
        if v in nums:
            pass
        else:
            result = False
            break
    if result:
        print('Yes')
        exit()

# 縦方向の判定
for i in range(3):
    result = True
    for j in range(3):
        if board[j][i] in nums:
            pass
        else:
            result = False
            break
    if result:
        print('Yes')
        exit()

# 斜め方向の判定
if board[0][0] in nums and board[1][1] in nums and board[2][2] in nums:
    print('Yes')
    exit()

if board[0][2] in nums and board[1][1] in nums and board[2][0] in nums:
    print('Yes')
    exit()


print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <iostream>

using namespace std;

int main()
{
    int n, k;
    int ans[1001];

    cin >> n >> k;

    for (int i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;

        int mass = min(a-1, min(n-a, min(b-1, n-b)));

        switch(mass%3) {
            case 0:
                ans[i] = 1;
                break;

            case 1:
                ans[i] = 2;
                break;

            case 2:
                ans[i] = 3;
                break;
        }
    }

    for (int i = 0; i < k; i++) {
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 3084
/**
 *		author:  zvm
 *		created: 25.09.2020 17:48:09
**/

#include <bits/stdc++.h>

using namespace std ;

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

	int h, w ;
	cin >> h >> w ;

	int n = 10 ;

	vector<vector<int>> dis(n,vector<int>(n));
	for( int i = 0 ; i < n ; ++i ) {
		for( int j = 0 ; j < n ; ++j ) {
			cin >> dis[i][j] ;
		}
	}

	for( int k = 0 ; k < n ; ++k ) {
		for( int i = 0 ; i < n ; ++i ) {
			for( int j = 0 ; j < n ; ++j ) {
				dis[i][j] = min( dis[i][j], dis[i][k]+dis[k][j] );
			}
		}
	}

	int ans = 0, val ;
	for( int i = 0 ; i < h ; ++i ) {
		for( int j = 0 ; j < w ; ++j ) {
			cin >> val ;
			if( val != -1 ) {
				ans += dis[val][1] ;
			}
		}
	}

	cout << ans << endl ;
}


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

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
using ll = long long int;
using ull =  unsigned long long int;

int main() {
	int N, M;
	cin >> N >> M;
	if (N >= 13) {
		cout << M << endl;
	}
	else if (N >= 6) {
		cout << M / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
int main(){
    vector<int> a(3);
    rep(i,3) cin>>a[i];
   int sum =a[0]+a[1]+a[2];
    if (sum >=22) cout<<"bust"<<endl;
    else cout << "win"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int t = 0;
        int h = 0;
        for(int x = 0; x < n; x++){
            String tc = scan.next();
            String hc  = scan.next();
            if(tc.compareToIgnoreCase(hc) == 0){
                t++;
                h++;
            }
            else if(tc.compareToIgnoreCase(hc) > 0){
                t = t + 3;
            }
            else{
                h = h + 3;
            }
        }
        System.out.println(t + " " + h);
    }
}


Measured memory_bytes: 29644
Scanf.scanf "%d %d" (fun n m ->
    let nei = Array.make n [] in
    let rev = Array.make n 0 in
    for i = 1 to n - 1 + m do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in
            let b = b - 1 in
            nei.(a) <- b :: nei.(a);
            rev.(b) <- rev.(b) + 1
        )
    done;
    let rec loop i =
        if rev.(i) = 0 then i else loop (i + 1)
    in
    let root = loop 0 in
    let par = Array.make n 0 in

    let rec loop next = function
        | [] -> if next <> [] then loop [] next
        | hd :: tl ->
            let rec loop2 next = function
                | [] -> loop next tl
                | x :: xs ->
                        rev.(x) <- rev.(x) - 1;
                        if rev.(x) > 0 then loop2 next xs else (
                            par.(x) <- hd + 1;
                            loop2 (x :: next) xs
                        )
            in
            loop2 next nei.(hd)
    in
    loop [] [ root ];
    Array.iter (Printf.printf "%d\n") par
)

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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; }
ll mod = 1e9+7;


int main(){
    int a,b; cin >> a >> b;
    if(a<=5){ 
        cout << 0 << endl;
        return 0;
    }else if(6<=a && a<=12){
        cout << b/2 << endl;
        return 0;
    }else{
        cout << b << endl;
        return 0;
    }
}

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

int main(void){
    int n, m; cin >> n >> m;
    vector<int> k(m), p(m);
    vector<vector<int>> s(m, vector<int>(n));
    for (int i = 0; i < m; i++)
    {
        cin >> k[i];
        for (int j = 0; j < k[i]; j++)
        {
            int a; cin >> a;
            s[i][a-1]++;
        }
    }
    for (int i = 0; i < m; i++)
    {
        cin >> p[i];
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        vector<int> num(m);
        for (int i = 0; i < n; i++)
        {
            if(bit & (1<<i)){
                for (int j = 0; j < m; j++)
                {
                    if(s[j][i] == 1){
                        num[j]++;
                    }
                }
            }            
        }
        bool ok = true;
        for (int i = 0; i < m; i++)
        {
            if(num[i]%2 != p[i]){
                ok = false;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

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

int keta(long long n) {
    int cnt = 0;
    while(n > 0) {
        n /= 10;
        cnt++;
    }
    return cnt;
}
int F(long long a, long long b) {
    int ka = keta(a);
    int kb = keta(b);
    return (ka > kb) ? ka : kb;
}
int main() {
    long long N;
    cin >> N;
    int ans = 11;
    long long i = 1;
    while(i*i <= N) {
        if(N % i == 0) {
            int f = F(i, N/i);
            if(ans > f) ans = f;
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
A = [None]*k
for i in range(k):
    d = int(input())
    A[i] = list(map(int, input().split()))

snuke = [0] * n
for i in range(k):
    for j in A[i]:
        snuke[j - 1] += 1

ans = 0
for i in snuke:
    if i == 0:
        ans += 1
print(ans)

Measured memory_bytes: 9200
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

ll y=100;
ll x;

void solve(){
    cin >> x;
    ll ans=0;
    while(y<x){
        y*=(ld)1.01;
        ans+=1;
        //cout << y << endl;
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3656
{-
import Control.Monad
import Data.Vector

main :: IO ()
main = do
  n <- readLn :: IO Int
  xs <- replicateM n readLn :: IO [Int]

  print $ count visited
  -}

import Control.Monad
import Data.Array

solve :: Int -> Int -> Array Int Int -> Int -> Int
solve b n bs a
    | a > n = -1
    | b == 2 = a
    | otherwise = solve (bs!b) n bs (a+1)

main :: IO ()
main = do
    n <- readLn :: IO Int
    xs <- replicateM n readLn :: IO [Int]
    let bs = listArray (1, n) xs
    print $ solve 1 n bs 0


Measured memory_bytes: 31100
n = gets.to_i

def is_yes?(x)
  if x % 4 == 0 || x % 7 == 0 || x % 11 == 0
    puts 'Yes'
    exit
  end
end

while n >= 4 do
  is_yes?(n)
  n -= 4
end

puts 'No'

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

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

    lint n = s.length();

    lint ans = 0;
    for(lint i=0; i<n; i++) {
        ans += (s[i] != s[n-i-1]);
    }

    cout << ans/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<vector<int>> a(2, vector<int>(n));
    for(int i = 0; i < 2; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cin >> a[i][j];
        }
    }
    int ans = 0;
    
    for(int i = 0; i < n; i++)
    {
        int tmp = 0;
        for(int j = 0; j <= i; j++)
        {
            tmp += a[0][j];
        }
        for(int j = i; j < n; j++)
        {
            tmp += a[1][j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}



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

void plot(int h, int w)
{
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (i%2 != j%2)
                cout << ".";
            else
                cout << "#";
        }
        cout << endl;
    }
    cout << endl;
}

int main(void)
{
    while (true) {
        int h, w;
        cin >> h >> w;
        if (h==0 || w ==0)
            break;
        plot(h, w);
    }
    return 0;
}


Measured memory_bytes: 3104
#!/usr/bin/env python3
n = int(input())
k = [list(map(int,input().split())) for _ in range(3)]
cnt = [[0] * n for _ in range(2)] 
# cnt[0][i]がb[i]より小さいa[j]の個数、cnt[1][i]がb[i]より大きいc[j]の個数
a = sorted(k[0])
b = sorted(k[1])
c = sorted(k[2])
for i in range(n):#b[i] に対して二分探索
    l = -1
    r = n #極端にとる
    while r-l > 1:#r-l =1で終了
        # 条件はb[i] > a[j]でb[i] >= a[j+1]
        k = (l+r)//2
        if b[i] > a[k]: l = k
        else: r = k
    cnt[0][i] = l+1
    l = -1
    r = n #極端にとる
    while r-l > 1:#r-l =1で終了
        # 条件はb[i] < b[j]でb[i] <= a[j+1]
        k = (l+r)//2
        if b[i] < c[k]: r = k
        else: l = k
    cnt[1][i] = n-r
#print(cnt)#a,cのみす
""" ACするが、O(n**2)
i = 0
j = 0
while i < n:
    if b[i] < c[j]: 
        cnt[1][i] = n-j
        i +=1
    else: j+=1
    if j >= n:
        j = n-1
        cnt[1][i] = 0
        i += 1
i = 0
j = 0
while i < n:
    if b[i] > a[j]:
        j+= 1
    else:
        cnt[0][i] = j
        i += 1
    if j >= n:
        j = n-1
        cnt[0][i] = n
        i += 1"""
ans = 0
for i in range(n):
    ans += cnt[0][i]*cnt[1][i]
print(ans) 

Measured memory_bytes: 26352
#pragma GCC optimize("O2")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define N 10005
vector<int>v[N];
int n,a[N];
priority_queue<int>q;
bool vv[2002][2002],vis[N],vvv[N];
void dfs(int x)
{
	vis[x]=1;
	for(int i=1;i<=n;i++)
	{
		if(!vis[i]&&vv[x][i])
		{
			v[x].push_back(i);
			vvv[i]=1;
			dfs(i);
		}
	}
}
int main()
{
	//freopen("rearranging.in","r",stdin);
	//freopen("rearranging.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	{
		if(__gcd(a[i],a[j])!=1)
		{
			vv[i][j]=vv[j][i]=1;
		}
	}
	for(int i=1;i<=n;i++)
	if(!vis[i])dfs(i);
	for(int i=1;i<=n;i++)if(!vvv[i])q.push(i);
	while(!q.empty())
	{
		int a1=q.top();
		printf("%d ",a[a1]);
		q.pop();
		for(int i=0;i<v[a1].size();i++)
		{
			int j=v[a1][i];
			q.push(j);
		}
	}
	puts("");
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll x,st=100,dy=0;
int main(){
	cin>>x;
	while(st<x)
	{
		dy++;
		st+=st/100;
	}
	cout<<dy<<endl;
	return 0;
}

Measured memory_bytes: 3636
*A, = map(int, input().split())
# IOTJLSZ
d = {c: A[i] for i, c in enumerate('IOTJLSZ')}


# TSZは端を処理できない
# 2K->K
# O:2->1
# II:4->2
# IJL:6->3
# JJ:4->2
# LL:4->2

def max_pick(x):
    return x - x % 2


ret = 0
if d['I'] and d['J'] and d['L']:
    ret = max(ret, d['O'] + max_pick(d['I'] - 1) + max_pick(d['J'] - 1) + max_pick(d['L'] - 1) + 3)
ret = max(ret, d['O'] + max_pick(d['I']) + max_pick(d['J']) + max_pick(d['L']))
print(ret)


Measured memory_bytes: 3064
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;using ull=unsigned long long;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

int main()
{
    ll n=in(),k=in();
    vector<bool>d(10,true);REP(i,k)d[in()]=false;
    for(ll ans=n;;++ans){
        ll ansc=ans;bool foo=true;
        while(ansc>0){
            foo&=d[ansc%10];
            ansc/=10;
        }
        if(foo){
            cout<<ans<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int a,b,t;
    cin >> a >> b >> t;
    cout << t / a * b << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#
# Next Mayor
#
n, total_stones = gets.chomp.split.map { |s| s.to_i}
while [n, total_stones] != [0, 0]
  left_stones = total_stones
  my_stones = []
  n.times do
    my_stones << 0
  end

  
  winner = -1
  catch(:break) do
    loop do
      n.times do |i|
        # p "debug"
        # p left_stones
        # p my_stones

        if left_stones == 1 and  my_stones[i] == (total_stones-1)
          winner = i
          throw(:break)
        elsif left_stones == 0
          left_stones += my_stones[i]
          my_stones[i] = 0
        else
          left_stones -= 1
          my_stones[i] += 1
        end
      end
    end
  end
  puts winner
  
  n, total_stones = gets.chomp.split.map { |s| s.to_i}
end

Measured memory_bytes: 8592
import sys

def main():
    N = int(input())
    As = list(map(int, sys.stdin.readlines()))

    max_a = max(As)
    max_count = As.count(max_a)

    if max_count > 1:
        for _ in range(N):
            print(max_a)
        sys.exit()
    
    _As = As[:]
    _As.remove(max_a)
    max_a2 = max(_As)

    for i in As:
        if i == max_a:
            print(max_a2)
        else:
            print(max_a)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 23712
N, M = map(int ,input().split())
light = [list(map(lambda x: int(x)-1, input().split()))[1:] for _ in range(M)]
p = [int(i) for i in input().split()]

ans = 0

for i in range(1 << N):
    flag = True
    for m in range(M):
        onsum = 0
        for j in range(N):
            if i >> j & 1 and j in light[m]:
                onsum+=1
        if onsum%2!=p[m]:
            flag = False
            break
    if flag == True:
        ans+=1

print(ans)

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

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    rep(i,1000) {
        if(a<= k*i&&k*i<=b) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main(){
    int A, B, C, K;
    cin >> A >> B >> C >> K;

    int i = 0;
    bool flag = false;
    while (i <= K){
        if (A >= B) {
            B = B*2;
            i++;
            continue;
        }
        if (B >= C) {
            C = C*2;
            i++;
            continue;
        }
        
        if (B > A & C > B){
            flag = true;
            break;
        }
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main()
{
  int N;
  char c[3][3];
  rep(i,3) cin >> c[i];

  cout << c[0][0] << c[1][1] << c[2][2] << endl;;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        for (int i=0;i<c.length;i++) {
            if (c[i] == '?') c[i] = 'D';
        }
        StringBuilder sb = new StringBuilder();
        for (int i=0;i<c.length;i++) {
            sb.append(c[i]);
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 41576
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ans := make([]int, n)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		ans[a - 1]++
		ans[b - 1]++
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
	public static void main(String[] args) {
		// practice contest

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		// int A = sc.nextInt();
		int[] array = new int[N];

		for (int i = 0; i < array.length; i++) {
			array[i] = sc.nextInt();
		}

		Arrays.sort(array);

		for (int j = 1; j < array.length; j++) {
			if (array[j - 1] == array[j]) {
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
	}
}

Measured memory_bytes: 64748
/* code of Ayush Tiwari
    codeforces- servermonk
    codechef- ayush572000
*/

#include <bits/stdc++.h>
#define ll long long

//STL
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define all(v) v.begin(), v.end()

//loops
#define forn(i,a,b) for(int i=a;  i<b; i++)
#define rforn(i,a,b) for(int i=a; i>=b; i--)

// defined values
#define maxn 200004
#define Mod 1000000007

// fast io
#define FIO() ios_base::sync_with_stdio(0);cin.tie(0);


using namespace std;


void solution(){

    // This is the main code
    ll n,k;
    cin>>n>>k;
    ll dp[n+1][k+1];
    ll w[n],val[n];
    forn(i,0,n) cin>>w[i]>>val[i];
    forn(i,0,n+1){
        forn(j,0,k+1){
            if(i==0 || j==0) dp[i][j]=0;
            else if(w[i-1]<=j) dp[i][j]=max(val[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][k];

}


int main(){
    
    #ifndef ONLINE_JUDGE
    freopen("E:/CP/input.txt","r",stdin);
    freopen("E:/CP/output.txt","w",stdout);
    #endif  
    
    FIO()   
    
    ll t=1;
    //cin>>t;
    while (t--)
    {
        solution();
    }
    return 0;
}

Measured memory_bytes: 82420
#include <iostream>
#include <string.h>

using namespace std;

int main()
{

    char str[110], rot[110];
    cin >> str >> rot;

    bool check = true;
    for (int i = 0; i < strlen(str); i++){
        check = true;
        for (int i = 0; i < strlen(str); i++){
            if (str[i] != rot[i]){
                check = false;
            }
        }

        if (!check){
            char car = str[strlen(str)-1];
            for (int j = strlen(str)-1; j > 0; j--){
                str[j] = str[j-1];
            }
            str[0] = car;
        }

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

    cout << "No" << endl;

    return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll H,W;
int N;
set<pair<int,int>> S;
vector<ll> Rs,Cs;
ll NR,NC;
ll weight[1010][1010];
ll ret;
ll mo=1000000007;
int D[100][100];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	ll r2=(mo+1)/2;
	ll r3=(mo+1)/3;
	
	cin>>H>>W>>N;
	Rs.push_back(0);
	Rs.push_back(H);
	Cs.push_back(0);
	Cs.push_back(W);
	FOR(i,N) {
		cin>>y>>x;
		Rs.push_back(y);
		Rs.push_back(y+1);
		Cs.push_back(x);
		Cs.push_back(x+1);
		S.insert({y,x});
	}
	sort(ALL(Rs));
	sort(ALL(Cs));
	Rs.erase(unique(ALL(Rs)),Rs.end());
	Cs.erase(unique(ALL(Cs)),Cs.end());
	
	NR=Rs.size()-1;
	NC=Cs.size()-1;
	FOR(y,NR) FOR(x,NC) {
		weight[y][x]=(Rs[y+1]-Rs[y])*(Cs[x+1]-Cs[x])%mo;
		if(S.count({Rs[y],Cs[x]})) weight[y][x]=0;
	}
	
	FOR(y,NR) {
		ll t=Rs[y+1]-Rs[y];
		ll L=0,R=0;
		FOR(x,NC) {
			FOR(i,y) L+=weight[i][x];
			for(i=y+1;i<NR;i++) R+=weight[i][x];
		}
		(ret+=(L%mo)*(R%mo)%mo*(t-1))%=mo;
		(ret+=(W%mo)*((L+R)%mo)%mo*((t*(t-1)/2)%mo))%=mo;
		(ret+=W*W%mo*t%mo*(t+1)%mo*r2%mo*r2%mo*(((2*t+1)*r3+mo-1)%mo))%=mo;
	}
	FOR(x,NC) {
		ll t=Cs[x+1]-Cs[x];
		ll L=0,R=0;
		FOR(y,NR) {
			FOR(i,x) L+=weight[y][i];
			for(i=x+1;i<NC;i++) R+=weight[y][i];
		}
		(ret+=(L%mo)*(R%mo)%mo*(t-1))%=mo;
		(ret+=(H%mo)*((L+R)%mo)%mo*((t*(t-1)/2)%mo))%=mo;
		(ret+=H*H%mo*t%mo*(t+1)%mo*r2%mo*r2%mo*(((2*t+1)*r3+mo-1)%mo))%=mo;
	}
	
	FOR(y,NR) FOR(x,NC) if(weight[y][x]) {
		int cy,cx,ty,tx;
		FOR(ty,NR) FOR(tx,NC) D[ty][tx]=101010;
		queue<int> Q;
		D[y][x]=0;
		Q.push(y*100+x);
		while(Q.size()) {
			cy=Q.front()/100;
			cx=Q.front()%100;
			Q.pop();
			
			int d[4]={1,0,-1,0};
			FOR(i,4) {
				ty=cy+d[i];
				tx=cx+d[i^1];
				if(ty<0 || ty>=NR || tx<0 || tx>=NC) continue;
				if(weight[ty][tx]==0) continue;
				if(D[ty][tx]<=D[cy][cx]+1) continue;
				D[ty][tx]=D[cy][cx]+1;
				Q.push(ty*100+tx);
				if(y*100+x<ty*100+tx) {
					(ret+=weight[y][x]*weight[ty][tx]%mo*D[ty][tx])%=mo;
				}
			}
		}
		
	}
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 512