akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv,  digitDP//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal ,RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag; vll path; vl D;
//***********//
int main() {
	string T;
	cin >> T;
	N = T.length();
	vll dp(N + 1,vl(2,0));
	for (i = 0; i < N+1; i++) {
		dp[i][0] = -INF;
		dp[i][1] = -INF;
	}
	dp[0][0] = 0;
	for (i = 0; i < N; i++) {
		if (T[i] == '?') {
			T[i] = 'D';
		}
	}
	cout << T;
}

Measured memory_bytes: 14480
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e4+10;

ll arr[maxn];
int K,Q,n,x,m;
ll sum[maxn],zero[maxn];
ll fun(){
    x%=m;
    ll cnt = n-1;
    for(int i = 1;i<=K;i++){
        sum[i] = sum[i-1] + arr[i]%m;
        zero[i] = zero[i-1] + (arr[i]%m == 0);
    }
    ll cnt1 = (n-1)/K*zero[K]+zero[(n-1)%K];
    ll cnt2 = ((n-1)/K*sum[K]+sum[(n-1)%K] + x )/m;
    return cnt-cnt1-cnt2;
}
int main(){
    cin>>K>>Q;
    for(int i = 1;i<=K;i++) scanf("%lld",&arr[i]);
    while(Q--){
        scanf("%d%d%d",&n,&x,&m);
        printf("%lld\n",fun());
    }

    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws Exception {
		
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String boxstr[] = new String[line.length()];
        int box[] = new int[line.length()];
        int answw = Integer.parseInt(line);   //n
        int ans = 0;
        
        for(int i = 0;i<line.length();i++){
        	
            boxstr[i] = String.valueOf(line.charAt(i));
            
            box[i] = Integer.parseInt(boxstr[i]);   //n
            
            ans +=box[i];
            
            
            
        }
        if(answw%ans == 0){
        	System.out.println("Yes");
        	
        }else{
        	System.out.println("No");
        }
        	
        
	}
}


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

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

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl

#define MOD 1000000007

#define MAX_N 252
#define MAX_V 125252

int n,x;
int s[MAX_N];
ll dp[MAX_V][2];

ll modinv(ll a){
	ll b=MOD-2, r=1;
	while(b){
		if(b&1)r=r*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return r;
}

int main(){
	scanf("%d%d",&n,&x);
	REP(i,n)scanf("%d",s+i);
	sort(s,s+n);
	reverse(s,s+n);
	int cur = 0;
	dp[x][cur] = 1;
	REP(i,n){
		cur ^= 1;
		REP(j,MAX_V)dp[j][cur]=0;
		int modulo = s[i];
		ll p = modinv(n-i);
		ll q = (MOD+1ll-p) % MOD;
		FORR(v,0,MAX_V){
			(dp[v][cur] += dp[v][cur^1] * q % MOD) %= MOD;
			(dp[v%modulo][cur] += dp[v][cur^1] * p % MOD) %= MOD;
		}
	}
	ll factn = 1;
	FOR(i,1,n+1)factn = factn*i%MOD;
	ll ans = 0;
	REP(i,MAX_V){
		ans += dp[i][cur]*factn%MOD*i%MOD;
		ans %= MOD;
	}
	printf("%lld\n",ans);
	return 0;
}


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


int main() {
	// your code goes here
	int n;
	cin >> n;
	vector <int> vec(n);
	
	for(int i = 0; i < n; i++){
	    cin >> vec[i];
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
	    int cnt = 1;
	    int j = i+1;
	    while(j < n && vec[j] == vec[i]){
	          cnt++;    j++;
	    }
	    //cout << vec[i] << " " << cnt << endl;
	    ans += cnt/2;
	    if(j != n) i = j-1;
	    else break;
	}
	cout << ans;
	return 0;
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long min = long.MaxValue;
		for(int i=0; i < (1 << N); i++){
			long v = 1;
			for(int j=0;j<N;j++){
				if(((i >> j) & 1) == 1){
					v *= 2;
				} else {
					v += K;
				}
			}
			min = Math.Min(v,min);
		}
		
		Console.WriteLine(min);
		
	}
	int N,K;
	public Sol(){
		N = ri();
		K = ri();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
using namespace std;
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include <unordered_set>
#include <set>
#include <unordered_map>

#define INT_MIN     (-2147483647 - 1)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(c) for(int i = 0; i <(c); ++i)
#define rrep(n) for(int i = (n) ; i >=0 ; --i)
#define fora(i, s, c) for(int i = (s); i < (c); ++i)
#define forr(i, s, c) for(int i = (s); i > (c); --i)
#define endl "\n"
#define ret(n) return n
#define pb push_back
#define eb emplace_back
#define ff first;
#define ss second;
#define mp make_pair;
#define all(p) p.begin(),p.end()
#define mid(s,e) (s+(e-s)/2)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef priority_queue<int> pqint;
typedef priority_queue<ll> pqll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

vi dp;
int mincost(vi& ht, int n, int idx)
{
	if (idx == n - 1)
		return 0; //reached
	if (dp[idx] != -1)
		return dp[idx];
	if (idx + 2 < n)
	{
		int jump_one = abs(ht[idx + 1] - ht[idx]) + mincost(ht, n, idx + 1);

		int jump_two = abs(ht[idx + 2] - ht[idx]) + mincost(ht, n, idx + 2);

		dp[idx] =  min(jump_one, jump_two);
		return dp[idx];
	}
	else if (idx + 1 < n)
	{
		dp[idx] = abs(ht[idx + 1] - ht[idx]) + mincost(ht, n, idx + 1);
		return dp[idx];
	}
	
}

int main()
{
	int n;
	cin >> n;
	vi ht(n);
	rep(n)
		cin >> ht[i];
	dp.resize(n, -1);
	auto ans = mincost(ht, n, 0);
	cout << ans;
	ret(0);
}
 	

Measured memory_bytes: 8832
using System;
using System.Text.RegularExpressions;
 
namespace Key
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] rs = new string[2] {"[qwertasdfgzxcvb]", "[yuiophjklnm]" };
            string n;
            while ((n = Console.ReadLine()) != "#")
            {
                for(int i = 0; i < 2; i++)
                    n = new Regex(rs[i] + '+').Replace(n, "0");
                Console.WriteLine("{0}", n.Length - 1);
            }
        }
    }
}

