akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
using ll = long long;
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    //vector<vector<int>> d(N, vector<int>(1000000000, -1));
    vector<vector<pair<int, int>>> d(100001, vector<pair<int, int>>());
    vector<pair<int, string>> ans(100001, pair<int, string>());

    for (int i = 0; i < M; i++)
    {
        int p, y;
        cin >> p >> y;
        d[p - 1].push_back(pair<int, int>(y, i));
    }
    for (int i = 0; i < 100001; i++)
    {
        sort(d[i].begin(), d[i].end());
    }

    for (int i = 0; i < 100001; i++)
    {
        int k = 1;
        for (auto p : d[i])
        {
            stringstream sout, sout2;
            sout << setw(6) << setfill('0') << i + 1;
            sout2 << setw(6) << setfill('0') << k;
            ans.push_back(pair<int, string>(p.second, sout.str() + sout2.str()));
            k++;
        }
    }
    sort(ans.begin(), ans.end());
    for (auto v : ans)
        cout << v.second << endl;
    return 0;
}

Measured memory_bytes: 14820
inpl = lambda: list(map(int,input().split()))
def bisect_left_withkey(a, x, lo=0, hi=None, key=lambda x: x, keyvalue_x=False):
    left = lo
    right = len(a) if hi is None else hi
    kx = key(x) if keyvalue_x else x
    while left + 1 < right:
        new = (left + right)//2
        kn = key(a[new])
        if kx <= kn:
            right = new
        else:
            left = new
    if key(a[left]) == kx:
        return left
    else:
        return right

N, K = inpl()
A = inpl()
F = inpl()
A.sort(reverse=True)
F.sort()
score = [A[i]*F[i] for i in range(N)]

def achievable(m):
    k = 0
    for i in range(N):
        k += max(0, (score[i]-m-1)//F[i] + 1)
        if k > K:
            return False
    return True

M = max(score)
print(bisect_left_withkey(range(M+1), True, key=achievable))

Measured memory_bytes: 120396
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()

//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;   
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = (int)2e5 + 5;

int mn[MAXN], mx[MAXN];

int arr[MAXN];

int n, k, ans;

void addEl(deque<int> &D, int x, bool asc) {
    while (!D.empty() && (arr[D.back()] > arr[x]) == asc) {
        D.pop_back();
    }       

    D.pb(x);
}

void delEl(deque<int> &D, int x) {
    while (!D.empty() && D.front() <= x) {
        D.pop_front();
    }
}

void solve() {
    scanf("%d %d", &n, &k);

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &arr[i]);
    }

    deque<int> A, B;
    int cnt = 0;

    for (int i = 1; i <= k; ++i) {
        addEl(A, i, 1);
        addEl(B, i, 0);

        if (i < k) {
            cnt += (arr[i] < arr[i + 1]);
        }
    }

    mn[1] = A.front();
    mx[1] = B.front();
    int ext = 0;

    if (cnt == k - 1) {
        ext = 1;    
    }
    else {
        ans = 1;
    }
    
    for (int i = 1; i + k <= n; ++i) {
        addEl(A, i + k, 1);
        addEl(B, i + k, 0);
        delEl(A, i);
        delEl(B, i);
        mn[i + 1] = A.front();
        mx[i + 1] = B.front();
        cnt -= (arr[i] < arr[i + 1]);
        cnt += (arr[i + k - 1] < arr[i + k]);

        if (cnt == k - 1) {
            ext = 1;
            continue;
        }

        if (mx[i + 1] == i + k && mn[i] == i) {
            // nothing
        }
        else {
            ++ans;
        }                                    
    }    

    printf("%d\n", ans + ext);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val n=readLine()!!.toInt()
    val b=readLine()!!.split(" ").map { intArrayOf(it.toInt(),0) }
    val result = Array(n){0}
    var count = n
    while (count>0){
        for (i in n-1 downTo 0){
            if(b[i][0]-1 == b[i][1]){
                b[i][1]=-2*n
                for (j in i+1 until n)b[j][1]+=1
                count-=1
                result[count]=b[i][0]
                break
            }else if(b[i][0]-1 < b[i][1]|| b[i][0]-1 >i){
                println("-1")
                return
            }
        }

    }
    result.reversed().forEach { println(it) }
}

