akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;

#define ALL(s) (s).begin(),(s).end()
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<(char)(P[i]+'a');}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



const int MAX_V = 30;
struct Graph {
    int V;
    vector<int> list[MAX_V];
    vector<int> back[MAX_V];
    
    Graph(int n = 0) : V(n) {}
    void init(int n = 0) {V = n; for (int i = 0; i < MAX_V; ++i) {list[i].clear(); back[i].clear();} }
    inline vector<int>& operator [] (int i) {return list[i];}
    
    void direct(int f, int t) {
        list[f].push_back(t);
        back[t].push_back(f);
    }
};

ostream& operator << (ostream& s, const Graph& G) {for (int i = 0; i < G.V; ++i) {s << i << " : " << G.list[i];} return s;}

Graph G;



void Edfs(Graph &G, int v, vector<int> &walk) {
    while (!G[v].empty()) {
        int to = G[v][G[v].size()-1];
        G[v].pop_back();
        Edfs(G, to, walk);
    }
    walk.push_back(v);
}

bool EulerCycle(Graph &G, vector<int> &walk) {
    walk.clear();
    int s = -1, odd = 0, E = 0;
    for (int i = 0; i < G.V; ++i) {
        int in = G.back[i].size(), out = G[i].size();
        if (out != in) ++odd;
        E += out;
        if (out > 0) s = i;
    }
    if (odd == 0) {
        Edfs(G, s, walk);
        reverse(walk.begin(), walk.end());
        return (walk.size() == E+1);
    }
    else return false;
}


int N;
string str;

int main() {
    while (cin >> N, N) {
        G.init(26);
        
        int c1, c2;
        for (int i = 0; i < N; ++i) {
            cin >> str;
            c1 = str[0]-'a', c2 = str[str.size()-1]-'a';
            
            G.direct(c1, c2);
        }
        
        vint res;
        if (EulerCycle(G, res)) {
            puts("OK");
        }
        else {
            puts("NG");
        }
    }
    
    return 0;
}


Measured memory_bytes: 1316
#include<stdio.h>
int main(void){
	int number;
	int a[5000] = {0};
	int i,j,k;
	int sum = 0;
	int max = -1000000;
	while(scanf("%d",&number)){
		if(number == 0){
			break;
		}
		for(i = 0;i < number;i++){
			scanf("%d",&a[i]);
		}
		for(i = 0;i < number;i++){
			for(j = i;j < number;j++){
				sum += a[j];
				if(sum > max){
					max = sum;
				}
			}
			sum = 0;
		}
		printf("%d\n",max);
		sum = 0;
		max = -1000000;
	}
	return 0;
}

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

string S, T;
int lenS, lenT, ans=1e9;

int f(string a, string b, int N) {
	int res = 0;
	for(int i=0; i<N; i++) {
		if (a[i] != b[i])
			res++;
	}
	return res;
}

