akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
#include <utility>
#include <bitset>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
const int N=1e4+10;
vector<pi> graph[N];
bitset<N> went;
int dep[N][2],top,rad;
int max(int a,int b){return a>b?a:b;}
void dfs(int now,bool f){
    if(dep[now][f]>top){
        top=dep[now][f];
        rad=now;
    }
    went[now]=true;
    for(pi i:graph[now])if(!went[i.F]){
        dep[i.F][f]=dep[now][f]+i.S;
        dfs(i.F,f);
    }
    return ;
}
int main(){
    int n,l,r,w;
    scanf("%d",&n);
    for(int i=0;i<n;i++)dep[i][0]=dep[i][1]=0;
    went.reset();
    for(int i=1;i<n;i++){
        scanf("%d%d%d",&l,&r,&w);
        graph[l].PB({r,w});
        graph[r].PB({l,w});
    }
    went.reset();
    top=rad=0;
    dep[0][false]=0;
    dfs(0,false);
    went.reset();
    top=0;
    dep[rad][false]=0;
    dfs(rad,false);
    went.reset();
    dep[rad][true]=0;
    dfs(rad,true);
    for(int i=0;i<n;i++)printf("%d\n",max(dep[i][0],dep[i][1]));
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e15;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 1e5 + 100;
const int LOG = 20;
const int mod = 1e9 + 7;
const int MX = 1e6 + 100;
typedef long long li;
const li MOD = 1000000000949747713ll;

int a[MAXN];
int dp[MAXN];

void solve() {
    int n,k;
    cin >>n >> k;
    for(int i=1;i<=n;++i){
        cin >> a[i];
    }
    dp[0] = 0;
    for(int i=1;i<=k;++i){
        bool flag = 0;
        for(int j=1;j<=n;++j){
            if(i - a[j] >=0){
                if(dp[i - a[j]] == 0){
                    flag = true;
                    break;
                }
            }
        }
        if(flag){
            dp[i] = 1;
        }
    }
    if(dp[k]){
        cout <<"First";
    } else{
        cout <<"Second";
    }
}

signed main() {
#ifdef zxc
    debug = 1;
    freopen("../input.txt", "r", stdin);
#else

#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;

    while (t--)
        solve();
    dout << endl << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int cnt = 0;
		if(A*N < B) {
			cnt = A*N;
		}else {
			cnt = B;
		}

		System.out.println(cnt);

   		sc.close();
        return ;

    }
    
}



Measured memory_bytes: 23764
N = int(input())
S = list(input())
for i in range(len(S)):
    s = S[i]
    if ord(s)+N >= 91:
        ss = chr(ord(s) + N-26)
        #print(ss)
        S[i] = ss
    else:
        #print(ord(s)+N)
        ss = chr(ord(s)+N)
        #print(ss)
        S[i] = ss