Measured memory_bytes: 11184
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>

using namespace std;

int main() {
long long int k,a,b;
 long long int sum,h;
  cin >> k >> a >> b;
 
  if(a+2>=b){
   sum=k+1;
  }
  else{
    if(k-a-1>=0){
    sum=sum+b;
    k=k-a-1;//0に初期化
    while(k>=2){
        sum=sum+b-a;
        k=k-2;
    }
    sum=sum+k;
    }
    else{
      sum=k+1;
  }
  }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt(); //棒の本数
        int bar[] = new int[w];
        int n = sc.nextInt(); //交換の回数
        String str;

        for(int i=0; i<w; i++) bar[i] = i+1;

        for(int i=0; i<n; i++){
            int t;
            str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0]) - 1;
            int b = Integer.parseInt(ab[1]) - 1;
            t = bar[a];
            bar[a] = bar[b];
            bar[b] = t;
        }

        for(int i=0; i<w; i++) System.out.println(bar[i]);

        sc.close();
    }
}


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

using namespace std;
typedef long long ll;

const int N = 400007;
const int M = 1000000007;
ll c[N];
ll d[N];
ll pot2[N];

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

    int n; cin >> n;

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

    pot2[0] = 1;
    for(int i = 1; i <= 2 * n; ++i) pot2[i] = pot2[i-1] * 2ll % M;

    sort(c, c + n);

    d[0] = 0;
    for(int i = 1; i <= n; ++i) {
        d[i] = 2ll * d[i-1] % M;
        d[i] += 2ll * (( d[i-1] + pot2[2 * (i-1)] ) % M) % M;
        d[i] %= M;
    }

    ll ans = 0;
    int cur = 0;
    for(int i = n-1; i >= 0; --i) {
        ll aux = (2ll * d[cur] * pot2[2 * i] % M) * c[i] % M;
        aux = (aux + (2ll * c[i] * pot2[2 * (n-1)] % M)) % M;
        ans = (ans + aux)%M;
        cur++;
    }

    cout << ans << endl;


}

Measured memory_bytes: 8448
n, m = gets.split.map(&:to_i)
l = 0
r = 100000

m.times do |i|
  tmpl, tmpr = gets.split.map(&:to_i)
  l = [l, tmpl].max
  r = [r, tmpr].min
end