Measured memory_bytes: 37900
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - pushpush
            int n = int.Parse(Console.ReadLine());
            var a = ReadLine();
            a.Reverse();

            var b = new List<int>();
            var c = new List<int>();

            for(int i = 0; i < n; i++)
            {
                if (i % 2 == 0)
                {
                    b.Add(a[i]);
                }
                else
                {
                    c.Add(a[i]);
                }
            }

            c.Reverse();
            b.AddRange(c);

            Console.WriteLine(String.Join(" ", b));
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 47928
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int ax, ay, bx, by;
	cin >> ax >> ay >> bx >> by;
	ff(i, 0, bx - ax) {
		cout << 'R';
	}
	ff(i, 0, by - ay) {
		cout << 'U';
	}
	ff(i, 0, bx - ax) {
		cout << 'L';
	}
	ff(i, 0, by - ay) {
		cout << 'D';
	}//1lap finnished
	cout << 'D';
	ff(i, 0, bx - ax+1) {
		cout << 'R';
	}
	ff(i, 0, by - ay+1) {
		cout << 'U';
	}
	cout << 'L';
	cout << 'U';
	ff(i, 0, bx - ax+1) {
		cout << 'L';
	}
	ff(i, 0, by - ay+1) {
		cout << 'D';
	}
	cout << 'R';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	std::ios_base::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	int m[s.size()+1][t.size()+1];
	for(int i=0;i<=s.size();i++)
	{
		for (int j = 0; j <= t.size(); ++j)
		{
			if(i==0||j==0) m[i][j]=0;
			else{
				if(s[i-1]==t[j-1]) m[i][j]=m[i-1][j-1]+1;
				else m[i][j]=max(m[i-1][j],m[i][j-1]);
			}
		}
	}

	string ans;
	int i=s.size();
	int j=t.size();
	while(m[i][j]!=0)
	{	//cout<<" i "<<i<<" j "<<j<<endl;
		if(s[i-1]==t[j-1])
		{
			ans+=s[i-1];
			i--;
			j--;
		}
		else if(m[i-1][j]>=m[i][j-1]){
			i--;
		}
		else if(m[i-1][j]<m[i][j-1]){
			j--;
		}
	}

	reverse(ans.begin(), ans.end());
	cout<<ans;

	return 0;
}

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



int main()
{
	long long n;

	std::cin >> n;

	std::map<long long, long long > m;
	long long ans = 0;
	for (size_t i = 0; i < n; i++) {
		long long l;

		std::cin >> l;
		m[l]++;
	}

	for (auto it = m.begin(); it != m.end(); it++) {
		if (it->second % 2 == 1) {
			ans++;
		}
	}

	std::cout << ans << std::endl;





	

	return 0;
}

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

typedef long long ll;