print(''.join(S))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
int main(){
    boost;
    string s;   cin>>s;
    ll n = s.length(), m = n/2;
    bool spal = true;
    for(ll i = 0; i <= m/2; i++){
        if(s[m-i-1] == s[i] && s[m+i+1] == s[n-i-1] && s[n-i-1] == s[i])    continue;
        spal = false;   break;
    }
    if(spal)    cout<<"Yes"<<endl;
    else        cout<<"No"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{	
		var N = GetLong();
		var H = GetLongs(N);
		long max = 0;
		long cnt = 0;
		for(var i = 0; i < N; i++)
		{
			if(H[i] >= max)
			{
				cnt++;
				max = H[i];
			}
		}
		WriteLine(cnt);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 13396
function Check(a,b) {
  if (a % 3 == 0 || b % 3 == 0 || (a+b)%3 == 0){
    return 'Possible';
  }
  return 'Impossible';
}

function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");
  tmp = input[0].split(" ");

  //文字列から10進数に変換するときはparseIntを使います
  // var firstLineInput = parseInt(input[0], 10);
  var a = parseInt(tmp[0], 10);
  var b = parseInt(tmp[1], 10);

  //出力
  console.log(Check(a,b));
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int n, m;
vector<int> arr;
vector<int> visited;
vector< vector<int> > dy;

void DFS(int cur, int goal){
    for(int i = 0; i < dy[cur].size(); i++){
        if(visited[dy[cur][i]] == 0){
            visited[dy[cur][i]] = visited[cur];
            DFS(dy[cur][i], goal);
        }
    }
}

int main(void){
    cin >> n >> m;
    arr = vector<int>(n + 1, 0);
    visited = vector<int>(n + 1, 0);
    dy = vector<vector<int> >(n + 1);
    for(int i = 1; i <= n; i++) cin >> arr[i];
    for(int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        dy[a].push_back(b);
        dy[b].push_back(a);
    }

    int result = 0;
    for(int i = 1; i <= n; i++){
        if(visited[i] == 0){
            visited[i] = i;
            DFS(i, arr[i]);
        }
    }

    for(int i = 1; i <= n; i++){
        if(visited[i] == visited[arr[i]]) result++;
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 9472
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
    vector<int> par, w;
    
    UnionFind(int n) : par(n, -1), w(n, 0) { }
    void init(int n) { par.assign(n, -1); w.assign(n, 0); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) {
            ++w[x];
            return false;
        }
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        w[x] += w[y];
        ++w[x];
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
 
    int wei(int x) {
        return w[root(x)];
    }
};

void solve() {
	int n, m; cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int x, y ,z; cin >> x >> y >> z;
        --x; --y;
        uf.merge(x, y);
    }
    set<int> se;
    rep(i, n) {
        se.insert(uf.root(i));
    }
    cout << se.size() << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long d = sc.nextLong();
        int cnt = 0;

        for (int i = 0; i < n; i++) {
            long tmp1 = sc.nextLong();
            long tmp2 = sc.nextLong();
            long dis = tmp1 * tmp1 + tmp2 * tmp2;
            if (dis <= d * d) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

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



signed main() {
 double w,h,x,y;
 cin>>w>>h>>x>>y;
 if(2*x==w&&2*y==h)cout<<w*h/2.0<<' '<<1;
 else cout<<w*h/2.0<<' '<<0;



 
   

      return 0;

}


Measured memory_bytes: 256
il = lambda: list(map(int, input().split()))
ils = lambda n, s="int(input())": [eval(s) for _ in range(n)]

s = input()
t = input()
S = ""
T = ""

se = dict()
cnt = 0
for j in s:
    if not(j in se.keys()):
        se[j] = cnt
        cnt += 1
    S += str(se[j])

se = dict()
cnt = 0
for j in t:
    if not(j in se.keys()):
        se[j] = cnt
        cnt += 1
    T += str(se[j])

if S == T:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4144
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var NK = IO.RSInt;
            var a = IO.RSInt;

            NK[0] -= NK[1];
            int g = 1;
            while (NK[0] > 0)
            {
                g++;
                NK[0] -= NK[1] - 1;
            }
            WriteLine(g);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 26492
import bisect
n, m, k = map(int, input().split())
aList = list(map(int, input().split()))
bList = list(map(int, input().split()))

cList = [0]
dList = [0]
for a in aList:
    t = a + cList[-1]
    if t <= k:
        cList.append(a + cList[-1])
    else:
        break
for b in bList:
    t = b + dList[-1]
    if t <= k:
        dList.append(b + dList[-1])
    else:
        break
cList.pop(0)
dList.pop(0)
n = len(cList)
m = len(dList)

if len(cList) == 0:
    print(bisect.bisect_right(dList, k))
else:
    a = 0
    for i in range(0, n+1):
        if i == n:
            lim = k
        else:
            lim = k - cList[n-1-i]
        a = max(a, n - i + bisect.bisect_right(dList, lim))
    print(a)

Measured memory_bytes: 119548
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end
int main() {
    int N,M,X;
    int a=0,b=0;
    int A[101];
    cin >> N >> M >> X;

    rep(i, M){
        cin >> A[i];
        if(X>A[i]) a++;
        else b++;
    }
    cout << min(a,b) << endl;
    return 0;
}



Measured memory_bytes: 256
n=int(input())
l=[int(x) for x in input().split()]

l.sort()
ans=0

for i in range(len(l)-2):
    for j in range(i+2,len(l)):
        a=l[i]
        c=l[j]
        b_min=i+1
        b_max=j-1
        while b_max-b_min>1:
            if l[(b_max+b_min)//2]>c-a:
                b_max=(b_max+b_min)//2
            else:
                b_min=(b_max+b_min)//2
        if l[b_min]>c-a:ans+=j-b_min
        elif l[b_max]>c-a:ans+=j-b_max
print(ans)

Measured memory_bytes: 74316
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
	int N;
	cin >> N;
	int ans;

	if(N%111 != 0)
	{
		ans = ((N / 111) + 1) * 111; 
	}
	else
	{
		ans = N;
	}

	cout << ans << endl;

	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    //cin >> T;
    while(T--){
       string s,t;
       cin>>s>>t;
       int ans=0;
       rep(i,s.length()){
        if(s[i]!=t[i]) ans++;
       }
       cout<<ans<<el;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){cout<<a[i]<<endl;}
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  vll a(5);ll i,ans;ain(i,5,a);ans=0;
  //caricurate
  rep(i,5){ans+=(a[i]/10)*10+10*(a[i]%10?1:0);}
  vll s(5);rep(i,5){s[i]=ans-(10-(a[i]%10?a[i]%10:10));}
  //output
  cout<<*min_element(s.begin(),s.end())<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = long long ;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

struct Sieve {
    ll n;
    vi f;
    vi primes;
    // constructor
    Sieve(ll n=1) : n(n), f(n+1,0) {
        f.at(0) = -1;
        f.at(1) = -1;
        for(ll i = 2; i <= n; ++i){
            if (f.at(i)!=0) continue;
            primes.push_back(i);
            f.at(i) = i;
            for (ll j = i*i; j <= n; j += i) {
                if(f.at(j)==0) f.at(j) = i;
            }
        }
    }
    // xが素数かを判定
    bool isPrime(ll x) {
        return f.at(x) == x;
    }
    // xを素因数分解する関数(分解後の値を昇順の配列にして返す)
    // (100) => ([2,1,5,5]);
    vi primeFactorizedList(ll x) {
        vi res;
        while (x != 1) {
            res.push_back(f.at(x));
            x /= f.at(x);
        }
        return res;
    }
    // 素因数分解したときの各因数の個数をsecondに持つpairにする
    vector<P> primeFactorizedPair(ll x) {
        vi fl = primeFactorizedList(x);
        if (fl.size() == 0) return {};
        vector<P> res(1, P(fl.at(0), 0));
        for (ll p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    ll n;
    cin >> n;
    Sieve s = Sieve(55556);
    vi cand;
    for(ll p:s.primes){
        string str = to_string(p);
        if((str.at(str.size()-1)-'0')==1){
            cand.push_back(p);
        }
        if(cand.size()>55) break;
    }
    rep(i,n) cout << cand.at(i) << " ";
    cout << endl;
}

Measured memory_bytes: 768
N, A, B = gets.split.map(&:to_i)

if N == 1
    if A == 1 && B == 1
        print 1
    else
        print -1
    end

elsif N == 2
    if A == 2 && B == 1
        print '1 2'
    elsif A == 1 && B == 2
        print '2 1'
    else
        print -1
    end

# 1 2 3 4 5 ...
elsif B == 1
    if A == N
        print (1..N).to_a.join(' ')
    else
        print -1
    end

#####   middle = 3, wide = 13
#####
###
#
#
elsif A + B - 1 <= N && N <= A * B 
    stairs = Array.new(B){Array.new()}
    middle = (N - A + B - 2) / (B - 1)
    wide = N - A + middle
    wide.times do |i|
        stairs[i % B].unshift(N - i)
    end
    stairs[0] = (1..(N - wide)).to_a + stairs[0]
    result = []

    str = ''
    stairs.each do |stair|
        str << stair.join(' ')
        str << ' '
    end
    str.chop!
    print str

else
    print -1 
end


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

int main() 
{
	int a, b;
	cin >> a >> b;
	string ans1, ans2;
	for(int i=0; i< (int) a; i++)
		ans1 += (b + '0');
	for(int i=0; i< (int) b; i++)
		ans2 += (a + '0');

	cout << (a < b ? ans2 : ans1) << '\n';
}

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

ll f(ll f3,ll f5,ll f7, ll val, ll n){
    ll sum=0;
    if(val>n)return 0;
    if(f3&&f5&&f7)sum++;
    sum+=f(f3+1,f5,f7,val*10+3,n);
     sum+=f(f3,f5+1,f7,val*10+5,n);
      sum+=f(f3,f5,f7+1,val*10+7,n);
      return sum;
}

int main(){
  int n,k;cin>>n>>k;
  vector<ll> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(),v.end());
  ll ans=1e9;
  for(int i=0;i<n-k+1;i++){
      ans=min(ans,v[i+k-1]-v[i]);
  }
  cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;

int main()
{
    while (1) {
        int w, d; cin >> w >> d;
        if (!w) break;
        int cnt1[21] = {}, cnt2[21] = {};
        loop (w, i) {
            int h; cin >> h;
            cnt1[h]++;
        }
        loop (d, i) {
            int h; cin >> h;
            cnt2[h]++;
        }

        int ans = 0;
        loop (21, i) {
            ans += max(cnt1[i], cnt2[i]) * i;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define MN 100005
using namespace std;
inline ll in(){
    ll x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
ll a[MN],n,mx,mn,x,y;
int main()
{
	n=in();
	for (int i=1;i<=n;++i) a[i]=in();a[n+1]=2ll;mn=mx=2ll;
	for (int i=n;i;--i){
		mx/=a[i];if (!mx) {printf("-1");return 0;}
		mx=(mx+1ll)*a[i]-1ll;
		if (mn%a[i]) mn=(mn/a[i]+1ll)*a[i];
	}x=mx,y=mn;
	for (int i=1;i<=n;++i){
		x-=(x%a[i]);y-=(y%a[i]);
	}if (x!=2||y!=2) {printf("-1");return 0;}
	printf("%lld %lld",mn,mx);return 0;
}

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


int main() {
  queue <pair<string, int>> Q;
 
  int n,q; 
  cin >> n >> q;;
  for(int i = 0;i < n;i++) {
    string name;
    int qty; 
    cin >> name >> qty;
    Q.push(make_pair(name, qty));
  }

  int elapsed_time = 0;
  while (!Q.empty()) {
    pair <string, int> p;
    p = Q.front();
    Q.pop();
    int remain_time;
    remain_time = p.second - q;
    if (remain_time > 0) {
      Q.push(make_pair(p.first, remain_time));
      elapsed_time += q;
    } else {
      elapsed_time += p.second;
      cout << p.first << " " << elapsed_time << endl;
    };
  }

  return 0;
}


Measured memory_bytes: 6248
#include <iostream>
#include <string>

int main()
{
	int a, b, k;
	std::cin >> a >> b >> k;

	while (true)
	{
		if (a % 2 == 1)a -= 1;
		a /= 2;
		b += a;
		k -= 1;
		if (k == 0)break;

		if (b % 2 == 1)b -= 1;
		b /= 2;
		a += b;
		k -= 1;
		if (k == 0)break;
	}
	std::cout << a <<" "<< b;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  
  vector<int> index(N);
  int max;
  for (int j=0;j<N;j++){
    max = 0;
   for (int i=0;i<N;i++){
    if ((max <= vec.at(i))&&(j==0)){
       max = vec.at(i);
       index.at(j) = i;
    }
    if ((max < vec.at(i)) && (j>0)){
     for (int k=0;k<j;k++){
      if (index.at(k)==i){
       break;
      }
      else if (k==j-1){
       max = vec.at(i);
       index.at(j) = i;
      }
     }
    }
   }
  }
  
  int sum=0;
  if (N%2==0){
    for (int i=0;i<N;i+=2){
      sum += vec.at(index.at(i)) - vec.at(index.at(i+1));
    }
  }
  else {
    for (int i=0;i<N-1;i+=2){
      sum += vec.at(index.at(i)) - vec.at(index.at(i+1));
    }
    sum += vec.at(index.at(N-1));
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
using namespace std;
#define N 1005
typedef long long ll;

ll n,m;

int main(){
    string s="";
    cin>>n;
//    cout<<n;
    while(n){
        if(n%26==0){
            n/=26;
            n--;
            s+='z';
        }
        else{
            m=n/26;
            m*=26;
            s+='a'-1+(n-m);
            n/=26;
        }
    }
    reverse(s.begin(),s.end());
    cout<<s;
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
int main (){
	int n, k;
	scanf ("%d %d\n", &n, &k);
	int arr[n];
		for (int A=0;A<n;A++ ){
			scanf("%d", &arr[A]);
		}
		for (int j=0;j<n-k;j++){
			if(arr[j]<arr[j+k]){
				printf("Yes\n");
			}else{
				printf("No\n");
			}
		}

	
	return 0;
}

Measured memory_bytes: 2416
# ABC084C - Snuke Festival
# Binary search
from bisect import bisect_left, bisect_right

n = int(input())
A, B, C = [sorted(list(map(int, input().rstrip().split()))) for _ in range(3)]
lgth = len(C)
ans = 0
for i in B:
    ans += bisect_left(A, i) * (lgth - bisect_right(C, i))
print(ans)

Measured memory_bytes: 23244
#include <bits/stdc++.h>
#define pb push_back
#define s(a, x, y) sort(a.begin()+x, a.begin()+y);
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
char x;
int main() {
	cin>>x;
	if(x>='A'&&x<='Z') cout<<"A";
	else cout<<"a";
	return 0;
}

Measured memory_bytes: 3528
N=int(input())
A=[int(input()) for i in range(N)]
B=set()
B.add(1)
b=1
count=0
while True:
    b=A[b-1]
    count+=1
    if b==2:
        print(count)
        break
    elif b in B:
        print(-1)
        break
    else:
        B.add(b)

Measured memory_bytes: 13200
a, b = gets.split(' ')

if a == 'H' && b == 'H'
  puts 'H'
elsif a == 'H' && b == 'D'
  puts 'D'
elsif a == 'D' && b == 'H'
  puts 'D'
elsif a == 'D' && b == 'D'
  puts 'H'
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define oo(i,a) for (int i = 0; i < (a); i++)
#define ooo(i,a,b) for (int i = a; i < (b); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const char newl = 10;
const int MOD = 998244353;
const int N = 100005;
// set N | watch out for overflow | n == 1 |
vector<vector<int>> adj;
int d[2005];
vector<int> cnt;
void run(){
   int n;
   int x, y;
   cin >> n;
   cin >> x >> y;
   adj.resize(n + 1);
   for (int i = 1; i < n; i++) {
      adj[i].pb(i + 1);
      adj[i + 1].pb(i);
   }
   adj[x].pb(y);
   adj[y].pb(x);
   cnt.resize(n);
   for (int i = 1; i <= n; i++){
      queue<int> q;
      memset(d, -1, sizeof d);
      q.push(i);
      d[i] = 0;
      while (!q.empty()){
         int f = q.front(); q.pop();
         for (auto &u : adj[f]){
            if (d[u] == -1){
               d[u] = d[f] + 1;
               q.push(u);
            }
         }
      }
      for (int j = 1; j <= n; j++) cnt[d[j]]++;
   }
   for (int k = 1; k < n; k++){
      cout << cnt[k] / 2 << newl;
   }
   return ;
}
int main(){
   ios_base::sync_with_stdio(0);
   cout.tie(0);cin.tie(0);
   int t = 1;
   // cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      // cout << "Case #" << tc << ": ";
      run();
   }
   return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef long long ll;

const int MOD = 1000000007;

void solve() {
  int N, X;
  cin >> N >> X;
  int ans = 1, cur = 0;
  for (int i = 0; i < N; i++) {
    int l;
    cin >> l;
    cur += l;
    if (cur > X) {
      break;
    } else {
      ans++;
    }
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


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

using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main(){
    int n;
    cin>>n;
    int v[n],c[n];
    for(int i=0;i<n;i++)
        cin>>v[i];
     for(int i=0;i<n;i++)
        cin>>c[i];
    int sum=0;
    for(int i=0;i<n;i++){
        if(v[i]>c[i])
            sum+=(v[i]-c[i]);
           
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int T = sc.nextInt();
	int c=0;
	int t=0;
	int minC=1000;
	boolean cre = false;
	for(int i=0;i<N;i++){
	    c=sc.nextInt();
	    t=sc.nextInt();
	    if(t <= T){
		if(c<minC)
		    minC=c;
		cre=true;
	    }
	}
	if(cre)System.out.print(minC);
	else System.out.print("TLE");
    }
}


Measured memory_bytes: 23124
def main():
    N = int(input())
    h = list(map(int, input().split()))
    costs = [0] * N
    costs[0] = 0
    costs[1] = abs(h[0] - h[1])

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

    print(costs[N-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 13928
function main(input) {
  const arg = input.split('\n')
  const number = arg[0]
  let items = arg.slice(1, number + 1)
  
  const set = new Set(items)
  items = Array.from(set)
 
  console.log(set.size-1)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 57848
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var k = sc.nextInt();
		var l = new int[k];
		var r = new int[k];
		for (var i = 0; i < k; i++) {
			l[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		sc.close();

		var calc = new Main().new ModCalc();
		var count = new int[n + 1];
		var sum = new int[n + 1];
		count[1] = 1;
		sum[1] = 1;
		for (var i = 2; i <= n; i++) {
			for (var j = 0; j < k; j++) {
				var min = l[j];
				var max = r[j];
				if (i - min > 0) {
					count[i] = calc.add(count[i], sum[i - min]);
				}
				if (i - max - 1 > 0) {
					count[i] = calc.subtract(count[i], sum[i - max - 1]);
				}
			}
			sum[i] = calc.add(sum[i - 1], count[i]);
		}
		System.out.println(count[n]);
	}

	public class ModCalc {
		private int mod = 998244353;

		public ModCalc() {
		}

		public int add(int a, int b) {
			return (int) (((long) a + b) % mod);
		}

		public int subtract(int a, int b) {
			return (int) (((long) a - b + mod) % mod);
		}

		public int multiply(int a, int b) {
			return (int) (((long) a * b) % mod);
		}

		public int divide(int a, int b) {
			return multiply(a, pow(b, mod - 2));
		}

		public int pow(int n, int k) {
			if (k == 0) {
				return 1;
			} else if (k % 2 == 0) {
				int p = pow(n, k / 2);
				return multiply(p, p);
			} else {
				int p = pow(n, (k - 1) / 2);
				return multiply(multiply(p, p), n);
			}
		}

		public int combine(int n, int k) {
			int sum1 = 1;
			int sum2 = 1;
			for (int i = 0; i < k; i++) {
				sum1 = multiply(sum1, n - i);
				sum2 = multiply(sum2, i + 1);
			}
			return divide(sum1, sum2);
		}
	}
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/02  Problem: ABC 101 D / Link: http://abc101.contest.atcoder.jp/tasks/abc101_d  ----- */


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	auto digitsum = [](LL a) {
		LL ret = 0;
		while (a) {
			ret += a % 10;
			a /= 10;
		}
		return ret;
	};

	if (0) {
		VL ret;
		FOR(i, 1, 100000) {
			bool ok = 1;
			FOR(j, i + 1, 100000) {
				ok &= (i*digitsum(j) <= j * digitsum(i));
			}
			if (ok) {
				ret.push_back(i);
			}
		}
		for (auto it : ret) {
			cout << it << ", ";
		}cout << endl;
		return 0;
	}

	if (0) {
		FOR(i, 1, 1000 + 1) {
			cout << i << " " << 1.0*i / (1.0*digitsum(i)) << (i % 10 == 9 ? " Suf9" : "") << endl;
		}

		return 0;
	}

	LL N;
	cin >> N;
	VL ans;
	LL ten = 1;
	FOR(i, 0, 15) {
		FOR(j, 1, 135 + 1) {
			ans.push_back(ten*(j + 1) - 1);
		}
		ten *= 10;
	}
	SORT(ans);
	UNIQ(ans);
	DD(de(SZ(ans)));
	set<LL>prohibit(ALL(ans));
	FOR(i, 0, SZ(ans)) {
		FOR(j, i + 1, SZ(ans)) {
			LL a = ans[i], b = ans[j];
			if (prohibit.count(a) && prohibit.count(b) && a*digitsum(b) > b*digitsum(a)) {
				prohibit.erase(a);
				break;
			}
		}
	}
	DD(de(SZ(prohibit)));
	FOR(k, 0, N) {
		auto it = prohibit.begin();
		cout << *it << endl;
		prohibit.erase(it);
	}

	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N;
	double W, ans = 0.0;
	cin >> N >> W;
	vector<pair<double, double>> vw(N);
	for (pair<double, double>& i : vw) cin >> i.first >> i.second;
	sort(vw.begin(), vw.end(), [](pair<double, double>& a, pair<double, double>& b) { return a.first / a.second > b.first / b.second; });
	for (pair<double, double>& i : vw) {
		if (W < i.second) {
			ans += W / i.second * i.first;
			break;
		}
		else {
			W -= i.second;
			ans += i.first;
		}
	}
	printf("%.6f\n", ans);
}


Measured memory_bytes: 4460
//arc082_d.cpp
//Sat Jul 20 19:04:48 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	vector<int> nums;
	for (int i=0;i<n;i++){
		int temp;
		cin >> temp;
		if (temp == i+1){
			nums.push_back(i+1);
		}
	}

	if (nums.size()==0){
		cout << "0" << endl;
		return 0;
	}

	int ans = 0;
	int i=0;
	for (i=0;i<nums.size()-1;i++){
		if (nums[i]+1==nums[i+1]){
			i++;
		}
		ans++;
	}

//	cout << i << endl;

	if (i==nums.size()-1){
		ans++;
	}

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

Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int MAX = 101010;
  vi is_prime(MAX, 1);
  is_prime[0] = 0; is_prime[1] = 0;
  for (int i = 2; i < MAX; i++) {
    if(is_prime[i]){
      for (int j = 2*i; j < MAX; j += i) {
        is_prime[j] = 0;
      }
    }
  }

  int q; cin >> q;
  vi l(q), r(q);
  rep(i, q){
    cin >> l[i] >> r[i];
  }

  vi C(MAX,0);
  rep(i, MAX){
    if(is_prime[i] && is_prime[(i+1)/2]) C[i]++;
  }
  vi S(MAX+1,0);
  rep(i, MAX) S[i+1] = S[i] + C[i];

  rep(i, q){
    std::cout << S[r[i]+1] - S[l[i]] << '\n';
  }
  return 0;
}


Measured memory_bytes: 2560
from itertools import permutations
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
X = sorted(list(permutations(list(range(1,N+1)))))
for i,x in enumerate(X):
    if x==P: a=i
    if x==Q: b=i
print(abs(a-b))

Measured memory_bytes: 8308
a, b, c, x, y = map(int, input().split())
if(a + b < 2 * c):
    print(a * x + b * y)
else:
    if(x > y):
        print(min(x * 2 * c, y * 2 * c + (x - y) * a))
    else:
        print(min(y * 2 * c, x * 2 * c + (y - x) * b))

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 2e5 + 5, M = 3 * N ;
using namespace std ;

bool vis[M], f[M] ;
int n, e, ter[M], nxt[M], lnk[N], rec[M], sza[N], szb[N], pos[N] ;

void add(int x, int y) {
	ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e, rec[e] = e + 1 ;
	ter[++ e] = x, nxt[e] = lnk[y], lnk[y] = e, rec[e] = e - 1 ;
}

void dfs(int p) {
	for (int i = lnk[p] ; i; i = lnk[p]) if (vis[i]) {
		int u = ter[i] ;
		lnk[p] = nxt[i] ;
		vis[i] = vis[rec[i]] = false, f[i] = true ;
		dfs(u) ;
	} else lnk[p] = nxt[i] ;
}

int main() {
	scanf("%d", &n) ;
	int x ;
	rep(i, 1, n) {
		scanf("%d", &x) ;
		if (x == - 1) add(2 * n + 1, i) ; else
			add(x, i), ++ sza[x] ;
	}
	rep(i, 1, n) {
		scanf("%d", &x) ;
		if (x == - 1) add(2 * n + 1, n + i) ; else
			add(x + n, i + n), ++ szb[x] ;
	}
	rep(i, 1, n) if ((sza[i] & 1) != (szb[i] & 1)) {
		puts("IMPOSSIBLE") ;
		return 0 ; 
	}
	rep(i, 1, n) if (sza[i] & 1) ; else add(i, i + n), pos[i] = e ;
	puts("POSSIBLE") ;
	rep(i, 1, e) vis[i] = true ;
	dfs(2 * n + 1) ;
	rep(i, 1, n) if (sza[i] & 1) printf("0 ") ; else {
		if (f[pos[i]]) printf("1 ") ; else printf("-1 ") ;
	}
	puts("") ;
	return 0 ;
}

Measured memory_bytes: 15360
n = int(input())
s = input()

west,east = [0], [0]
w,e = 0,0
for i in range(1,n):
    if s[i-1] == 'W':
        w += 1
    west.append(w)
    if s[-i] == 'E':
        e += 1
    east.append(e)

ans = 10**9
for w,e in zip(west, east[::-1]):
    if ans > w + e:
        ans = w+e
print(ans)

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

using namespace std;
using ll = long long;

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

  ll k;
  cin >> k;

  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  int ans = 1;
  ll r = 7 % k;
  while (r != 0) {
    r = r * 10 + 7;
    r %= k;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3664
#include <iostream>

using namespace std;

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

    int N, M;
    cin >> N >> M;
    int num[N + 1];
    bool red[N + 1];
    for (int i = 1; i <= N; ++i) {
        num[i] = 1;
        red[i] = false;
    }
    red[1] = true;

    for (int i = 0; i < M; ++i) {
        int xi, yi;
        cin >> xi >> yi;
        if (red[xi])
            red[yi] = true;
        --num[xi];
        ++num[yi];
        if (!num[xi])
            red[xi] = false;
    }

    int res = 0;
    for (int i = 1; i <= N; ++i) {
        if (red[i])
            ++res;
    }

    cout << res << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int k,num[] = {0,0,0,0,0},temp=0,q;
  cin >> num[0] >> num[1] >> num[2] >> k;
  for(int p = 0; p < 2; p++){
		for(q = p + 1; q < 3; q++){
			if(num[p] < num[q]){
				temp = num[p];
				num[p] = num[q];
				num[q] = temp;
			}
		}
	}
  for(int m = 0;m<k;m++) num[0] = num[0]*2;
  cout << num[0]+num[1]+num[2] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] l = new int[n];
			for (int i = 0; i < n; i++) {
				l[i] = scanner.nextInt();
			}
			scanner.nextLine();
			Arrays.sort(l);
			int sum = 0;
			for (int i = 0; i < n - 1; i++) {
				sum += l[i];
			}
			if (sum > l[n - 1]) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000

int main(){

	string S,T;
	cin>>S>>T;
	
	vector<int> SA(S.size()+1,0),SB(T.size()+1,0);
	
	for(int i=1;i<=S.size();i++){
		if(S[i-1] == 'A')SA[i] = 1;
		else SA[i]=2;
		SA[i]+=SA[i-1];
	}
	
	for(int i=1;i<=T.size();i++){
		if(T[i-1] == 'A')SB[i] = 1;
		else SB[i]=2;
		SB[i]+=SB[i-1];
	}
	
	int Q;
	cin>>Q;
	
	for(int i=0;i<Q;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		
		int X = SA[b] - SA[a-1];
		int Y = SB[d] - SB[c-1];
		
		X = abs(X-Y);
		
		if(X%3==0)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	
	return 0;
}

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

using namespace std;

bool checker(double a, double b,double x, double y, double px, double py, bool f);

double calc_slope(double x1, double y1, double x2, double y2);

int main(){
  double x1,y1,x2,y2,x3,y3,xp,yp;
  double a1, a2, a3, b1, b2, b3;
  vector<double> x1s,y1s,x2s,y2s,x3s,y3s,xps,yps;
  while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
    x1s.push_back(x1);
    y1s.push_back(y1);
    x2s.push_back(x2);
    y2s.push_back(y2);
    x3s.push_back(x3);
    y3s.push_back(y3);
    xps.push_back(xp);
    yps.push_back(yp);
  }

  for(int i=0; i<x2s.size(); i++){
    bool flag = true, f;
    x1 = x1s[i];
    y1 = y1s[i];
    x2 = x2s[i];
    y2 = y2s[i];
    x3 = x3s[i];
    y3 = y3s[i];
    xp = xps[i];
    yp = yps[i];


    a1 = calc_slope(x1,y1,x2,y2);
    if(a1==0 && y1==y2){
      b1 = y1;
      f = false;
    }else if(a1==0 && x1==x2){
      b1 = x1;
      f = true;
    }else{
      b1 = -a1*x1+y1;
    }
    flag &= checker(a1,b1,x3,y3,xp,yp,f);

    a2 = calc_slope(x2,y2,x3,y3);
    if(a2==0&&y2==y3){
      b2 = y2;
      f = false;
    }else if(a2==0&&x2==x3){
      b2 = x2;
      f = true;
    }else{
      b2 = -a2*x2+y2;
    }
    flag &= checker(a2,b2,x1,y1,xp,yp,f);

    a3 = calc_slope(x3,y3,x1,y1);
    if(a3==0&&y3==y1){
      b3 = y3;
      f = false;
    }else if(a3==0&&x3==x1){
      b3 = x3;
      f = true;
    }else{
      b3 = -a3*x3+y3;
    }
    flag &= checker(a3,b3,x2,y2,xp,yp,f);

    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}

bool checker(double a, double b, double ox, double oy, double px, double py, bool flag){
  if(a == 0 && flag){
    if(b < ox && b < px){
      return true;
    }
    else if(b > ox && b > px){
      return true;
    }else{
      return false;
    }
  }else if(a==0){
    if(b < oy && b < py){
      return true;
    }
    else if(b > oy && b > py){
      return true;
    }else{
      return false;
    }
  }

  if(oy < a*ox+b && py < a*px+b){
    return true;
  }
  else if(oy > a*ox+b && py > a*px+b){
    return true;
  }
  else{
    return false;
  }
}

double calc_slope(double x1, double y1, double x2, double y2){
  if(x1 > x2){
    return (y1-y2)/(x1-x2);
  }else if(x1 < x2){
    return (y2-y1)/(x2-x1);
  }else{
    return 0;
  }
}

Measured memory_bytes: 1248
//
//  main.cpp
//  2
//
//  Created by RISHAV SINGH MEHTA on 01/03/20.
//  Copyright © 2020 RISHAV SINGH MEHTA. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <set>
#define ll long long
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    ll int i,j,k,l,N,M,a,b,c;
    map<ll int, bool> bb,mz;
    ll int A[5][5],B[5][5]={0};
    for (i=0; i<3; i++) {
        for (j=0; j<3; j++) {
            cin>>c;
            A[i][j]=c;
            if (i==j) {
                bb[c]=true;
            }
            if ((i+j)==2) {
                mz[c]=true;
            }
        }
    }
    cin>>N;
    b=0;a=0;
    bool yeh=false;
    for (i=0; i<N; i++) {
        cin>>c;
        if (bb[c]==true) {
            b=b+1;
            bb[c]=false;
        }
        if (mz[c]==true) {
            a=a+1;
            mz[c]=false;
        }
        for (j=0; j<3; j++) {
            for (k=0; k<3; k++) {
                if (A[j][k]== c) {
                    B[j][k]=1;
                }
            }
        }
    }
    if (b==3 || a==3) {
        yeh= true;
    }
    if (yeh == false) {
        for (i=0; i<3; i++) {
            for (j=0; j<3; j++) {
                if (B[i][j]==1) {
                    yeh=true;
                }else{
                    yeh=false;
                    break;
                }
            }
            
            if (yeh == true) {
                break;
            }
        }
    }
    if (yeh==false) {
        for (i=0; i<3; i++) {
            for (j=0; j<3; j++) {
                if (B[j][i]==1) {
                    yeh=true;
                }else{
                    yeh=false;
                    break;
                }
            }
            if (yeh == true) {
                break;
            }
        }
    }
    if (yeh == true) {
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}



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

#define ll long long

#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
    int n,a,b; cin>>n>>a>>b;
    int ans;
    ans = min(n*a,b);
    printf("%d\n",ans);
    return 0;  
}

Measured memory_bytes: 256