akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
using namespace std;

class Process {
	int time;
	string name;
public:
	Process(int t, char* n) {
		time = t;
		name = n;
	}
	int take(int n) {
		time -= n;
		if (time > 0) return -1; //?¶???±?????????
		else return time + n;
	}
	string getname() { return name; }
};

int main() {
	int quontam, num, now = 0;
	queue<Process> processes;

	scanf("%d %d", &num, &quontam);

	for (int i = 0; num > i; i++) {
		char str[11];
		int time;
		scanf("%s %d", str, &time);
		processes.push(Process(time, str));
	}
	while (!processes.empty()) {
		int taken = processes.front().take(quontam);
		if (taken == -1) {
			now += quontam;
			processes.push(processes.front());
		}
		else {
			now += taken;
			printf("%s %d\n", processes.front().getname().c_str(), now);
		}
		processes.pop();
	}
	return 0;
}

Measured memory_bytes: 6384
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn pow_mod(base: i64, power: i64, modulo: i64) -> i64 {
    let mut base = base;
    let mut power = power;
    let mut ans = 1;
    while power > 0 {
        if power & 1 == 1 {
            ans = ans * base % modulo;
        }
        power >>= 1;
        base = base * base % modulo;
    }
    ans
}

#[allow(dead_code)]
fn inv_mod(a: i64, modulo: i64) -> i64 {
    pow_mod(a, modulo - 2, modulo)
}

const MOD: i64 = 998244353;
const FACT_MAX: usize = 300100;
static mut FACTORIAL: [i64; FACT_MAX + 1] = [0; FACT_MAX + 1];
static mut RFACTORIAL: [i64; FACT_MAX + 1] = [0; FACT_MAX + 1];
fn init_fact() {
    unsafe {
        if FACTORIAL[0] == 0 {
            FACTORIAL[0] = 1;
            for i in 1..FACT_MAX + 1 {
                FACTORIAL[i] = (FACTORIAL[i - 1] * i as i64) % MOD;
            }
            RFACTORIAL[FACT_MAX] = inv_mod(FACTORIAL[FACT_MAX], MOD);
            for i in (0..FACT_MAX).rev() {
                RFACTORIAL[i] = RFACTORIAL[i + 1] * (i as i64 + 1) % MOD;
            }
        }
    }
}
#[allow(dead_code)]
fn fact(n: usize) -> i64 {
    init_fact();
    unsafe { FACTORIAL[n] }
}
#[allow(dead_code, unused_comparisons)]
fn combi(n: usize, m: usize) -> i64 {
    if n < m || m < 0 {
        return 0;
    }
    init_fact();
    unsafe { FACTORIAL[n] * RFACTORIAL[m] % MOD * RFACTORIAL[n - m] % MOD }
}