puts l > r ? 0 : r - l + 1


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    string n;
    vector<ll> ans;
    set<ll> hate;
    ll k; 
    cin >> n >> k;

    rep(i, k) {
        ll d; cin >> d;
        hate.insert(d);
    }
    ll large = 0;
    rep(i, 10) {
        if(!hate.count(i)) large = i;
    }

    bool over = false;
    rep(i, n.size()) {
        if(i == 0) {
            bool ok = false;
            ll tmp = 0;
            rep(i, n.size()) {
                tmp += large*a_n(10, i);
            }
            if(tmp >= stoll(n)) ok = true;

            // 繰り上がり
            if(!ok) {
                over = true;
                frep(j, 1, 9) {
                    if(!hate.count(j)) {
                        ans.push_back(j);
                        break;
                    }
                }
            }
        }
        if(over) {
            rep(j, 10) {
                if(!hate.count(j)) {
                    ans.push_back(j);
                    break;
                }
            }
        }
        else {
            ll m = ll(n[i]-'0');
            frep(j, m, 9) {
                if(!hate.count(j)) {
                    if(j > m) over = true;
                    ans.push_back(j);
                    break;
                }
            }
        }
    }

    rep(i, ans.size()) cout << ans[i];
    cout << endl;

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

ll my_gcd(ll a, ll b) {
    if(b == 0) return a;
    return my_gcd(b, a%b);
}

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


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

int main() 
{
    int a, b;
    cin >> a >> b;//改行を気にしない
    if(a*b % 2 == 1)
    {
      cout << "Odd" << endl;
    }else
    {
      cout << "Even" << endl;
    }
    
}


Measured memory_bytes: 256
import sys
from itertools import combinations

N,M,X = map(int,input().split())
CA = [list(map(int,input().split())) for _ in range(N)]
A=[0]*(M+1)

ans=0

for i in range(N):
    ans+=CA[i][0]
    for j in range(1,M+1):
        A[j]+=CA[i][j]


for i in range(1,M+1):
    if A[i] <X:
        print(-1)
        sys.exit()


for i in range(1,N+1):
    for e in combinations(range(N),i):
        c = 0
        A = [0]*M
        for f in e:
            c += CA[f][0]
            for j in range(M):
                A[j] += CA[f][j+1]
        if min(A) >= X:
            ans = min(ans,c)
        
else:
    print(ans)

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int x,y,z;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n,a,b;cin>>n>>a>>b;
    rep(i,n){
        int p;cin>>p;
        if(p<=a)x++;
        else if(p<=b)y++;
        else z++;
    }
    cout<<(min({x,y,z}))<<endl;
    return 0;
}


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