int main () {
	cin >> S >> T;
	lenS = S.length();
	lenT = T.length();
	for(int i=0; i<lenS-lenT+1; i++) {
		ans = min(ans, f(S.substr(i, lenT), T, lenT));
	}
	cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define fo0n for(int i=0;i<n;i++)
const int M =1e9+7;
const int N=1e5+3;
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
using namespace std;
struct node{
	int x,y;
};
void solve (){
	char x;
	cin>>x;
	switch (x){
		case 'A' : cout<<'T'; break;
		case 'C' : cout<<'G'; break;
		case 'T' : cout<<'A'; break;
		case 'G' : cout<<'C'; break;
	}
}
int main(){
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
}




Measured memory_bytes: 256
//Indomie, Mie dari Indonesia
#include <iostream>
#include <cstdio>
#include <vector>
#include <cassert>
#include <cmath>
#include <queue>
#include <cstring>
using namespace std;
#define pb push_back
const int LogN=18;
const int MAXN=200000;
int n,air,jarak[(1<<(LogN))+5],terkanan[LogN+5][MAXN+5],terkiri[LogN+5][MAXN+5];
int pos[MAXN+5],l,r,komponen;
bool ans[MAXN+5];
vector <int> daftarair;
void isiair(int air){
	while(air>0)
		daftarair.pb(air),air/=2;
	daftarair.pb(0);
	assert(daftarair.size()-1<=LogN);
}
void isiterkanan(int jenis){
	int last=1;
	for(int i=2;i<=n;i++)
	{
		if(pos[i]-pos[i-1]>daftarair[jenis])
		{
			while(last!=i)
			{
				terkanan[jenis][last]=i-1;
				last++;
			}
		}
	}
	while(last!=n+1)
	{
		terkanan[jenis][last]=n;
		last++;
	}
}
void isiterkiri(int jenis){
	int last=n;
	for(int i=n-1;i>=1;i--)
	{
		if(pos[i+1]-pos[i]>daftarair[jenis])
		{
			while(last!=i)
			{
				terkiri[jenis][last]=i+1;
				last--;
			}
		}
	}
	while(last!=0)
	{
		terkiri[jenis][last]=1;
		last--;
	}
}
void isiterkanan(){
	for(int i=0;i<daftarair.size();i++)
		isiterkanan(i);
}
void isiterkiri(){
	for(int i=0;i<daftarair.size();i++)
		isiterkiri(i);
}
int totalkomponen(){
	int ret=0;
	int now=1;
	while(now<=n)
	{
		ret++;
		now=terkanan[0][now];
		now++;
	}
	return ret;
}
bool bfs(){
	queue <int> cari;
	memset(jarak,-1,sizeof(jarak));
	jarak[0]=1;
	if(l<=jarak[0]&&jarak[0]<=r)
		jarak[0]=r+1;
	cari.push(0);
	while(!cari.empty())
	{
		//cout<<"bfs"<<endl;
		int u=cari.front();
		if(jarak[u]>n)
		{
			//cout<<"terkanannya "<<jarak[u]<<endl;
			return true;
		}
		cari.pop();
		//cout<<u<<endl;
		for(int i=1;i<daftarair.size();i++)
		{
			if(u&(1<<(i-1)))
				continue;
			int v=(u|(1<<(i-1)));
			int nextpos=terkanan[i][jarak[u]]+1;
			if(l<=nextpos&&nextpos<=r)
				nextpos=r+1;
			if(jarak[v]==-1)
			{
				jarak[v]=nextpos;
				cari.push(v);
			}
			else
				jarak[v]=max(jarak[v],nextpos);
		}
	}
	return false;
}
int main()
{
	scanf("%d%d",&n,&air);
	isiair(air);
	for(int i=1;i<=n;i++)
		scanf("%d",&pos[i]);
	isiterkanan();
	isiterkiri();
	komponen=totalkomponen();
	for(int i=1;i<=n;i++)
	{
		//cout<<"loop "<<i<<endl;
		if(komponen>daftarair.size())
		{
			ans[i]=false;
		}
		else if(i!=1&&terkanan[0][i]==terkanan[0][i-1])			//in the same komponen
		{
			ans[i]=ans[i-1];
		}
		else
		{
			l=terkiri[0][i];
			r=terkanan[0][i];
			if(bfs())
				ans[i]=true;
			else
				ans[i]=false;
		}
		if(ans[i])
			printf("Possible\n");
		else
			printf("Impossible\n");	
	}
}

Measured memory_bytes: 36352
#include <iostream>

using namespace std;

int main() {
    int n ,a, b=2, c, i=0;
    cin >> n;
    a=n;
    while (true){
        c = a%b;
        if(c==0){
            if(i == 0){
                cout << (a) << endl;
            }else{
                cout << (n*2/a) << endl;
            }
            return 0;
        }else{
            b=a;
            a=c;
            i++;
        }
    }
}

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

def sieve(n):
    prime = [True] * (n + 1)
    i = 2
    while i * i <= n:
        if prime[i]:
            for j in range(i * i, n + 1, i):
                prime[j] = False
        i += 1
    return [i for i in range(2, n + 1) if prime[i]]

primes = sieve(10 ** 5 + 10)
for p in primes:
    if p >= x:
        print(p)
        exit()
raise Exception

Measured memory_bytes: 4172
#include <iostream>

int main(){
    int N;
    int* A;
    std::cin>>N;
    A=new int[N];
    for(int i=0;i<N;i++){
        std::cin>>A[i];
    }

    bool b=true;
    for(int i=0;i<N;i++){
        if(A[i]%2==0){
            if(!(A[i]%3==0||A[i]%5==0)){
                b=false;
                break;
            }
        }
    }

    if(b){
        std::cout<<"APPROVED";
    }else{
       std::cout<<"DENIED"; 
    }

    delete[] A;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void solve()
{
    int n,i,m,num[6],s,c;
    cin>>n>>m;
    memset(num,-1,sizeof(num));
    for( i=1;i<=m;++i)
    {
        cin>>s>>c;
        if(num[s]==-1)
        {
            num[s]=c;
            continue;
        }
        else
        {
            if(num[s]!=c)
                {
                    cout<<-1<<endl;
                    return ;
                }
        }
        
    }
    if(num[1]==0 && n!=1)
    {
       cout<<-1<<endl;
        return ;
    }
    if(num[1]==-1 )
    {
        if(n!=1)
            num[1]=1;
        else
        {
                num[1]=0;
        }
    }
    
    
    for(i=1;i<=n;++i)
        {
            if(num[i]==-1)
                num[i]=0;
            cout<<num[i];
        }
    cout<<endl;
    return ;
        
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    // int _t;cin>>_t;while(_t--)
    solve();
}

Measured memory_bytes: 256
import math
 
N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'
 
input()
d = None
u = set()
for x in map(int, input().split()):
  d = math.gcd(d or x, x);
  s = set()
  while x > 1:
    p = spf[x]
    s.add(p)
    x //= p
  if u & s:
    r = 'setwise'
  u |= s
print('not' if d > 1 else r, 'coprime')

Measured memory_bytes: 179460
INF = 10 ** 9
MOD = 10 **9 + 7
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  collections import deque
from math import factorial

def main():
    n = int(input())
    Robot = [tuple(map(int,input().split())) for _ in range(n)]
    Robot.sort(key = lambda x: sum(x))

    ans = n
    now = -INF
    for i in range(n):
        if now <= Robot[i][0] - Robot[i][1]:
            now = sum(Robot[i])
        else:
            ans -= 1
    print(ans)
if __name__=='__main__':
    main()


Measured memory_bytes: 21692
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll n;
    ll ans =0;
    double d;
    cin >> n >> d;
    REP(i,n){
        double tmpx;
        double tmpy;
        cin >> tmpx >> tmpy;
        double tmp = tmpx*tmpx + tmpy*tmpy;
        if( d>= sqrt(tmp)){
            ans ++;
        }
    }
    cout << ans <<endl;
    return 0;
}

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

using namespace std;

struct packet {
    int time, src, dst;
};

bool operator<(const packet& a, const packet& b)
{
    return a.time<b.time;
}

int main()
{
    int n, m;
    while(cin >> n >> m, n|m)
    {
        bool infected[n+1];
        fill(infected+2, infected+n+1, false);
        infected[1] = true;
        packet ps[m];
        for(int i=0; i<m; i++)
        {
            cin >> ps[i].time >> ps[i].src >> ps[i].dst;
        }
        sort(ps, ps+m);
        int count = 1;
        for(int i=0; i<m; i++)
        {
            if(infected[ps[i].src])
            {
                if(!infected[ps[i].dst]) count++;
                infected[ps[i].dst] = true;
            }
        }
        cout << count << endl;
    }

}

Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.00)

