akhauriyash/Code-Regression huggingface dataset:
n,q=map(int,input().split())
ab=[list(map(lambda x:int(x)-1,input().split())) for _ in [0]*(n-1)]
pq=[list(map(int,input().split())) for _ in [0]*q]
for i in range(q):
    pq[i][0]-=1

graph=[[] for _ in [0]*n]
[graph[a].append(b) for a,b in ab if a<b]
[graph[b].append(a) for a,b in ab if a>b]

plus=[0 for _ in [0]*n]
for i,j in pq:
    plus[i]+=j

pos=[]
ans=[0 for _ in [0]*n]
temp=0
q=[0]
memo=[False for _ in [0]*n]

while q:
    i=q.pop(-1)
    if memo[i]==False:
        pos.append(i)
        temp+=plus[i]
        ans[i]=temp
    memo[i]=True

    while graph[i]:
        j=graph[i].pop(-1)
        if memo[j]==False:
            q.append(j)
            break
    else:
        temp-=plus[pos[-1]]
        pos.pop(-1)
        if pos!=[]:
            q.append(pos[-1])
print(*ans)

Measured memory_bytes: 133664
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [n;_] = reads int
    let xs = reads int
    let bs =
        List.sort xs
        |> List.pairwise
        |> List.map (fun (x, y) -> y - x)
        |> List.sortDescending
    List.skip (min (n - 1) (List.length bs)) bs
    |> List.sum
    |> printfn "%i"
    0

Measured memory_bytes: 38736
#include <iostream>
#include <cstdio>
#define N 300005
using namespace std;

int n, k, sum, c[N], cnt[N], ans[N];
int main() {
	int i, t;
	cin >> n;
	for(i=0; i<n; i++) {
		scanf("%d", &t);
		c[t]++;
		cnt[c[t]]++;
	}
	for(i=n; i; i--) {
		while(k*i <= sum) sum += cnt[++k];
		ans[i] = k-1;
	}
	for(i=1; i<=n; i++) printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<cstdio>

const int SIZE = 100000 + 7;

using namespace std;

struct query{
	int d, v, c;
}que[SIZE];

int f[SIZE][14];
int head[SIZE], ver[SIZE * 2], nxt[SIZE * 2];
int N, M, Q, tot = 1;

inline void add(const int &u, const int &v) {
	ver[++tot] = v;
	nxt[tot] = head[u];
	head[u] = tot;
}

inline void BFS(const int &s, const int &d, const int &c) {
	f[s][d] = c;
	if( !d ) return;
	
	if(!f[s][d - 1]) BFS(s, d - 1, c);
	for(int i = head[s]; i; i = nxt[i]) {
		int v = ver[i];
		if(!f[v][d - 1]) BFS(v, d - 1, c);
	}
}

int main() {
	scanf("%d%d",&N,&M);
	for(int i = 1; i <= M; ++i) {
		int a, b; scanf("%d%d",&a,&b);
		add(a, b); add(b, a);
	}
	scanf("%d",&Q);
	for(int i = Q; i >= 1; --i)
		scanf("%d%d%d",&que[i].v,&que[i].d,&que[i].c);
	for(int i = 1; i <= Q; ++i)
		if(!f[que[i].v][que[i].d]) BFS(que[i].v, que[i].d, que[i].c);
	for(int i = 1; i <= N; ++i)
		printf("%d\n",f[i][0]);
	return 0;
}

Measured memory_bytes: 9216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a[] = new long[n];

		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
			if (a[i] == 0) {
				System.out.println(0);
				return;
			}
		}

		long prod = 1;
		for (int i = 0; i < n; i++) {
			if (1000000000000000000l  / prod< a[i]) {
				System.out.println(-1);
				return;
			} else {
				prod *= a[i];
			}
		}

		System.out.println(prod);

		sc.close();
	}

}


Measured memory_bytes: 61676
# coding: utf-8
import re
import math
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#main
n=int(input())
s=input()
print(s.count("ABC"))