ll inf = 1LL<<60;
int main(){
    int n,m,r;
    cin >> n >> m >> r;
    vector<vector<pair<ll,int> > >g(n);
    for(int i=0;i<m;i++){
        int s,t;
        ll d;
        cin >> s >> t >> d;
        g[s].push_back(make_pair(d,t));
    }
    vector<ll>dst(n);
    for(int i=0;i<n;i++){
        dst[i] = inf;
    }
    dst[r] = 0;
    priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >pq;
    pq.push(make_pair(0,r));
    while(!pq.empty()){
        auto x = pq.top();
        pq.pop();
        if(dst[x.second]!=x.first)continue;
        for(auto y:g[x.second]){
            if(dst[y.second]>dst[x.second]+y.first){
                dst[y.second] = dst[x.second]+y.first;
                pq.push(make_pair(dst[y.second],y.second));
            }
        }
    }
    for(int i=0;i<n;i++){
        if(dst[i]==inf){
            cout << "INF" << endl;
        }else{
            cout << dst[i] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 19376
fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let s: String = std::io::Read::bytes(stdin.lock())
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    s.parse().ok().expect("error")
}

fn main() {
    let n: u32 = input();
    let mut flag: bool = false;
    for i in 0..n / 7 + 1 {
        for j in 0..(n - 7 * i) / 4 + 1 {
            if n == 7 * i + 4 * j {
                flag = true;
            }
        }
    }
    println!("{}", if flag {"Yes"} else {"No"});
}

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

int main(){
    long long w,n,ans = 0;
    cin>>n>>w;
    vector<long long> weight(w+1);
    for(int item = 0;item<n;item++){
        int ni,wi;
        cin>>ni>>wi;
        for(int i = w-ni;i>=0;i--){
            weight[i+ni] = max(weight[i+ni],weight[i]+wi);
        }
    }
    for(int x = 0;x<=w;x++){
        ans = max(ans,weight[x]);
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 1024
import sys
def main():
    N,M=tuple(map(int,sys.stdin.readline().split()))
    H=list(map(int,sys.stdin.readline().split()))
    E=[[] for _ in [0]*N]
    for _ in [0]*M:
        a,b=tuple(map(lambda x:int(x)-1,sys.stdin.readline().split()))
        E[a].append((b,(H[b]-H[a])))
        E[b].append((a,(H[a]-H[b])))
    res=0
    for e in E:
        if len(e)==0:res+=1
        else:
            if all(list(map(lambda x:x[1]<0,e))):res+=1
    print(res)
if __name__=='__main__':main()

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

using namespace std;

int p[111];

int main(){
  //  freopen("input.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d", p + i);
    }
    sort(p, p + n);
    int ans = p[n - 1] / 2;
    for (int i = n - 2; i >= 0; i--){
        ans += p[i];
    }
    printf("%d\n", ans);
    return 0;
}


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

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int M1,D1,M2,D2;
	cin >> M1 >> D1 >> M2 >> D2;
	cout << (M1 < M2 ? 1 : 0);
	// cout << "[deb: val ]" << val <<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000009
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string s,t,p;
    cin>>s>>t;
    s += s;
    bool ans=false;
    for (int i=0;i<t.size() && !ans;i++) {
        p = s.substr(i,t.size());
        if (p==t) ans=true;
    }
    if (ans) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int L = Integer.parseInt(sc.next());
        double edge = L / 3.0;
        double ans = edge * edge * edge;
        System.out.println(String.format("%.12f", ans));
    }
}

Measured memory_bytes: 21972
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int a,b,c,x; cin >> a >> b >> c >> x;
  int ans = 0;

  for(int i = 0; i <= a; i++) {
    for(int j = 0; j <= b; j++) {
      for(int k = 0; k <= c; k++) {
        if(x == (i*500) + (j*100) + (k*50)) { ans++; }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    string s;
    cin>>s;
    int len=s.length();
    string ans;
    if(s[len-1]=='s'){
        ans=s+"es";
    }else{
        ans=s+"s";
    }
    
    cout<<ans<<endl;
    return 0;
}

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

signed main(void)
{
	int a, b;
	cin >> a >> b;
	if (a  % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
	return 0;
}


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

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABQ = ReadIntList();
            var s = new List<long>();
            var t = new List<long>();

            s.Add(-1000000000000);
            for (int i = 0; i < ABQ[0]; i++)
            {
                s.Add(ReadLong());
            }
            s.Add(1000000000000);
            t.Add(-1000000000000);
            for (int i = 0; i < ABQ[1]; i++)
            {
                t.Add(ReadLong());
            }
            t.Add(1000000000000);
            for (int i = 0; i < ABQ[2]; i++)
            {
                long x = ReadLong();
                var a = BinarySearch(s, x);
                var c = BinarySearch(t, x);
                var ans = new List<long>();
                for (int j = 0; j <= 1; j++)
                {
                    for (int k = 0; k <= 1; k++)
                    {
                        ans.Add(Math.Abs(s[a + j] - x) + Math.Abs(t[c + k] - s[a + j]));
                        ans.Add(Math.Abs(t[c + k] - x) + Math.Abs(s[a + j] - t[c + k]));
                    }
                }
                Console.WriteLine(ans.Min());
            }

#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
        private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while(upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


Measured memory_bytes: 22000
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
 
int n, m, x;
 
int a[2123][2123];
int b[2123][2123];
int c[2123][2123];
int d[2123][2123];
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> x;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            char s;
            cin >> s;
            a[i][j] = (s == '1');
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + (a[i][j] == 1 && a[i][j - 1] == 1);
            c[i][j] = c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1] + (a[i][j] == 1 && a[i - 1][j] == 1);
            d[i][j] = d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1] + a[i][j];
        }
    }
    while(x--){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int v = b[x2][y2] - b[x2][y1] - b[x1 - 1][y2] + b[x1 - 1][y1];
        int h = c[x2][y2] - c[x2][y1 - 1] - c[x1][y2] + c[x1][y1 - 1];
        cout<<d[x2][y2] - d[x2][y1 - 1] - d[x1 - 1][y2] + d[x1 - 1][y1 - 1] - v - h<<'\n';
    }
    return 0;
}


Measured memory_bytes: 71424
import collections
N,P=map(int,raw_input().split())