int main(){
    char s; cin >> s;
    vector<char> alphabet;
    alphabet = {'a','b','c','d','e','f','g','h','i','j',
                'k','l','m','n','o','p','q','r','s','t',
                'u','v','w','x','y','z'};
    
    for(int i=0;i<alphabet.size()-1;i++){
        if(s == alphabet.at(i)){
            cout << alphabet.at(i+1) << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LiangJiaJun main
using namespace std;
int n,sx,sy,lt;
int LiangJiaJun(){
    scanf("%d",&n);
    sx=0;sy=0;lt=0;
    for(int i=1;i<=n;i++){
        int t,x,y,rt,sum;
        scanf("%d%d%d",&t,&x,&y);
        rt=t-lt;
        lt=t;
        sum=abs(x-sx)+abs(y-sy);
        sx=x;sy=y;
        if(sum>rt){
            return puts("No"),0;
        }
        else{
            if(sum%2!=rt%2){
                return puts("No"),0;
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 256
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))
    
print(-sum(a))

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

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

    queue<ll> Q;
    for(int i=1; i<=9; i++){
        Q.push(i);
    }

    for(int i=0; i<K-1; i++){
        ll s = Q.front(); // i番目のLunlun Number
        Q.pop();
        for(int j=-1; j<=1; j++){
            ll add = (s%10)+j;
            if(0<=add && add<=9){
                Q.push(s*10+add);
            }
        }
    }
    cout << Q.front() << endl;


    return 0;
}

Measured memory_bytes: 1792
s = int(input())
if s<4:
    if s == 3:
        print(1)
    else:
        print(0)
    exit()
mod = 10**9+7
dp = [0]*(s+1)
dp[0] = 1
for i in range(3, s+1):
    dp[i] = sum(dp[:i-2])%mod
print(dp[-1])

Measured memory_bytes: 9188
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	long long int n, k;
	cin >> n >> k;
	if (n == 1) {
		cout << k << endl;
		return 0;
	}

	cout << (long long int)(k * pow(k - 1, n - 1)) << endl;
	return 0;
}

Measured memory_bytes: 256
include Math
define_method :max, -> (a,b) { a > b ? a : b }
define_method :min, -> (a,b) { a < b ?  a : b }
define_method :swap, -> (a,b) { a, b = b, a }
define_method :rep, -> (num, &block) { num.times do |i| block.call(i)  end }
define_method :repl, -> (st,en, &block) { st.upto en-1 do |i| block.call(i) end }
define_method :array, -> (size,init = nil) { Array.new(size){init} }
define_method :darray, -> (size1, size2, init = nil) { Array.new(size1){Array.new(size2){init}} }
define_method :gi, -> () { gets.split.map(&:to_i) }
define_method :gs, -> () { gets.chomp }
define_method :putall, -> (obj) { obj.each do |o| puts o end }



n = gi[0]
ans = Float::INFINITY

repl 1,sqrt(n)+1 do |i|
	if n % i == 0
		a = (n / i).to_s.length
		b = i.to_s.length
		m = max(a,b)
		ans = m if m < ans
	end
end

puts ans


Measured memory_bytes: 1916
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int d,n;
    cin >> d >> n;
    if(n != 100){
    if(d == 0){
        cout << n << endl;
    }else{
        if(d == 1){
            cout << n*100 << endl;
        }else{
            cout << n*10000 << endl;
        }
    }
    }else{
        if(d == 0){
        cout << n + 1<< endl;
        }else{
            if(d == 1){
                cout << n*100 + 100<< endl;
            }else{
                cout << n*10000 + 10000<< endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
// Last Change:                           11/26/2018 20:12:17.
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <list>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

#define NUMMAX 100000

void CountingSort(int A[], int B[], int n) {
  int C[NUMMAX + 5];
  for (int i = 0; i <= NUMMAX; i++) { // = が大事
    C[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    C[A[i]]++;
  }
  for (int i = 1; i <= NUMMAX; i++) {
    C[i] = C[i] + C[i - 1];
  }
  for (int i = n; i >= 0; i--) {
    B[C[A[i]] - 1] = A[i];
    C[A[i]]--;
  }
}

int main() {
  int n, A[2000000], B[2000000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  CountingSort(A, B, n);

  for (int i = 0; i < n; i++) {
    if (i) {
      cout << " ";
    }
    cout << B[i];
  }
  cout << endl;
}



Measured memory_bytes: 19096
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int R, G, B, N; cin >> R >> G >> B >> N;
    int res = 0;
    
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= N; ++j) {
            int tmp = N - i*R - j*G;
            int k = tmp / B;
            if (tmp % B == 0 && k >= 0) ++res;
        }
    }
    cout << res << endl;

}


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

ll N;
vector<ll> t, a;
vector<ll> thyou, ahyou;

int main() {
    cin >> N;
    t.resize(N); a.resize(N);
    thyou.resize(N); ahyou.resize(N);
    for (int i = 0; i < N; i++) scanf("%Ld %Ld", &t[i], &a[i]);

    thyou[0] = t[0]; ahyou[0] = a[0];
    for (int i = 1; i < N; i++) {
        for (ll j = max(thyou[i-1]/t[i], ahyou[i-1]/a[i]); 1; j++) {
            if (thyou[i-1] <= j*t[i] && ahyou[i-1] <= j*a[i]) {
                thyou[i] = j*t[i];
                ahyou[i] = j*a[i];
                break;
            }
        } 
    }
    cout << thyou[N-1]+ahyou[N-1] << endl;
    return 0;
}

Measured memory_bytes: 256
import math
K=int(input())

answer=0
for i in range(1,K+1):
  for j in range(1,K+1):
    gcd_ij=math.gcd(i,j)    
    for k in range(1,K+1):
      gcd_ijk=math.gcd(gcd_ij,k)
      answer+=gcd_ijk
print(answer)

Measured memory_bytes: 67688
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <functional>

#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
 int n,wr=0,er=0; cin >> n;
 string s; cin >> s;
 rep(i,n){
   if(s[i] == 'W'){
     wr++;
   } else {
     er++;
   }
 }
 int ans;
 char keep; keep = s[0];
 if(s[0] == 'W'){
   ans = er;
   wr -= 1;
 } else {
   ans = er;
   er -= 1;
 }
 int wl = 0, el = 0;
 for(int i=1;i<n;i++){
   if(keep == 'W' && s[i] == 'W'){
     wl++;
     wr--;
   }
   if(keep == 'W' && s[i] == 'E'){
     wl++;
     er--;
   }
   if(keep == 'E' && s[i] == 'W'){
     el--;
     wr--;
   }
   if(keep == 'E' && s[i] == 'E'){
     el++;
     er--;
   }
   keep = s[i];
   ans = min(ans,wl+er);
 }
  
 cout << ans;
     
 
 
 return 0;
}

Measured memory_bytes: 900
N,K=gets.chomp.split.map(&:to_i)
ans=0

if K==0
  puts N*N
  exit
end

(K+1).upto(N) do |b|
  ans += N/b*(b-K)
  ans += N%b-(K-1) if N%b-(K-1) > 0
end
puts ans

Measured memory_bytes: 3836
#include<iostream>
#include<cstdio>

using namespace std;

int main(int argc, char *argv[])
{
  int a,b,c;
  int rectangles = 0;
  int lozenges = 0;;
  
  while(scanf("%d,%d,%d",&a,&b,&c) != EOF){
    if(a==b){
      lozenges++;
    }
    else if(c*c ==a*a+b*b){
      rectangles++;
    }
  }
  cout <<rectangles<<endl;
  cout<<lozenges<<endl;
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main(void){
  string s;
  cin>>s;
  int flg=0;
    if(s[0]=='1'){
    flg++;
  }
  if(s[1]=='1'){
    flg++;
  }
  if(s[2]=='1'){
    flg++;
  }
  cout<<flg<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
	mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
	mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
	mint operator+(const mint a) const {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
 		return a;
	}

	// for prime mod
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

typedef vector<mint> vm;

int main() {
//	cout << fixed << setprecision(15);
	int h, w;
	cin >> h >> w;
	vector<string> a(h+2);
	rep1(i, h) {
		cin >> a[i];
		a[i] = "#" + a[i] + "#";
	}
	a[0] = a[h+1] = string(w+2, '#');

	vector<vm> dp(h+2, vm(w+2));
	dp[1][1] = 1;
	rep1(i, h) rep1(j, w) {
		if(i == 1 && j == 1) continue;
		if(a[i][j] == '#') continue;
		dp[i][j] = dp[i-1][j] + dp[i][j-1];
	}
	cout << dp[h][w].x << endl;
}


Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
void sol() {
  string s;
  cin >> s;
  if(s[4] == s[5] && s[2] == s[3]) {
    cout << "Yes";
  }
  else cout << "No";
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


Measured memory_bytes: 256
function main(input) {
  const args = input.split('\n');
  const a = args[0].split(' ').map(n => parseInt(n, 10));
  const N = a[0];
  const M = a[1];
  
  let list = {};
  let ans = 0;
  
  //リスト初期化
  for (let i = 1; i <= M; i++) {
    list[i] = 0;
  }
  
  //各人の好きな食べ物ループ
  for (let i = 1; i <= N; i++) {
    ary = args[i].split(' ').map(n => parseInt(n, 10));
    for (let j = 1; j <= ary[0]; j++) {
      key = ary[j];
      list[key]++;
    }
  }
  
  //みんなが好きならプラスする
  for (key in list) {
    if (list[key] === N) { ans++; }
  }
  
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29500
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

ll A[310][310];
ll B[310][310];
const ll INF = 1e9+7;

int main() {
	int N;
	cin >> N;
	rep(i,N) {
		rep(j,N) {
			cin >> A[i][j];
		}
	}

	vector<pair<ll,pii> > v;
	rep(i,N) {
		rep(j,N) {
			rep(k,N) {
				if(A[i][j] > A[i][k] + A[k][j]) {
					cout << -1 << endl;
					return 0;
				}
			}
			if(i < j) {
				v.push_back(pair<ll,pii>(A[i][j], pii(i,j)));
			}
		}
	}

	rep(i,310) {
		rep(j,310) {
			B[i][j] = INF;
		}
		B[i][i] = 0;
	}

	sort(all(v));
	ll res = 0;
	rep(i,v.size()) {
		pii e = v[i].se;
		if(B[e.fi][e.se] != v[i].fi) {
			B[e.fi][e.se] = B[e.se][e.fi] = v[i].fi;
			res += v[i].fi;
			rep(_,2) {
				rep(j,N) {
					if(B[j][e.fi] + B[e.fi][e.se] < B[j][e.se]) {
						B[j][e.se] = B[e.se][j] = B[j][e.fi] + B[e.fi][e.se];
						rep(k,N) {
							B[j][k] = min(B[j][k], B[j][e.se] + B[e.se][k]);
							B[k][j] = min(B[k][j], B[k][e.se] + B[e.se][j]);
						}
					}
				}
				swap(e.fi, e.se);
			}
		}
	}
	cout << res << endl;

	return 0;
}


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

int main()
{
    double n, x[200], ave = 0, ans = 0;
    cin >> n;
    rep(i, n)
    {
        cin >> x[i];
        ave += x[i];
    }
    ave = round(ave / n);

    rep(i, n)
    {
        ans += pow(x[i] - ave, 2);
        // cout<<pow(x[i] - ave, 2)<<endl;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3832
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

int main() {
    string s, r;
    cin >> s;
    std::vector<char> v;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '0') r += '0';
        if(s[i] == '1') r += '1';
        else if(s[i] == 'B' && r.length() != 0) r.pop_back();
    }
    for(auto i: r) cout << i;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


int main() {
    string S;
    ll p = 1000000007;
    cin >> S;
    S = "x" + S;
    int N = S.size();
    ll ques_num = 1;
    v2ll dp(N + 2, vll(3,0));
    for (int i = N; i >= 0; i--) {
        if (S[i] == 'C') {  
            dp[i][0] = dp[i + 1][0];
            dp[i][1] = dp[i + 1][1];
            dp[i][2] = (dp[i + 1][2] + ques_num) % p;
        }
        else if (S[i] == 'B') {
            dp[i][0] = dp[i + 1][0];
            dp[i][1] = (dp[i + 1][1] + dp[i + 1][2]) % p;
            dp[i][2] = dp[i + 1][2];
        } 
        else if (S[i] == 'A') {
            dp[i][0] = (dp[i + 1][0] + dp[i + 1][1]) % p;
            dp[i][1] = dp[i + 1][1];
            dp[i][2] = dp[i + 1][2];
        }
        else if (S[i] == '?') {
            dp[i][2] = ((dp[i + 1][2] * 3) % p + ques_num) % p;
            dp[i][0] = ((dp[i + 1][0] * 3) % p + dp[i + 1][1] ) % p;
            dp[i][1] = ((dp[i + 1][1] * 3) % p + dp[i + 1][2] ) % p;
            ques_num = (ques_num * 3) % p; 
        }
        else {
            dp[i][0] = dp[i + 1][0];
            dp[i][1] = dp[i + 1][1];
            dp[i][2] = dp[i + 1][2];
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 5756
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

struct BinaryIndexed {
  ll num;
  vll bit;

  BinaryIndexed(ll x = MAX) {
	num = x;
	bit.resize(x + 1, 0);
  }

  ll sum(ll i) {
	ll ret = 0;
	while (i > 0) {
	  ret += bit[i];
	  i -= i & -i;
	}
	return ret;
  }

  void add(ll i, ll x) {
	if (i == 0) cout << "access 0 index" << endl;
	while (i <= num) {
	  bit[i] += x;
	  i += i & -i;
	}
  }
};

int main(void) {
  cin >> n;
  vll a(n), b(n);
  rep(i, n) scan(a[i]);
  if (n == 1) {
	cout << a[0] << endl;
	return 0;
  }
  ll low = 1, up = mod, mid, sum, zero;

  while (up - low > 1) {
	BinaryIndexed b1, b2;
	mid = (up + low) / 2;
	rep(i, n) a[i] >= mid ? b[i] = 1 : b[i] = -1;
	sum = 0; zero = 1; cnt = 0;

	rep(i, n) {
	  sum += b[i];
	  if (sum > 0) {
		cnt += b1.sum(sum);
		cnt += zero;
		cnt += b2.sum(n);
	  }
	  else if (sum == 0) {
		cnt += zero;
		cnt += b2.sum(n);
	  }
	  else {
		if (sum == -1) cnt += b2.sum(n);
		else cnt += b2.sum(n) - b2.sum((-sum)-1);
	  }

	  if (sum == 0) zero++;
	  else if (sum > 0) b1.add(sum, 1);
	  else b2.add(-sum, 1);
	}
	if (cnt >= n * (n + 1) / 4) low = mid;
	else up = mid;
  }

  cout << low << endl;

  return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main(){
  string s;
  cin >> s;
  int len = s.length();
  int cnt = 0;
  FOR(i,0,len){
    if(s[i] == 'p') cnt++;
  }
  cout << len / 2 - cnt << endl;
  return 0;
}


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

string s;

int paint(int op)
{
	int cnt=0;
	for(int i=0; i<s.length(); i++)
	{
		if(i%2==op && s[i]!='0') cnt++;
		if(i%2!=op && s[i]!='1') cnt++;
	}
	return cnt;
}

int main()
{
	cin>>s;
	int ans=min(paint(0), paint(1));
	cout<<ans;
}

Measured memory_bytes: 512
import java.util.*;
	
	
	
	public class Main {
	
		public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			Integer a[] = new Integer[N];
			for (int i =0;i<N;i++) {
				a[i] = sc.nextInt();
			}
			Arrays.sort(a,Collections.reverseOrder());
			
			int sumAlice = 0;
			int sumBob = 0;
			
			for (int j=0;j<N;j++) {
				if (j%2 == 0) {
					sumAlice += a[j];
				}else {
					sumBob += a[j];
				}
			}
			
			int res = sumAlice - sumBob;
			
			System.out.println(res);
		}
		
		
	}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a , b;

int main()
{
    _FastIO;
    cin >> a >> b;
    if(a < 6){
        cout << "0" << endl;
        return 0;
    }
    if(a < 13){
        cout << b / 2 << endl;
        return 0;
    }
    cout << b << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////



int main() {
	string s;
	cin >> s;
	ll N = s.size();
	ll K;
	cin >> K;

	vector<ll> a(N);
	rep(i, N) a[i] = s[i] - 'a';

	rep(i, N - 1) {
		ll x = 26 - a[i];
		x %= 26;
		if (K >= x) {
			K -= x;
			a[i] = 0;
		}
	}

	a[N - 1] += K;
	a[N - 1] %= 26;

	rep(i, N) {
		cout << (char)('a' + a[i]);
	}
	


	system("PAUSE");
}


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

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll t1, t2, a1, a2, b1, b2;

	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	if (t1 * a1 + t2 * a2 == t1 * b1 + t2 * b2) {
		cout << "infinity" << endl;
	}
	else if ((a1 < b1 && a2 < b2) || (a1 > b1&& a2 > b2)) {
		cout << 0 << endl;

	}
	else{
		ll dx1 = t1 * (b1 - a1);
		ll dx2 = t2 * (b2 - a2);
		
		if (dx1 > 0) {
			dx1 *= -1;
			dx2 *= -1;
		}
		ll dx = dx1 + dx2;

		if (dx > 0) {
			ll n = (-dx1) / dx;
			if (((-dx1) % dx) == 0) {
				cout << 2 * n<<endl;
			}else{
				cout << 2 * n + 1 << endl;
			}
		}
		else {
			cout << 0 << endl;
			return 0;
		}
	}

	return 0;
}

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

int ruisekiwa[101][101];
int main()
{
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		for (int c = 0; c < a; c++) {
			int d; scanf("%d", &d);
			ruisekiwa[b + 1][c + 1] = ruisekiwa[b + 1][c] + ruisekiwa[b][c + 1] - ruisekiwa[b][c] + d;
		}
	}
	int MAX = -(1<<29);
	for (int e = 0; e < a; e++) {
		for (int f = e + 1; f <= a; f++) {
			for (int g = 0; g < a; g++) {
				for (int h = g + 1; h <= a; h++) {
					MAX = max(MAX, ruisekiwa[f][h] - ruisekiwa[e][h] - ruisekiwa[f][g] + ruisekiwa[e][g]);
				}
			}
		}
	}
	cout << MAX << endl;
}

Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#include <numeric>

using namespace std;

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

using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
ll modinv(ll a, ll mod)
{
    return modpow(a, mod - 2, mod);
}

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

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

    ll nume_a = 1;
    for (int i = n; i > n - a; i--)
    {
        nume_a = nume_a * i % mod;
    }
    ll nume_b = 1;
    for (int i = n; i > n - b; i--)
    {
        nume_b = nume_b * i % mod;
    }
    ll deno_a = 1;
    for (int i = a; i > 0; i--)
    {
        deno_a = deno_a * i % mod;
    }
    ll deno_b = 1;
    for (int i = b; i > 0; i--)
    {
        deno_b = deno_b * i % mod;
    }
    ll inv_deno_a = modinv(deno_a, mod);
    ll inv_deno_b = modinv(deno_b, mod);

    ll res;
    res = modpow(2, n, mod) - 1;
    res = (mod + res - nume_a * inv_deno_a % mod) % mod;
    res = (mod + res - nume_b * inv_deno_b % mod) % mod;
    cout << res << "\n";
}

Measured memory_bytes: 256
fn main() {
    let v = read_vec::<usize>();
    let (k, q) = (v[0], v[1]);
    let d = read_vec::<i64>();
    let mut queries = vec![];
    for _ in 0..q {
        let v = read_vec::<i64>();
        let (n, x, m) = (v[0], v[1], v[2]);
        queries.push((n, x % m, m));
    }

    for (n, x, m) in queries {
        let mut d_mod = d.iter().map(|&v| v % m).collect::<Vec<_>>();
        let mut increment = d_mod.iter().sum::<i64>() * ((n - 1) / k as i64);
        increment += d_mod
            .iter()
            .take(((n - 1) % k as i64) as usize)
            .sum::<i64>();

        let mut eq =
            d_mod.iter().fold(0, |s, &x| if x == 0 { s + 1 } else { s }) * ((n - 1) / k as i64);
        for i in 0..((n - 1) % k as i64) as usize {
            if d_mod[i] == 0 {
                eq += 1;
            }
        }
        let dec = (x + increment) / m;
        println!("{}", n - 1 - dec - eq);
    }
}

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main()
{

    int c[3][3];

    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> c[i][j];
        }
    }
    int l1 = c[0][0] + c[1][1] + c[2][2];
    int l2 = c[1][0] + c[2][1] + c[0][2];
    int l3 = c[2][0] + c[0][1] + c[1][2];

    int r1 = c[0][2] + c[1][1] + c[2][0];
    int r2 = c[0][1] + c[1][2] + c[2][0];
    int r3 = c[0][2] + c[1][0] + c[2][1];

    if (((l1 == l2) and (l1 == l3)) and ((r1 == r2) and (r1 == r3)))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }


    return 0;
}

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

n_max = 10**6+1

ans = 0
flag = [True] * (n_max)
for i in range(n-1):
    if(not flag[a[i]]):
        continue

    if(a[i]!=a[i+1]):
        ans += 1
    for j in range(a[i],n_max,a[i]):
        flag[j] = False

ans += flag[a[-1]]*1
print(ans)

Measured memory_bytes: 96664
#include <bits/stdc++.h>
#define rep(n) for (int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define repeat_from_reverse(i, m, n) for( int i = (n) - 1; (i) >= (m); --(i) )
#define el cout<<endl
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t t=0; t<v.size(); ++t){cout << " " << #v << "[" << t << "]=" << v[t];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    vector<int> a(3);
    int k;
    cin >> a[0] >> a[1] >> a[2] >> k;
    sort(a.begin(), a.end());
    a[2] <<= k;
    cout << a[0] + a[1] + a[2] << endl;
}

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

typedef struct _data_st
{
    int rows, columns;
    struct _data_st *next;
} data_st;

int main(int argc, char *argv[])
{
    data_st *head = NULL, *tail = NULL;
    for (int rows, columns; scanf("%d %d", &rows, &columns) && (rows || columns);)
    {
        data_st *data = (data_st *)malloc(sizeof(data_st));
        *data = (data_st){.rows = rows, .columns = columns, .next = NULL};
        head = head ?: data;
        if (tail)
        {
            tail->next = data;
        }
        tail = data;
    }
    while (head)
    {
        data_st *data = head;
        head = head->next;
        for (int row = 0; row < data->rows; ++row)
        {
            for (int column = 0; column < data->columns; ++column)
            {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
        free(data);
    }
    return 0;
}



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

int main() {
  int a, b, N;
  cin >> N;
  a = 0;
  b = N;
  
  for(int i =0; i < N; i++) {
    a += b % 10;
    b /= 10;
    
    if (b>0) {
      continue;
    }
    else if (b == 0){
      if (N%a == 0) {
        cout << "Yes" << endl;
      }
      else if (N%a !=0) {
        cout << "No" << endl;
      }      
      break;
    }
  }
}
     

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;


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


  string s;
  cin >> s;

  int max = 0;
  for (int i = 0; i < s.length(); i++) {
    for (int j = 1; j < s.length() - i + 1; j++) {
      if (regex_match(s.substr(i, j), regex("[ACGT]+")) && j > max) {
        max = j;
      }
    }
  }
  pr(max);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int data,triangle[3],i,j,k,tmp;
	
	scanf("%d",&data);
	for(i=0;i<data;i++)
	{
		scanf("%d %d %d",&triangle[0],&triangle[1],&triangle[2]);
		
		for(j=0;j<2;j++)
			{
				for(k=j+1;k<3;k++)
					{
						if(triangle[j]<triangle[k])
						{
							tmp=triangle[j];
							triangle[j]=triangle[k];
							triangle[k]=tmp;
						}
					}
			}
		if((triangle[0]*triangle[0])==(triangle[1]*triangle[1])+(triangle[2]*triangle[2]))
			printf("YES\n");
		else
			printf("NO\n");
			
	}
	
	return 0;
}

Measured memory_bytes: 580