Measured memory_bytes: 5612
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
bool use[10];
int N, K, ans = 1 << 30;
void solve(int k,int x) {
	if (x >= N) {
		ans = min(ans, x);
		return;
	}
	rep(i, 10) {
		if (k == 0 && i == 0) continue;
		if (!use[i]) continue;
		solve(k + 1, x * 10 + i);
	}
}
int main() {
	cin >> N >> K;
	rep(i, 10) use[i] = 1;
	rep(i, K) {
		int D;
		cin >> D;
		use[D] = 0;
	}
	solve(0, 0);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    long long int n,ans=0;
    cin>>n;
    vector<long long int>a(10000000);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        if(a[i+1]<a[i]){
            ans+=((a[i])-a[i+1]);
            a[i+1]=a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 81408
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
    ll d;
    while (scanf("%lld",&d)) {
        if (!d) break;
        int n, m;
        scanf("%d%d",&n,&m);
        ll store[n+1], k;
        store[0]=0;
        for (int i=1; i<n; i++) scanf("%lld",&store[i]);
        sort(store, store+n);
        store[n]=d;
        ll res=0;
        for (int i=0; i<m; i++) {
            scanf("%lld",&k);
            int pos=upper_bound(store, store+n, k)-store;
            res+=min(store[pos]-k, k-store[pos-1]);
        }
        printf("%lld\n",res);
    }
}

Measured memory_bytes: 0
def main():
    N = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return

    prod = 1
    for a in A:
        prod *= a
        if prod >  1000000000000000000:
            print('-1')
            return
    print(prod)
main()


Measured memory_bytes: 21776
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        sc.close();

        if(a%2==1 || b%2 == 1 || c%2 == 1){
            System.out.print("0");
            return;
        }

        if(a==b && b== c){
            System.out.print("-1");
            return;
        }

        for(int i=1; i>0; i++){
            int ta = b/2 + c/2;
            int tb = a/2 + c/2;
            int tc = a/2 + b/2;
            a = ta;
            b = tb;
            c = tc;
            if(a%2==1 || b%2 == 1 || c%2 == 1){
                System.out.print(i);
                break;
            }
        }
	}
}


Measured memory_bytes: 35724
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define rn return
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;


int main(){
    int K; cin >> K;
    cout << (K%2 == 0? K*K/4:(K-1)/2*(K+1)/2);
    rn 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    int n,k;
    cin >> n >> k;
    cout << (1+(k-1)*2 <= n ? "YES" : "NO") << endl;

    
    
    
    

    return 0;
}


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