Soin=[]
for i in range(2,int(P**0.5)+1):
    while P%i==0:
        P=P/i
        Soin.append(i)
if P!=1:
    Soin.append(P)

Soin_s=collections.Counter(Soin)

Ans=1
for s in Soin_s:
    if Soin_s[s]>=N:
        Ans=Ans*(s**(Soin_s[s]/N))
print Ans

Measured memory_bytes: 34552
def gcd(a,b):
  if a<b:
    a,b=b,a
  while a%b>0:
    a,b=b,a%b
  return b

def lcm(a,b):
  return (a//gcd(a,b))*b

N,M=map(int,input().split())
S=input()
T=input()

length=lcm(N,M)
S=S[::length//M]
T=T[::length//N]
if S==T:
  print(length)
else:
  print(-1)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long;
using ld = long double;

const int N = 222;

int g[N][N];

int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n, m, d;
	
	cin>>n>>m>>d;
	vector<int> r(d);
	for(int & rr : r) cin>>rr;
	
	int inf = 1e9;
	for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(i!=j) g[i][j] = inf;
	
	for(int k=0;k<m;++k){
		int i,j,l;
		cin>>i>>j>>l;
		g[i][j] = min(g[i][j], l);
		g[j][i] = min(g[j][i], l);
	}
	
	for(int k=1;k<=n;++k)
	for(int i=1;i<=n;++i)
	for(int j=1;j<=n;++j) g[i][j] = min(g[i][j], g[i][k]+g[k][j]);
	
	sort(ALL(r));
	ll ans = inf;
	ans*=ans;
	do{
		ll res = 0;
		for(int k=1;k<d;++k) res+=g[r[k-1]][r[k]];
		ans = min(ans, res);
	}while(next_permutation(ALL(r)));
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 384
import math

def solve(y, z):
  res = 0
  for i in range(len(y)):
    res += (y[i]-z[i])**2
  return math.sqrt(res)

n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    dist = solve(x[i], x[j])
    if int(dist) == dist: ans += 1
print(ans)

Measured memory_bytes: 9060
module Main where

import Data.Functor

main :: IO ()
main = do
  { [x] <- getInts
  ; putInts [x^3]
  }

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i, h) cin >> s[i];
  int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1};
  int dy[] = {0, -1, -1, -1, 0, 1, 1, 1};
  REP(i, h) REP(j, w){
    if(s[i][j] == '#') continue;
    int count = 0;
    REP(k, 8){
      int xd = j+dx[k];
      int yd = i+dy[k];
      if(xd < 0 || w <= xd || yd < 0 || h <= yd) continue;
      if(s[yd][xd] == '#') count++;
    }
    s[i][j] = (char)(count + '0');
  }
  REP(i, h) cout << s[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100002;

int n, A[CMax], ats;

int main() {
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    sort(A, A + n);

    for (int i = 0; i < n; i++) {
        if (i % 2 == n % 2) {
            ats -= A[i];
        } else {
            ats += A[i];
        }
    }

    printf("%d\n", ats);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	//入力
  	int n,m,x,y;cin>>n>>m>>x>>y;
  	vector<int> a(n);
  	vector<int> b(m);
  
  	for(int i=0;i<n;i++){
    	cin>>a.at(i);
    }
  	for(int i=0;i<m;i++){
    	cin>>b.at(i);
    }
  
  	//aとbの範囲がかぶってないかどうか？
  	sort(a.begin(),a.end());
  	sort(b.begin(),b.end());
  	if(a.at(a.size()-1)>=b.at(0)){
    	cout<<"War"<<endl;
      	return 0;
    }
  	
  	//x<z<=yの間に境界値があるかどうか
    for(int j=a.at(a.size()-1)+1;j<=b.at(0);j++){
        if(x<j && j<=y){
          cout<<"No War";
          return 0;
        }
     }
      	cout<<"War"<<endl;
}



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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat (i, a, b) for (int i = (a); i < (b); i++)
#define rep (i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int n, t, i;
    cin >> n;
    vector<int> height;
    vector<bool> lock(n, false);
    if (n == 1) {
        puts("Yes");
        return 0;
    }
    for (i = 0; i < n; i++) {
        cin >> t;
        height.push_back(t);
    }
    for (i = 0; i < n; i++) {
        if (i >= 1 && height[i - 1] >= height[i])
            continue;
        else
            height[i]--;
    }
    for (i = 0; i < n - 1; i++) {
        if (height[i] > height[i + 1]) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n;
    cin >> n;
    vector<ll>a(n),b(n);
    for(ll i=0;i<n;i++) cin >> a[i] >> b[i];
    ll ans=0;
    for(ll i=n-1;i>=0;i--){
        a[i]+=ans;
        ll dx=b[i]-a[i];
        if(a[i]==0) continue;
        if(dx>=0){
            ans+=dx;
        }else{
            dx*=-1;
            if(dx%b[i]==0) continue;
            ll cn=dx/b[i];
            b[i]*=cn+2;
            ans+=b[i]-a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4840
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, M, p;
int a[20001];

int main() {
    scanf("%d\n", &N);
    M = N + 1;
    FOR(i, 1, N) {
        scanf("%d", &p);
        a[p] = i + p * M;
    }
    FOR(i, 1, N) printf("%d ", a[i]);
    printf("\n");
    DOWN(i, N, 1) printf("%d ", i * M);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int n,x;
    cin>>n;
    if(n==2||n==8||n==64||n==32||n==16||n==128||n==256||n==512||n==1||n==4||n==1000||n==243||n==216||n==343||n==27)
    {
        cout<<n<<NL;
        return 0;
    }
    for(int i=n;i>=1;i--)
    {
        x=i;
        if(x==2||x==8||x==64||x==32||x==16||x==128||x==256||x==512||x==1||x==4||x==1000||x==243||x==216||x==343||x==27)
       {
        cout<<x<<NL;
        return 0;
       }
        int y=sqrt(i);
        if(y*y==x)
        {
            cout<<x<<NL;
            return 0;
        }
    }
    return 0;
}



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

int main() {
	// ----- 変数宣言 -----
	long long x, y;
	int length = 0;

	// ----- 入力 -----
	cin >> x >> y;

	// ----- 計算 -----

	// x<=y で終わり
	while (x <= y) {

		// 2倍する
		x *= 2;

		// 長さを足す
		length += 1;
	}

	// ----- 出力 -----
	cout << length << endl;

}

Measured memory_bytes: 256
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	X := sc.nextInt()
	shou := X / 100
	amari := X % 100
	fiveShou := amari / 5
	fiveAamari := amari % 5
	if fiveShou > shou || (fiveShou == shou && fiveAamari > 0) {
		fmt.Println(0)
		return
	}
	fmt.Println(1)
}


Measured memory_bytes: 640
#include <iostream>
#include <cctype>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	string s,t,tmp;
	bool ans = false;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 0; j < s.size(); j++) {
			if (s == t) {
				ans = true;
				break;
			}
			tmp=s[s.size()-1];

			s.pop_back();
			s.insert(0, tmp);
		}
	}
	if (ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;cin>>a>>b;
  int A=(a+11)%13,B=(b+11)%13;
  if (A==B) cout<<"Draw"<<endl;
  else cout<<(A>B ? "Alice":"Bob")<<endl;
  return 0;
}

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

class Program
{
	static void Main()
	{
        long[] input = InLongs().ToArray();
        long n = input[0];
        long k = input[1];
        long[] a = InLongs().OrderByDescending(x => x).ToArray();
        long[] f = InLongs().OrderBy(x => x).ToArray();

        long[] p = new long[n];
        long max = 0;
        long sum = 0;
        for (int i = 0; i < n; i++)
        {
            p[i] = a[i] * f[i];
            max = Math.Max(max, p[i]);
            sum += a[i];
        }

        if(k >= sum)
        {
            Console.WriteLine(0);
            return;
        }

        long min = 0;
        while (true)
        {
            if (max == min + 1)
            {
                break;
            }
            long x = (max + min) / 2;
            long count = 0;
            for (int i = 0; i < n; i++)
            {
                if (p[i] > x)
                    count += (p[i] - x + f[i] - 1) / f[i];
            }
            if (count <= k)
            {
                max = x;
            }
            else
            {
                min = x;
            }
        }

        Console.WriteLine(max);


	}

	static string[] InStrs()
	{
		return Console.ReadLine().Split(' ');
	}
	static IEnumerable<int> InInts()
	{
		return Console.ReadLine().Split(' ').Select(x => int.Parse(x));
	}
	static IEnumerable<long> InLongs()
	{
		return Console.ReadLine().Split(' ').Select(x => long.Parse(x));
	}


}

Measured memory_bytes: 51572
import math
n=int(input())
num=int(math.sqrt(n*2))
num2=(num*(num+1))//2
num3=n-num2
if num3>num:
    num+=1
    num3-=num
if num3<0:
    num-=1
    num3+=num+1
ans=list(range(1,num+1))
for i in range(num3):
    ans[-i-1]+=1
for i in ans:
    print(i)


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

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];

  ll dp[n + 1][n + 1];  // この区間で自分に回ってきたとき、自分がとれる最大値
  memset(dp, 0, sizeof(dp));
  for (int w = 1; w <= n; w++)
    for (int i = 0; i + w <= n; i++)
      dp[i][i + w] = max(v[i] - dp[i + 1][i + w], v[i + w - 1] - dp[i][i + w - 1]);

  cout << dp[0][n] << endl;
}


