akhauriyash/Code-Regression huggingface dataset:
import scala.io.StdIn

case class Card(suit: String, rank: Int) extends Ordered[Card] {
  override def toString():String = {
    s"$suit $rank"
  }

  def compare(that: Card): Int = {
    val (thisSuitIdx, thatSuitIdx) = (Card.suitSeq.indexWhere(_ == this.suit),
      Card.suitSeq.indexWhere(_ == that.suit))
    val suitComp = thisSuitIdx compare thatSuitIdx
    if(suitComp != 0){
      suitComp
    }else{
      this.rank compare that.rank
    }
  }

  def getNextCard: Option[Card] = {
    this match {
      case Card("D", 13) => None
      case Card(s, 13) =>
        Some(Card(Card.suitSeq(Card.suitSeq.indexWhere(_ == s)+1), 1))
      case Card(s, r) => Some(Card(s, r+1))
    }
  }
}

object Card{
  val suitSeq = Seq("S", "H", "C", "D")
}

object Main {
   def main(args: Array[String]): Unit = {
    StdIn.readInt()
    val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null).toList
    val cardList = for{
      in <- inputs
      val Array(suit, rankT, _*) = in.split(" ")
    }yield(Card(suit, rankT.toInt))
    def from(card: Option[Card]): Stream[Option[Card]] = Stream.cons(card, from(card.flatMap(_.getNextCard)))
    val fillCardList = from(Some(Card("S", 1))).takeWhile(_ != None).map(_.get).toList
    (fillCardList diff cardList).foreach(println _)
  }
}

Measured memory_bytes: 44396
MOD = 1000000007

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

cnts = [3 if i == 0 else 0 for i in range(N + 1)]

res = 1
for a in A:
    res = res * cnts[a] % MOD
    cnts[a] -= 1
    cnts[a + 1] += 1

print(res)


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

int main() {
	int n,m;cin>>n>>m;
	vector<int> a(m),b(m);
	vector<vector<int>> v(n,vector<int>(0));
	for(int i=0;i<m;i++){
		cin>>a[i]>>b[i];
		a[i]--;
		b[i]--;
		v[a[i]].push_back(b[i]);
		v[b[i]].push_back(a[i]);
	}
	vector<int> used(n,0);
	used[a[0]]=1;
	used[b[0]]=1;
	vector<vector<int>> l(2,vector<int>(0));
	for(int i=0;i<2;i++){
		if(i==0){
		l[0].push_back(a[0]);
		}else{
			l[1].push_back(b[0]);
		}
		while(1){
			int flag=0;
			for(int j=0;j<v[l[i].back()].size();j++){
				if(used[v[l[i].back()][j]]==0){
					used[v[l[i].back()][j]]=1;
					l[i].push_back(v[l[i].back()][j]);
					flag=1;
					break;
				}
			}
			if(flag==0)break;
		}
	}
	cout<<l[0].size()+l[1].size()<<endl;
	for(int i=l[1].size()-1;i>=0;i--){
		cout<<l[1][i]+1<<' ';
	}
	for(int i=0;i<l[0].size();i++){
		cout<<l[0][i]+1<<' ';
	}

	cout<<endl;
	return 0;
}


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

using namespace std;

int num[100005];

