akhauriyash/Code-Regression huggingface dataset:
#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 ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

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

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

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

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

#define int long long
const int N = 2e3 + 10;
int n , x , y;
int ans[N];
vector<int> v[N];
void bfs(int s , int *lev){

	bool vis[N];
	memset(vis , false , sizeof vis);

	queue<int> q;
	q.push(s);
	lev[s] = 0;
	vis[s] = true;
	while(!q.empty()){

		int node = q.front();
		q.pop();
		for(int it : v[node]){

			if(!vis[it]){

				vis[it] = true;
				q.push(it);
				lev[it] = lev[node] + 1;
			}
		}
	}


}

void solve(){

	int x;
	cin>>x;

	int ans = (x/500)*1000;
	x = x - (x/500)*500;

	ans += (x/5)*5;

	cout<<ans<<endl;
}

signed main(){

    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}




Measured memory_bytes: 256
s=input()
t=0
if s[0]=="A":
    if(s[2:-1].count("C")==1):
        for i in s:
            if i!="A" and i!="C":
                if i.isupper():
                    t=0
                    break
                else:
                    t=1
if t==0:
    print("WA")
else:
    print("AC")


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

#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

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

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


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

int main()
{
    int N;
    cin >> N;
    int cnt = 0;
    for(int i=1;i<=N;i++)
    {
        for(int j=1;j<=N/i;j++)
        {
            if(i*j<N)
            {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3580
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    int n, m, tot = 0, a;
    cin >> n >> m;
    rep(i, m){
        cin >> a;
        tot += a;
    }
    if(tot > n) cout << "-1" << endl;
    else cout << n - tot << endl;
    
}

Measured memory_bytes: 3620
n, m, d = map(int, input().split())
x = [input() for _ in range(n)]
cnt = sum(len(r)-d+1 for row in x for r in row.split("#") if len(r) >= d)
x = ["".join(c) for c in list(zip(*x))]
cnt += sum(len(r)-d+1 for row in x for r in row.split("#") if len(r) >= d)
print(cnt)


Measured memory_bytes: 5660
A, B, C, X, Y = map(int, input().split())
if A+B > 2*C:
    if X < Y:
        if B*(Y-X)+2*C*X > 2*C*Y:
            print(2*C*Y)
        else:
            print(B*(Y-X)+2*C*X)
    else:
        if A*(X-Y)+2*C*Y > 2*C*X:
            print(2*C*X)
        else:
            print(A*(X-Y)+2*C*Y)
else:
    print(A*X+B*Y)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;

const int N=1e2+20;

int n,m,a[N];

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

	sort(a,a+n);
	int sum=accumulate(a,a+n,0);
	if(4*m*a[n-m]<sum) printf("No");
	else printf("Yes");
}

Measured memory_bytes: 3816
#include <iostream>
using namespace std;
int main() {
    int n, m, a[105];
    while (cin >> n >> m) {
        int tot = 0, k = 0;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            tot += a[i];
        }
        for (int i = 0; i < n; i++) {
            if (a[i] * 4 * m >= tot) {
                k++;
            }
        }
        cout << (m <= k ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define i64 long long
#define maxn (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
	int n; cin>>n;
	int H[n];
	for(int i=0;i<n;i++){
		cin>>H[i];
	}
	int i,j,cnt =0;
	for(i=0;i<n;i++){
		for(j=0;j<i;j++){
			if(H[j]>H[i]) break;
		}
		if(j==i) cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
s = input()
t = input()

len_s = len(s)
len_t = len(t)

ans = len_t

for i in range(len_s - len_t + 1):
  u = s[i: i+len_t]
  d = sum(0 if c1 == c2 else 1 for c1, c2 in zip(t, u))
  ans = min(d, ans)

print(ans)

Measured memory_bytes: 9116
#include <iostream>

using namespace std;

int num(const string &s, int i) {
    if (i == s.size()) return 0;
    int ost = s.size() - i - 1;
    return max((s[i] > '0' ? ost * 9 + s[i] - '0' - 1 : 0), s[i] - '0' + num(s, i + 1));
}

int main() {
    string n;
    cin >> n;
    cout << num(n, 0) << "\n";
    return 0;
}

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

int main()
{
    int n,a;
    cin >> n;
    int k[n+1] = {0};
    for(int i= 0 ; i<n-1; i++)
    {
        cin >> a;
        k[a]++;
    }
    for(int i=1; i<=n; i++)
        cout << k[i] << "\n";
}


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

int c()
{
    int x;
    int n;
    std::cin >> x >> n;
    
    vector<int> input(200, 0);
    for(int i = 0; i < n; i++)
    {
        int myNum = 0;
        cin >> myNum;
        input[myNum]++;
    }
    
    int min = 1000;
    int ans = 0;
    for(int i = 0; i < 200; i++)
    {
        if(input[i])
        {
            continue;
        }
        
        int temp = abs(i - x);
        if(temp < min)
        {
            min = temp;
            ans = i;
        }
    }
    
    std::cout << ans << std::endl;
    
    return 0;
}

int main(int argc, const char * argv[])
{
    c();
    return 0;
}

Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long a = sc.nextLong();
		long v = sc.nextLong();
		long b = sc.nextLong();
		long w = sc.nextLong();
		long t = sc.nextLong();
		
		// 計算
		String result = "NO";
		if((v-w)*t >= abs(a-b)) result = "YES";
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 25404
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp  make_pair
#define ff first
#define ss second
#define pq priority_queue
#define sf(x) scanf("%d",&x)
int inf = (1e9) + 7;


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



	vi v;
	int aux;
	for (int i = 0; i < n; ++i)
	{
		sf(aux);
		v.pb(aux);		
	}


	vi ans;

	if(n%2)
	{
		for (int i = n-1; i >= 0; i-=2)
		{
			ans.pb(v[i]);
		}
		for (int i = 1; i < n; i+=2)
		{
			ans.pb(v[i]);
		}
	}
	else
	{
		for (int i = n-1; i >= 0; i-=2)
		{
			ans.pb(v[i]);
		}
		for (int i = 0; i < n; i+=2)
		{
			ans.pb(v[i]);
		}
	}

	for (int i = 0; i < v.size(); ++i)
	{
		printf("%d ",ans[i] );
	}
	printf("\n");
}

Measured memory_bytes: 3828
#!/usr/bin/env python3
l=[]
for i in range(1,3000):
  ll=[]
  x,y=(int(i) for i in input().split())
  if x==0 and y==0:
    break
  ll.append(x)
  ll.append(y)
  l.append(ll)

for j in range(len(l)):
  X=min(l[j][0],l[j][1])
  Y=max(l[j][0],l[j][1])
  print(str(X)+" "+str(Y))


Measured memory_bytes: 5980
n, m = map(int, input().split())
ans = 0
cnt = 0
for a, b in sorted(list(map(int, input().split())) for _ in range(n)):
    if cnt + b <= m:
        ans += a * b
        cnt += b
    else:
        ans += a * (m - cnt)
        cnt = m
    if cnt == m:
        break
print(ans)


Measured memory_bytes: 27756
#include <bits/stdc++.h>
    #define HAR BAR LAGTA HAI APUN HI J BHAGWAAN HAI!!
    #define UTSAV  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define ll long long int
    #define MAX 1e9
    #define MIN -1e9
    #define mod 1000000007
    #define pb push_back
    #define all(x) (x).begin(), (x).end()
    #define debug(x) cerr<<#x<<'='<<(x)<<endl;
    #define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
    #define mxn 100005
    using namespace std;
    int main()
    {
        UTSAV
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll a1 = b*d;
        ll b1 = a*c;
        ll c1 = a*d;
        ll d1 = b*c;
        cout<<std::max(a1,std::max(b1,std::max(c1,d1)))<<endl;
        return 0;
    }
       

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
int a[3333], sg[3333];

// edge
int cnt, h[3333];
struct edge
{
    int to, pre;
} e[3333];
void add(int from, int to)
{
    cnt++;
    e[cnt].pre = h[from];
    e[cnt].to = to;
    h[from] = cnt;
}

pii pr[3333];
int main(void)
{
    int N;
    scanf("%d", &N);
    for(int i = 1; i <= N; i++) scanf("%d", a + i), pr[i] = pii(a[i], i);
    for(int i = 1; i < N; i++)
    {
        int u, v;
        scanf("%d %d", &u, &v);
        if(a[u] > a[v]) add(v, u);
        if(a[v] > a[u]) add(u, v);
    }
    sort(pr + 1, pr + 1 + N);
    for(int i = 1; i <= N; i++)
    {
        int x = pr[i].second;
        if(!sg[x])
        for(int j = h[x]; j; j = e[j].pre) sg[e[j].to] = 1;
    }
    for(int i = 1; i <= N; i++) if(sg[i]) printf("%d ", i);
    puts("");
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()

typedef long long ll;

int N;
vector<int> A,B;
vector<pair<int, int>> A_sorted,B_sorted;

struct UnionFind{
    vector<int> Parent;
    vector<int> sizes;
    UnionFind(int n):Parent(n),sizes(n,1){ rep(i,n)Parent[i]=i; }
    //find the root of x
    int root(int x){
        if(x!=Parent[x]){
        Parent[x] = root(Parent[x]);
        }
        return Parent[x];
    }
    //merge x and y
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(sizes[x] < sizes[y]) swap(x, y);
        Parent[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x,int y){ return root(x) == root(y); }
    int size(int x){ return sizes[root(x)]; }
};

void INPUT(){
    cin>>N;
    A.resize(N);B.resize(N);
    rep(i,N){
        cin>>A[i];
        A_sorted.push_back({A[i],i});
    }
    rep(i,N){
        cin>>B[i];
        B_sorted.push_back({B[i],i});
    }
    sort(all(A_sorted));sort(all(B_sorted));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    INPUT();
    //sortしてA[i]<=B[i]を満たないならいかなる置換でも達成できない
    rep(i,N){
        if(A_sorted[i].first>B_sorted[i].first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    //sortして達成可能な場合
    //sortしたときの対応関係から、互いに素な巡回置換の数を数える
    UnionFind uni(N);
    rep(i,N){
        uni.unite(A_sorted[i].second,B_sorted[i].second);
    }
    //互いに素な巡回置換の個数（つまり、UnionFindのグループの数）
    int cnt = 0;
    rep(i,N){
        if(uni.Parent[i] == i)cnt++;
    }
    /*
    互いに素な巡回置換が1つのとき、N-1回の互換（swap）で表現でき、
    そこから互いに素な循環が1つ増えるたびに、必要な互換の数は1ずつ減るので、
    cnt > 1のときはN-2回以内のswapで達成可能
    */
    if(cnt > 1){
        cout<<"Yes"<<endl;
        return 0;
    }
    /*
    互いに素な巡回置換が1つのとき
    Bの隣り合う要素をswapすれば、1つの巡回置換を2つに分解できる
    */
    rep(i,N-1){
        if(A_sorted[i+1].first <= B_sorted[i].first){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3444
#include<stdio.h>
#include<string.h>

#define MAX 1000

int LCS(char *,char *,int,int);

int main(void){
	int n;
	char X[MAX],Y[MAX];
	int i;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s",X);
		scanf("%s",Y);

		printf("%d\n",LCS(X,Y,strlen(X),strlen(Y)));
	}

	return 0;
}

int LCS(char *X,char *Y,int X_len,int Y_len){
	int table[Y_len+1][X_len+1];
	int i,j;

	for(i=1;i<=Y_len;i++) table[i][0]=0;
	for(i=0;i<=X_len;i++) table[0][i]=0;

	for(j=1;j<=Y_len;j++){
		for(i=1;i<=X_len;i++){
			if(Y[j-1]==X[i-1]) table[j][i]=table[j-1][i-1]+1;
			else if(table[j-1][i]>=table[j][i-1]) table[j][i]=table[j-1][i];
			else table[j][i]=table[j][i-1];
		}
	}

	return table[Y_len][X_len];
	
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, c=0, r, k;
  cin >> n;
  vecll a(n), b(n);
  forll(i, 0, n)
  	cin >> a[i] >> b[i];
  forll(i, 0, n){
	r = (a[n-1-i] + c) % b[n-1-i];
	if (r == 0)
	  continue;
	k = (a[n-1-i] + c) / b[n-1-i];
	c += (b[n-1-i] - r);
  }
  cout << c << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<queue>
#include<cstring>
#define up 1
#define right 2
#define down 3
#define left 4
#define mod 1000000007
#define ll long long

using namespace std;


int main(){
    cin.sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = min(a , b) + min(c, d);
    cout << ans;

}



Measured memory_bytes: 764
#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(){
    int n;
    cin>>n;
    map<string,int>mp;
    rep(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}

Measured memory_bytes: 3540
#include<iostream>
using namespace std;
int main()
{
	long long int x,t;
	cin>>x>>t;
	if(x-t==0)
	{
		cout<<0<<endl;
	}
	if(x-t>0)
	{
		cout<<x-t<<endl;
	}
	if(x-t<0)
	{
		cout<<0<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <limits.h>
 
#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;



int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vi x(N), y(M);
    for (int i = 0; i < N; i++)
        cin >> x[i];
    for (int i = 0; i < M; i++)
        cin >> y[i];
    
    int maxX = *max_element(begin(x), end(x));
    int minY = *min_element(begin(y), end(y));
    
    maxX = max(maxX, X);
    minY = min(minY, Y);

    bool ans = (maxX < minY);
    cout << (ans ? "No War" : "War") << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
long long a;
char c;
int b, d;
int main()
{
   cin>> a>> b;
  cin>> c;
  cin>> d;
  b*= 100;
  b+= d;
  long long rez= a*b;
  rez= rez/100;
  cout<< rez;
    return 0;
}


Measured memory_bytes: 3164
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct

  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    if t.size <= 0 then failwith "out of size" else
    let rec max_heapify i =
      let l = 2*i in
      let r = 2*i + 1 in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m = i then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(m);
        t.node.(m) <- tmp;
        max_heapify m
      end in
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    max_heapify 1;
    ret

  let push x t =
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      let p = parent i in
      if i <= 1 || M.compare t.node.(p) t.node.(i) >= 0 then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(p);
        t.node.(p) <- tmp;
        doit p
      end in
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    doit t.size

end

module H = MakeBinaryHeap(struct type t = (int * int) let compare (_, x) (_, y) = y - x end)

let dijkstra g n =
  let reached_p = Array.make n false in
  let min_costs = Array.make n max_int in
  min_costs.(0) <- 0;
  let h = H.make 500000 (0, 0) in
  H.push (0, 0) h;
  while not (H.empty_p h) do
    let (u, x) = H.pop h in
    reached_p.(u) <- true;
    if x > min_costs.(u) then ()
    else
      List.iter (fun (v, c) ->
        let x = min_costs.(u) + c in
        if not reached_p.(v) && x < min_costs.(v) then begin
          min_costs.(v) <- x;
          H.push (v, x) h;
        end) g.(u);
  done;
  min_costs

let rec make_pair acc = function
  | [] -> acc
  | v :: c :: tl -> make_pair ((v, c) :: acc) tl
  | _ -> assert false

let make_pair lst = make_pair [] lst

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let g = Array.make n [] in
  for _ = 0 to n - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | u :: _ :: l -> g.(u) <- make_pair l
    | _ -> assert false
  done;
  dijkstra g n |> Array.iteri (fun i e -> Printf.printf "%d %d\n" i e)

Measured memory_bytes: 33780
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <map>

typedef long long ll;
#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define MOD 1000000007
#define EPS 1e-7
#define INF INT_MAX
#define PI  3.14159265358979323846264338327950288
inline ll toll(std::string s) { ll v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;
typedef pair<ll, ll> pll;

int loop_mod[11][11];
int sum_loop[11];
int main()
{
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    
    repi(i,1,13 - 1)
    {
        repi(j,1,7 - 1)
        {
            //cout << 9*(7*(i + 1) + (j + 1) - 7) % 11 << " ";
            loop_mod[i-1][9*(7*(i + 1) + (j + 1) - 7) % 11] = 1;
            sum_loop[9*(7*(i + 1) + (j + 1) - 7) % 11]++;
        }
    }
    
    ll loop = (n - 2)/11;
    ll mod_plus = 0;
    if (loop > 0)
    {
        mod_plus = (n - 2)%11;
    }else{
        mod_plus = (n - 2)%11;
    }
    
    ans += loop*sum_loop[k];
    
    rep(i,mod_plus)
    {
        ans += loop_mod[i][k];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
roomNum, aisleNum = map(int, input().split())
aisles = [ list(map(int, input().split())) for _ in range(aisleNum) ]

aisleTree = [ [] for _ in range(roomNum+1) ]

for roomA, roomB in aisles:
    aisleTree[roomA].append(roomB)
    aisleTree[roomB].append(roomA)

from collections import deque
que = deque()
distanceFromRoom1 = [-1] * (roomNum+1)
distanceFromRoom1[0] = 0
distanceFromRoom1[1] = 0
for room in aisleTree[1]:
    que.append(room)
    distanceFromRoom1[room] = 1

while que:
    room = que.popleft()
    dist = distanceFromRoom1[room]
    for nextRoom in aisleTree[room]:
        if distanceFromRoom1[nextRoom] == -1:
            que.append(nextRoom)
            distanceFromRoom1[nextRoom] = room

if min(distanceFromRoom1) == -1:
    print('No')
else:
    print('Yes')
    for ans in distanceFromRoom1[2:]:
        print(ans)

Measured memory_bytes: 58656
#include<bits/stdc++.h>
#define reg register
#define maxn 100005
using namespace std;
inline int read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
stack <int> Q, F;
int L[maxn * 20], R[maxn * 20], t[maxn], sum[maxn * 20], lx[maxn],rx[maxn],ly[maxn],ry[maxn],a[maxn];
long long cnt, n, ans, ansx , p, anss, sumx;
int build(int l,int r)
{
    int num=++cnt;
    if(l!=r)
    {
        int mid=(l+r)>>1;
        L[num]=build(l,mid);
        R[num]=build(mid+1,r);
    }
    return num;
}
int update(int pre,int l,int r,int x)
{
    int num=++cnt;
    L[num]=L[pre];R[num]=R[pre];sum[num]=sum[pre]+1;
    if(l!=r)
    {
        int mid=(l+r)>>1;
        if(x<=mid)L[num]=update(L[pre],l,mid,x);
        else R[num]=update(R[pre],mid+1,r,x);
    }
    return num;
}
int query(int k, int v, int l, int r, int Lc ,int Rc)
{
    int mid = l + r >> 1, res = 0;
    if(r <= Rc && l >= Lc) { res = sum[k] - sum[v]; return res;}
    if (Lc <= mid)
       res += query(L[k], L[v], l, mid, Lc, Rc);
    if (Rc > mid)
       res += query(R[k], R[v], mid + 1, r, Lc, Rc);
    return res;

}
int main() {
    n = read();
    for(int i = 1; i <= n; i++) a[i] = read();
    for(int i = 1; i <= n; i++)
    {
        while(!Q.empty() && Q.top() < a[i])
            Q.pop(),F.pop();
            if(!Q.empty()) lx[i] = F.top();
            Q.push(a[i]); F.push(i);
    }
    while(!Q.empty()) Q.pop(), F.pop();
    for(int i = n; i >= 1; i--)
    {
        while(!Q.empty() && Q.top() < a[i])
            Q.pop(),F.pop();
            if(!Q.empty()) rx[i] = F.top();
            else rx[i] = n + 1;
            Q.push(a[i]); F.push(i);
    }
    t[0] = build(1, n);
    for(int i = 1; i <= n; i++)
    {
     t[i] = update( t[i - 1], 1, n, a[i]);
    }
    for(int i = 1; i <= n; i++)
    {
                p = rx[i]; ansx = sumx = 0;
                int l = rx[i] + 1, r = n ;
                while(l <= r){
                    int mid = l + r >> 1;
                    ans = query(t[mid], t[p], 1, n, a[i], n);
                    if(ans) { ansx++; r = mid - 1; sumx = mid;}
                    else l = mid + 1;
                }
                if(ansx == 0) sumx = n + 1;
                ry[i] = sumx;
                ansx = sumx = 0; p = lx[i] - 1;
                l = 1, r = lx[i] - 1;
                while(l <= r){
                    int mid = l + r >> 1;
                    ans = query(t[p], t[mid - 1], 1, n, a[i], n);
                    if(ans) { ansx++; l = mid + 1; sumx = mid;}
                    else r = mid - 1;
                }
                if(ansx == 0) sumx = 0;
                ly[i] = sumx;
    }
    for(int i = 1; i <= n; i++)
    {
             anss += 1ll *  (ry[i] - rx[i]) * (i - lx[i]) * a[i] + 1ll * (lx[i] - ly[i]) * (rx[i] - i) * a[i];
    }
    printf("%lld\n", anss);
  return 0;
}

Measured memory_bytes: 26156
n = int(input())
a = sorted(map(int, input().split()))

from bisect import bisect_left
ans_n = a[-1]

p = bisect_left(a, (ans_n+1)//2)
ans_r = a[p] if p != n-1 else a[p-1]
if abs(a[p] - ans_n/2) > abs(a[p-1] - ans_n/2):
  ans_r = a[p-1]

print(ans_n, ans_r)

Measured memory_bytes: 14428
#include <iostream>
int H = 0, W = 0;
char a[105][105];
int main(void){
    std::cin >> H >> W;
    for(int i=1; i<=H; ++i){
        for(int j=1; j<=W; ++j){
            std::cin >> a[i][j];
        }
    }
    for(int i=0; i<=H+1; ++i){
        for(int j=0; j<=W+1; ++j){
            if(i==0 || j==0 || i==H+1 || j==W+1){
                std::cout << "#";
            }else{
                std::cout << a[i][j];
            }
        }
        std::cout << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){

    char S[100];
    int i,j,ans = 0,lenth,check_kaibun;

    scanf("%s",S);
    lenth = strlen(S);

    check_kaibun = 1;
    for(i = 0;i < lenth;i++){
        //printf("左から%d番目：%c 右から%d番目；%c\n",i,S[i],i,S[lenth - 1 - i]);
        if(S[i] != S[lenth - 1 - i]) check_kaibun = 0;
    }
    if(check_kaibun == 1){
        ans++;
        //printf("Condition1 Successed!\n");
    }else{
        //printf("Condition1 Failed!");
    }
    //printf("\n");

    check_kaibun = 1;
    int Condition2 = (lenth - 1)/2;
    for(i = 0;i < Condition2;i++){
        //printf("左から%d番目：%c 右から%d番目；%c\n",i,S[i],i,S[Condition2 - 1 - i]);
        if(S[i] != S[Condition2 - 1 - i])  check_kaibun = 0;
    }
    if(check_kaibun == 1){
        ans++;
        //printf("Condition2 Successed!\n");
    }else{
        //printf("Condition2 Failed!\n");
    }
    //printf("\n");

    check_kaibun = 1;
    int Condition3 = (lenth + 3)/2;
    for(i = Condition3 - 1;i < lenth;i++){
        //printf("左から%d番目：%c 右から%d番目：%c\n",i,S[i],i,S[lenth - 1 - i]);
        if(S[i] != S[lenth - 1 - i]) check_kaibun = 0;
    }
    if(check_kaibun == 1){
        ans++;
        //printf("Condition3 Successed!\n");
    }else{
        //printf("Condition3 Failed!\n");
    }
    //printf("\n");

    if(ans == 3) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>

using namespace std;
int main() {
    int n, t, i;
    long long int a[210000], stop_time=0;
    cin >> n >> t;
    if(n == 1) {
        cout << t << endl;
        return 0;
    }
    for(i=0; cin >> a[i]; i++);
    for(i=0; i<n; i++) {
        stop_time += max(a[i+1] - a[i] - t, 0LL);
    }
    cout << a[n-1] + t - stop_time << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <unordered_map>
#include <climits>
#include <cmath>

using namespace std;

template<class T>
T read()
{
    T value;
    std::cin >> value;
    return value;
}

template<class F>
void times_do(size_t n, F func)
{
    for(size_t i = 0; i < n; ++i) func();
}

template<class T>
vector<T> reads(size_t n)
{
    vector<T> a;
    a.reserve(n);
    times_do(n, [&](){
        a.push_back(read<T>());
    });
    return a;
}

int main()
{
    const int N = read<int>();
    const vector<int> a = reads<int>(N);

    int button = 1;
    for(int i = 0; i < N; ++i)
    {
        button = a.at(button - 1);
        if(button == 2)
        {
            cout << (i + 1) << endl;
            return 0;            
        }
    }
    
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


map<ll,ll> v;
ll N,P;

void decom(ll n)
{
    // 割る数の初期値
    ll a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            ++v[a];
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    ++v[n];
}


int main() {
  scanf("%lld%lld", &N,&P);

  ll ans = 1;

  decom(P);
  
  for(auto i : v){
    // cout << i.first << " " << i.second << endl;
    if(i.second >= N){
      FOR(j,1,i.second/N) ans *= i.first;
    }
  }

  cout << ans << endl;
}



Measured memory_bytes: 256
#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()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> odd(n/2), even(n/2);
    rep(i, n/2){
        cin >> odd[i] >> even[i];
    }

    sort(all(odd));
    sort(all(even));
    odd.push_back(0);
    even.push_back(0);

    int cnt1 = 1, cnt2 = 1;
    int m1 = 0, m2 = 0;
    int M1 = 0, M2 = 0;
    int tmp1, tmp2;
    rep(i, n/2){
        if(odd[i] == odd[i+1]){
            cnt1 ++;
        }else{
            if(m1 < cnt1){
                tmp1 = odd[i];
                M1 = m1;
                m1 = cnt1;
            }else if(M1 < cnt1){
                M1 = cnt1;
            }
            cnt1 = 1;
        }

        if(even[i] == even[i+1]){
            cnt2 ++;
        }else{
            if(m2 < cnt2){
                tmp2 = even[i];
                M2 = m2;
                m2 = cnt2;
            }else if(M2 < cnt2){
                M2 = cnt2;
            }
            cnt2 = 1;
        }
    }

    ll ans = 0;
    if(tmp1 == tmp2){
        ans = n - M1 - m2;
        ll ans2 = n - M2 - m1;
        ans = min(ans, ans2);
    }else{
        ans = n - m1 - m2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 896
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner.Split(bufio.ScanWords)

	s := nextString()
	p := nextString()
	n := len(s)

	for i := 0; i < n; i++ {
		failed := false
		for j := 0; j < len(p); j++ {
			if s[(i+j)%n] != p[j] {
				failed = true
				break
			}
		}
		if !failed {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}



Measured memory_bytes: 1116
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
int n, L, T, x[N], w[N];

void read_input() {
	cin >> n >> L >> T;
	for (int i = 0; i < n; i++)
		cin >> x[i] >> w[i];
}

void solve() {
	int st = 0;
	for (int i = 0; i < n; i++, st = (st % n + n) % n) {
		st += w[i] & 1? L - x[i] > T? 0: (T + x[i]) / L: x[i] < T? (x[i] - L - T + 1) / L: 0;
		x[i] = (1LL * x[i] + (w[i] & 1? T: -T) % L + L) % L;
	}
	sort(x, x + n);
	for (int i = 0; i < n; i++)
		cout << x[(st + i) % n] << endl;
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input(), solve();
	return 0;
}


Measured memory_bytes: 2048
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n+1) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def kr(edge,N):
    res = 0
    node = []
    G = UnionFind(N)
    for cost, p, q, in edge:
        if not G.same(p, q):
            G.union(p, q)
            res += cost
    return res

def solve():
    n,m=map(int,input().split())
    if n==0 and m==0:
        exit()
    edge=[]
    for _ in range(m):
        a,b,cost=map(int,input().split())
        edge.append((cost,a,b))
    edge.sort()
    ans=kr(edge,n)
    print(ans)
    return solve()
if __name__=="__main__":
  solve()



Measured memory_bytes: 5664
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    ll x, k, d;
    cin >> x >> k >> d;
    ll t = abs(x)%d;
    ll c = abs(x)/d;
    if(c > k){
        cout << (abs(x) - k*d) << endl;
        return 0;
    }else{
        k -= c;
        if(k%2 == 0){
            cout << t << endl;
            return 0;
        }
        if(k%2 == 1){
            cout << d - t << endl;
            return 0;
        }
    }
}

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

int main(){
    ll k, a, b;
    cin >> k >> a >> b;
    ll ans = 1;
    if(b - a == 1 || a > b || k <= a){
        cout << 1 + k << endl;
        return 0;
    }
    ll c = k - a + 1;
    if(c % 2 == 0) cout << c / 2 * b - c / 2 * a + a << endl;
    else cout << 1 + (c - 1) / 2 * b - (c - 1) / 2 * a + a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int SelectionSort(int A[], int n)
{
  int i,j,t,mini;
  int count=0;
  for(i=0;i<n;i++){
    mini=i;
    for(j=i;j<n;j++){
      if (A[j]<A[mini]){
        mini=j;
      }
    }
    if (mini!=i){
      t=A[i];
      A[i]=A[mini];
      A[mini]=t;
      count++;
    }
  }
  return count;
}

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

  int count=SelectionSort(data,n);

  for(i=0;i<n-1;i++){
    printf("%d ",data[i]);
  }
  printf("%d\n%d\n",data[n-1],count);
  return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;

ll F(ll a,ll b){
    int A=to_string(a).size();
    int B=to_string(b).size();
    return max(A,B);
}

int main() {
    ll n,ans=inf,a,b;
    cin>>n;
    
    for (ll i=1;i*i<=n;i++) {
        if(n%i==0){
            a=i;
            b=n/i;
            ans=min(ans,F(a,b));
        }
    }

    cout<<ans<<endl;
}



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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

 
int main(){
  int x[5];
  int ans;
  for(int i=0; i<5; i++){
    cin >> x[i];
    if(x[i]==0) ans = i + 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
 
#define ALL(c) (c).begin(), (c).end()
#define REP(i, n) for(auto i = 0 * (n); i < (n); ++i)
#define FOR(i, s, n) for(size_t i = (s); i < (n); ++i)

typedef bitset<26*25> Vector;
typedef vector<Vector> Matrix;
struct GaussJordanBit {
	typedef size_t T;
	GaussJordanBit(Matrix mat, T col) : x(move(mat)) {
		T row = x.size(), r = 0;
		REP(c, col) {
			T p = r;
			FOR(i, r, row) if (x[i][c]) p = i;
			swap(x[r], x[p]);
			if (x[r][c]) {
				if (c == col - 1) possible = 0; // ??????????????????????????????????????????
				REP(i, row) if (r != i && x[i][c]) x[i] ^= x[r];
				if (++r == row) break;
			}
		}
		rank = r;
	}
	Matrix x;
	T rank;
	bool possible = 1; // ?????¢????¬?????¨????????§£??????????????´???????????????????§£????????? <-> true
};

bool ba[30][30];

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios::sync_with_stdio(0);
	int m, n, d;
	while (cin >> m >> n >> d, m || n || d) {
		Matrix A(n * m);
		REP(i, n) {
			REP(j, m) {
				cin >> ba[i][j];
				A[i * m + j][i * m + j] = 1;
				REP(k, n) {
					REP(l, m) {
						int dis = abs(i - k) + abs(j - l);
						if (dis == d) {
							A[k * m + l][i * m + j] = 1;
						}
					}
				}
				A[i * m + j][n * m] = ba[i][j];
			}
		}
		cout << (GaussJordanBit(move(A), n * m + 1).possible ? 1 : 0) << endl;
	}
}

Measured memory_bytes: 3184
#include<stdio.h>
#define N 1001

int strlen(char s[]) {
  int w = 0;
  while (1) {
    if (s[w] == '\0')
      break;
    w++;
  }
  return w;
}

int max(int a, int b, int c){
  int m = a;
  if (m < b)
    m = b;
  if (m < c)
    m = c;
  return m;
}

int c[N][N];
char X[N], Y[N];

int main(){
  int q, xl = 0, yl = 0, h = 0, i = 0, j = 0;
  int d, ans = 0;

  for (i = 0; i < N; i++) {
    c[i][0] = 0;
  }
  for (i = 0; i < N; i++) {
    c[0][i] = 0;
  }

  scanf("%d", &q);
  for (h = 0; h < q; h++) {

    scanf("%s", X);
    scanf("%s", Y);
    xl = strlen(X);
    yl = strlen(Y);

    for (i = 1; i <= xl; i++) {
       for (j = 1; j <= yl; j++) {
        if (X[i-1] == Y[j-1])
          d = 1;
        else
          d = 0;
        c[i][j] = max(c[i-1][j-1] + d, c[i-1][j], c[i][j-1]);
        if(c[i][j] > ans)
          ans = c[i][j];
      }
    }
    printf("%d\n", ans);
    ans = 0;
  }
  return 0;
}

Measured memory_bytes: 4516
n, x = map(int, input().split())
l= [int(num) for num in input().split()]

k = []
kk = 0
k.append(kk)

for i in l:
    kk += i
    k.append(kk)

answer = 0
for j in k:
    if j <= x :
        answer += 1
    
print(answer)

Measured memory_bytes: 3060
# 入力
S = input()

# 白黒白黒... に塗り替える場合と　黒白黒白... に塗り替える場合の塗り替え枚数を比較し解を求める
ans = min(
    sum(S[i] == str(i % 2) for i in range(len(S))),
    sum(S[i] == str((i + 1) % 2) for i in range(len(S)))
)

# 出力
print(ans)


Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int x, y;
	cin >> x >> y;
	int sum = 0;
	for (int i = 0; i <= x; i++) {
		sum = 2 * i + 4 * (x - i);
		if (sum == y) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int N;long M,a,b;
long A;
template<typename T>
T extgcd(T a,T b,T&x,T&y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	T q=a/b;
	T g=extgcd(b,a-q*b,y,x);
	y-=q*x;
	return g;
}
main()
{
	cin>>N>>M;
	b=1;
	for(int i=0;i<N;i++)
	{
		cin>>A;
		long ta=A/2,tb=A;
		long x,y;
		long g=extgcd(tb,-b,x,y);
		if((a-ta)%g==0)
		{
			x*=(a-ta)/g;
		}
		else
		{
			cout<<0<<endl;
			return 0;
		}
		long B=b/(g>0?g:-g)*tb;
		long AA=ta+tb*x;
		AA%=B;if(AA<0)AA+=B;
		a=AA;
		b=B;
		if(a>M)
		{
			cout<<0<<endl;
			return 0;
		}
	}
	cout<<(M-a)/b+1<<endl;
}


Measured memory_bytes: 384
def main():
    N = int(input())
    P = [int(input()) for i in range(N)]

    Q = [0]*(N+1)
    for i in range(N):
        Q[P[i]] = i+1

    ans = 1
    pre = Q[1]
    cur = 1
    for q in Q[2:]:
        if pre < q:
            cur += 1
        else:
            ans = max(ans, cur)
            cur = 1
        pre = q
    ans = max(ans, cur)
    print(N - ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 91112
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 510000;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main() {
COMinit();
int h,w,a,b;
cin>>h>>w>>a>>b;
int ans=0;
for(int i=0;i<h-a;i++){
  ans=(ans+COM(b-1+i,i)*COM(h-2-i+w-b,w-b-1))%MOD;
}
cout<<ans;

return 0;
}


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

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

int n; 

int fact[11];

int cnt(vector<int> x) {
    set<int> se;
    for(int i = 1; i <= n; ++i) se.insert(i);
    int res = 0;
    rep(i, n - 1) {
        int y = x[i];
        int k = 0;
        for(auto ite = se.begin(); ite != se.end() ; ++ite) {
            if(*ite == y) {
                res += fact[n - 1 - i] * k;
                ite = se.erase(ite);
                break;
            } else {
                ++k;
            }
        }
    }
    return res;
}

void solve() {
	cin >> n;
    fact[0] = 1;
    fact[1] = 1;
    rep1(i, 10) {
        fact[i] = fact[i - 1] * i;
    }
    vector<int> p(n), q(n);
    rep(i, n) {
        cin >> p[i];
    }
    rep(i, n) {
        cin >> q[i];
    }
    cout << abs(cnt(p) - cnt(q)) << endl;
}

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

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

typedef struct pp{
  char name[100];
  int t;
}P;

int main(){

  int size, q, head = 0, total = 0;

  cin >> size;

  int tail = size;

  P *u = new P[size + 2];

  cin >> q;

  for(int i = 0; i < size; i++){
    cin >> u[i].name >> u[i].t;
    //cout << u[i].name << u[i].t << endl;
  }

  while(head != tail){
    if(u[head].t > q){
      u[head].t = u[head].t - q;
      u[tail] = u[head];
      tail++;
      if(tail > size + 1){
        tail = 0;
      }
      total = total + q;
    }
    else{
      total = total + u[head].t;
      cout << u[head].name << ' ' << total << endl;
    }
    head++;
    if(head > size + 1){
      head = 0;
    }
  }

  delete[] u;

  return 0;
}



Measured memory_bytes: 7688
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int i, j, a[3][3];
	for(i=0; i<3; i++){
		for(j=0; j<3; j++){
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	map<int, int> b;
	for(i=0; i<n; i++){
		int x;
		cin >> x;
		b[x]++;
	}
	bool flag = false;
	int count_row = 0, count_dia = 0, count_col = 0;
	for(i=0; i<3; i++){
		count_row = 0;
		for(j=0; j<3; j++){
			if(i==j && b[a[i][j]]) count_dia++;
			if(b[a[i][j]]){
				count_row++;
				//b[a[i][j]]--;
			}
		}
		//cout << count_row << " " << count_dia << endl;
		if(count_row==3){
			flag = true;
			break;
		}
	}
	if(flag || count_dia==3){
		cout << "Yes\n";
		return 0;
	}
	else{
		for(j=0; j<3; j++){
			count_col = 0;
			for(i=0; i<3; i++){
				if(b[a[i][j]]) count_col++;
			}
			if(count_col==3){
				flag = true;
				break;
			}
		}
		if(flag) cout << "Yes\n";
		else if(b[a[0][2]] && b[a[1][1]] && b[a[2][0]]) cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		String x = Integer.toString(a[0]);
		String y = Integer.toString(a[1]);
		String z = Integer.toString(a[2]);
		String w = Integer.toString(a[3]);
		
		int[] b = new int[12];
		b[0] = Integer.valueOf(x+y);
		b[1] = Integer.valueOf(x+z);
		b[2] = Integer.valueOf(x+w);
		b[3] = Integer.valueOf(y+x);
		b[4] = Integer.valueOf(y+z);
		b[5] = Integer.valueOf(y+w);
		b[6] = Integer.valueOf(z+x);
		b[7] = Integer.valueOf(z+y);
		b[8] = Integer.valueOf(z+w);
		b[9] = Integer.valueOf(w+x);
		b[10] = Integer.valueOf(w+y);
		b[11] = Integer.valueOf(w+z);		
		
		Arrays.sort(b);
		System.out.println(b[2]);
	}
}

Measured memory_bytes: 30048