Measured memory_bytes: 70656
s = int(input())


def f(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3 * n + 1


def a(i, s):
    if i == 1:
        return s
    return f(a(i - 1, s))


i = 1
a_l = []
while True:
    a_l.append(a(i, s))
    if len(a_l) != len(set(a_l)):
        print(i)
        break
    i += 1

Measured memory_bytes: 3060
frag = 0
n = int(input())
word = []
past = []
for i in range(n):
    word.append(input())
for i in range(n-1):
    if(len(word[i])==1):
        if(word[i][0] != word[i+1][0]):
            frag = 1
            break
    else:
        if(word[i][-1] != word[i+1][0]):
            frag = 1
            break
    if(word[i] in past):
        frag = 1
        break
    else:
        past.append(word[i])
if(word[len(word)-1] in past):
    frag = 1
if(frag == 1):
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	int n, c, k; cin >> n >> c >> k;
	vector<int> t(n);
	rep(i, n) cin >> t[i];
	sort(t.begin(), t.end());
	
	int ans = 0, tt = -1, m = 0;
	rep(i, n){
		if(tt == -1){
			tt = t[i];
			ans++;
			m = 0;
		}
		if(i != n-1){
			m++;
			if(t[i+1] - tt > k || m+1 > c) tt = -1;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

vector<int>invalidDigits;
bool isOk(int n){
	while(n){
		int curDigit = n % 10;
		n /= 10;
		if(find(invalidDigits.begin(), invalidDigits.end(),
				curDigit) != invalidDigits.end())
			return false;
	}
	return true;
}

int main(){
	int n, k;
	cin >> n >> k;
	while(k--){
		int d;
		cin >> d;
		invalidDigits.push_back(d);
	}
	while(true){
		if(isOk(n)){
			cout << n << '\n';
			break;
		}
		n++;
	}
	return 0;
}


Measured memory_bytes: 256
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
x = gets.chomp.to_i

ret = 0
(a+1).times do |i|
  y = x - 500 * i
  break if y < 0
  (b+1).times do |j|
    break if (z = y - 100 * j) < 0
    ret += 1 if z % 50 == 0 && z / 50 <= c
  end
end

p ret

Measured memory_bytes: 1788
#include<bits/stdc++.h> 
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=1;i<=1000;++i)
	{
		if(a*i%b==c)
		{
			cout<<"YES";
			return 0;
		}
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
import heapq
def main():
    n,k=map(int,input().split())
    V=list(map(int,input().split()))
    ans=0
    for a in range(min(k+1,n+1)):
        for b in range(min(k-a,n-a)+1):
            cd=k-(a+b)
            H=[]
            sum_V=0
            for i in range(n):
                v=V[i]
                if i+1<=a or i>=n-b:
                    sum_V+=v
                    if v<0:
                        heapq.heappush(H,V[i])
            while H and cd>0:
                sum_V-=heapq.heappop(H)
                cd-=1
            ans=max(sum_V,ans)
    print(ans)


if __name__=='__main__':
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>

int main (){
    int a,b,c,d,m,n;
    std::cin >> a >> b >> c >> d;
    std::cout << c-(d-b) << " "<< d+(c-a) << " " << a-(d-b) << " " << b+(c-a) << "\n";
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

const int mod=1000000007;
int modpow(int a,int b){
    int ret=1;
    rp(i,b){
        ret = (ret*a)%mod;
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
    vi a(n);
    rp(i,n){
        cin >> a[i];
    }
    sort(a);
    if(a[0]){
        rp(i,n){
            if(a[i]!=(i/2)*2+1){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << modpow(2,n/2) << endl;
        return 0;
    }else{
        rp(i,n){
            if(a[i]!=((i+1)/2)*2){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << modpow(2,n/2) << endl;
        return 0;
    }
    return 0;
}



Measured memory_bytes: 640
N = int(input())
X = list(map(int,input().split()))
B = [i for i in X]
B.sort()
mid_s = B[int(N/2)-1]
mid_l = B[int(N/2)]
for i in range(N):
    if X[i] <= mid_s:
        print(mid_l)
    elif X[i] >= mid_l:
        print(mid_s)

Measured memory_bytes: 26772
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int gcd(int n, int m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int r = n % m;
        n = m;
        m = r;
    }
    return n;
}

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

    int n, k;
    cin >> n >> k;

    int r = 0, m = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        r = gcd(r, a);
        m = max(m, a);
    }

    cout << &"IMPOSSIBLE"[(k % r == 0 && k <= m) * 2] << endl;

    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
if 2 * k > n + 1:
    exit(print(-1))
else:
    if n % 2 == 0:
        for i in range(n):
            if i % 2 == 0:
                print(k + i // 2, k + (i + n * 3) // 2, k + i + n * 2)
            else:
                print(k + i // 2 + n // 2, k + i // 2 + n, k + i + n * 2)
    else:
        for i in range(n):
            if i % 2 == 0:
                print(k + i // 2, k + (i + n * 3) // 2, k + i + n * 2)
            else:
                print(k + i // 2 + n // 2 + 1, k + i // 2 + n, k + i + n * 2)

Measured memory_bytes: 9204
#include<stdio.h>
int main(){
	int A, B, C, D, AB,CD,HK;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	AB = A*B;CD = C*D;
	if (AB == CD){
		HK = CD;
	}
	else if(AB<CD){
		HK = CD;
	}
	else{
		HK = AB;
	}

	printf("%d\n",HK);
	return 0;
}


Measured memory_bytes: 128
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt().sortedDescending().toMutableList()
    A.add(0)
    val B = A.toIntArray()
    val a = B[0]
    val h = a / 2
    var b1 = 0; var b2 = 0
    for (n in 1 until N) {
        if (h <= A[n]) {
            b1 = A[n]
            b2 = A[n+1]
        }
    }
    val ans = if (Math.abs(h - b1) <= Math.abs(h - b2)) b1 else b2
    println("${a} ${ans}")
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { it.toInt() + d }



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





int main() {
	int n;
	scanf("%d",&n);
	int arr[100005],x;
	memset(arr,0,sizeof arr);
	int cnt=0,temp=0;
	for(int i=0;i<n;i++){
        scanf("%d",&x);
        arr[x]++;
        if(x>0)
        arr[x-1]++;
        arr[x+1]++;
        temp=max(arr[x-1],arr[x+1]);
        cnt= max(cnt,max(temp,arr[x]));
        temp=0;
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;cin>>N;
	string S[N];int P[N];
	vector<pair<string,int>> ans(N); 
	for(int i=0;i<N;i++){
		cin>>ans[i].first>>P[i];
		ans[i].second=i;
	}sort(ans.begin(),ans.end());
	vector<pair<int,int>> check;
    
	string s=ans[0].first;
	for(int i=0;i<N;i++){
		int k=ans[i].second;
		if(ans[i].first==s){
			check.push_back(make_pair(P[k],k+1));
		}else{
			sort(check.begin(),check.end());
			reverse(check.begin(),check.end());
            /*for(int j=0;j<N;j++){
                cout<<check[j].first<<" "<<check[j].second<<endl;
            }*/
			for(int j=0;j<check.size();j++){
				cout<<check[j].second<<endl;
			}check.clear();
			check.push_back(make_pair(P[k],k+1));
            s=ans[i].first;
		}
	}sort(check.begin(),check.end());
    reverse(check.begin(),check.end());
    for(int j=0;j<check.size();j++){
		cout<<check[j].second<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
    long long a, b, c,d,i;
    scanf("%lld %lld", &a, &b);
    
    for (i = 1; i <= b; i++) {
        d = a * i;
        if (d % b == 0) {
            break;
        }
       
    }
    printf("%lld", d);
    return 0;
}

Measured memory_bytes: 128
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ull a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

int main(void) {
    cin >> n;
    rep(i, 1, 42) {
        a = pow(2, i);
        b = pow(2, i - 1);
        if (n < a && n >= b) {
            cout << a - 1 << endl;
            return 0;
        }
    }
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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 main(){
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  rep(i,1000){
    int check[3] = {i/100, i/10%10, i%10};
    bool ok[3] = {false};
    int k = 0;
    rep(j,n){
      if(s[j]-'0' == check[k]){
        ok[k] = true;
        k++;
      }
    }
    if(ok[0] && ok[1] && ok[2]) ans++;
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int p,a[3005],iC[3005][3005],inv[3005],ans;
int xs[3005][3005],g[3005];
int main(){
    scanf("%d",&p);
    for(int i=0;i<p;i++) scanf("%d",&a[i]);
    iC[0][0]=1;
    for(int i=1;i<=3000;i++){
        iC[i][0]=iC[i][i]=1;
        for(int j=1;j<i;j++) iC[i][j]=iC[i-1][j-1]+iC[i-1][j],iC[i][j]%=p;
    }
    for(int i=1;i<=3000;i++){
        for(int j=0;j<=i;j++) if((j&1)^(i&1)) iC[i][j]=p-iC[i][j];
    }
    inv[1]=1;
    for(int i=2;i<p;i++) inv[i]=(p-p/i)*inv[p%i]%p;
    inv[0]=1;
    for(int i=1;i<p;i++) inv[i]=inv[i]*inv[i-1]%p;
    for(int i=1;i<p;i++) xs[1][i]=1;
    for(int i=2;i<p;i++){
        for(int j=i;j<p;j++) xs[i][j]=(xs[i-1][j-1]+xs[i][j-1])*i%p;
    }
    for(int i=p-1;i>=1;i--){
        ans=0;
        for(int j=0;j<=i;j++) ans=(ans+iC[i][j]*a[j])%p;
        for(int j=i+1;j<p;j++){
            ans=(ans-xs[i][j]*g[j]%p+p)%p;
        }
        g[i]=ans*inv[i]%p;
    }
    g[0]=a[0];
    for(int i=0;i<p;i++) printf("%d ",g[i]);

    return 0;
}

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

int main(){
    string s; cin >> s;
    int si = int(s[s.size()-1]) - '0';
    if(si==2 || si==4 || si==5 || si==7 || si==9){
        cout << "hon" << endl;
    } else if(si==3){
        cout << "bon" << endl;
    } else {
        cout << "pon" << endl;
    }
}


Measured memory_bytes: 3608
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int main(){
	int n,m;
	cin>>n>>m;
	map<int,int>ma;
	int t=0;
	ma[t]++;
	ll out=0;
	rep(i,n){
		int a;cin>>a;
		(t+=a)%=m;
		out+=ma[t];
		ma[t]++;
	}
	
	cout<<out<<endl;
}





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

int n, m;
int p[200000];
int r[200000];

int root(int x) {
    if (r[x] == x) {
        return x;
    } else {
        r[x] = root(r[x]);
        return r[x];
    }
}

void marge(int x, int y) {
    r[root(x)] = root(y);
}

bool same(int x, int y) {
    return root(x) == root(y);
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        r[i] = i;
    }
    while (m--) {
        int x, y;
        cin >> x >> y;
        marge(x, y);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (same(i, p[i])) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(void){
	int maxC=0,maxLen=0;
	string s,maxS1,maxS2;
	map<string,int> m;

	while(cin>>s){
		m[s]++;
		if(maxC < m[s]){
			maxC = m[s];
			maxS1 = s;
		}
		if(maxLen < s.length()){
			maxLen = s.length();
			maxS2 = s;
		}
	}

	cout<<maxS1<<" "<<maxS2<<endl;

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int T,D,ta,tb,da,db,i,j;
  double min=2000000000,cal;
  cin >> T >> D >> ta >> tb >> da >> db;
  i=0;
  while(1){
    j=0;
    if(i+j>D) break;
    while(1){
      cal=(1.0*ta*i+tb*j)/(i+j);
      if(cal>T&&min>cal-T) min=cal-T;
      else if(cal<=T&&min>T-cal) min=T-cal;
      j+=db;
      if(i+j>D)	break;
    }
    i+=da;
  }
  printf("%.10f\n",min);
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int K, N;
    cin >> K >> N;
    vector<int> vec(N);
    for(int i=0;i<N;i++){
        cin >> vec[i];
    }

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

    int maxDist = 0;
    for(int i=1;i<N;i++){
      if ((vec[i] - vec[i-1]) > maxDist){
          maxDist = vec[i] - vec[i-1];
      }
    }

    if ((vec[0] + K - vec[N-1]) > maxDist){
        maxDist = vec[0] + K - vec[N-1];
    }

    int answer;
    answer = K - maxDist;

    cout << answer << endl;
} 

Measured memory_bytes: 1024