fn main() {
    let n = read::<usize>();
    let a = read::<i64>();
    let b = read::<i64>();
    let k = read::<i64>();
    let mut ans = 0;
    for acnt in 0..n + 1 {
        let rest = k - a * acnt as i64;
        if rest < 0 || rest % b != 0 || rest / b > n as i64 {
            continue;
        }
        let bcnt = rest / b;
        // println!("{} {}", acnt, bcnt);
        ans = (ans + combi(n, acnt as usize) * combi(n, bcnt as usize) % MOD) % MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 8956
#include<bits/stdc++.h>
using namespace std;
int main(){
int x,n;
cin >> x >> n;
vector<int>a(n+1);
vector<bool>b(110,0);
for(int i = 0;i<n;i++) {cin >> a[i];b[a[i]] = 1;}
int mini = INT_MAX;int ans = -1;
for(int i = 0;i<105;i++){
    if(b[i]==0) {
            int j = abs(x-i);
            if(j<mini){ans = i;mini = j;}
}}
cout << ans;
return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int tb[10][10];

int check(vector<int>a){
  int res=0;
  for(int i=0;i<a.size();i++)res=tb[res][a[i]];
  return res;
}

int main(){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)cin>>tb[i][j];
  
  int ans=0;
  for(int i=0;i<10000;i++){
    int n=i;
    vector<int> a;
    while(n)a.push_back(n%10),n/=10;
    while(a.size()<4)a.push_back(0); 
    reverse(a.begin(),a.end());
    int res=check(a);
    a.push_back(res);
    set <vector<int> > used;
    
    int flg=0;
    for(int i=0;i<5;i++)
      for(int j=0;j<10;j++){
	int tmp=a[i];
	if(a[i]==j)continue;
	a[i]=j;
	flg|=!check(a);
	a[i]=tmp;
      }
    
    for(int j=0;j<a.size()-1;j++){
      swap(a[j],a[j+1]);      
      if(a[j]==a[j+1]||used.count(a))continue;
      used.insert(a);
      flg|=!check(a);
      swap(a[j],a[j+1]);
    }
    ans+=flg;
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 3152
import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	    String s[]=br.readLine().split(" ");
      	int a=Integer.parseInt(s[0]);
		int b=Integer.parseInt(s[1]);
      	System.out.println(a*b);
    }
}

Measured memory_bytes: 25340
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

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

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

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

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

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int H, W, N;
    cin >> H >> W >> N;
    cout << round_up(N, max(H, W)) << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N, ans=1e17;
	ll a[55], b[55];

	cin >> N;
	rep(i,N) cin >> a[i];
	rep(i,N) cin >> b[i];

	rep(i,N) if( a[i] != b[i] && a[i] <= b[i]*2 ){
		cout << -1 << endl;
		return 0;
	}

	ll cost = (1ll<<50)-1;
	rrep(n,52) if( cost & (1ll<<n) ){
		ll k = cost ^ (1ll<<n);
		vector<int> v;
		rep(i,52) if( k&(1ll<<i) ){
			v.push_back(i+1);
		}
		ll dp[52]={};
		rep(i,51) dp[i] = (1ll<<i);
		reps(i,1,51) for(auto t: v){
			dp[i] |= dp[i%t];
		}
		bool ok = true;
		rep(i,N) if( !(dp[a[i]] & (1ll << b[i])) ){
			ok = false;
		}
		if(ok) cost = k;
	}
	ans = cost * 2ll;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define MAXN 1005
map<int,int> A;
int main(){
	int n;
	cin>>n;
	while(n--){
		int tmp;
		cin>>tmp;
		A[tmp]++;
	}
	int num=0;
	for(map<int,int>::iterator it=A.begin();it!=A.end();it++){
		if(it->second % 2==1)
			num++;
	}
	cout<<num;
	return 0;
}

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

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

    if(d == 22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
    else if(d == 23){
        cout << "Christmas Eve Eve" << endl;
    }
    else if(d == 24){
        cout << "Christmas Eve" << endl;
    }
    else{
        cout << "Christmas" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N;cin>>N;
  static int t[100010],x[100010],y[100010];
  for(int i=0;i<N;i++)cin>>t[i]>>x[i]>>y[i];

  int T=t[0];
  int dist=abs(x[0])+abs(y[0]);
  int chk=T-dist;
  if(chk<0){
    cout<<"No"<<endl;
    return 0;
  }else{
    if(chk%2!=0){
      cout<<"No"<<endl;
      return 0;
    }
  }

  for(int i=0;i<N-1;i++){
    int T=t[i+1]-t[i];
    int dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
    int chk=T-dist;

    if(chk<0){
      cout<<"No"<<endl;
      return 0;
    }else{
      if(chk%2!=0){
        cout<<"No"<<endl;
        return 0;
      }

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


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int64_t dp[51][51][2501];

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

    int x[50];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    // 最初のi枚のうちj枚を使ってkを作る通り数
    for (int i = 0; i <= n; i++) {
        dp[i][0][0] = 1;
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            for (int k = 0; k <= 2500; k++) {
                dp[i][j][k] = dp[i - 1][j][k];
                if (k - x[i - 1] >= 0) dp[i][j][k] += dp[i - 1][j - 1][k - x[i - 1]];
            }
        }
    }

    int64_t r = 0;
    for (int j = 1; j <= n; j++) {
        r += dp[n][j][j * a];
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 49024
n = int(input())
vs = list(map(int, input().split()))

vs = list(reversed(sorted(vs)))

while len(vs) >= 2:
    v1 = vs.pop()
    v2 = vs.pop()
    v = (v1 + v2) / 2.0
    vs.append(v)
print(vs[0])
    


Measured memory_bytes: 2940
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
		int k = sc.nextInt();
		int sum=0;
		ArrayList<Integer> ar = new ArrayList<>();
		for(int i=0;i<n;i++){
			ar.add(sc.nextInt());
        }
		Collections.sort(ar,Collections.reverseOrder());  
		for(int j=0;j<k;j++){
        	sum+=ar.get(j);
        }
		System.out.print(sum);
    }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
class Solve{
    int R;
    int C;
    int n;
    int[] r;
    int[] c;
    long[] a;
    long minh;
    long minv;
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        getinput();
        Vertex[] horizontal = new Vertex[R];
        Vertex[] vertical = new Vertex[C];
        for(int i=0;i<R;i++){
            horizontal[i] = new Vertex(true);
        }
        for(int i=0;i<C;i++){
            vertical[i] = new Vertex(false); 
        }
        for(int i=0;i<n;i++){
            horizontal[r[i]].Add(new Edge(vertical[c[i]],a[i]));
            vertical[c[i]].Add(new Edge(horizontal[r[i]],a[i]));
        }
        for(int i=0;i<R;i++){
            if(!horizontal[i].check){
                minh = 1000000001;
                minv = 1000000001;
                if(!dfs(0,horizontal[i])){
                    Console.WriteLine("No");
                    return;
                }
                if(minh+minv<0){
                    Console.WriteLine("No");
                    return;
                }
            }
        }
        Console.WriteLine("Yes");
    }
    bool dfs(long i,Vertex v){
        v.i = i;
v.check = true;
        if(v.h && i < minh){
            minh = i;
        }
        else if(!v.h && i < minv){
            minv = i;
        }
        for(int j=0;j<v.edges.Count;j++){
            if(!v.edges[j].v.check){
                if(!dfs(v.edges[j].cost-i,v.edges[j].v)){
                    return false;
                }
            }
            else if(v.edges[j].v.i+i != v.edges[j].cost){
                return false;
            }
        }
        return true;
    }
    void getinput(){
        string[] str = Console.ReadLine().Split(' ');
        R = int.Parse(str[0]);
        C = int.Parse(str[1]);
        n = int.Parse(Console.ReadLine());
        r = new int[n];
        c = new int[n];
        a = new long[n];
        for(int i=0;i<n;i++){
            str = Console.ReadLine().Split(' ');
            r[i] = int.Parse(str[0])-1;
            c[i] = int.Parse(str[1])-1;
            a[i] = int.Parse(str[2]);
        }
    }    
}
class Vertex{
    public List<Edge> edges;
    public long i;
    public bool h;
    public bool check;
    public void Add(Edge e){
        edges.Add(e);
    }
    public Vertex(bool b){
        h = b;
        check = false;
        edges = new List<Edge>();
    }
}
class Edge{
    public Vertex v;
    public long cost;
    public Edge(Vertex v0,long i){
        v = v0;
        cost = i;
    }
}

Measured memory_bytes: 44808
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;



int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n;
        cin >> n;
        double a[n+1],dp[n+1];
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        dp[0]=1;
        for(int i=0; i<n; i++){
            double p_head=a[i];
            double p_tail=1-a[i];
            for(int j=i+1; j>=0; j--){
                if(j==0){
                    dp[j]=dp[j]*p_tail;
                }
                else{
                    dp[j]=dp[j-1]*(p_head)+dp[j]*p_tail;
                }
            }
        }
        double s=0.00;
        for(int i=n/2+1; i<=n; i++){
            s=s+dp[i];
        }
        cout << setprecision(10) <<  s << '\n';


       



   
    

}


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

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    ll a[n+7] = {0};
    a[0] = 1;
    int m;
    cin >> m;
    for (int i = 0; i < m; i++){
        int t;
        cin >> t;
        a[t] = -1;
    }
    if (a[1] != -1) a[1] = 1;
    else a[1] = 0;
    for (int i = 2; i < n+1; i++){
        if (a[i] == -1) a[i] = 0;
        else a[i] = (a[i - 1] + a[i - 2])% 1000000007;
    }
    cout << a[n] % 1000000007;
    return 0;
}


Measured memory_bytes: 1024
function f(s)
	N=length(s)
	ret=zeros(Int,N)
	ret[1]=N
	i=1
	j=0
	while i<N
		while i+j<N&&s[j+1]==s[i+j+1]
			j+=1
		end
		ret[i+1]=j
		if j==0
			i+=1
			continue
		end
		k=1
		while i+k<N&&k+ret[k+1]<j
			ret[i+k+1]=ret[k+1]
			k+=1
		end
		i+=k
		j-=k
	end
	ret
end
function main()
	N=parse(Int,readline())
	s=chomp(readline())
	ans=0
	for i=1:N
		A=f(s[i:end])
		for j=0:N-i
			ans=max(ans,min(j,A[j+1]))
		end
	end
	println(ans)
end
main()


Measured memory_bytes: 166912
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ull = unsigned long long;
constexpr int INF = 2e9;
constexpr int MAX = 1e5+5; //N*V

int main(){
  int n, W, w, v, ans;
  cin>>n>>W;
  vector<ull> dp(MAX, INF);
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    cin>>w>>v;
    for(int j = MAX-1; j >= v; j--){
      dp[j] = min(dp[j], w+dp[j-v]);
    }
  }
  for(int i = 1; i < MAX; i++){
    if( dp[i] <= W )
      ans = i;
  }
  cout<<ans<<"\n";
  return 0;
}


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


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

    vector<int> A(N);
    for(int i(0); i < N; ++i) cin >> A[i];

    long long ans = 0;
    int MaxNum = 0;
    for(int i = 0; i < N; ++i){
        MaxNum = max(MaxNum,A[i]);
        ans += MaxNum - A[i];
    }
    
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3552
a,b=map(int,input().split())
if ( a<0 and b>0 ) or ( a>0 and b<0 ) or a==0 or b==0:
	print('Zero')
else:
	if a>0 and b>0:
		print('Positive')
	else:
		c=b-a
		print('Positive' if c&1 else 'Negative')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs            v.size()
#define ss            s.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii            pair<int, int>
#define int           long long
#define ull           unsigned long long
#define pb            push_back
#define mpp           make_pair
#define Okay          0
#define pi            3.14159

const int inf = 1e6;
const int cont = 1e18;
using namespace std;

void solve(){
    int n;
    cin>>n;
    set<int>st;
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        st.insert(a);
    }
    int ans = st.size();
    if(ans%2 ==0)ans--;
    cout<<ans<<endl;
}