int main()
{
     int n;
     cin>>n;
     map<int,int>mm;
     int x;
     for(int i=1;i<n;++i)
     {
        cin>>x;
        mm[x]++;
     }
     for(int i=1;i<=n;++i)
        cout<<mm[i]<<endl;
     return 0;
}


Measured memory_bytes: 13004
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(){cout << -1 << '\n';}
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; string s, t; cin >> n >> s >> t;
    int len = 0;
    REPS(i,n){
        if(s.substr(n-i,i) == t.substr(0,i))len = i;
    }
    cout << n * 2 - len << '\n';
}


Measured memory_bytes: 3584
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int a[501][501];
string ans[250001];

int main() {
  int a, b;
  cin >> a >> b;
  int cnt = 0;
  for(int i = a; i <= b; i++){
    string s = to_string(i);
    rep(j, 2){
      if(s[j] != s[4-j]) break;
      if(j == 1) cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 2176
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    let t: String = read!();

    let mut t = t.chars().collect::<Vec<char>>();
    t.reverse();

    let mut bef = 'P';
    let mut ans = vec![];
    for (i, &x) in t.iter().enumerate() {
        if x == '?' {
            ans.push('D');
        // match bef {
        // 'D' => {
        //     if i == t.len() - 1 || t[i + 1] == 'D' {
        //         ans.push('D');
        //     } else {
        //         bef = 'P';
        //         ans.push('P');
        //     }
        // }
        // 'P' => {
        //     bef = 'D';
        //     ans.push('D');
        // }
        // _ => {}
        }
        // } else {
        //     ans.push(x);
        //     bef = x;
        // }
        else {
            ans.push(x);
        }
    }

    ans.reverse();

    for i in ans {
        print!("{}", i);
    }

    println!();
}


Measured memory_bytes: 4136
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));
        int n, x, count = 0;
        String[] data;

        try {
            while (true) {
                data = br.readLine().split(" ");
                n = Integer.parseInt(data[0]);
                x = Integer.parseInt(data[1]);
                if (n == 0 && x == 0)
                    return;
                for (int i = 1; i <= n; i++) {
                    for (int j = i + 1; j <= n; j++) {
                        for (int k = j + 1; k <= n; k++) {
                            if (i + j + k == x)
                                count++;
                        }
                    }
                }
                System.out.println(count);
                count = 0;
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 25104
package main

import (
   "fmt"
   "sort"
)

func solution(n, k int, h []int) int {
   sort.Ints(h)
   out := 1 << 31
   for i := 0; i < n-k+1; i++ {
        lo := h[i]
        hi := h[i+k-1]
        out = min(out, hi-lo)
   }
   return out
}

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

func main() {
   var n, k int
   fmt.Scan(&n, &k)
   h := make([]int, n)
   for i := range h {
        fmt.Scan(&h[i])
   }
   fmt.Println(solution(n, k, h))
}

Measured memory_bytes: 6320
#include<stdio.h>
int main(){
  int n,k,s,i;
  scanf("%d",&n);
  s=0;
  
  k=n;
  

  for(i=0;i<11;i++){
    s=s+n%10;
    n=n/10;
  }
  
  if(k%s==0)
    printf("Yes");
  else printf("No");
  
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main(){

int N;
cin >>N;

int V[N];
int C[N];
int ans=0;
for(int i=0;i<N;i++){
cin>>V[i];
}
for(int i=0;i<N;i++){
    cin>>C[i];
}
for(int i=0;i<N;i++){
    
    if(V[i]>C[i]){
        ans+=(V[i]-C[i]);
    }

}
cout<<ans;
    return 0;
}

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

int main() {
    int n,h,w,a,b,g=0;
    cin >> n >> h >> w;
    for (int i=0;i<n;i++) {
        cin >> a >> b;
        if (a >= h && b >= w) {g++;}
    }
    cout << g << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int u=753;
  int ans=100000;
  string s;cin >> s;
  for(int i=0;i<s.size()-2;i++){
    int a=(s[i]-'0')*100;
    int b=(s[i+1]-'0')*10;
    int c=s[i+2]-'0';
    int t=a+b+c;
    ans = min(ans,abs(u-t));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
console.log((args=>{
  const [[N],A] = args.trim().split('\n').map( r=>r.split(' ').map(v=>parseInt(v)));
  A.sort((a,b)=>b-a);
  let l = 0, r = N-1;
  while ( r - l > 1 ) {
    const m = l + (r-l)/2|0;
    if ( A[m] < 0 ) r = m;
    else l = m;
  }
  const q = [];
  let b = A[0], c = A[A.length-1];
  const B = A.slice(1,r), C = A.slice(r,A.length-1);
  while ( B.length ) {
    const b = B.pop();
    q.push(`${c} ${b}`);
    c -= b;
  }
  q.push(`${b} ${c}`);
  b -= c;
  while ( C.length ) {
    const c = C.pop();
    q.push(`${b} ${c}`);
    b -= c;
  }
  return `${b}\n` + q.join`\n`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 63096
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/* MACROS */ 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */ 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

// #define cerr if(false)cerr
/* CODE STARTS HERE */

int main() {
    IOS;
    string S, T; cin >> S >> T;
    if(S.size() < T.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    else {
        string s = S;
        vector<string> ans;
        for(int i = S.size() - T.size(); i >= 0; i--) {
            bool can = true;
            for(int j = 0; j < T.size(); j++) {
                if(S[i + j] != T[j] && S[i + j] != '?') {
                    can = false;
                    break;
                }
            }
            if(can) {
                for(int j = 0; j < S.size(); j++) {
                    if(s[j] == '?') s[j] = 'a';
                }
                for(int j = 0; j < T.size(); j++) {
                    s[i + j] = T[j];
                }
                ans.push_back(s);
            }
        }
        sort(all(ans));
        if(ans.size() != 0) cout << ans[0] << endl;
        else cout << "UNRESTORABLE" << endl;
        return 0;
    }
}

Measured memory_bytes: 3664
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
constexpr ll TEN(ll n){return n==0?1:10ll*TEN(n-1);}

constexpr ll inf = TEN(9)+5;
constexpr ll linf = 3*TEN(18);

int A[3][3];
bool opened[3][3];

signed main()
{
    rep(i, 3) rep(j, 3) cin >> A[i][j];

    int N; cin >> N;
    rep(i, N) {
        int a; cin >> a;
        rep(j, 3) rep(k, 3) if (A[j][k] == a) opened[j][k] = true;
    }

    bool flag = false;

    rep(i, 3) {
        if (opened[i][0] and opened[i][1] and opened[i][2]) flag = true;
    }
    rep(i, 3) {
        if (opened[0][i] and opened[1][i] and opened[2][i]) flag = true;
    }
    if (opened[0][0] and opened[1][1] and opened[2][2]) flag = true;
    if (opened[0][2] and opened[1][1] and opened[2][0]) flag = true;

    puts(flag?"Yes":"No");
}


Measured memory_bytes: 3584
public class Main {

  private static void solve() {
    int n = ni();
    int[] a = na(n);
    long ret = 0;

    long now = a[0];
    for (int i = 1; i < n; i++) {
      ret += Math.max(0, now - a[i]);
      now = Math.max(now, a[i]);
    }
    System.out.println(ret);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 58084
#include<stdio.h>
#include<string.h>
#include<limits.h>

int main(){
	char n[2][1000];
	int box[3][1000]={0};
	int i,j,end,count,finish=0,m,k;
	
	scanf("%d",&m);
	for(k=0;k<m;k++){
	scanf("%s%s",n[0],n[1]);
	for(j=0;j<2;j++){
		for(i=strlen(n[j])-1,count=0;i>=0;i--,count++){
	switch(n[j][i]){
		case '0':
		box[j][count]=0;
		break;
		
		case '1':
		box[j][count]=1;
		break;
		
		case '2':
		box[j][count]=2;
		break;
		
		case '3':
		box[j][count]=3;
		break;
		
		case '4':
		box[j][count]=4;
		break;
		
		case '5':
		box[j][count]=5;
		break;
		
		case '6':
		box[j][count]=6;
		break;
		
		case '7':
		box[j][count]=7;
		break;
		
		case '8':
		box[j][count]=8;
		break;
		
		case '9':
		box[j][count]=9;
		break;
		
		
	}
		}
	}
	if(strlen(n[0])>=strlen(n[1]))end=strlen(n[0]);
	else end=strlen(n[1]);
		for(i=0;i<end;i++)box[2][i]=box[0][i]+box[1][i];
	finish=end;
		for(i=0;i<end;i++){
			if(box[2][i]>=10){
				box[2][i]=box[2][i]%10;
				box[2][i+1]+=1;
				if(i==end-1)finish=end+1;
			}
		}
		if(finish<=80){for(i=finish-1;i>=0;i--)printf("%d",box[2][i]);
		printf("\n");
		}
		else printf("overflow\n");
		
		for(i=0;i<3;i++){
			for(j=0;j<80;j++)box[i][j]=0;
		}
	}
return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f,maxn=1e3+50;
int a[maxn][maxn],nowp[maxn],vis[maxn],n;
int main()
{
	int i,j,k,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		nowp[i]=1;
		for(j=1;j<=n-1;j++)
			cin>>a[i][j];
	}
	int cnt=1;
	while(1)
	{
		bool f=false;
		for(i=1;i<=n;i++)
		{
			if(nowp[i]>=n || vis[i]==cnt)
				continue;
   			j=a[i][nowp[i]];
			if(vis[j]!=cnt && nowp[j]<n && a[j][nowp[j]]==i)
			{
				nowp[j]++;
				nowp[i]++;
				vis[i]=vis[j]=cnt;
				f=true;
			}
		}
		if(!f)
			break;
		cnt++;
	}
	for(int i=1;i<=n;i++)
	{
		if(nowp[i]!=n)
		{
			cout<<-1;
			return 0;
		}
	}
	cout<<cnt-1;
	return 0;
}

Measured memory_bytes: 4352
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

ll MODP = 998244353;

int main(){
   int H,W,M;
   cin >> H >> W >> M;
   vector<int> I(H+1,0),J(W+1,0);
   vector<int> h(M),w(M);
   rep(i,M){
     cin >> h[i] >> w[i];
     I[h[i]]++;
     J[w[i]]++;
   }

   int maxinum = 0,maxjnum = 0;
   for(int i = 1;i <= H;i++){
     if(I[i] > maxinum){
       maxinum = I[i];
     }
   }
   for(int j = 1;j <= W;j++){
     if(J[j] > maxjnum){
       maxjnum = J[j];
     }
   }

   map<int,int> mi,mj;

   for(int i = 1;i <= H;i++){
     if(I[i] == maxinum){
       mi[i] = maxinum;
     }
   }
   for(int j = 1;j <= W;j++){
     if(maxjnum == J[j]){
       mj[j] = maxjnum;
     }
   }

   ll all = (mi.size())*(mj.size());

  rep(i,M){
    if(mi.count(h[i]) && mj.count(w[i])){
        all--;
      }
    }

  if(all){
    cout << maxinum + maxjnum << endl;
  }else{
    cout << maxinum + maxjnum - 1 << endl;
  }






}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n,k;
int t[101010], d[101010];
P p[101010];
i64 kind[101010], sk = 0;
void solve(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> t[i] >> d[i];
		p[i] = P(d[i],t[i]);
	}
	sort(p,p+n,greater<P>());
	
	i64 cnt = 0, ans = 0;
	priority_queue<int, vector<int>, greater<int>> pq;
	for(int i = 0; i < k; i++){
		if(kind[p[i].second] == 0) sk++;
		if(kind[p[i].second] > 0) pq.push(p[i].first);
		kind[p[i].second]++;
		cnt += p[i].first;
	}
	cnt += sk*sk;
	chmax(ans, cnt);
	
	for(int i = k; i < n; i++){
		if(pq.empty()) break;
		if(kind[p[i].second] == 0){
			int q = pq.top(); pq.pop();
			sk++;
			kind[p[i].second]++;
			cnt = cnt-q+sk*2-1 + p[i].first;
			chmax(ans, cnt);
		}
	}
	
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 3840
unittest
{
	assert( [ "2", "1 5", "2 4", "3 6" ].parse.expand.solve == 3 );
	assert( [ "3", "1 1 1", "2 2 2", "3 3 3" ].parse.expand.solve == 27 );
	assert( [ "6", "3 14 159 2 6 53", "58 9 79 323 84 6", "2643 383 2 79 50 288" ].parse.expand.solve == 87 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	input.popFront;
	auto bs = input.front.split.to!( long[] );
	input.popFront;
	auto cs = input.front.split.to!( long[] );
	return tuple( as, bs, cs );
}

auto solve( long[] as, long[] bs, long[] cs )
{
	auto r = 0L;
	auto ai = 0L;
	auto ci = 0L;
	
	as.sort();
	bs.sort();
	cs.sort();
	
	// Bを基準にする
	foreach( b; bs )
	{
		// Bより小さいAの数を検索
		while( ai < as.length && as[ ai ] < b ) ai++;
		
		// Bより大きいCの数を検索
		while( ci < cs.length && cs[ ci ] <= b ) ci++;
		auto cr = cs.length - ci;
		
		// 組み合わせの数を計算
		r += ai * cr;
	}
	
	return r;
}


Measured memory_bytes: 13308
#include <iostream>
#include <vector>
#include <map>
#include <set>

typedef long long int ll;

using namespace std;
ll a,b,c,n,m,q,aa[100000],bb[100000],cc[100000],dd[100000];
bool ra,rb,rc;
vector<ll> va(20),vb;

#define CE cout<<endl
#define C cout<<
#define E <<endl

int main(){
    cin>>n>>m>>q;
    for(int i=0;i<q;i++){
        cin>>aa[i]>>bb[i]>>cc[i]>>dd[i];
    }
    ll rmax=0;
    for(int ia=1;ia<=m;ia++){
        for(int ib=ia;ib<=m;ib++){
            for(int ic=ib;ic<=m;ic++){
                for(int id=ic;id<=m;id++){
        for(int ie=id;ie<=m;ie++){
            for(int ifi=ie;ifi<=m;ifi++){
                for(int ig=ifi;ig<=m;ig++){
        for(int ih=ig;ih<=m;ih++){
            for(int ii=ih;ii<=m;ii++){
                for(int ij=ii;ij<=m;ij++){

                    va={ia,ib,ic,id,ie,ifi,ig,ih,ii,ij};
                    ll rn = 0;
                    for(int i=0;i<q;i++){
                        if(va[bb[i]-1]-va[aa[i]-1]==cc[i])rn+=dd[i];
                    }
                    rmax = max(rmax,rn);

                }
            }
        }
                }
            }
        }
                }
            }
        }
    }
    C rmax E;

}

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

int n; //カードの枚数は2n
int m; //操作の回数
int k; //操作の種類
vector<int> card;
vector<int> C;

void rifleshuffle(){
    C = card;
    card.clear();
    for(int i = 0; i < n; i++){
        card.push_back(C[i]);
        card.push_back(C[n + i]);
    }
}

void cutk(int K){//引数はどこでカットするかを示す整数k
    C = card;
    card.clear();
    for(int i = K; i < (2 * n); i++) card.push_back(C[i]);
    for(int i = 0; i < K; i++) card.push_back(C[i]);
}

int main(void){
    cin >> n >> m;
    //可変長配列cardに１から2nまでの数を順に格納する（初期状態を作る）
    for(int i = 1; i <= (2 * n); i++){
        card.push_back(i);
    }
    for(int i = 1; i <= m; i++){
        cin >> k;
        if(k == 0) rifleshuffle();
        else cutk(k);
    }
    for(int i = 0; i < (2 * n); i++){
        cout << card[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3152
#include<stdio.h>
#include<math.h>
#define M 100000000

int main(){
  int N,i,j,tmp,left,right;
  int k=0;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }


  //for(i=0;i<N;i++){
    //printf("%d",A[i]);
  //}   
  int waru=A[0];
  for(i=1;i<N;i++){
    while(1){
      if(waru==0||A[i]==0){
        break;
      }
      if(waru>A[i]){
        waru=waru%A[i];
      }
      else if(waru<A[i]){
        A[i]=A[i]%waru;
      }
      else{
        A[i]=0;
      }

    }
      //printf("%d",waru);
    waru=waru+A[i];
  }
  printf("%d",waru);
  return 0;
}


Measured memory_bytes: 512
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

int32_t main(){_
    //freopen("input","r",stdin);
    int x,y;
    cin >> x >> y;
    int a = x * y;
    a /= __gcd(x,y);
    if(a == x) rc(-1);
    rc(a - x);
}

Measured memory_bytes: 256
#define lp(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#include<bits/stdc++.h>
using namespace std;
using dl=long long;

int main(){
    string a,b,c;
    char turn='a',ans;
    cin>>a>>b>>c;
    while(1){
        if(turn=='a'){
            if(a.empty()==true){
                ans='A';
                break;
            }
            turn=a[0];
            a.erase(a.begin());
        }
        else if(turn=='b'){
            if(b.empty()==true){
                ans='B';
                break;

            }
            turn=b[0];
            b.erase(b.begin());
        }
        else if(turn=='c'){
            if(c.empty()==true){
                ans='C';
                break;

            }
            turn=c[0];
            c.erase(c.begin());
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <vector>
#include <cmath>
 #include <iostream>
using namespace std;
#define sz(x)          (int)((x).size(x))
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define REP(i, y)  for (__typeof(x) i = 0; i < y; i++)
#define REPI(i, y)  for (__typeof(x) i = y; i > 0; i--)
typedef long long      ll;
typedef pair<int, int> P;
typedef pair<P, int>   PP;
typedef vector<int>    VV;
typedef vector<P>      VVP;
typedef vector<PP>     VVPP;
const   int            INF = 2<<20;
const   double         EPS = 1E-8;
const   int            MAX_N = 100001;
 
int main() {
  sci(N);
  long long A[MAX_N];
  long long B[MAX_N];
  long long update=0;
  for (int i=0; i<N; i++) {
    sci(a); sci(b);
    A[i] = a;
    B[i] = b;
  }
  for (int i=N-1; i>=0; i--) {
      int k=1;
      if(A[i]==0) {
        continue;
      }
      //while(k*B[i] < (A[i]+update)) k++;
      //int k = (A[i]+update)/B[i];
      //k++;
      //update += k*B[i] - (A[i]+update);
    A[i] += update;
    update += (B[i] - A[i] % B[i]) % B[i];
  }
  cout<<update<<endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <vector>
#include <algorithm>

using namespace std;
int main(){
  int N;
  cin >> N;
  int W[N];
  for(int i=0;i<N;i++) cin >> W[i];

  bool init=false; int ans = 0;
  for(int T=0;T<N;T++){
    int S0 = 0;
    int S1 = 0;
    for(int i=0;i<T;i++) S0 += W[i];
    for(int i=T;i<N;i++) S1 += W[i];
    if(init){
      ans = min(ans,abs(S0-S1));
    }else{
      ans = abs(S0-S1);
      init = true;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# A=gets.to_i
# B=gets.split.map(&:to_i)
# C=N.times.map{gets.to_i}
# D=N.times.map{gets.split.map(&:to_i)}
# S=gets.chomp
# MOD=1000000007

N,K=gets.split.map(&:to_i)

if K>(N-1)*(N-2)/2
  puts -1
  exit
end

base=N
out=[]
(N-1).times do |i|
  out << "#{base} #{i+1}"
end

count=(N-1)*(N-2)/2
a,b=base-1,base-2
while count!=K
  out << "#{a} #{b}"
  if b!=1
    b-=1
  else
    a-=1
    b=a-1
  end
  count-=1
end

puts out.size
puts out.join("\n")

Measured memory_bytes: 2172
fun popCount(bits: Long): Long {
    var b = bits
    b -= ((b shr 1) and 0x5555555555555555)
    b = (b and 0x3333333333333333) + ((b shr 2) and 0x3333333333333333)
    b = (b + (b shr 4)) and 0x0f0f0f0f0f0f0f0f
    b += (b shr 8)
    b += (b shr 16)
    b += (b shr 32)
    return b and 0x0000007f
}

fun modPow(_a: Long, _n: Long, mod: Long): Long {
    var res = 1L
    var a = _a
    var n = _n
    while (n > 0) {
        if (n and 1 == 1L) res = res * a % mod
        a = a * a % mod
        n = n shr 1
    }
    return res
}

fun f(_n: Long): Int {
    var n = _n
    var res = 0
    while (n > 0) {
        n %= popCount(n)
        res += 1
    }
    return res
}

fun main() {
    val n = readLine()!!.toInt()
    val x = readLine()!!

    val popCountX = x.count { it == '1' }
    val a0 = popCountX - 1
    val a1 = popCountX + 1
    var a0mod = 0L
    var a1mod = 0L

    for (b in x) {
        if (a0 != 0) {
            a0mod = (a0mod * 2 + b.toInt() - '0'.toInt()) % a0
        }
        a1mod = (a1mod * 2 + b.toInt() - '0'.toInt()) % a1
    }

    for (i in (0 until n).reversed()) {
        val res = if (x[n - 1 - i] == '1') {
            if (a0 != 0) {
                var next = a0mod
                next -= modPow(2L, i.toLong(), a0.toLong())
                while (next < 0) next += a0
                f(next) + 1
            } else {
                0
            }
        } else {
            var next = a1mod
            next += modPow(2L, i.toLong(), a1.toLong())
            next %= a1
            f(next) + 1
        }
        println(res)
    }
}

Measured memory_bytes: 57124
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

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

  if (A % 2 * B % 2 * C % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }

  int x = max({A, B, C});
  int y = min({A, B, C});
  int z = A + B + C - x - y;

  cout << y * z << endl;
  return 0;
}


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


vector<string> goku;

int checkKu(int bgn, int chlen) {
	int len = 0;
	int i = 0;
	while (1) {
		len += goku[bgn+i].size();
		i+=1;
		if (len > chlen)return -1;
		else if (len == chlen)return i;
	}
}

bool solve(int start) {
	int Ku[5] = { 5,7,5,7,7 }, k = start;
	for (int i = 0; i < 5; i++) {
		int j = checkKu(k, Ku[i]);
		//cout << j << endl;
		if (j > 0)k += j;
		else return false;
	}
	return true;
}

int main() {

	while (1) {
		int n;
		goku.clear();
		cin >> n;
		if (n == 0)break;
		//input
		for (int i = 0; i < n; i++) {
			string str;
			cin >> str;
			goku.push_back(str);
		}

		int s = 0;
		while (1) {
			if (solve(s))break;
			else s++;
		}
		cout << s + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3180
# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()

# int(input())
# map(int, input().split())

n = int(input())

st = {i * j for i in range(1, 10) for j in range(1, 10)}

if n in st:
    print('Yes')
else:
    print('No')


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

int main()
{
    int N;
    cin >> N;
    vector<vector<ll>> X(N, vector<ll>(3, 0));
    vector<vector<ll>> dp(N + 1, vector<ll>(3, 0));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> X[i][j];
        }
    }
    for (int i = 1; i <= N; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if (j != k)
                {
                    dp[i][k] = max(dp[i][k], dp[i - 1][j] + X[i - 1][k]);
                }
            }
        }
    }
    cout << *max_element(dp[N].begin(), dp[N].end()) << endl;

    return 0;
}

Measured memory_bytes: 11136
import java.util.*;

class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      
      int n = sc.nextInt();
      int k = sc.nextInt();
      int[] h = new int[n];
      
      for(int i=0;i<n;i++){
       h[i] = sc.nextInt();    	
       }
      int cnt = 0;
      for(int i=0;i<n;i++){
      	if(h[i] >= k){
      		cnt++;
     	 }	
      }
      
      System.out.println(cnt);
    }
}

Measured memory_bytes: 59372