int main(){
    //int ans=0;
    bool ans=false;
    int H,N;
    
    cin>>H>>N;
    
    vector<int> A;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        A.push_back(a);
    }

    int sum=0;

    for(auto item :A){
        sum+=item;
    }

    if(sum>=H){
        ans=true;
    }
  
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 892
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    a, b = MII()
    grid=[['#' for i in range(100)] for j in range(50)]
    grid+=[['.' for i in range(100)] for j in range(50)]
    for i in range(a-1):
        grid[(i//50)*2][(i%50)*2]='.'
    for i in range(b-1):
        grid[(i//50)*2+51][(i%50)*2]='#'
    print(100,100)
    print(*[''.join(grid[i]) for i in range(100)], sep='\n')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<iostream>
using namespace std;
const static int MAX = 200000;

int n, k;
int A[MAX];

double solve(){
    int ans, sum = 0;
    for(int i = 0; i < k; i++){
        sum += A[i];
    }
    ans = sum;
    for(int i = 0; i < n - k; i++){
        sum += A[k + i] - A[i];
        if(ans < sum){
            ans = sum;
        }
    }

    return (double)ans/2;
}

int main(){
    int p;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> p;
        A[i] = (p+1);
    }
    printf("%.8lf\n",solve());

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc =new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if(a < c && c < b){
            System.out.println("Yes");
        }else if(b < c && c < a){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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

using namespace std;

int main () {
	int n;
	cin >> n;
	int h [n], h2 [n+1];
	for (int i = 0; i < n; i++) {
		cin >> h [i];
	}
	h2 [0] = 0;
	h2 [1] = 100005;
	for (int i = 0; i < n-1; i++) {
		h2 [i+1] = min (h2 [i+1],h2 [i] + abs (h [i] - h [i+1]));
		h2 [i+2] = h2 [i] + abs (h [i] - h [i+2]);
	}
	cout << h2 [n-1];
	return 0;
}


Measured memory_bytes: 1024
import sys
readline = sys.stdin.buffer.readline

n = int(readline())
lst1 = list(map(int,readline().split()))

def cumsum(lst): #元のリストを保持
    res = lst[:]
    for i in range(1,len(res)):
        res[i] += res[i-1]
    return res
lst2 = [0] + cumsum(lst1)

ans = 0

dic1 = dict()
for i in lst2:
    if i in dic1:
        ans += dic1[i]
        dic1[i] += 1
    else:
        dic1[i] = 1

print(ans)

Measured memory_bytes: 83988
x,n=map(int,input().split())
if n==0:
  print(x)
  quit()
lst=list(map(int,input().split()))
a=list(range(-1,102))
for i in lst:
  if i in a:
    a.remove(i)
if len(a)==0:
  print(x)
  quit()
b=[]
for j in a:
  b.append(abs(j-x))
print(a[b.index(min(b))])



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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int h, w;
  scanf("%d %d",&h, &w);
  char field[h + 1][w + 1];
  int d[3] = {-1, 0, 1};

  string s;
  REP (i, h) {
    cin >> s;
    REP (j, w) {
      field[i][j] = s.at(j);
    }
  }

  int ans[h][w];
  REP (i, h) {
    REP (j, w) {
      ans[i][j] = 0;
    }
  }

  REP (i, h) {
    REP (j, w) {
      if (field[i][j] == '#') {
        ans[i][j] = INF;
        REP (k, 3) {
          REP (l, 3) {
            if (i + d[k] >= 0 && i + d[k] < h && j + d[l] >= 0 && j + d[l] < w) {
              ans[i + d[k]][j + d[l]] += 1;
            }
          }
        }
      }
    }
  }
  REP (i, h) {
    REP (j, w) {
      if (ans[i][j] >= INF) printf("#");
      else printf("%d",ans[i][j]);
      if (j == w - 1) printf("\n");
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int x = sc.nextInt();
      int t = sc.nextInt();
      if(x>t) {
    	  System.out.println(x-t);
      } else {
    	  System.out.println(0);
      }
    	  
      
    }
 }


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

int main(){
  int A, B;                                       //A != Bより K = (A + B) / 2
  scanf("%d %d", &A, &B);

  if((A + B) % 2 == 0)
    cout << (A + B) / 2 << endl;
  else
    cout << "IMPOSSIBLE" <<endl;

  return 0;
}

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

int main() {
  char c;
  
  cin >> c;

  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout<<"vowel"<<endl;
  }else{
    cout<<"consonant"<<endl;
  }
}


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>

using namespace std;

int64_t digit(int64_t n)
{
    int64_t ans = 0;
    while (n > 0)
    {
        ans += n % 10;
        n /= 10;
    }
    return ans;
}

int main()
{
    int64_t n;
    cin >> n;
    cout << (n % digit(n) == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;

string ans;
vector<string> vec;
int main(){
  string s;
  string t;
  cin>>s>>t;
  for(int i=0;i<s.size()-t.size()+1;i++){
    bool flag=true;
    int memo=i;
    for(int j=0;j<t.size();j++){
      if(s[i+j]!=t[j] && s[i+j]!='?')flag=false;
    }
    if(flag){
      assert(memo!=-1);
      for(int k=0;k<s.size();k++){
        if(k==memo){
          ans+=t;
          k+=t.size()-1;
        }
        else if(s[k]!='?')ans+=s[k];
        else ans+='a';
      }
      vec.push_back(ans);
      ans="";
    }
  }

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

  if(vec.size()==0){
    cout<<"UNRESTORABLE"<<endl;
  }else{
    cout<<vec[0]<<endl;
    //cout<<vec[1]<<endl;
  }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

int dy[5] = {-1, 0, 1, 0, 0};
int dx[5] = {0, -1, 0, 1, 0};

int main(void) {
    int n;

    cin>>n;

    cout<<n*n*n<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
div_t div_mtwo(int a)
{
   div_t ret;
   ret.quot = a / -2;
   ret.rem = a % -2;
   if (ret.rem < 0)
   {
      ret.quot++;
      ret.rem += 2;
   }
   return ret;
}
int main()
{
   int n;
   div_t tmp;
   string ans = "";
   cin >> n;
   tmp.quot = n;
   tmp.rem = 0;
   while (tmp.quot != 0)
   {
      tmp = div_mtwo(tmp.quot);
      ans += '0' + tmp.rem;
   }
   reverse(ans.begin(), ans.end());
   ans = ans.empty() ? "0" : ans;
   cout << ans << endl;
   return 0;
}


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

int main() {
    string S, T;
    cin >> S >> T;

    bool ans = false;
    for (int i = 0; i < S.length(); i++) {
        if (S == T) {
            ans = true;
            break;
        }
        S = S.back() + S.substr(0, S.length() - 1);
    }
    
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

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

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int n, m;
   map<string, int> mp;
   cin >> n;
   for(int i = 0;i < n;i++) {
      string x;
      cin >> x;
      auto iter = mp.find(x);
      if (iter != mp.end()) {
         iter->second++;
      } else {
         mp.emplace(x, 1);
      }
   }
   cin >> m;
   for(int i = 0;i < m;i++) {
      string x;
      cin >> x;
      auto iter = mp.find(x);
      if (iter != mp.end()) {
         iter->second--;
      } else {
         mp.emplace(x, -1);
      }
   }
   auto store = mp.begin();
   int max = 0;
   for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
        if(max<itr->second) {
           store = itr;
           max = itr->second;
        }
   }
   cout << max << endl;
   return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int N;
   cin >> N;
   int a[N];
   int cnt4 = 0;
   int cntn2 = 0;
   for (int i = 0; i < N; i++) {
      cin >> a[i];
      if (a[i] % 4 == 0) cnt4++;
      if (a[i] % 2 != 0) cntn2++;
   }
   if (N == cntn2 + cnt4 && cntn2 <= cnt4 + 1) cout << "Yes" << endl;
   else if (cntn2 <= cnt4) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

// ABC100 at 2018/06/16

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solveA();
    }

    private void solveA() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (A > 8 || B > 8) {
            System.out.println(":(");
        } else {
            System.out.println("Yay!");
        }
    }

    private void solveB() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveC() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveD() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveE() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

    private void solveF() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(N);
    }

}

Measured memory_bytes: 23252
# coding: utf-8


def main():
    n = int(input())
    count = 0
    
    for i in range(1, 10):
        syo, amari = divmod(n, i)
        if syo <= 9 and amari == 0:
            print('Yes')
            break
            
        else:
            count += 1
            
    if count == 9:
        print('No')
    
    return 0
    
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<ll> sumw(n+1, 0);
    rep(i, 0, n) {
        ll w;
        cin >> w;
        sumw[i+1] = sumw[i] + w;
    }
    ll ans = INF;
    rep(i, 0, n) chmin(ans, abs(sumw[n] - 2 * sumw[i]));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,sum,ans=1,pd[1002];
deque <int> ag[1002];
deque <int> upd,nw,r;
int main()
{
	cin>>n,sum=n*(n-1)/2;
	for(int i=1;i<=n;i++)
		for(int j=1;j<n;j++){
			int p;
			scanf("%d",&p);
			ag[i].push_back(p);
		}
	for(int i=1;i<=n;i++)
		if(!pd[i]&&!pd[ag[i][0]]&&ag[i][0]!=i&&ag[ag[i][0]][0]==i)
			r.push_back(i),r.push_back(ag[i][0]),
			upd.push_back(i),upd.push_back(ag[i][0]),
			pd[i]=pd[ag[i][0]]=1,sum--,
//			cout<<i<<" "<<ag[i][0]<<endl,
			ag[ag[i][0]].pop_front(),ag[i].pop_front();
//	for(int i=1;i<=n;i++)
//		if(ag[i].size())cout<<ag[i][0]<<" ";
//		else cout<<"NULL ";
//	cout<<endl<<endl;
	while(sum){
//		cout<<upd.size()<<" "<<sum<<endl;
		if(!upd.size())cout<<-1,exit(0);
		ans++;
		while(r.size())pd[r[0]]=0,r.pop_front();
		while(upd.size()){
			int t=upd[0];upd.pop_front();
			if(!ag[t].size())continue;
			int to=ag[t][0];
			if(!ag[to].size())cout<<-1,exit(0);
//			cout<<t<<" "<<to<<" "<<pd[t]<<" "<<pd[to]<<" "<<ag[to][0]<<endl;
			if(pd[t]||pd[to]||ag[to][0]!=t)continue;
			sum--;
			r.push_back(t),r.push_back(to);
			nw.push_back(t),nw.push_back(to);
			ag[t].pop_front(),ag[to].pop_front();
			pd[t]=pd[to]=1;
		}
		while(nw.size())upd.push_back(nw[0]),nw.pop_front();
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

    int N; cin >> N;
    int A,B;
    cin >> A >> B;
    rep(i,N-1){
        int a,b; cin >> a >> b;
        int pos=max((A-1)/a,(B-1)/b)+1;
        A=a*pos; B=b*pos;
    }
    cout << A+B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mr make_pair
using namespace std;
int m,n,x,y,wz,X,Y,Z;
char an[1010][1010];
int main(){
	cin>>n>>m>>x>>y;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)an[i][j]='.';
	wz=(n/2)*(m/2);
	X=(n%2)*(m/2);Y=(n/2)*(m%2);Z=(n%2)*(m%2)*(max(x-X,0)%2)*(max(y-Y,0)%2);
	if (max(x-X+1,0)/2+max(y-Y+1,0)/2-Z>wz)puts("NO");
	else{
		puts("YES");
		for (int i=1;i<=min(x,X);i++){an[n][i*2-1]='<';an[n][i*2]='>';}
		x-=min(x,X);
		for (int i=1;i<=min(y,Y);i++){an[i*2-1][m]='^';an[i*2][m]='v';}
		y-=min(y,Y);
		for (int i=1;i<=n/2;i++){
			for (int j=1;j<=m/2;j++){
				if (x>=2){
					x-=2;an[i*2-1][j*2-1]='<';an[i*2-1][j*2]='>';
					an[i*2][j*2-1]='<';an[i*2][j*2]='>';
				}else{
					if (y){
						y--;an[i*2-1][j*2-1]='^';an[i*2][j*2-1]='v';
						if (y){y--;an[i*2-1][j*2]='^';an[i*2][j*2]='v';}
					}else{
						if (x){x--;an[i*2][j*2-1]='<';an[i*2][j*2]='>';}
					}
				}
			}
		}
		if (x){
			an[n][m]='v';an[n-1][m]='^';
			an[n-2][m-1]='<';an[n-2][m]='>';
		}
		for (int i=1;i<=n;i++){
			for (int j=1;j<=m;j++)putchar(an[i][j]);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main (void)
{
    float a, b, c, d, e, f;
    float x, y;
    while(scanf("%f%f%f%f%f%f", &a, &b, &c, &d, &e, &f) != EOF){
        y = (d * c - a * f) / (d * b - a * e);
        x = (c - b * y) / a;
        printf("%.3f %.3f\n", x, y);
    }
    return (0);
}


Measured memory_bytes: 2020
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using pii = pair<int, int>;

bool cmp1(pii x, pii y) {
    return (x.first>y.first) || (x.first==y.first && x.second<y.second);
}

bool cmp2(pii x, pii y) {
    return x.second>y.second;
}

int main() {
    int n, h;
    cin >> n >> h;
    vector<pii> ks(n);
    for(int i=0; i<n; i++) {
        cin >> ks[i].first >> ks[i].second;
    }
    sort(ks.begin(), ks.end(), cmp1);
    int sw = ks[0].first;
    sort(ks.begin(), ks.end(), cmp2);
    int ct = 0;
    for(int i=0; h>0 && i<n && ks[i].second>sw; i++) {
        ct++;
        h -= ks[i].second;
    }
    if(h>0) {
        ct += (h + sw - 1) / sw;
    }
    cout << ct << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
typedef long long int llint;

int main(void){

  llint h;
  std::cin >> h;

  llint count = 0;
  llint now = 1;
  while(h!=0){
    count+=now;
    now*=2;
    h/=2;
  }

  std::cout << count << std::endl;

  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
// #define for(i, n) for(int i=0; i<(n); i++)

using namespace std;
 
int main() {
    fastio
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    for(int i = 1;i<=H; i++){
    	for(int j = 1; j<=W; j++){
    		if(i<=B){
    			if(j<=A)
    				cout<<1;
    			else
    				cout<<0;
    		}
    		else{
    			if(j<=A)
    				cout<<0;
    			else
    				cout<<1;
    		}
    	}
    	cout<<endl;
    }
 
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define REPR(i, n) for(ll i = n; i >= 1; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
const ld INF = 1e9+123;
#define VEC(type,A,N) vector<type> A(N+10)
#define VECi(type,A,N,i) vector<type> A(N+10,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N+10,vector<type>(M+10))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N+10,vector<type>(M+10,i))
#define ALL(v) v.begin()+1, v.end()-9
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    int N;
    cin>>N;
    string S;
    int E=0;
    REP(i,N){
        cin>>S;
        if(S[i-1]=='E')E++;
    }
    int m=INF,W=0;
    REP(i,N){
        if(S[i-1]=='E')E--;
        m=min(m,E+W);
        if(S[i-1]=='W')W++;
    }
    
    cout<<m;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define loops(i, s, n) for (int i = s; i < n; i++)
#define loop(i, n) for (int i = 0; i < n; i++)
#define eps 1e-9
#define loopitr(mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define even_set 0xAAAAAAAA ... 1010101010
#define odd_set 0x55555555 ... 01010101
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vall(v) v.begin(), v.end()
#define mkp make_pair
#define ret return
#define cont continue
#define ff first
#define ss second
#define cnt_bits __builtin_popcount
const int mod = 1000000007;

int main()
{

    fastio;
    int n, w;
    cin >> n >> w;
    ll arr[n+1][2];
    ll sum = 0;
    loops(j,1,  n+1)
    {
        cin >> arr[j][0] >> arr[j][1];
        sum += arr[j][1];
    }
    

    ll dp[n+1][sum+1];
    loop(i, n+1)
      loop(j, sum+1) 
        dp[i][j] = INT32_MAX;
    
    loop(i, n+1)
        dp[i][0] = 0;

    loops(i, 1, n+1){
        loops(j, 1, sum+1){
            dp[i][j] = dp[i-1][j];
            dp[i][j] = min(dp[i][j] ,((j-arr[i][1] >=0 )? dp[i-1][j-arr[i][1]] + arr[i][0] : INT32_MAX));
        }
    }

    // loop(i, n+1){
    //   loop(j, sum+1) 
    //     cout<<dp[i][j]<<" ";
    //  cout<<endl;   
    // }
    // cout<<endl;
    

    ll ans = -1;
    loops(j, 1, sum+1 ){
        if(dp[n][j] <= w)
           ans = j;
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

vector<string> split(string s, char c) {
    vector<string> v;
    string t = "";

    auto v_push = [&](string sp) {
        if (sp == "") return;
        v.push_back(sp);
    };

    rep(i, s.length()) {
        if (s[i] == c) {
            v_push(t);
            t = "";
        } else if (i == (int)s.length() - 1) {
            t.push_back(s[i]);
            v_push(t);
        } else {
            t.push_back(s[i]);
        }
    }
    return v;
}

ll inversion(string s) {
    int a = 0;
    ll res = 0;
    for (auto c : s) {
        if (c == 'A') a++;
        else {
            res += a;
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    string t;
    s.push_back('X');

    rep(i, s.length() - 1) {
        if (s[i] == 'B' && s[i + 1] == 'C') {
            t.push_back('D');
            i++;
        } else if (s[i] == 'A') {
            t.push_back('A');
        } else {
            t.push_back('.');
        }
    }
    vector<string> v = split(t, '.');
    ll ans = 0;
    for (auto ti : v) {
        ans += inversion(ti);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3472
#include <stdio.h>
#define rep(i,n)for(int i=0;i<n;i++)

int test(int i,int a,int b,int c,int d){
	int op[3],A[3]={b,c,d},ans=7;
	op[0]=i/4;op[1]=(i%4)/2;op[2]=i%2;
	ans-=a;
	rep(j,3){
		op[j]*=2;
		if(op[j])ans-=A[j];
		else ans+=A[j];
	}
	if(ans==0){
 		char s=45-op[0],t=45-op[1],u=45-op[2];
		printf("%d%c%d%c%d%c%d=7",a,s,b,t,c,u,d);
		return 1;
	}
	return 0;
}

int main(){
	int a,b,c,d;
	scanf("%d",&d);
	a=d/1000;
	b=(d%1000)/100;
	c=(d%100)/10;
	d%=10;
	rep(i,8)if(test(i,a,b,c,d))return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
int cnt(int level){
    return pow(2,level+2)-3;
}
int solve(int level,int x){
    if(level==0)return 1;
    else{
        if(x==1)return 0;
        else if(x<=cnt(level-1)+1)return solve(level-1,x-1);
        else if(x==cnt(level-1)+2)return solve(level-1,cnt(level-1))+1;
        else if(x<=cnt(level)-1)return solve(level-1,cnt(level-1))+1+solve(level-1,x-cnt(level-1)-2);
        else return 2*solve(level-1,cnt(level-1))+1;
    }
}
signed main(){
    int n,x;
    cin>>n>>x;
    cout<<solve(n,x)<<endl;
    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int n, k; in(n); in(k);
  vl h(n); ina(h,n);
  int ans = 0;
  rep(i,n) if(h[i]>=k) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
function main(input) {
    var line = input.split(' ');
    var D = parseInt(line[0]);
    var N = parseInt(line[1]);
    var answer = Math.pow(100, D) * (N === 100 ? 101: N);
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 22964
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int[] nl = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = nl[0];
            int l = nl[1];

            var ls = new List<string>();
            for (int i = 0; i < n; i++)
            {
                ls.Add(ReadLine());
            }
            ls = ls.OrderBy(x => x).ToList();
            WriteLine(string.Join("", ls));
            
        }
    }
}

Measured memory_bytes: 13664
import bisect

N,K = map(int,input().split())
A = list(map(int,input().split()))

# dp[i]:残りの石がi個の時、先手が負けなら0、勝ちなら1
dp = [0 for _ in range(K+1)]

for i in range(1,K+1):
  rank = bisect.bisect_right(A, i)
  if rank == 0:
    dp[i] = 0
  else:
    for j in range(rank):
      if i-A[j] >= 0 and dp[i-A[j]] == 0:
        dp[i] = 1
        break
print('First' if dp[K] == 1 else 'Second')


Measured memory_bytes: 47932
s_orig = gets.chomp
t_orig = gets.chomp

s = s_orig.codepoints
t = t_orig.codepoints

s_size = s.size
t_size = t.size

dp = Array.new(s_size+1) { Array.new(t_size+1,0) }

0.upto(s_size-1).each do |i|
  dpi = dp[i]
  dpi1 = dp[i+1]
  0.upto(t_size-1).each do |j|
    if s[i] == t[j]
      dpi1[j+1] = dpi[j] + 1
    else
      dpi1[j+1] = dpi1[j] > dpi[j+1] ? dpi1[j] : dpi[j+1]
    end
  end
end

ans = ''
y = s_size
x = t_size

while y>0
  if dp[y-1][x] == dp[y][x]
    y-=1
  elsif dp[y][x-1] == dp[y][x]
    x-=1
  else
    y-=1
    x-=1
    ans << s_orig[y]
  end
end

# dp.each{|l| p l}

puts ans.reverse


Measured memory_bytes: 72700
#Bubble sort

n = int(input())

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

count = 0
flag = True
while flag:
    flag = False
    for i in range(n-1,0,-1):
        if A[i] < A[i-1]:
            A[i],A[i-1] = A[i-1],A[i]
            flag = True
            count += 1

print(*A)
print(count)


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

int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	if(a>b){swap (a,b);}
	int p=a*b;
	int flag=0;
	for(int i=a;i<=b;i++){
	    int x=p*i;
	    if(x%2!=0){
	        flag=1;
	        break;
	    }
	}
	if(flag==1){
	    cout<<"Yes";
	}
	else{
	    cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> v[N];
  REP(i,N){
    int t,d;
    cin>>t>>d;
    t--;
    v[t].push_back(d);
  }
  vector<lint> a,b;
  REP(i,N){
    if(v[i].empty())continue;
    sort(ALL(v[i]),greater<int>());
    a.push_back(v[i][0]);
    FOR(j,1,v[i].size())b.push_back(v[i][j]);
  }
  sort(ALL(a),greater<lint>());
  sort(ALL(b),greater<lint>());
  // for(auto i:a)cerr<<i<<" ";
  // cerr<<endl;
  // for(auto i:b)cerr<<i<<" ";
  // cerr<<endl;
  vector<lint> sa,sb;
  sa.push_back(0);
  sb.push_back(0);
  for(auto i:a)sa.push_back(i+sa.back());
  for(auto i:b)sb.push_back(i+sb.back());
  // for(auto i:sa)cerr<<i<<" ";
  // cerr<<endl;
  // for(auto i:sb)cerr<<i<<" ";
  // cerr<<endl;
  lint ans=0;
  FOR(i,1,K+1){
    if(sa.size()<i+1)continue;
    if(sb.size()<K-i+1)continue;
    lint temp=(lint)i*i;
    temp+=sa[i];
    temp+=sb[K-i];
    ans=max(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 8052
#include<iostream>
using namespace std;
int main()
{
int hi,hy;
int ki,ky;
int pi,py,pii,pyy;
int hp,kp;
cin >> hi >> hy >> ki >> ky >> pi >> py >> pii >> pyy;
hp=( pi * hi ) + ( hy * py ) + ( hi / 10 * pii ) + ( hy / 20 * pyy );
kp=( pi * ki ) + ( ky * py ) + ( ki / 10 * pii ) + ( ky / 20 * pyy );
if(hp == kp) cout << "even\n";
else if(hp > kp) cout << "hiroshi\n" ;
else cout << "kenjiro\n";
return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    ll n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    ll mn = min(a,b);
    mn = min(mn,c);
    mn = min(mn,d);
    mn = min(mn,e);
    cout << 5+(n+mn-1)/mn-1 << endl;    
}

Measured memory_bytes: 384
a = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
k = int(input())
b = a.split(", ")
print(b[k-1])


Measured memory_bytes: 38256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353//1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

struct p
{
	ll a;
	int b;
	int c;
};

inline int func(int a, int b)
{
	if (a > b)
		return a - b;
	else
		return b - a;
}

int main()
{
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<int> p(a), q(b), r(c);
	for (int i = 0; i < a; i++)
		cin >> p[i];
	for (int i = 0; i < b; i++)
		cin >> q[i];
	for (int i = 0; i < c; i++)
		cin >> r[i];
	sort(p.begin(), p.end(), greater<int>());
	sort(q.begin(), q.end(), greater<int>());
	sort(r.begin(), r.end(), greater<int>());

	ll z = 0;
	int s = 0, t = 0, u = 0;

	for (int i = 0; i < x; i++)
	{
		if (u >= c || p[s] > r[u])
		{
			z += p[s];
			s++;
		}
		else
		{
			z += r[u];
			u++;
		}
	}

	//	この時点でp[s]からはu個まで使用可能
	int ms = u;
	
	for (int i = 0; i < y; i++)
	{

		if (ms <= 0 || s >= a || q[t] > p[s])
		{
			if (u >= c || q[t] > r[u])
			{
				z += q[t];
				t++;
			}
			else
			{
				z += r[u];
				u++;
			}
		}
		else
		{
			if (u >= c || p[s] > r[u])
			{
				z += p[s];
				s++;
				ms--;
			}
			else
			{
				z += r[u];
				u++;
			}
		}
	}

	printf("%lld", z);
	return 0;
}


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

x -= 1
y -= 1

dis = [[-1]*n for _ in range(n)]
dis_cnt = [0]*(n-1)

for i in range(n):
  for j in range(n):
    if i>j:
      continue
    dis[i][j] = min( abs(j-i), abs(x-i) + abs(j-y) + 1, abs(y-i) + abs(j-x)+1 )
    if dis[i][j]>0:
      dis_cnt[dis[i][j]-1] += 1
    
#print(dis_cnt)
[print(dis_cnt[i]) for i in range(n-1)]

Measured memory_bytes: 81244
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,(n))


class B121 {
public:
	void solve(std::istream& in, std::ostream& out) {
    string a,b;
    in >> a >> b;
    int t = stoi(a + b);
    REP(i,t){
      if(i * i == t) {
        out << "Yes" << endl;
        return;
      }
    }
    out << "No" << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	B121 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3580
using System;
using static System.Console;

namespace ABC84
{
    class Program
    {
        static void Main(string[] args) {
            string Id = ReadLine();
            string[] Idsa = Id.Split(' ');
            string HanS = ReadLine();
            string[] Hana = HanS.Split('-');
            bool fl = true;
            if (Hana.Length != 2) {
                fl = false;
            }
            if (( Hana[0].Length == Int32.Parse(Idsa[0]) ) && ( Hana[1].Length == Int32.Parse(Idsa[1]) )) {

            } else {
                fl = false;
            }
            if (fl == true) {
                WriteLine("Yes");
            } else {
                WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
vector<int> graph[100005];
int dp[100005];
int dfs(int v){
	if(dp[v]!=-1)
		return dp[v];
	int ans=0;
	for(int i=0;i<graph[v].size();i++){
		int x=graph[v][i];
		ans = max(dfs(x) + 1, ans);
	}
	return dp[v] = ans;
}
int main(){
	fast
	int n, m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x, y;
		cin>>x>>y;
		x--;
		y--;
		graph[x].push_back(y);
	}
	memset(dp, -1, sizeof(dp));
	int ans=0;
	for(int i=0;i<n;i++){
		ans=max(ans, dfs(i));
	}
	cout<<ans;
	return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  
  int n1, n2, n3, n4, n5;
  
  n1 = A + B;
  n2 = A - B;
  n3 = A * B;
  
  n4 = max(n1, n2);
  n5 = max(n3, n4);
    
  cout << n5 << endl;
}

Measured memory_bytes: 256
import sys
from math import hypot

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N, D = MAP()
ans = 0
for i in range(N):
    x, y = MAP()

    d = hypot(x, y)
    if d < D + EPS:
        ans += 1
print(ans)


Measured memory_bytes: 9552