bool comp(int a, int b)
{
    return a > b;
}
int main()
{
    int n;
    scanf("%d", &n);
    int flag=0,flag1=0;
    for(int i = 0; i < n ; i++)
        scanf("%d", &num[i]);

    sort(num, num + n, comp);

    for(int i = 0; i < n-1;)
    {
        if(num[i]==num[i+1]&&flag==0)
            flag=num[i],i+=2;
        else if(num[i]==num[i+1]&&flag&&flag1==0)
            flag1=num[i],i+=2;
        else if(num[i]!=num[i+1])
            i++;
        else if(flag&&flag1)
            break;
    }
    cout<<(long long )flag*flag1<<endl;

    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		if (A < 10 && B < 10) {
			System.out.println(A * B);
		} else {
			System.out.println("-1");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl a(n), K(n);
    rep(i,n){
        cin >> a[i] >> K[i];
    }
    ll ans = 0;
    rep(i,n){
        if(a[i] >= K[i]){
            while(1){
                if(a[i] % K[i] == 0){
                    ans ^= a[i] / K[i];
                    break;
                }else if(a[i] < K[i]){
                    break;
                }
                int dir = a[i] / K[i] + 1;
                a[i] -= dir*((a[i]-a[i]/K[i]*K[i]-1)/dir+1);
            }
        }
    }
    if(ans == 0){
        cout << "Aoki\n";
    }else{
        cout << "Takahashi\n";
    }
    return 0;
}


Measured memory_bytes: 256
x = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
li = make_divisors(x)
#print(make_divisors(x))
#[1, 33, 3, 11]

for l in li:
    for k in range(-1000,1000):
        b = k
        a = b + l
        if a**4 +a**3*b +(a**2)*(b**2)+a*(b**3)+b**4 == x//l:
            print(a,b)
            exit()

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

int N;

void func(int n, string str, int cnt) {
  if (n == N) {
    cout << str << endl;
    return;
  }
  for (int i = 0; i <= cnt; i++) {
    char c = 'a' + i;
    if (i == cnt) func(n+1, str + c, cnt + 1);
    else func(n+1, str + c, cnt);
  }
}

int main() {
  cin >> N;
  func(1, "a", 1);
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
3 1000
120
100
140
)");
#define cin input
#endif

int main()
{
	int n, x;
	int count = 0;
	cin >> n >> x;

	int m, mn;
	cin >> m;
	mn = m;

	for (int i=0; i<n; i++)
	{
		x-=m;

		if(mn > m)
			mn = m;

		cin >> m; 
	}

	while (x/mn != 0)
	{
		x-=mn;
		count++;
	}

	cout << count + n << endl;
}

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

int main(){
    string o,e;
    cin>>o;
    cin>>e;
    ll n = e.size();
    
    for(ll i=0;i<n;++i){
        cout<<o[i]<<e[i];
    }
    if(o.size() != e.size()){
        cout<<o[o.size()-1];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds; 
using namespace std;



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
 
 
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k,t=1;

void solve()
{
   map<ll,ll>f;
   cin>>n;
   vector<ll>v(n);
   ll sum=0;
   for(ll i=0;i<n;i++)cin>>v[i],f[v[i]]++,sum+=v[i];
   cin>>m;
   while(m--)
   {
       cin>>a>>b;
       if(f[a]!=0)
       {
           sum-=(a*f[a]);
           sum+=(f[a]*b);
           f[b]+=f[a];f[a]=0;
       }
       cout<<sum<<"\n";
   }
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

 // cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 9760
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(v)";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var a = o.r(5);
  var ans = 0, x = 10;
  for(var i = 0; i < 5; i++){
    ans += Math.ceil(a[i]/10) * 10;
    if(a[i] % 10 && x > a[i] % 10)x = a[i] % 10;
  }
  return ans - 10 + x;
}

Measured memory_bytes: 21192
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int zk[200000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>zk[i];
	}
	int sum=1,ans=0;
	for(int i=0;i<n;i++){
		if(zk[i]==sum){
			sum++;
			ans++;
		}
	}
	if(sum==1) cout<<-1<<endl;
	else cout<<n-ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.stream.Stream;

public class Main {

	  public static void main(String[] args) throws IOException {

		    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		    String[] strArr = in.readLine().split("\\s");
		    BigInteger[] bigIntArr = new BigInteger[strArr.length];
		    for (int index = 0; index < strArr.length; index++) {
		    	bigIntArr[index] = BigInteger.valueOf(Long.valueOf(strArr[index]));
		    }
		    // 実際の処理と結果
		    System.out.println(gcd(bigIntArr));
		  }

		  public static BigInteger gcd(BigInteger[] arr) {
		    return Stream.of(arr)
		    .reduce(BigInteger::gcd)
		    .orElse(BigInteger.ZERO);
		  }

}



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

// long long modpow(long long base, long long power, long long modvalue) {
//     base%= modvalue;
//     long long res = 1;
//     while (power > 0) {
//         if (power & 1)
//             res = res * base % modvalue;
//         base = base * base % modvalue;
//         power >>= 1;
//     }
//     return res;
// }
long long modpow(long long base, long long power, long long modvalue){
   
    if(power == 0) return 1;
   
    if(power&1){
        long long current_value = modpow(base, power - 1, modvalue);
        return ((current_value%modvalue)*(base%modvalue))%modvalue;
    }else{
        long long current_value = modpow(base, power/2, modvalue);
        return ((current_value%modvalue)*(current_value%modvalue))%modvalue;
       
    }
}

long long get_modpow_value(string &s, long long ones){
    long long n = s.size();
    long long modpow_value = 0;
    for(long long i = 0; i < n; i++){
        if(s[i] == '1'){
            modpow_value += modpow(2, n - i - 1, ones);
            modpow_value %= ones;
        }
    }
    
    return modpow_value%ones;
}

int main(){
    long long n;
    string s;
    cin >> n >> s;
    
    long long ones = 0;
    for(long long i = 0; i < n; i++){
        if(s[i] == '1'){
            ones += 1;
        }
    }
    long long possible_rem1 = 0, possible_rem2 = 0;
    if(ones > 1)possible_rem1 = get_modpow_value(s, ones - 1);
    if(ones >= 0)possible_rem2 = get_modpow_value(s, ones + 1);
     
    for(long long i = 0; i < n; i++){
        long long current_ones = ones;
        long long rem;
        if(s[i] == '0'){
            current_ones += 1;
            rem = possible_rem2 + modpow(2, n - 1 - i, current_ones);
            rem %= current_ones; 
        }else{
            current_ones -= 1;
            if(current_ones == 0){
                cout << 0 << endl;
                continue;
            }   
            rem = possible_rem1 - modpow(2, n - 1 - i, current_ones);
            rem = (current_ones + (rem % current_ones)) % current_ones;
        }
        
        long long res = 1;
        while(rem != 0){
            res += 1;
            rem = rem%__builtin_popcount(rem);
        }
        cout << res << endl;
    }
    
    return 0;
    
    
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  for (int i = A; i <= B; i++) {
    if (i <= A + K - 1 || i >= B - K + 1) cout << i << endl;
  }
  
  return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
int main(){
  char s[100];
  int i=0,count=0;
  int l;
  scanf("%s",s);
  while(s[i])
    i++;
  l=i;
  for(i=0;i<l/2;i++){
    if(s[i]!=s[l-i-1])
      count++;
  }
  printf("%d\n",count);
  return 0;}


Measured memory_bytes: 128
N, L = list(map(int, input().split()))
S = [input() for i in range(N)]
num = []
ans = []
answer = []
for i in range(len(S)):
    num.append(list(map(ord, str(S[i]))))
num.sort()
for i in range(len(num)):
    ans.append(list(map(chr, num[i])))
for i in range(len(ans)):
    answer.append("".join(ans[i]))
print("".join(answer))

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

using namespace std;

const int maxN = 2e5+10, base = 1e9+7;
int N,X,Y;
int dd[maxN], sl[maxN];
long long ans;
vector <int> L, V, prime, color[maxN];

bool cmp(int a, int b) { return color[a][0] < color[b][0]; }

void eratos()
{
    for (int i=2; i < maxN/2; i++)
        if (!dd[i])
            for (int j=2; j*i < maxN; j++) dd[i*j] = 1;
    for (int i=2; i < maxN; i++)
        if (!dd[i]) prime.push_back(i);
}

void fact(int k, int w)
{
    for (int i=0; i < prime.size(); i++)
    {
        int x = prime[i], t = k, res = 0;
        if (x > k) return;
        while (t) t /= x, res += t;
        sl[i] += res*w;
    }
}

long long mulpower(int x, int n)
{
    if (n == 1) return x;
    long long w = mulpower(x, n/2);
    w = (w*w)%base;
    return n%2 == 0 ? w : (w*x)%base;
}

int main()
{
    eratos();
    cin >> N >> X >> Y;
    for (int i=0,c,w; i < N; i++)
    {
        cin >> c >> w;
        if (color[c].empty()) L.push_back(c);
        color[c].push_back(w);
    }
    for (int i=1; i <= N; i++) sort(color[i].begin(),color[i].end());
    sort(L.begin(),L.end(),cmp);
    int vt = 0, sum = 0;
    for (int i=1; i < L.size(); i++)
        if (color[L[0]][0] + color[L[i]][0] <= Y) vt = i;
    for (int i=0; i <= vt; i++)
    {
        int x = L[i], num = 1;
        for (int j=1; j < color[x].size(); j++)
        {
            if (color[x][0] + color[x][j] <= X) num = j+1;
            if (i && color[x][j] + color[L[0]][0] <= Y) num = j+1;
            if (L.size() > 1 && i != 1 && color[x][j] + color[L[1]][0] <= Y) num = j+1;
        }
        V.push_back(num); sum += num;
    }
    fact(sum, 1);
    for (int i=0; i < V.size(); i++) fact(V[i], -1);
    ans = 1;
    for (int i=0; i < prime.size(); i++)
        if (sl[i]) ans = (ans * mulpower(prime[i], sl[i]))%base;
    cout << ans;
}


Measured memory_bytes: 12404
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

class Calc_Mod{//calculate mod
    public:
        unsigned int mod=1000000007;
        ll plus_mod(ll a,ll b){
            return (a+b)%mod;
        }
        ll minus_mod(ll a,ll b){
            return (a-b)%mod;
        }
        ll multi_mod(ll a,ll b){
            return a*b%mod;
        }
        ll LSM(ll a,int b){//a^b%mod
            queue<int> q;
            while(b>=1){
                q.push(b%2);
                b/=2;
            }
            ll ans=1;
            while(!q.empty()){
                if(q.front()==1){
                    ans=multi_mod(ans,a);
                }
                a=multi_mod(a,a);
                q.pop();
            }
            return ans;
        }
        ll div_mod(ll a,ll b){// a/b
            return multi_mod(a,LSM(b,mod-2));
        }
        ll combi(ll a,ll b){//aCb
            ll ans=1;
            ll kaijo=1;
            rep(i,b){
                ans=multi_mod(ans,a-i);
                kaijo=multi_mod(kaijo,b-i);
            }
            ans=div_mod(ans,kaijo);
            return ans;
        }
        
};
int main()
{
    int s;
    cin >> s ;
    Calc_Mod c;
    if(s<=2){
        cout << 0 << endl;
    }else if(s==3){
        cout << 1 << endl;
    }else if(s==4){
        cout << 1 << endl;
    }else if(s==5){
        cout << 1 << endl;
    }else if(s==6){
        cout << 2 << endl;
    }
    else{
        ll ans=0;int i=0;
        while(s>=0){
            s-=3;
            ans+=c.combi(s+i,i);
            ++i;
            ans%=MAX;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3584
from collections import Counter
def facto(n):
    a = []
    t = n
    for i in range(2, int(n**0.5)+1):
        if t%i==0:
            c = 0
            while t%i==0:
                c += 1
                t //= i
            a += [i]*c
    if t!=1:
        a += [t]
    if a==[]:
        a += [n]
    return a

n = int(input())
mod = pow(10,9)+7
ans = 1
F = Counter()
for i in range(1,n+1):
    F += Counter(facto(i))

del F[1]
for key, val in F.items():
    ans *= val+1
print(ans%mod)

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

double solve() {
    ll N;
    cin >> N;
    
    return ((N+1)/2)/(double)N;
}

int main() {
    cout.precision(15);
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.equals("Sunny"))
        System.out.println("Cloudy");
        else if(s.equals("Cloudy"))
        System.out.println("Rainy");
        else
        System.out.println("Sunny");
        sc.close();
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int prime(int n)
{
    ll i;
    if(n==1){return 0;}
    else if(n==2){return 1;}
    else
    {
        for(i=2;i<n;i++)
        {
            if(n%i==0){return 0;}
        }
    }
    return 1;
}
int main()
{

    ll n,i,j,k,l,a,b,c,d,m,f1,f2;
    cin>>a>>b;
    ll arr[10]={1,3,5,7,8,10,12};
    ll arr1[10]={4,6,9,11};
    ll arr2[10]={2};
    f1=-1;
    f2=-1;
    for(i=0;i<6;i++)
    {
        if(arr[i]==a){f1=1;}
        if(arr[i]==b){f2=1;}
    }
    if(f1==1&&f2==1)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    f1=-1;
    f2=-1;
    for(i=0;i<5;i++)
    {

        if(arr1[i]==a){f1=1;}
        if(arr1[i]==b){f2=1;}
    }
    if(f1==1&&f2==1)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    f1=-1;
    f2=-1;
    for(i=0;i<1;i++)
    {
        if(arr2[i]==a){f1=1;}
        if(arr2[i]==b){f2=1;}
    }
    if(f1==1&&f2==1)
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> str(H);
    for (int i = 0; i < H; i++)
        cin >> str[i];

    for (int w = 0; w < W + 2; w++)
        cout << "#";
    cout << endl;
    for (int h = 0; h < H; h++) {
        cout << "#" << str[h] << "#" << endl;;
    }
    for (int w = 0; w < W + 2; w++)
        cout << "#";
    cout << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <functional>
#include <chrono>
using namespace std;

#define rep(i,s,n) for(ll i=s;i<(n);++i)
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll INF = (1LL << 60);
constexpr ll MOD = (1e9 + 7);
//constexpr ll MOD = (998244353);

using vl = vector<ll>;
using vvl = vector<vector<ll>>;

template<class T>
vector<vector<T>> vvt(T init, ll m, ll n) {
	vector<vector<T>> ans = vector<vector<T>>(m, vector<T>(n, init));
	return move(ans);
}

template<class T>
vector<T> vt(T init,ll n) {
	vector<T> ans = vector<T>(n, init);
	return move(ans);
}

template<class T>
T maxVec(vector<T> &v) {
	T ans = -INF;
	rep(i,0, v.size()) {
		ans = max(ans, v[i]);
	}
	return ans;
}

// 素数判定
bool judge(ll n) {
	for (ll i = 2; i * i <= n; i++) if (n %= i)return false;
	return true;
}


template <class C>
void print(const C& c, std::ostream& os = std::cout)
{
	std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, ", "));
	os << std::endl;
}

ll count(ll n,ll r) {
	ll ans = 0,check = 1;
	rep(i,0, r) {
		if ((n & check) > 0) {
			ans++;
		}
		check = check << 1;
	}
	return ans;
}

class UnionFind {
public:
	vl parent;
	UnionFind(ll n) {
		parent = vl(n, -1);
	}

	ll root(ll n) {
		if (parent.at(n) < 0)return n;
		parent.at(n) = root(parent.at(n));
		return parent.at(n);
	}

	ll size(ll n) {
		return -parent.at(root(n));
	}

	bool connect(ll a, ll b) {
		if (root(a) == root(b))return false;
		a = root(a); b = root(b);
		if (size(a) < size(b))swap(a, b);
		parent[a] += parent[b];
		parent[b] = a;
		return true;
	}
};

bool sortshihyo(ll a, ll b) {
	return a > b;
}

int main() {
	ll n, w;
	cin >> n >> w;
	auto wv = vvt(ll(0), n, 2);
	rep(i, 0, n) {
		cin >> wv[i][0] >> wv[i][1];
	}
	unordered_map<ll, vl> mp;
	mp[0] = vl(0, 0);
	mp[1] = vl(0, 0);
	mp[2] = vl(0, 0);
	mp[3] = vl(0, 0);
	rep(i, 0, n) {
		mp[wv[i][0] - wv[0][0]].push_back(wv[i][1]);
	}
	rep(i, 0,4) {
		sort(mp[i].begin(), mp[i].end(), sortshihyo);
	}
	auto ruiseki = vvt(ll(0), 4, n + 1);
	rep(i, 0, 4) {
		rep(j, 0, mp[i].size()) {
			ruiseki[i][j + 1] = ruiseki[i][j] + mp[i][j];
		}
	}
	ll c,ans = 0;
	rep(i, 0, n+1) {
		c = i * wv[0][0];
		if (c > w)break;
		rep(j, 0, n+1) {
			c = i * wv[0][0] + j * (wv[0][0] + 1);
			if (c > w)break;
			rep(k, 0, n+1) {
				c = i * wv[0][0] + j * (wv[0][0] + 1) + k * (wv[0][0] + 2);
				if (c > w)break;
				rep(l, 0, n+1) {
					c = i * wv[0][0] + j * (wv[0][0] + 1) + k * (wv[0][0] + 2) + l * (wv[0][0] + 3);
					if (w < c)break;
					ans = max(ans, ruiseki[0][i] + ruiseki[1][j] + ruiseki[2][k] + ruiseki[3][l]);
				}
			}
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    long long x,y,ans=0;
    cin>>x>>y;
    long long p=y/x;
    while(p>0) p=p/2,ans++;
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//
//
//using namespace __gnu_pbds;
using namespace std;

#define pb                     push_back
#define ll                     long long
#define forn(i,n)              for(int i=0; i<(int)n; i++)
#define forn1(i,n)              for(int i=1; i<=(int)n; i++)

#define sfd(a)                 scanf("%d", &a)
#define sffd(a,b)              scanf("%d%d", &a, &b)
#define sffl(a,b)              scanf("%lld%lld", &a,&b)
#define sfl(a)                 scanf("%lld", &a)

#define pii                    pair<int , int>
#define pll                    pair<ll , ll>
#define ff                     first
#define ss                     second
#define mem(a, val)            memset(a, val, sizeof(a))
#define all(x)                 (x).begin(), (x).end()

#define mx                     200005
#define INF_mx                 1e18
#define gcd(a,b)               __gcd(a, b)
#define lcm(a,b)               (a*b)/__gcd(a,b)
#define PRINT                  cout<<"hi"<<endl
#define PI acos(-1)
#define fast_in_out          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Q    int q; cin>>q; while(q--)
/*
tree<
       int,
     null_type,
     less<int>,
     rb_tree_tag,
     tree_order_statistics_node_update>t;
*/
vector<ll>red, green, colLess;
int main()
{
    fast_in_out

    int x,y, n,m,c, val;
    cin>>x>>y>>n>>m>>c;

    for(int i=0; i<n; i++) cin>>val, red.pb(val);
    for(int i=0; i<m; i++) cin>>val, green.pb(val);
    for(int i=0; i<c; i++)cin>>val, colLess.pb(val);

    sort(all(red));
    sort(all(green));
    sort(all(colLess));

    int i=n-x, j=m-y;
    ll ans=0;
    while(c){
            ll tm=colLess.back();
        if( (tm<red[i] && tm<green[j]) || i==n || j==m){
          break;
        }else if(tm>red[i] && tm<green[j]){
          ans+=tm;
          i++;
        }else if(tm<red[i] && tm>green[j]){
          ans+=tm;
          j++;
        }else if(tm>red[i]&&tm>green[j]){
          if(red[i]<green[j]){
            ans+=tm;
            i++;
          }else {
            ans+=tm;
            j++;
          }
        }
        colLess.pop_back();
        c--;
    }

    if(i<n)
    while(c){
        ll tm=colLess.back();

        if(tm>red[i]) ans+=tm;
        else break;

        i++;
        colLess.pop_back();
        c--;
    }
     if(j<m)
    while(c){
        ll tm=colLess.back();

        if(tm>green[j]) ans+=tm;
        else break;

        j++;
        colLess.pop_back();
        c--;
    }

    for(  ; i<n ; i++){
        ans+=red[i];
    }
    for(  ;  j<m; j++){
        ans+=green[j];
    }
    cout<<ans<<endl;
    return 0;
}

/*

3 1 3 1 5
1 2 2
1
6 6 6 6 6

*/


Measured memory_bytes: 3444
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.abs

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (R, G, B, N) = readIntegerList()
    var ans = 0L
    for (r in 0..(N / R)) {
        for (g in 0..(N / G)) {
            val b = N - r * R - g * G
            if (b >= 0 && b % B == 0) {
                ans++
            }
        }
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36448
#include<stdio.h>
#include<math.h>

int main(void){
	double x1,x2,x3,y1,y2,y3;
	int n;
	double a1,b1,c1,a2,b2,c2,x,y,r;

	scanf("%d",&n);

	while(n--){
		scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
		a1=2*(x2-x1);
		b1=2*(y2-y1);
		c1=x1*x1-x2*x2+y1*y1-y2*y2;
		a2=2*(x3-x1);
		b2=2*(y3-y1);
		c2=x1*x1-x3*x3+y1*y1-y3*y3;
		x=(b1*c2-b2*c1)/(a1*b2-a2*b1);
		y=(c1*a2-c2*a1)/(a1*b2-a2*b1);
		r=sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));
		printf("%.3lf %.3lf %.3lf\n",x,y,r);
		fflush(stdin);
		fflush(stdout);
	}
	return 0;
}

Measured memory_bytes: 0
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

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

func main() {
	N := nextInt()
	s := make([]int, N)
	for i := 0; i < N; i++ {
		s[i] = nextInt()
	}
	sort.Ints(s)
	fmt.Println(s[N/2] - s[N/2-1])
}


Measured memory_bytes: 3804
#include<iostream>
using namespace std;
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int count=0;
    for(int i=0; i<3; i++)
    {
        if(s1[i]==s2[i])
        {
            count++;
        }
    }
    cout<<count<<endl;
}


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

using namespace std;

int main(void) {
    int flag, N, m;
    string S;
    int left[200010]={0}, right[200010]={0};
    cin >> N >> S;
    for (int i=1;i<=N;i++) {
        if (S[i-1] == '#') left[i]++;
        left[i] += left[i-1];
    }
    for (int i=N-1;i>=0;i--) {
        if (S[i] == '.') right[i]++;
        if (i<N-1) right[i] += right[i+1];
    }

    m = 200010;
    for (int i=0;i<=N;i++) {
        m = min(m,left[i] + right[i]);
    }
    cout << m << endl;

    return 0;
}

Measured memory_bytes: 2180
n,x = map(int,input().split())
xs = list(map(int,input().split()))
xs.append(x)
xs.sort()
n_xs = []
for i in range(1,n+1):
  n_xs.append(xs[i]-xs[i-1])
import fractions
ans = n_xs[0]
for i in range(1, n):
  ans = fractions.gcd(ans, n_xs[i])
print(ans)

Measured memory_bytes: 82324
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  bool flag=true;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]) flag=false;
  }
  if(s.size()!=t.size()-1) flag=false;
  if(flag) cout<<"Yes";
  else cout<<"No";
}


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

int getPopcount(const string& X)
{
    int cnt = 0;
    for (char ch : X) cnt += (ch == '1') ? 1 : 0;
    return cnt;
}

int getPopcount(int X)
{
    int cnt = 0;
    while (X > 0) {
        cnt += (X & 1);
        X = X >> 1;
    }
    return cnt;
}

int pow(long long base, long long p, long long rem)
{
    if (p == 0) return (long long)1;
    if (p % 2 == 1) {
        long long val = base * pow(base, p - 1, rem);
        return (int)(val % rem);
    }
    long long val = pow(base, p / 2, rem);
    val %= rem;
    long long ans = ((val * val) % rem);
    return (int)ans;
}

int getModValue(const string& X, int pop)
{
    int rem = 0;
    for (int i = X.size() - 1, j = 0; i >= 0; --i, ++j) {
        if (X[i] == '1') {
            rem += pow(2, j, pop);
            rem %= pop;
        }
    }
    return rem;
}

int compute(int num)
{
    if (num == 0) return 0;
    int pc = getPopcount(num);
    return 1 + compute(num % pc);
}

void solve()
{
    int N;
    string X;
    cin >> N >> X;

    int pop = getPopcount(X);
    int modPlus = getModValue(X, pop + 1);
    int modMinus = pop - 1 > 0 ? getModValue(X, pop - 1) : 0;

    for (int i = 0, j = N - 1; i < N; ++i, --j) {
        bool add = (X[i] == '0');
        int popChild = add ? pop + 1 : pop - 1;
        if (popChild <= 0) {
            cout << 0 << "\n";
        }
        else {
            int powChild = pow(2, j, popChild);
            int modChild = add ? (modPlus + powChild) : (modMinus - powChild + popChild);
            modChild = (modChild) % popChild;
            cout << 1 + compute(modChild) << "\n";
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
#define AC ios::sync_with_stdio(0),cin.tie(0);
#define ll long long int
int main(){
	AC
 	ll n,W;
	cin>>n>>W;
	vector<ll> dp(W+1);
	for(ll i=0;i<n;++i){
		ll weight,value;
		cin>>weight>>value;
		for(ll noww=W-weight;noww>=0; noww--){
			dp[noww+weight]=max(dp[noww+weight],dp[noww]+value);
		}
	}
	ll ans=0;
	for(ll i=0;i<=W;i++)ans=max(ans,dp[i]);
	cout<<ans<<endl;	
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

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

  vector<int64_t> a(n);
  int64_t m = 0;
  for (auto&& aa : a) {
    cin >> aa;
    m += aa;
  }

  sort(a.begin(), a.end());

  int64_t count = 0;
  if (a.front() > 0) {
    m -= 2 * a.front();
    count = 1;
  } else if (a.back() <= 0) {
    m *= -1;
    m += 2 * a.back();
    count = a.size() - 1;
  } else {
    for (auto i : irange(0L, n)) {
      if (a[i] <= 0) {
        m -= 2 * a[i];
        ++count;
      } else {
        break;
      }
    }
  }

  vector<pair<int64_t, int64_t>> ans;
  int64_t current = m;
  for (auto i : irange(0L, count - 1)) {
    current += a[i];
    ans.emplace_back(current, a[i]);
  }

  bool flag = true;
  for (auto i : irange(n-1, count-1, -1L)) {
    if (flag) {
      current = a[i] - current;
      ans.emplace_back(a[i], current);
      flag = false;
    } else {
      current += a[i];
      ans.emplace_back(current, a[i]);
    }
  }

  cout << m << "\n";
  for (auto it = ans.rbegin(); it != ans.rend(); ++it) {
    cout << it->first << " " << it->second << "\n";
  }
}

Measured memory_bytes: 4336
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int w, h;
  cin >> w >> h;
  int c[h][w];
  int w_sum[h] = {}, h_sum[w] = {};
  int i, j;
  for (i = 0; i < h; i++) {
    for (j = 0; j < w; j++) {
      cin >> c[i][j];
      w_sum[i] += c[i][j];
      h_sum[j] += c[i][j];
    }
  }
  int result = true;
  for (i = 0; i < h && result; i++) {
    bool equal = (c[0][0] == c[i][0] ? true : false);
    for (j = 0; j < w; j++) {
      if (equal) {
        if (c[0][j] != c[i][j]) {
          result = false;
          break;
        }
      } else {
        if (c[0][j] == c[i][j]) {
          result = false;
          break;
        }
      }
    }
  }
  for (i = 0; i < w && result; i++) {
    bool equal = (c[0][0] == c[0][i] ? true : false);
    for (j = 0; j < h; j++) {
      if (equal) {
        if (c[j][0] != c[j][i]) {
          result = false;
          break;
        }
      } else {
        if(c[j][0] == c[j][i]) {
          result = false;
          break;
        }
      }
    }
  }

  for (i = 0; i < h; i++) {
    if (w_sum[i] != w / 2 && w_sum[i] != (w + 1) / 2) {
      result = false;
      break;
    }
  }
  for (i = 0; i < w; i++) {
    if (h_sum[i] != h / 2 && h_sum[i] != (h + 1) / 2) {
      result = false;
      break;
    }
  }
  cout << (result ? "yes" : "no") << endl;

  return 0;
}



Measured memory_bytes: 6896
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    ll n;
    cin>>n;
    vector<ll> hs(n);
    rep(i, n) cin>>hs[i];

    hs[0]--;
    rep(i, n - 1) {
        if (hs[i + 1] < hs[i]) {
            cout<<"No"<<endl;
            return 0;
        }
        if (hs[i + 1] - hs[i] > 0) hs[i + 1]--;
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

long long N, M;
string S;

int main(){
	cin >> N >> M;
	cin >> S;


	vector<long long> ans;
	long long cur = N;

	while(cur > 0) {
		bool ng = true;
		for(long long len = M; len > 0; len--) {
			if(cur - len >= 0 && S[cur - len] == '0') {
				cur -= len;
				ans.push_back(len);
				ng = false;
				break;
			}
		}
		if(ng) {
			cout << -1 << endl;
			return 0;
		}
	}

	for(long long i = ans.size() - 1; i >= 0; i--) {
		cout << ans[i];
		if(i != 0) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}

Measured memory_bytes: 4372
n=int(input())
x=list(map(int,input().split()))
mod=10**9+7
inv=[0,1]
for i in range(2,n+1):
  inv+=[inv[mod%i]*(mod-int(mod/i))%mod]
l=[]
z=1
for i in range(1,n):
  z*=i
  z%=mod
l2=[z for i in range(n-1)]
for i in range(n-1):
  l.append(x[i+1]-x[i])
for i in range(n-1):
  l2[i]*=inv[i+1]
  l2[i]%=mod
l3=[]
l3.append(l2[0])
for i in range(n-2):
  l3.append(l3[-1]+l2[i+1])
ans=0
for i in range(n-1):
  ans+=l3[i]*l[i]
  ans%=mod
print(ans)

Measured memory_bytes: 67480
#include <bits/stdc++.h>
using namespace std;
int main(){
  int h, w;
  cin >> h >> w;
  string s[h][w];
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cin >> s[i][j];
      if(s[i][j] == "snuke"){
        cout << (char)('A' + j) << i + 1 << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	Yn(a==b&&b==c);
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int[][] graph = new int[N][N];
    for (int i = 0; i < M; i++) {
      int a = scanner.nextInt() - 1;
      int b = scanner.nextInt() - 1;
      graph[a][b] = graph[b][a] = 1;
    }

    boolean[] visited = new boolean[N];
    System.out.println(dfs(N, graph, visited, 0, 0));
  }

  private static int dfs(int N, int[][] graph, boolean[] visited, int numVisited, int id) {
    visited[id] = true;
    numVisited++;
    if (numVisited == N) {
      return 1;
    }
    int count = 0;
    for (int i = 0; i < N; i++) {
      if (graph[id][i] == 1 && !visited[i]) {
        boolean[] copy = new boolean[N];
        System.arraycopy(visited, 0, copy, 0, N);
        count += dfs(N, graph, copy, numVisited, i);
      }
    }
    return count;
  }
}


Measured memory_bytes: 23636
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	vector<int> G(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> G[i];
		--G[i];
	}

	auto loop = false;
	auto u = 0;
	auto ans = 0;
	vector<int> d(N, INT_MAX);
	d[0] = 0;
	while (K > 0)
	{
		auto v = G[u];
		if (!loop && d[v] < INT_MAX)
		{
			loop = true;
			--K;
			ans = v;

			auto num = d[u] - d[v] + 1;
			K %= num;

			u = v;
		}
		else
		{
			--K;
			ans = v;
			d[v] = d[u] + 1;
			u = v;
		}
	}

	cout << ans  + 1 << endl;

	return 0;
}

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

int main() {
  char str[1010];
  scanf("%s", str + 1);
  int len = strlen(str + 1);
  if (str[len] != 's')
    printf("%ss\n", str + 1);
  else
    printf("%ses\n", str + 1);
  return 0;
}

Measured memory_bytes: 3748
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(){
		
		bool chk = true;
		foreach(var n in A){
			if(n % 2 == 1) continue;
			if(n % 3 == 0) continue;
			if(n % 5 == 0) continue;
			chk = false;
		}
		
		Console.WriteLine(chk ? "APPROVED" : "DENIED");
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	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: 13140
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

void solve() {
	int n;
	cin >> n;
	
	vi a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	sort(rall(a));
	
	priority_queue<ii> q;
	int i = 0;
	ll ans = 0;
	q.push({a[i], a[i]});
	i++;
	while(i < n) {
		ii p = q.top(); q.pop();
		ans += p.ff;
		q.push({min(p.ff, a[i]), max(p.ff, a[i])});
		q.push({min(p.ss, a[i]), max(p.ss, a[i])});
		i++;
	}
	
	cout << ans << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

Measured memory_bytes: 6148
from heapq import heappush, heappop

def main():
  n, m, s, g = map(int, input().split())
  s -= 1
  g -= 1
  edges = [[] for _ in range(n)]
  for _ in range(m):
    u, v, t, c = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append((t, t + c, v))
  
  score = {}
  score[(0, 0)] = 0
  que = []
  heappush(que, (0, 0, s))
  while que:
    total, time, node = heappop(que)
    if node == g:
      print(total)
      break
    for start, end, to in edges[node]:
      if start < time:continue
      new_total = total + (start - time)
      if (to, end) not in score or score[(to, end)] > new_total:
        score[(to, end)] = new_total
        heappush(que, (new_total, end, to))

main() 


Measured memory_bytes: 59100
#include <stdio.h>
int main(){
 int d[3];
 int i,s;
 scanf("%d %d %d",&d[0],&d[1],&d[2]);
 for(i=0;i<3;i++){	 
 if(d[i] == 5){s = s + 5 ;}
 if(d[i] == 7){s = s + 7 ;}
 }
 if(s == 17){
 printf("YES");}
 else
   printf("NO");
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n,m = l_in()
h = l_in()

edges=[[] for _ in range(n)]
good=[True]*n

for _ in range(m):
    a,b=l_in()
    if h[a-1] > h[b-1]:
        good[a-1] = good[a-1] and True
        good[b-1] = False
    if h[b-1] > h[a-1]:
        good[b-1] = good[b-1] and True
        good[a-1] = False
    if h[b-1] == h[a-1]:
        good[b-1] = False
        good[a-1] = False

print(sum(good))
        


Measured memory_bytes: 87524
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    int n;
    cin >> n;
    vector<vector<bool>> found(3, vector<bool>(3));
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (bingo[j][k] == b)found[j][k] = true;
            }
        }
    }

    bool ret = false;
    for (int i = 0; i < 3; i++) {
        bool tate = true, yoko = true;
        for (int j = 0; j < 3; j++) {
            if (!found[i][j])yoko = false;
            if (!found[j][i])tate = false;
        }
        if (tate || yoko)ret = true;
    }

    bool l = true, r = true;
    for (int i = 0; i < 3; i++) {
        if (!found[i][i])l = false;
        if (!found[i][2 - i])r = false;
    }
    if (l || r)ret = true;

    cout << (ret ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

int main(){
	fast;	
	int N;
	cin >> N;
 
  ll t = 1,a = 1;
  for(int i = 0; i < N; i++){
    int x,y;
    cin>>x>>y;
	ll n=max(ceil(t/(ld)x),ceil(a/(ld)y));
	t=n*x;
	a=n*y;
  }
  cout << t + a << endl;
}
	


Measured memory_bytes: 256
from collections import Counter

n = int(input())
s = []
for i in range(n):
  s.append(input())

cnt = -1
counter_s = Counter(s)
ans = []
for word, num in counter_s.most_common():
  if cnt == -1 or cnt == num:
    ans.append(word)
    cnt = num
  else:
    break

ans.sort()
for word in ans:
  print(word)

Measured memory_bytes: 45040
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#define pb push_back
#define mk make_pair
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, pair<int, int> >piii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int inf = 1e9;
const LL INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 1e5 + 5;
char s[maxn];
LL d[maxn];
LL qpow(LL a, LL p, LL n){
	LL res = 1;
	for(; p; a = a * a % n, p >>= 1) {
		if(p & 1) {
			res = res * a % n;
		}
	}
	return res;
}
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> s;
	LL res = 0;
	int n = strlen(s);
	d[n - 1] = 1;
	for(int i = n - 2; i >= 0; --i){
		d[i] = 3 * d[i + 1] % M;
	}
	int c = 0;
	// cout << d[0] << endl;
	for(int i = 0; i < n; ++i){
		if(s[i] == '1'){
			if(c == 0) {
				res = (d[i] + 2) % M;
				++c;
			} else {
				LL t = qpow(2, c, M);
				res = (res + (d[i] + 1) * t % M) % M;
				++c;
			}
			// cout << res << endl;
			// res = (res + d[i]) % M;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1152
def slimes(n, sli):

    ans = 0
    sliset = ""

    for i in sli:
        if sliset != i:
            ans += 1
            sliset = i

    return ans

def main():
    n = int(input())
    sli = list(str(input()))
    print(slimes(n, sli))

if __name__ == '__main__':
    main()

Measured memory_bytes: 4084