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

int main(){
	int a1,a2,a3,b1,b2,b3;
	int x[4][4];
	for(int i=1; i<=3; i++){
		for(int j=1; j<=3; j++){
			cin>>x[i][j];
		}
	}
	a1=0;
	b1=x[1][1]-a1;
	b2=x[1][2]-a1;
	b3=x[1][3]-a1;
	a2=x[2][1]-b1;
	a3=x[3][1]-b1;
	if(a2+b2==x[2][2] && a2+b3==x[2][3] && a3+b2==x[3][2] && a3+b3==x[3][3]){
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N,M=list(map(int, input().split()))
a=[0]*N
b=[0]*N
for i in range(0,N):
    a[i],b[i]=list(map(int, input().split()))
c=[0]*M
d=[0]*M
for i in range(0,M):
    c[i],d[i]=list(map(int, input().split()))
for i in range(0,N):
    kyori=abs(a[i]-c[0])+abs(b[i]-d[0])
    ba=0
    for j in range(1,M):
        if kyori>abs(a[i]-c[j])+abs(b[i]-d[j]):
            kyori=abs(a[i]-c[j])+abs(b[i]-d[j])
            ba=j
    print(ba+1)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n + 1];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		a[n] = 0;
		int l = 0;
		int r = 0;
		int sum = 0;
		long ans = 0;
		while(l < n) {
			boolean flag = (sum + a[r]) == (sum ^ a[r]);
			if(r < n && flag) {
				sum += a[r];
				r++;
			} else {
				ans += r - l;
				sum -= a[l];
				l++;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 80116
#include <iostream>
using namespace std;
 
long H, W;
 
int main(){
  cin >> H >> W;
  if(H == 1 || W == 1){
    cout << 1 << endl;
  }
  else if((H * W)%2 == 0){
    cout << H * W / 2 << endl;
  }
  else{
    cout << (((H * W)-1) / 2) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,T,A;
    double d=1e6;
    int f=0;
    cin>>N>>T>>A;
    for(int i=1;i<=N;i++){
        double h;
        cin>>h;
        double val=fabs(A-(T-h*0.006));
        if(val<d) {d=val;f=i;}
    }
    cout<<f;
    return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int r; cin >> r;
  int result = r*r;
  cout << result << endl;
  return 0;
}

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

l = [[0]  * 10 for _ in range(10)]

for i in range(1,n+1):
    s=str(i)
    l[int(s[0])][int(s[-1])] +=1

r=0
for i in range(1,10):
    for j in range(1,10):
        r += l[i][j] * l[j][i]

print(r)

Measured memory_bytes: 3060
import java.util.Scanner;

class Main
{

    static int n,t;
    static int[][]a = new int[100][100];
    static int[]c  = new int[100];
    static int[]d = new int[100];
    static int[]f = new int[100];

    public static void visit(int l)
    {
	int m;
	c[l] = 1;
	d[l] = ++t;

	for(m = 0; m < n; m++)
	    {
		if(a[l][m] == 0)
		    continue;

		if(c[m] == 0)
		    {
			visit(m);
		    }
	    }
	
	c[l] = 2;
	f[l] = ++t;
    }
    
    public static void main(String[] args)
    {
	Scanner In = new Scanner(System.in);

	int l,m,k;

	n = In.nextInt();

	for(int i = 0; i < n; i++)
	    {
		for(int j = 0; j < n; j++)
		    {
			a[i][j] = 0;
		    }
	    }
	for(int i = 0; i < n; i++)
	    {
		l = In.nextInt();
		k = In.nextInt();
		l--;
		for(int j = 0; j < k; j++)
		    {
			m = In.nextInt();
			m--;
			a[l][m] = 1;
		    }
	    }


	int p;
	for(p = 0; p < n; p++)
	    c[p] = 0;

	t = 0;

	for(p = 0; p < n; p++)
	    {
		if(c[p] == 0 ) visit(p);
	    }

	for(p = 0; p < n; p++)
	    {
		System.out.println((p + 1) + " " + d[p] + " " + f[p]);
		}
    }
}

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

using ll = long long;
using ld = long double;

int main(void)
{
    ll x;
    cin >> x;
    if(x>=400 && x<=599)
    {
        cout << 8 << endl;
    }
    else if(x>=600 && x<=799)
    {
        cout << 7 << endl;
    }
    else if(x>=800 && x<=999)
    {
        cout << 6 << endl;
    }
    else if(x>=1000 && x<=1199)
    {
        cout << 5 << endl;
    }
    else if(x>=1200 && x<=1399)
    {
        cout << 4 << endl;
    }
    else if(x>=1400 && x<=1599)
    {
        cout << 3 << endl;
    }
    else if(x>=1600 && x<=1799)
    {
        cout << 2 << endl;
    }
    else if(x>=1800 && x<=1999)
    {
        cout << 1 << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	
	int l1 = 0, l2 = 0, l3 = 0;
	
	while(n--)
	{
		int x;
		cin >> x;
		
		if(x <= a)
			l1++;
		else
			if(x <= b)
				l2++;
			else
				l3++;
	}
	
	cout << min(l1, min(l2, l3));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int w,h;
int sx,sy;
int gx,gy;
int n;

vector<vector<int>> field;
int de[] = {1, 0, -1, 0};

void dfs(int x ,int y, int c) {
  if(x < 1 || x > w || y < 1 || y > h || field[x][y] != c) return;
  field[x][y] = -1;
  dfs(x + 1, y, c);
  dfs(x - 1, y, c);
  dfs(x, y + 1, c);
  dfs(x, y - 1, c);
}

int main() {
  while(cin >> w >> h, w && h) {
    field.assign(101, vector<int>(101, 0));
    cin >> sx >> sy;
    cin >> gx >> gy;
    cin >> n;
    int dd[] = {4, 2};
    for(int i = 0;i < n;i++) {
      int c, d, x, y;
      cin >> c >> d >> x >> y;
      for(int xx = x; xx < x + dd[d];xx++) {
        for(int yy = y;yy < y + dd[d ^ 1];yy++) {
          field[xx][yy] = c;
        }
      }
    }
    if(field[sx][sy] == 0) {
      cout << "NG" << endl;
      continue;
    }
    dfs(sx, sy, field[sx][sy]);
    if(field[gx][gy] == -1) {
      cout << "OK" << endl;
    }
    else {
      cout << "NG" << endl;
    }
  }
}




Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000;
const ll mod = 1000000007;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
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;}
typedef pair<int, int> pair;
bool seen[100000];
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
 
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

//dpTable
int dp[100050];

int main(){
    ll L,R;
    cin >> L >> R;
    if (L + 2019 <= R) cout << 0 << endl;
    else {
        ll ans = 2019;
        for (ll i = L; i < R; i++) {
            for (ll j = i + 1; j <= R; j++) {
                ll hoge = (i * j) % 2019;
                ans = min(ans,hoge);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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


int main() {
    string s;
    cin >> s;

    if (s.length()==6 && s[2]==s[3] && s[4]==s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;



}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (m, d) = readLine()!!.split(' ').map { it.toInt() }
    println((22..d).count {
        val d1 = it % 10
        val d10 = it / 10
        d1 >= 2 && d10 >= 2 && d1 * d10 <= m
    })
}

Measured memory_bytes: 38304
N = int(input())

a_count = 0
b_count = 0
ab_count = 0
ans = 0

for i in range(N):
    S = input()
    head = S[0]
    tail = S[-1]
    if head == 'B' and tail == 'A':
        ab_count += 1
    elif head == 'B':
        b_count += 1
    elif tail == 'A':
        a_count += 1

    index = -1
    while True:
        index = S.find("AB", index + 1)
        if index == -1:
            break
        ans+= 1

if ab_count == 0:
    print(ans + min(a_count, b_count))
else:
    if a_count == 0 and b_count == 0:
        print(ans + ab_count - 1)
    elif a_count == 0 or b_count == 0:
        print(ans + ab_count)
    else:
        print(ans + ab_count + 1 + min(a_count, b_count) - 1)

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

int main() {
  string s,t;
  cin >> s;
  cin >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}



Measured memory_bytes: 3592
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H, W, K = list(map(int, sys.stdin.buffer.readline().split()))
S = [list(map(int, list(sys.stdin.buffer.readline().decode().rstrip()))) for _ in range(H)]


# print(S)

# TODO: H == 1

# @debug
def solve(counts):
    ts = [0] * len(counts)
    ret = 0
    for w in range(W):
        s = [0] * len(counts)
        div = False
        for i, cnts in enumerate(counts):
            s[i] += cnts[w]
            if s[i] > K:
                return INF
            if s[i] + ts[i] > K:
                div = True
        if div:
            ret += 1
            ts = s
        else:
            for i, c in enumerate(s):
                ts[i] += c
    return ret


if H == 1:
    ans = solve(S)
else:
    # 横の分割方法を全探索
    ans = INF
    for divs in itertools.product([True, False], repeat=H - 1):
        counts = []
        li = [0] * W
        for h, div in enumerate(divs):
            for w, c in enumerate(S[h]):
                li[w] += c
            if div:
                counts.append(li)
                li = [0] * W
        for w, c in enumerate(S[-1]):
            li[w] += c
        counts.append(li)
        ans = min(ans, solve(counts) + sum(divs))
print(ans)


Measured memory_bytes: 48988
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
ans = 0
for b in range(k+1, n+1):
    ans += n // b * (b - k) + max(n % b - k + 1 , 0)



if k:
    print(ans)
else:
    print(n ** 2)

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ll x;
    cin >> x;

    vector<bool> dp(x + 1);
    dp[0] = true;

    rep(i, x) {
        if (dp[i]) {
            rep(j, 6) {
                if (i + 100 + j <= x)
                    dp[i + 100 + j] = true;
            }
        }
    }

    dp[x] ? cout << "1" : cout << "0";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    int n;cin>>n;
    int k;cin>>k;
    set<int> st;
    for(int i=0;i<k;i++){
        int d;cin>>d;
        for(int j=0;j<d;j++){
            int x;cin>>x;
            st.insert(x);
        }
    }
    cout<<n-st.size()<<"\n";
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);

    solve();
    return 0;
}

Measured memory_bytes: 3660
#include<cstdio>
int n,a,b,c,x,i;
main(){
  scanf("%d%d",&n,&a);
  for(i=1;i<n;i++){
    scanf("%d",&b);
    if(b==a)continue;
    if(x){if(x==1&&b<a||x==-1&&b>a)x=0,c++;}
    else x=b>a?1:-1;
    a=b;
  }
  printf("%d",c+1);
}


Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define max 1000001
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
int dp[max],cnt[max];
int main()
{
        fast;
        int t=1;
        //cin>>t;
        while(t--)
        {
                int n;
                cin>>n;
                int a[n],c=0;
                for(int i=1;i<max;i++)
                      {
                            dp[i]=1;//intialize all to 1 ,i.e., all have no divisors
                            cnt[i]=0;//count of all no.s initialized to 0
                      }
                for(int i=0;i<n;i++)
                {
                        cin>>a[i];
                        cnt[a[i]]++;//count the occurence of a particular no.
                }

                for(int i=1;i<=max;i++)
                {
                       if(cnt[i]==1 && dp[i]==1)//increase count if unique and have no divisors except itself
                                c++;
                        if(cnt[i]>=1)//if element present,,,  initialize (dp) of its multiples to 0
                        {
                                for(int j=2*i;j<=max;j+=i)
                                        dp[j]=0;
                        }
                }
                cout<<c<<endl;
        }
}

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

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

using namespace std;
using ll=long long;

const int INF = 100000;

int main() {
    int S, W;
    cin >> S >> W;
    if (S > W) {
        cout << "safe";
    } else {
        cout << "unsafe";
    }

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
  
#define rep(i,b) for(int i = 0 ; i < b; i++)
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(a) (int)a.size()
#define mod 1000000007
#define dbg(a) cout<<#a<<" = "<<a<<endl
#define dbg2(a,b) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<endl
#define dbg3(a,b,c) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<endl
#define dbg4(a,b,c,d) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<endl
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>



void solve()
{
    int n;cin>>n;
    ld d,ans=0;
    while(n--){
        cin>>d;
        d=(ld)1/d;
        ans+=d;
    }
    ans=(ld)1/ans;
    cout<<ans;
}
 
int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(11);
    clock_t beg=clock();
    int t=1, n;
    // cin>>t;
    // n = t;
    while(t--){
        // cout << "Case #" << n-t << ": ";
        solve();
    }
    //
    clock_t end=clock();
    fprintf(stderr, "%lf sec\n", (double)(end-beg)/(CLOCKS_PER_SEC));
    return 0;
}

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

using namespace std;

int main(void) {
    constexpr long MOD = 1e9 + 7;
    auto inv = [&](long a) {
        long r = 1, b = MOD-2;
        while(b) {
            if(b&1) r *= a, r %= MOD;
            a *= a, a %= MOD;
            b >>= 1;
        }
        return r;
    };
    auto comb = [&](long a, long b) {
        long r = 1;
        for(long i=0; i<b; i++)
            r *= a-i, r %= MOD, r *= inv(i+1), r %= MOD;
        return r;
    };
    auto h = [&](long a, long b) {
        return comb(a+b-1, b);
    };

    long n, m;
    cin >> n >> m;

    char nprime[100000];
    nprime[0] = nprime[1] = 1;
    for(long i=2; i<1e5; i++) {
        if(nprime[i]) continue;
        for(long j=2; i*j<1e5; i++)
            nprime[i*j] = 1;
    }

    vector<long> v;
    for(long i=2; i*i<=m; i++) {
        if(m % i) continue;
        long c = 0;
        while(m % i == 0) c++, m /= i;
        v.push_back(c);
    }
    if(m > 1)
        v.push_back(1);

    long r = 1;
    for(auto &e: v)
        r *= h(n, e), r %= MOD;
    cout << r << endl;

}


Measured memory_bytes: 384
from collections import deque
 
S = input()
Q = int(input())
S = deque(S)
 
flg_reverse = False
 
for q in range(Q):
  _ = input()
  if _[0] == '1':
    flg_reverse = flg_reverse ^ True
  else:
    _T, _F, _C = _.split()
    ## リバース回数が奇数偶数のいずれかをチェック
    if _F == '1':
      if flg_reverse:
        S.append(_C)
      else:
        S.appendleft(_C)
    else:
      if flg_reverse:
        S.appendleft(_C)
      else:
        S.append(_C)        
 
S = list(S)
# reverseの部分を対応
if flg_reverse:
  S.reverse()
 
print(''.join(S))

Measured memory_bytes: 8436
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> vec(N+1,0);
    int cnt=0;
    for(int i=1; cnt<M; i++){
        if(N%2==1){
            cout << i << ' ' << N-i << endl;
        }else{
            if(i<=N/4){
                cout << i << ' ' << (N/4)*2+1-i << endl;
            }else{
                cout << (N/4)*2+(i-N/4) << ' ' << N-(i-(N/4)) << endl;
            }
        }
        cnt++;
    }
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }


int main(){
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    vector<vector<int>> G(N);
    REP(i, N) cin >> H[i];
    REP(i, M){
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    int ans = 0;
    REP(i, N){
        bool ok = true;
        for(int t : G[i]){
            if(H[i] <= H[t]){
                ok = false;
                break;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8804
#include <iostream>
#include <stdio.h>

int main(){
  int n, k;
  std::cin >> n >> k;
  int h[n];
  int count = 0;
  for(int i = 0; i < n; i++){
    scanf("%d",&h[i]);
    if(h[i] >= k) count++;
  }

  std::cout << count << std::endl;
  
  return 0;
}


Measured memory_bytes: 640
N, Y = map(int, input().split())

for i in range(N+1):
	for j in range(N-i+1):
		k = N - i - j
		result = 10000 * i + 5000 * j + 1000 * k
		if (result == Y):
			print('{} {} {}'.format(i, j, k))
			exit()

print('-1 -1 -1')

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;


int main(){
    int n;
    cin >> n;
    for (int i = 3; i <= n; i++){
        if (i % 3 == 0 || i % 10 == 3) {
            cout << " " << i;
        } else {
            int x = i;
            do {
                x /= 10;
                if (x == 3 || x%10 == 3) {
                    cout << " " << i;
                    break;
                }
            } while (x > 10);
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3076
import java.util.*;
public class Main
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        int k=sc.nextInt();
        int m=sc.nextInt();
        int cnt=0;
        TreeMap<Long,Integer> tmap=new TreeMap<>();
        long prod=1L*k;
        long ans=0;
        int ind=-1;
        for(int i=0;i<Math.min(n,m);i++)
        {
            tmap.put(prod%m,i);
            ans=ans+prod%m;
            cnt++;
            prod*=prod;
            prod%=m;
            if(tmap.containsKey(prod))
            {
                ind=tmap.get(prod);
                break;
            }
        }
        if(cnt==n)
        System.out.println(ans);
        else if(cnt<n)
        {
            long div=0;
            long sum=0;
            for(Map.Entry<Long,Integer> me:tmap.entrySet())
            {
                if(me.getValue()>=ind)
                {
                    sum=sum+me.getKey();
                    div++;
                }
            }
            ans=ans+sum*((n-cnt)/div);
            int cnt1=(int)((n-cnt)%div);
            for(Map.Entry<Long,Integer> me:tmap.entrySet())
            {
                if(me.getValue()>=ind&&me.getValue()<ind+cnt1)
                {
                    ans=ans+me.getKey();
                }
            }
            System.out.println(ans);
        }
    }
}

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;


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

    int n,k;
    cin >> n >> k;
    k=min(n,k);
    string s;
    cin >> s;
    s=s+'s';

    int com[n*3];
    for (int i=0;i<n*3;i++) com[i]=0;
    char bef='0';
    int cnt=0,id=0;
    
    for (int i=0;i<=n;i++){
        if (bef!=s[i]){
            bef=s[i];
            com[id]=cnt;
            cnt=1;
            id++;
        } else{
            cnt++;
        }
    }

    int pc[n*3+k*2];
    for (int i=0;i<n*3+k*2;i++) pc[i]=0;
    for (int i=0;i<3*n;i++){
        pc[i+1]=pc[i]+com[i];
    //    cerr << pc[i+1] << " ";
    }
    //cerr << el;


    int mx=0;
    for (int l=1;l<=id;l++){
        int r=l+k+k;
        if (l&1){
            r--;
        }
        mx=max(mx,pc[r]-pc[l-1]);
    //    cerr << mx << el;
    }

    cout << mx << el;

    return 0;
}

Measured memory_bytes: 3564
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <map>


using namespace std;

int main() {
    string s;
    map<char, int> m;
    cin >> s;
    for (auto c:s)m[c]++;
    bool res = true;
    for (auto mi:m) if (mi.second != 2) res = false;
    cout << (m.size() == 2 && res ? "Yes" : "No")
         << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long long ans=0;
	for(int i=0;i<(1<<(s.size()-1));i++)
	{
		long long num=s[0]-'0';
		for(int j=0;j<s.size()-1;j++)
		{
			if((i&(1<<j))==0)
			{
				//cout<<num<<endl;
				ans+=num;
				num=0;
			}
			num=num*10+(s[j+1]-'0');
		}
		//cout<<num<<endl;
		ans+=num;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 14.08.2020 13:05:23
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s.at(i);
    sort(s.begin(),s.end());
    
    int ans=1;
    rep(i,n-1) if(s.at(i)!=s.at(i+1)) ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
// おまじない
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
// 型alias
template<class T>
using vec = vector<T>;
using vint = vec<int>;
using vvint = vec<vint>;
using str = string;
using mstr = map<str, int>;
using mchar = map<char, int>;
using mint = map<int, int>;
// alias
#define gcd __gcd
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
signed main() {
    INCANT;
    int n, res = 0, a;
    cin>>n;
    queue<int> q[1111];
    rep(i, n){
        rep(j, n - 1){
            cin>>a;
            a--;
            q[i].push(a);
        }
    }
    int tmp = n*(n - 1)/2;
    for(;tmp > 0;res++){
        bool flag = true;
        bool used[1111] = {};
        rep(i, n){
            if(q[i].empty()){
                continue;
            }
            while(1){
	            int p = q[i].front();
	            if(!used[i] && !used[p] && q[p].front() == i){
	                used[i] = used[p] = true;
	                q[i].pop();
	                q[p].pop();
	                tmp--;
	                flag = false;
	            }else{
	            	break;
	            }
            }
        }
        if(flag){
            cout<<-1;
            return 0;
        }
    }
    cout<<res;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int h, a;
	cin >> h >> a;
	
	cout << ce(h, a) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,result;
	int v[100];
	int c[100];

	cin >> n;
	
	result = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int j = 0; j < n; j++) {
		cin >> c[j];
	}
	for (int k = 0; k < n; k++) {
		if (v[k] - c[k] > 0) {
			result += v[k] - c[k];
		}
	}

	cout << result;
}

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

#define fi first
#define se second

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

const ll D = 100007;

ll f(ll x)
{
    if (x % 4 == 3)
        return 0;
    if (x % 4 == 0)
        return x;
    if (x % 4 == 1)
        return 1;
    if (x % 4 == 2)
        return 1 ^ x;
}

int main()
{
    ll a, b;
    cin >> a >> b;
    if (a == 0)
        cout << f(b) << endl, exit(0);
    cout << (f(b) ^ f(a - 1)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
long long dist[1 << 18];
long long group[1 << 18]; char q;
long long n, Q, a, b, c;
vector<long long>gr[1 << 18];
int main() {
	while (true) {
		for (int i = 0; i < (1 << 18); i++) {
			dist[i] = 0; group[i] = i; gr[i].clear(); gr[i].push_back(i);
		}
		cin >> n >> Q; if (n == 0 && Q == 0)break;
		for (int i = 0; i < Q; i++) {
			cin >> q;
			if (q == '?') {
				cin >> a >> b;
				if (group[a] != group[b])cout << "UNKNOWN" << endl;
				else cout << dist[b] - dist[a] << endl;
			}
			if (q == '!') {
				cin >> a >> b >> c;
				long long L = group[a], M = group[b];
				if (group[a] != group[b] && gr[L].size() >= gr[M].size()) {
					long long K = dist[a] + c - dist[b];
					for (int j = 0; j < gr[M].size(); j++) {
						group[gr[M][j]] = L;
						gr[L].push_back(gr[M][j]);
						dist[gr[M][j]] += K;
					}
					gr[M].clear();
				}
				else if (group[a] != group[b]) {
					long long K = dist[b] - c - dist[a];
					for (int j = 0; j < gr[L].size(); j++) {
						group[gr[L][j]] = M;
						gr[M].push_back(gr[L][j]);
						dist[gr[L][j]] += K;
					}
					gr[L].clear();
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 21664
#include <bits/stdc++.h>
 
using namespace std;
 
const int maxn = 2000;
struct node {
    long long a,b,c,s;
} g[maxn];
int n,m;
long long s[maxn];
long long calc(int flag1,int flag2,int flag3,int i ) {
    long long ans = 0;
    if(flag1) ans += g[i].a;
    else ans -= g[i].a;
    if(flag2) ans += g[i].b;
    else ans -= g[i].b;
    if(flag3) ans += g[i].c;
    else ans -= g[i].c;
    return ans;
}
 
bool cmp(long long a,long long b) {
    return a > b;
}
 
long long getMax(int a,int b,int c) {
    for(int i = 1; i <= n; i++)
        s[i] = calc(a,b,c,i);
    sort(s + 1,s + 1 + n,cmp);
    long long sum = 0;
    for(int i = 1; i <= m; i++)
        sum += s[i];
    return sum;
}
int main() {
    while(cin >> n >> m) {
        memset(s,0,sizeof(s));
        long long ans = 0;
        for(int i = 1; i <= n; i++) cin >> g[i].a >> g[i].b >> g[i].c,g[i].s = g[i].a + g[i].b + g[i].c;
        ans = max(ans,getMax(1,1,1));
        ans = max(ans,getMax(1,1,0));
        ans = max(ans,getMax(1,0,1));
        ans = max(ans,getMax(0,1,1));
        ans = max(ans,getMax(1,0,0));
        ans = max(ans,getMax(0,0,1));
        ans = max(ans,getMax(0,1,0));
        ans = max(ans,getMax(0,0,0));
        cout << ans << endl;
    }
    return 0;
}


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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, M; cin >> N >> M;
  cout << N-M-1 << endl;

  return 0;
}

Measured memory_bytes: 3184
// $%U%$
// $%D%$/$%M%$/$%Y%$
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    int n = nxt();
    VI a(n+1, 0);
    for(int i = 1; i <= n; i++){
        for(int j = i; j <= n; j+=i) a[j]++;
    }
    ll ans = 0;
    for(int i = 1; i < n; i++) ans += a[i];
    printf("%lld\n", ans);
    return 0;
}




Measured memory_bytes: 7204
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int count0 = 0;
        int count1 = 0;
        for(int i = 0; i < s.length(); i++){
        	if(s.charAt(i) == '0'){
            	count0++;
            }else{
            	count1++;
            }
        }
        int ans = Math.min(count0, count1);
        System.out.println(ans * 2);
    }
}

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

#define _USE_MATH_DEFINES
#include<cmath>


int main(){
    double r, S, L;
    cin >> r;
    S = (r * 1.0) * (r * 1.0) * M_PI;
    L = 2.0 * M_PI * r;

    cout << fixed << setprecision(10) << S << " " << L << endl;
    return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    cin >> a >> b >> x;
    YN(a <= x && x <= a + b)
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n;
	cin>>n;
	map<string,int> m;
	rep(i,n){
		string s;
		cin>>s;
		m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;
	re 0;
}

Measured memory_bytes: 3576
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,k; cin>>n>>k;
    ll sn=1;
    while(sn*sn<=n) sn++;
    sn--;
    vector<vector<pair<ll,ll>>> dpu(k,vector<pair<ll,ll>>(sn-1)); 
    vector<vector<ll>> dp(k,vector<ll>(n/sn,0));
    rep(i,sn-1) dpu[0][i]=mk(1,n/(i+1)-n/(i+2));
    rep(i,n/sn) dp[0][i]=1;
    for(ll i=1;i<=k-1;i++){
        ll sum=0,cnt=0;
        rep(j,sn-1){
            sum+=dp[i-1][j]; cnt++;
            sum%=MOD;
            dpu[i][j]=mk(sum,dpu[0][j].second);
        }
        for(ll j=n/sn;j>=1;j--){
            if(j>sn-1){
                ll K=n/j;
                while(K>cnt){
                    sum+=dp[i-1][cnt];
                    sum%=MOD;
                    cnt++;
                }
                dp[i][j-1]=sum;
            }
            else{
                sum+=dpu[i-1][j-1].first*dpu[i-1][j-1].second;
                sum%=MOD;
                dp[i][j-1]=sum;
            }
        }
    }
    ll ans=0;
    rep(i,sn-1) ans=(ans+dpu[k-1][i].first*dpu[k-1][i].second)%MOD;
    rep(i,n/sn) ans=(ans+dp[k-1][i])%MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 74768
n, y = map(int, input().split())


for a in range(n + 1):
    for b in range(n + 1):
        c = n - (a + b)
        if c >= 0: 
            money = a * 10000 + b * 5000 + c * 1000
            if money == y:
                print(a, b, c)
                exit()

print(-1, -1, -1)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var S1 = Line();
            var S2 = Line();
            long count = S1[0] == S2[0] ? 3 : 6;

            for (int i = S1[0] == S2[0] ? 1 : 2; i < N;) {
                if(S1[i - 1] == S2[i - 1] && S1[i] == S2[i]) {
                    count = (count * 2) % 1000000007;
                    i++;
                } else if(S1[i - 1] == S2[i - 1] && S1[i] != S2[i]) {
                    count = (count * 2) % 1000000007;
                    i += 2;
                } else if(S1[i - 1] != S2[i - 1] && S1[i] == S2[i]) {
                    i++;
                } else if(S1[i - 1] != S2[i - 1] && S1[i] != S2[i]) {
                    count = (count * 3) % 1000000007;
                    i += 2;
                }

            }
            
            Console.WriteLine(count);
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

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

public class Main {      
        public static void main(String[] args) {
            Scanner in=new Scanner(System.in);
            long a=in.nextLong();
            long b=in.nextLong();
            long c=in.nextLong();
            long d=in.nextLong();
            long ar[]=new long[4];
            ar[0]=a*c;
            ar[1]=a*d;
            ar[2]=b*c;
            ar[3]=b*d;
            Arrays.sort(ar);
            
            System.out.println(ar[3]);
            
    }
}


Measured memory_bytes: 35624
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    private static int MAX = 300;
    private static int MIN = 1;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            while (sc.hasNext()) {
                int[] h_w = Stream.of(sc.nextLine().split(" "))
                        .mapToInt(Integer::parseInt)
                        .toArray();
                if (h_w.length != 2) {
                    throw new IllegalTestCaseException();
                }
                int h = h_w[0];
                int w = h_w[1];
                if (h == 0 && w == 0) {
                    break;
                }
                if (h > MAX || h < MIN || w > MAX || w < MIN) {
                    throw new IllegalTestCaseException();
                }
                for (int i = 0; i < h; i++) {
                    for (int j = 0; j < w; j++) {
                        if ((i + j) % 2 == 0) {
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }
        } catch (IllegalTestCaseException
                | NoSuchElementException
                | NumberFormatException e) {
            System.out.println(e);
        }
    }

    private static class IllegalTestCaseException extends RuntimeException {
        IllegalTestCaseException() {
            super("Illegal condition.");
        }
    }
}



Measured memory_bytes: 36288
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> cnt(n);
    rep(i, n) {
        a[i]--;
        if (a[i] == 0) {
            cnt[a[i]] = 1;
        } else {
            cnt[a[i]] = cnt[a[i]-1] + 1;
        }
    }
    cout << n - *max_element(all(cnt)) << endl;
}


Measured memory_bytes: 4768
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.{NumericRange, Queue}
import scala.collection.mutable
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextInt
    if (N != 0) {
      val A = Array.fill(N)(sc.nextInt).groupBy(x => x).map(x => (x._1, "*" * x._2.length))
      for (i <- Range(0, 10)) {
        println(A.getOrElse(i, "-"))
      }
      solve(sc)
    }
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


Measured memory_bytes: 80244
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
int M;
queue< int >q[312];
vector< int >mp;
int A;
int jdg;
int num[312];
int ans = 312;
int cnt;
int x;
int MAX;

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

	
	
	REP( i, N ){
		REP( j, M ){
			scanf("%d", &A);
			q[i].push( A );
		}
	}
		
	REP( i, M ){
		REP( j, N ){
			while( 1 ){
				jdg = 1;
				num[j] = q[j].front();
				if( mp.size() == M-1 ) break;
				REP( k, mp.size() ){
					
					if( mp[k] == num[j] ){
						jdg = 0;
						q[j].pop();
					}
				}
				if( jdg ) break;
			}
		}
		
		
		
		cnt = 1;
		MAX = 1;
		sort( num, num+N );
		
				
		FOR( j, 1, N ){
			if( num[j] == num[j-1] ) cnt++;
			else{				cnt=1;}
			if( cnt > MAX ){
				MAX = cnt;
				x = num[j];
				//cout<<x<<" "<<MAX<<endl;
			}
		}
		
		mp.push_back( x );
		ans = min( MAX, ans );
		//cout<<ans<<endl;
	}
	
	cout<<ans<<endl;
	
	return 0;

}

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

using namespace std;

int a, b, c, d;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> a >> b >> c >> d;
	int turn = 0;
	while (1) {
		if (turn % 2 == 0) {
			c -= b;
			if (c <= 0) {
				cout << "Yes";
				break;
			}
		}
		else {
			a -= d;
			if (a <= 0) {
				cout << "No";
				break;
			}
		}
		turn++;
	}

	return 0;
}

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

int main(){
	int w[10], k[10], ansk =0, answ = 0;
	for(int i=0; i < 20; i++){
		if(i < 10) cin >> w[i];
		else cin >> k[i-10];
	}
	sort(w, w+10);
	sort(k, k+10);

	answ = w[7] + w[8] + w[9];
	ansk = k[7] + k[8] + k[9];

	cout << answ << ' ' << ansk << endl;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

bool dp[611][611];
char a[611][611];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
			a[i+n][j]=a[i][j+n]=a[i+n][j+n]=a[i][j];
		}
	}
	int ans = 0;
	for(int x=0;x<n;x++)
	{
		bool pos=1;
		for(int i=0;i<n;i++)
		{
			for(int j=x;j<x+n;j++)
			{
				if(a[i][j]!=a[j-x][i+x]) pos=0;
			}
		}
		if(pos) ans++;
	}
	ans*=n;
	cout<<ans<<'\n';
}


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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int a[26] = {0};
    for(int i = 0; i < n; i++){
        a[s[i] - 'a']++;
    }
    for(int i = 0; i < 26; i++){
        if(a[i] % 2 != 0){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 256