int32_t main() {
   Fast;

   solve();
    return Okay;
}



Measured memory_bytes: 8312
(proclaim '(inline calc))
(defun calc (n &optional (result (list 0 0 0 0)))
  (if (= n 0)
      result
      (let ((tmp (read-line)))
        (cond ((equal tmp "AC")
               (incf (car result)))
              ((equal tmp "WA")
               (incf (cadr result)))
              ((equal tmp "TLE")
               (incf (caddr result)))
              ((equal tmp "RE")
               (incf (cadddr result))))
        (calc (- n 1) result))))

(let ((result (calc (read))))
  (format t "AC x ~A~%WA x ~A~%TLE x ~A~%RE x ~A~%"
          (car result)
          (cadr result)
          (caddr result)
          (cadddr result)))


Measured memory_bytes: 58836
package main

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

func main() {
	n := readi()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readi()
	}
	sort.Ints(a)

	ans := a[0]
	i := 0
	for {
		if i == n {
			break
		}
		tmp := a[i] % ans
		if tmp != 0 {
			if ans > tmp {
				a[i] = tmp
				ans = tmp
				i = 0
				continue
			}
		}
		i++
	}

	fmt.Println(ans)
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll INF=1000000010;
const ll MOD=1000000007;
const ll LINF=4000000000000000000;
const long double EPS=1e-9;
typedef pair<int,int> P;
int main(){
    ll n,k;cin>>n>>k;
    ll ans=0;
    if(k%2==0){
        ll co=0;
        for(int i=1;i<=n;i++){
            if(i%k==k/2){
                co++;
            }
        }
        ans+=co*co*co;
    }
    ll co2=0;
    for(int i=1;i<=n;i++){
        if(i%k==0){
            co2++;
        }
    }
    ans+=co2*co2*co2;
    cout<<ans<<endl;
}


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

#define REP(i,n) for(int i=0; i<(int)(n); i++)
using ll = long long;

int main(){
  ll n,k;
  cin>>n>>k;
  n %= k;
  cout << min(n, k-n) << endl;
  return 0;
}



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

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

   for(int i=1;i<=9;i++)
   {
       for(int j=1;j<=9;j++)
       {
           if(n==i*j)
           {
               cout<<"Yes"<<endl;
               return 0;
           }
       }
   }
   cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std; 
int main(){
  int n,i,j,z,temp,p,sum; 
  cin>>n; 
  sum=0;
  for(i=1;i<=n; i++){
    for(j=1;j<=n; j++){
      p=__gcd(i,j);
      for(z=1;z<=n; z++){
        temp=__gcd(p,z);
        sum=sum+temp;
      }
    }
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3632
S = list(input())


if (S[0] == 'R') and (S[0] == S[1] and S[1] == S[2]):
    i = 3

elif (S[1] == 'R') and (S[0] == S[1] or S[1] == S[2]):
    i = 2

elif (S[0] == S[1] and S[2] == 'S'):
    i = 0

else:
    i = 1

print(i)


Measured memory_bytes: 9132
#include <iostream>
using namespace std;
int main(){
    int n=-1;
    int a,b;
    while(cin>>n,n!=0){
       
        int sumA = 0;
        int sumB = 0;
        
        for(int i=0;i<n;i++){
            cin >> a >> b;
        
            if(a>b){
                sumA = sumA+a+b;
            }else if(a==b){
                sumA +=a;
                sumB +=a;
            }else if(b>a){
                sumB = sumB+a+b;
            }      
        }
        cout << sumA << " " << sumB << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
def solve():
  ans = 0
  K = int(input())
  A = list(map(int, input().split()))
  A = A[::-1]
  bottom = 2
  top = 2
  for a in A:
    bottom = -(-bottom//a)*a
    if bottom>top:
      return [-1]
    top = top//a*a+a-1
  return [bottom,top]
print(*solve())

Measured memory_bytes: 20504
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[] disliked = new boolean[m];
		
		for(int i = 0; i < n; i++) {
			int k = sc.nextInt();
			Set<Integer> isLiked = new HashSet<Integer>();
			for(int j = 0; j < k; j++) {
				int a = sc.nextInt() - 1;
				isLiked.add(a);
			}
			for(int j = 0; j < m; j++) {
				if(!isLiked.contains(j)) {
					disliked[j] = true;
				}
			}
		}
		
		int ans = 0;
		for(int i = 0; i < m; i++) {
			if(!disliked[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}



Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <queue>
#include <cstring>
#include <set>
#include <map>

using namespace std;

const int maxN = 510, oo = 23041997;

#define foru(i, l, r) for (int i = l; i <= r; ++i)
#define ford(i, r, l) for (int i = r; i >= l; --i)
#define repu(i, r) for (int i = 0; i < r; ++i)
#define ll long long
#define F first
#define S second
#define mp make_pair
#define pint pair < ll, int >

int c[maxN][maxN], f[maxN][maxN], m, n, pre[maxN], sr, sc, tr, tc, target, source, check[maxN], q[maxN], res;
char s[maxN];

bool find_flow() {
    foru(i, 0, m + n + 1) check[i] = 0;
    int l = 1, r = 1;
    q[1] = source;
    check[source] = 1;
    while (l <= r) {
        int u = q[l++];
        foru(v, 0, m + n + 1)
            if (f[u][v] < c[u][v] && !check[v]) {
                check[v] = 1;
                pre[v] = u;
                if (v == target) return true;
                q[++r] = v;
            }
    }
    return false;
}

void increase_flow() {
    int v = target, delta = oo;
    while (v != source) {
        int u = pre[v];
        delta = min(delta, c[u][v] - f[u][v]);
        v = u;
    }
    v = target; res += delta;
    while (v != source) {
        int u = pre[v];
        f[u][v] += delta;
        f[v][u] -= delta;
        v = u;
    }
}

int main() {
    scanf("%d %d\n", &m, &n);
    foru(i, 1, m) {
        scanf("%s\n", s);
        foru(j, 1, n) {
            if (s[j - 1] == 'S') {
                sr = i;
                sc = j + m;
            }
            if (s[j - 1] == 'T') {
                tr = i;
                tc = j + m;
            }
            if (s[j - 1] == 'o') c[i][j + m] = c[j + m][i] = 1;
        }
    }
    source = 0;
    target = m + n + 1;
    c[source][sr] = c[source][sc] = oo;
    c[tr][target] = c[tc][target] = oo;
    while (find_flow()) increase_flow();
    cout << ((res >= oo) ? -1 : res);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int A,B,C;
    cin >> A >> B >> C;
    int X,Y;
    cin >> X >> Y;
    int total = 0;
    REP(i, min(X,Y)){
        total += min(A+B, 2*C);
    }
    Rep(i, min(X,Y), max(X,Y)){
        if(X>Y) total += min(A, 2*C);
        else total += min(B, 2*C);
    }
    pr(total);
}

Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance

lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int N;
int X;
lng a[100010];
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X;
    REP(i, N) cin >> a[i];

    lng ans = 0;
    UP(i, 1, N-1) {
        lng x = a[i]+a[i-1]-X;
        if(x > 0) {
            ans += x;
            a[i] -= min(a[i], x);
            a[i-1] -= max(0LL, x-a[i]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
b = [0]*n
ok = 0
ng = min(a[-1], a[0]) + 1
if ng - ok == 1:
    b[0] = 0
    for i in range(1, n):
        b[i] = (a[i - 1] - b[i - 1] // 2) * 2
else:
    while ng - ok > 1:
        mid = (ok + ng)//2
        b[0] = mid*2
        for i in range(1, n):
            b[i] = (a[i-1] - b[i-1]//2)*2
        if sum(b) < sum_a:
            ok = mid
        elif sum(b) > sum_a:
            ng = mid
        elif sum(b) == sum_a:
            break
print(*b)

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

int main(){
	int N;
	cin>>N;
	int A[100];
	long long int cnt = 1, ret=1;;
	for(int i=0;i<N;i++){
		cin>>A[i];
		if(A[i] % 2 == 0) cnt *=2;
		ret *= 3;
	}
	cout<<ret - cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int eight_queen[8];
int final = 0;

bool check(int row, int value) {
	int data;
	for (int i = 0; i < 8; i++) {
		if (eight_queen[i] != -1) {
			data = eight_queen[i];
			if (value == data) return false;
			if ((value + row) == (data + i)) return false;
			if ((value - row) == (data - i)) return false;
		}
	}
	return true;
}

void print() {
	for (int j = 0; j < 8; j++) {
		for (int i = 0; i < 8; i++) {
			if (i == eight_queen[j])
				cout << "Q";
			else
				cout << ".";
		}
		cout << endl;
	}
}

void solution(int row) {
	if (row > 7 && (eight_queen[7] != -1)) {
		final = 1;
		print();
		return;
	}

	if (eight_queen[row] != -1 ) solution(row + 1);
	else {
		for (int index = 0; index < 8; index++) {	
			if (final == 1) return;
			if (check(row, index)) {
				eight_queen[row] = index;
				solution(row + 1);
				eight_queen[row] = -1;
			}
		}
	}
}



int main() {
	int n;
	cin >> n;
	int row, index;
	memset(eight_queen, -1, sizeof(eight_queen));
	for (int i = 0; i < n; i++) {
		cin >> row >> index;
		eight_queen[row] = index;
	}
	solution(0);
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define bit(x,j) ((x>>j)&1)
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
long long power(long long a, long long b) {
    //a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
    }
  ll int binomial(ll int n, ll int k) 
{ 
    ll int C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll int i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (int j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 
  vector<int> pr;
  bool prime[10000000];
void Sieve(ll int n) 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            pr.push_back(p);
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}
 


//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}
int sum(int n)  
{  
    if (n == 0)  
    return 0;  
    return (n % 10 + sum(n / 10));  
}  
ll int factorial(ll int n,ll int m) 
{ 
    ll int fact = 1; 
    for(int i=2;i<=n;i++) { 
        fact = (fact * i)%m; 
    } 
    return fact%m; 
} 

void reverse(string& str) 
{ 
    int n = str.length(); 
  
    // Swap character starting from two 
    // corners 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
} 


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


Measured memory_bytes: 3656
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

a,b,x,y = list(map(int, input().split()))

z = x * y // gcd(x,y)

def num(u,v,k):
    ww=v//k - (u-1)//k
    return ww

print((b-a+1)-(num(a,b,x)+num(a,b,y)-num(a,b,z)))



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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int get_ans(int cnt){

  int tmp = 0;
  int ret = 0;
  for(int i = 1; i < 1000; i++){
    
    if(tmp + i <= cnt){
      tmp += i;
      ret++;
    }else{
      break;
    }

  }

  return ret;

}

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

  ll n;
  cin >> n;

  map<ll, int> mp;
  for(ll i = 2; i <= 1e6; i++){
    while(n % i == 0){
      n = n / i;
      mp[i]++;
    }
  }

  if(n > 1){
    mp[n]++;
  }


  int ans = 0;
  for(auto p : mp){
    ans += get_ans(p.second);
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3656
/* BABA JAGAAAAAA  */  

#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define fast ios:: sync_with_stdio(false);cin.tie(NULL)
#define l long 
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;

 int main()
 {
     fast;  
    // 3rd//
    ll n;
    cin>>n;
    vector<ll>v(n);
     for(int i=0; i<n; i++)
     cin>>v[i];
      ll sum[n];
      sum[n-1]=v[n-1];
       for( ll i=n-2; i>=0; i--)
       {
           sum[i]=(sum[i+1]+v[i])%mod;
       }
      ll ans=0;
       for(ll  i=0;  i<n-1; i++)
       {
           ans=(ans%mod+(v[i]*sum[i+1]))%mod;
       }
        cout<<ans<<endl;
       
    
 
       return 0;
     
 }
  

Measured memory_bytes: 6372
#include<iostream>
#include<string>
#include<iomanip>

using namespace std;

int main(void) {
	int p=0;
	int i;
	char moji;
	string s;
	cin >> s;
	for ( i = 1; i <= 26; i++) {
		if (s.find(96 + i) ==s.npos) {
			moji = 96 + i;
			cout << moji << endl;
			p = 1;
			break;
		}
	}
	if (p==0) {
		cout << "None" << endl;
	}
	return 0;
}

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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

int const MAXNUM = int(1e6);

void solve() {
    int n;
    cin >> n;

    vector<int> vis(MAXNUM + 1, false);
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        if (v[i] == 1) {
            vis[1] = 1;
            continue;
        }

        int k = v[i];
        for (int j = 2; j * j <= k; j += 1) {
            bool used = false;
            while (k % j == 0) {
                used = true;
                k /= j;
            }
            if (used) vis[j] += 1;
        }
        if (k > 1) vis[k] += 1;
    }

    int maxVisited = 0;
    for (int i = 0; i < MAXNUM + 1; ++i) {
        if (vis[i]) {
            maxVisited = max(maxVisited, vis[i]);
        }
    }

    if (maxVisited == 1) {
        cout << "pairwise coprime" << '\n';
    } else if (maxVisited == n) {
        cout << "not coprime" << '\n';
    } else {
        cout << "setwise coprime" << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tcs;
    tcs = 1;
    while (tcs-- > 0) solve();
}


Measured memory_bytes: 11036
def div(n):
    if n==1:s=1
    else:s=2
    for i in range(2,n):
        if n%i==0:s+=1
    return s

n=int(input())
ans=0
for i in range(1,n+1,2):
    if div(i)==8:ans+=1
print(ans)

Measured memory_bytes: 9108
N,M  = map(int, input().split())
X  = list(sorted(map(int, input().split())))

if N >= M:
  print(0)

else:
  diff = []
  for i in range(M-1):
    diff.append(X[i+1] - X[i])

  diff.sort()
  print(sum(diff[:(M-N)]))

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

int main(){
    int N;
    int i,j;
    i=0;
    j=1;
    int ans; //海を眺められる旅館の数
    ans=1;

    int H[20];
    cin >> N;
    for(i=0; i < N; i++){
        cin >> H[i];
    }
    for (i=1; i<N; i++){
        for(j=0; j<=i; j++){
            if (j==i){
                ans =ans +1;
            }
            else if (H[i]<H[j]){
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int A = 26;
    const int M1 = 2e1;
    const int M2 = 1e4;
    int D; cin >> D;
    vector<int> c(A);
    REP(i,A) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(A));
    REP(i,D) REP(j,A) cin >> s[i][j];

    vector<int> last(A,-1);
    vector<int> ans(D);
    REP(i,D) {
        int mx = 0,a = -1;
        REP(j,A) {
            int tmp = (i-last[j])*c[j] + s[i][j];
            if (mx < tmp) {
                mx = tmp;
                a = j;
            }
        }
        ans[i]=a;
        last[a] = i;
    }
    auto calc = [&](const vector<int> &a){
        vector<int> l(A,-1);
        int score = 0;
        REP(i,D) {
            score += s[i][a[i]];
            l[a[i]] = i;
            REP(j,A) {
                score -= c[j]* (i-l[j]);
            }
        }
        return score;
    };

    int maxscore = calc(ans);

    random_device seed_gen;
    mt19937 engine(seed_gen());
    REP(_,M1) {
        int mx = maxscore;
        vector<int> a1(ans);
        REP(__,M2) {
            vector<int> a2(a1);
            a2[engine()%D] = engine() % A;
            int tmp = calc(a2);
            if (mx < tmp) {
                swap(a1,a2);
                mx = tmp;
            }
        }
        if (maxscore < mx) {
            swap(ans,a1);
            maxscore = mx;
        }
    }

    REP(i,D) OUT(ans[i]+1)

    return 0;
}

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

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

  int ans = 0;

  for (int i = 0; i < 1000; i++) {
    string A = S;
    string B = to_string(i);
    while (B.size() < 3) B = '0' + B;
    for (int i = 0; i < 3; i++) {
      int j = (int)A.find(B.at(i));
      if (j == -1) goto NG;
      A = A.substr(j + 1);
    }
    ans++;
    NG:;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 384
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
if N % 2 == 1:
    ls = list(range(0,N,2))
    ls = sorted(ls+ls)
    ls.pop(0)
    if sorted(A) != ls:
        print(0)
    else:
        print(2**((N-1)//2) % mod)
else:
    ls = list(range(1,N,2))
    ls = sorted(ls+ls)
    if ls != sorted(A):
        print(0)
    else:
        print(2**(N//2) % mod)

Measured memory_bytes: 13880
import bisect

N=int(input())

L=list(map(int,input().split()))

L_sorted=sorted(L)

ans=0

for i in range(2,N):  #2<=i<=N-1
    for j in range(1,i):   #1<=j<=i-1
        MIN=L_sorted[i]-L_sorted[j]+1
        MIN_index=bisect.bisect_left(L_sorted,MIN)
        number_of_indexes=(j-1)-MIN_index+1
        if number_of_indexes>0:
            ans+=number_of_indexes
        
print(ans)




Measured memory_bytes: 3188
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = INF;
  if (y - x > 0) ans = min(ans, y - x);
  if (y - (-x) >= 0) ans = min(ans, y - (-x) + 1);
  if (-y - x >= 0) ans = min(ans, -y - x + 1);
  if (-y - (-x) >= 0) ans = min(ans, -y - (-x) + 2);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long h = (long) Math.sqrt(n) + 1;
        long ans = n-1;
        for (int i =   1; i <= h; i++) {
            if(n % i == 0){
                long tmp = i-1 + (n/i)-1;
                if(tmp < ans) ans = tmp;
            }
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 23636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    string s,t;
    cin >> s >> t;
    int ans = 0;
    rep(i,3)if(s[i] == t[i])ans++;
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int k;
    cin>>k;
    ll sum = 0ll;
    for(int a=1;a<=k;++a)for(int b=1;b<=k;++b)for(int c=1;c<=k;++c){
        sum +=__gcd(__gcd(a,b),c);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[6] = {};
	while(scanf("%d",&a[0])!=EOF){
		for(int i=1;i<5;i++)scanf(",%d", &a[i]);
			int cnt=0,flag=true,card[13]={},max = 4;
		sort(a,a+5);
		for (int i=0;i<4;i++)for(int j=i+1;j<5;j++)
			if (a[i]==a[j])cnt++;
		int i=0;
		if(a[i]==1&&a[i+1]==10){
			i=1;
			max=5;
			a[5]=14;
		}
		for(;i<max;i++)if(a[i]+1!=a[i+1])flag=0;
if (cnt == 6)printf("four card\n");
else if (cnt == 4)printf("full house\n");
else if (flag)printf("straight\n");
else if (cnt == 3)printf("three card\n");
else if (cnt == 2)printf("two pair\n");
else if (cnt == 1)printf("one pair\n");
else printf("null\n");
}
}

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

int main () 
{ 
	vector<int> vec; 
	int x,n,i,t,temp,f=1;
	cin>>x>>n;
	temp=x;
	

	vector<int>::iterator it; 
	
	vector<int>::iterator it1; 
	
	for (int i=0; i<n; i++) {
		cin>>t; 
		vec.push_back(t);
	
	}
	if(n==0){
	    cout<<x;
	    
	}
	else{
	while(f){
	
	it = find (vec.begin(), vec.end(), x); 
	
	it1 = find (vec.begin(), vec.end(), temp); 
	if (it1 != vec.end()) 
	{ 
		 
		temp--;
		 
	} 
	
	else{
		cout << temp<<endl;
		break;
	}
	if (it != vec.end()) 
	{ 
		
		
		 x++;
	} 
	else{
		cout<<x<<endl; 
		break;
	}
		
}
}return 0; 
} 


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    while(true){
    int x = scan.nextInt();
    int y = scan.nextInt();
    if( x == 0 && y == 0 )break;
    if( x > y ){
    System.out.println(""+y+" "+x+"");
    }else{
    System.out.println(""+x+" "+y+"");
    }     
   }
  }
}

Measured memory_bytes: 35900
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		try {
			int seconds = Integer.parseInt(br.readLine());
			int hour 	= seconds / 3600;
			int minutes = seconds % 3600 / 60;
			seconds = seconds % 60;
			System.out.println(hour + ":" + minutes + ":" + "" +seconds);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}


Measured memory_bytes: 24480