akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;
long long a[100005];
long long b[100005];
int main()
{
    long long n, nr = 0;
    cin >> n;
    for(long long i = 1; i <= n; i ++)
        cin >> a[i] >> b[i];
    long long sum2 = 0;
    for(long long i = n; i >= 1; i --)
    {
        a[i] += sum2;
        long long sum = 0;
        if(a[i] % b[i] != 0)
        {
            if(a[i] < b[i])
                sum += (b[i] - a[i]);
            else if(a[i] > b[i])
                sum += (b[i] - a[i] % b[i]);
            sum2 += sum;
            nr += sum;
        }
    }
    cout << nr;
	return 0;
}



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

struct data {
  long long w, v;
};

long long n, w, b;
long long dp[105][105][3005] = {0};
vector<data> v;

long long solve();

int main() {
  cin >> n >> w;
  v.resize(n);
  for(int i = 0; i < n; ++i) cin >> v[i].w >> v[i].v;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  b = v[0].w;
  long long ans = 0;
  for(long long i = 0; i < n; ++i)
    for(long long j = 1; j <= n; ++j)
      for(long long k = 0; k + j * b <= w && k <= n * 3;
          ++k) {
        long long now = v[i].w - b;
        dp[i + 1][j][k] = dp[i][j][k];
        if(k - now >= 0)
          dp[i + 1][j][k] =
              max(dp[i + 1][j][k],
                  dp[i][j - 1][k - now] + v[i].v);
        ans = max(ans, dp[i + 1][j][k]);
      }
  return ans;
}

Measured memory_bytes: 248064
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	int N, K;
	char S[10];

	cin >> N;
	cin >> S;
	cin >> K;

	for (int i = 0; i < N; i++) {
		if (S[i] != S[K - 1]) {
			S[i] = '*';
		}
	}

	cout << S << endl;
}

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 Y = sc.nextInt();

        System.out.println(solve(X, Y));

        sc.close();
    }

    static int solve(int X, int Y) {
        return X + Y / 2;
    }
}

Measured memory_bytes: 35692
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int main(void){
    int n,ans = 0;
    cin >> n;
    vector<int> a(n);
    map<int,int> mp;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        mp[a[i]]++;
    }
    for(auto x:mp){
        if(x.second > x.first) ans += (x.second - x.first);
        else if(x.second < x.first) ans += x.second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5120
#include<algorithm>
#include<cstdio>
#define rep(i,a) for(int i=0;i<(a);++i)

const int MAX_N = 100000, INF = 1000000001;

int n, a[MAX_N];
int dp[MAX_N+1];

int main()
{
    scanf( "%d", &n );
    rep( i, n )
        scanf( "%d", a+i );

    std::fill( dp, dp+n+1, INF );

    rep( i, n )
        *std::lower_bound( dp, dp+n+1, a[i] ) = a[i];

    printf( "%d\n", std::lower_bound( dp, dp+n+1, INF )-dp );

    return 0;
}

Measured memory_bytes: 3524
using static System.Console;
public class Hello{
    public static void Main(){
        int a = int.Parse(ReadLine());
        int[] num = new int[4];
        for(int i=0;i<4;i++){
            num[i] = a%10;
            a/=10;
        }
        string b ="";
        for(int i=1;i<=8;i++){
            b = "";
            int k = 7-num[3];
            if((i/2)%2 == 0){
                k -= num[2];
                b+= "+";
                if((i/4)%2 == 0){
                    k-=num[1];
                    b+= "+";
                }else{
                    k+=num[1];
                    b+= "-";
                }
            }else{
                k += num[2];
                b+= "-";
                if((i/4)%2 == 0){
                    k-=num[1];
                    b+= "+";
                }else{
                    k+=num[1];
                    b+= "-";
                }
            }
            if(k == num[0]){
                b+= "+";
                break;
            }else if(k + num[0] == 0){
                b+= "-";
                break;
            }else{
                continue;
            }
        }
        WriteLine($"{num[3]}{b[0]}{num[2]}{b[1]}{num[1]}{b[2]}{num[0]}=7");
    }
}


Measured memory_bytes: 13268
import java.util.*;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] p = new int[N];
        for(int i = 0; i < N; i++) {
            p[i] = Integer.parseInt(sc.next());
        }
        
        int sw = 0;
        int w = 0;
        for(int i = 0; i < N-1; i++) {
            int min = p[i];
            int minidx = i;
            for(int j = i + 1; j < N; j++) {
                if(min > p[j]) {
                    min = p[j];
                    minidx = j;
                }
            }
            if(minidx != i) {
                w = p[i];
                p[i] = min;
                p[minidx] = w;
                sw++;
            }
        }
        
        if(sw <= 1) {
            System.out.println("YES");
        }else {
            System.out.println("NO");
        }
        
    }
}

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

using namespace std;

#define ll long long
#define mod 1000000007
  
void solve(){
	string s;
	cin>>s;
	int c = 0;
	int ans = 0;
	for(int i = 0;i<s.size();i++){
		if(s[i] == 'R'){
			c++;
		}else{
			ans = max(c,ans);
			c = 0;
		}
	}
	ans = max(ans,c);
	cout<<ans;
	
}

int main(){
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    while(1) {
        if (b <= a)
        {
            if (k == 0)
            {
                cout << "No" << endl;
                exit(0);
            }
            b *= 2;
        }
        else if (c <= b)
        {
            if (k == 0)
            {
                cout << "No" << endl;
                exit(0);
            }
            c *= 2;
        }
        else
        {
            break;
        }
        k--;
    }

    cout << "Yes" << endl;
}

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

// 基本戦略としてはそれぞれのコンテストでsqrt(A*B)位以内に入っている人間を全採用

int main() {
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        ll A, B;
        cin >> A >> B;
        if (A > B) {
            ll temp = A;
            A = B;
            B = temp;
        }
        if (A == B || A+1 == B) {
            cout << A+A-2 << "\n";
            continue;
        }
        ll sq = (ll)(sqrt(A*B)-0.001);
        ll ans = 2 * sq - 1;
        if (sq*(sq+1) >= A*B) ans--;
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
h={[1,2]=>6,[1,3]=>10,[1,4]=>12,[1,5]=>14,[1,6]=>27,[1,7]=>33,[2,3]=>7,[2,4]=>9,[2,5]=>12,[2,6]=>23,[2,7]=>30,[3,4]=>5,[3,5]=>8,[3,6]=>20,[3,7]=>27,[4,5]=>5,[4,6]=>17,[4,7]=>26,[5,6]=>12,[5,7]=>23,[6,7]=>10}
while(a=gets.to_i)>0
	x,y=gets.split.map(&:to_i)
	y+=x*60
	b=gets.to_i
	x,z=gets.split.map(&:to_i)
	z+=x*60
	c=h[([a,b].sort)]
	c/=2.0 if c<27&&((1050<=y&&y<=1170)||(1050<=z&&z<=1170))
	p c.ceil*50
end

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

int main() {
  int N,M;
  cin >> N >> M;
 
  vector<int>vec(M);
  for (int i=0; i<M; i++){
  cin >>vec.at(i);
  }
  int A = 0;
  for (int i=0; i<M; i++){
  A=A+vec.at(i);
  }
  
  if(N-A<0){
  cout << "-1" << endl;
  }
  
  else{
  cout << N-A <<endl;
  }
  
}


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

int main()
{
	int N;
	cin >> N;
	int ans = 1;
	int i = 1;
	while (i*i <= N)
	{
		ans = i*i;
		i++;
	}
	cout << ans << endl;
	return 0;
}

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


int main() {
  int N,K,M = 1;
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    if(M < K) {
      M *= 2;
    }
    else {
      M += K;
    }
  }
  cout << M << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
using namespace std;
#define LL long long

int n, a[10002], tmp, cnt;

int main(){

	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];

	for (int i = 0; i < n; i++){
		while (a[i] % 2 == 0){
			a[i] /= 2;
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
N = len(s)
n = len(t)
m = 0
T = list(t)
S = list(s)
if N == n:
    for i in range(n):
        if T[i] == S[i]:
            m += 1
else:
    for i in range(N-n):
        cnt = 0
        for j in range(n):
            if S[i+j] == T[j]:
                cnt += 1
        if m < cnt:
            m = cnt
print(n-m)


Measured memory_bytes: 9076
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		Console.WriteLine(string.Join("\n", new int[h[0]].Select(_ => Console.ReadLine()).SelectMany(x => new[] { x, x })));
	}
}


Measured memory_bytes: 28448
use std::io::*;
use std::str::*;

const MOD: i32 = 1000000007;

fn read<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let n: usize = read().unwrap();

    let mut b = Vec::new();
    for i in 0..n {
        let tmp: u64 = read().unwrap();
        b.push(tmp);
    }
    let mut ans = Vec::new();
    if n % 2 == 0 {
        for i in (0..n).rev() {
            if i % 2 == 0 {
                continue;
            }
            ans.push(b[i]);
        }
        for i in 0..n {
            if i % 2 != 0 {
                continue;
            }
            ans.push(b[i]);
        }
    } else {
        for i in (0..n).rev() {
            if i % 2 != 0 {
                continue;
            }
            ans.push(b[i]);
        }
        for i in 0..n {
            if i % 2 == 0 {
                continue;
            }
            ans.push(b[i]);
        }
    }
    for i in 0..n - 1 {
        print!("{} ", ans[i]);
    }
    println!("{}", ans[n - 1]);

    // let mut b = Vec::new();
    // for i in 0..n {
    //     let tmp: u64 = read().unwrap();
    //     b.push(tmp);
    //     b.reverse();
    // }
    // for i in 0..n - 1 {
    //     print!("{} ", b[i]);
    // }
    // println!("{}", b[n - 1]);
}


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

int main() {
  int n;
  cin >> n;
  bool flg = true;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    if(a % 2 == 0){
      if(a % 3 != 0 && a % 5 != 0) flg = false;
    }
  }
  if(flg) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  return 0;
}

Measured memory_bytes: 256
//10-B

//関数で考えるとわかりやすいかも
//三角関数　平方根の求め方　sqrt( x長さの2乗　＋　y長さの2乗 )

import java.util.Scanner;

class Main {
    public static void main(String [] args){
         
        Scanner sc = new Scanner(System.in);
        
        double a = sc.nextDouble();//辺の長さ a
        double b = sc.nextDouble();//辺の長さ b
        double C = sc.nextDouble();//aとbの間の角度
        double d = 0;//三角形　a,b　以外の残りの辺の長さ d
        double S;//面積
        double L;//周の長さ
        double h;// a を底辺にした時の高さ
        
        double rajiC = C * Math.PI / 180 ;//角度Cをラジアンに変換
        
        //高さ計算　計算式 h = b * sinC ※角度ではなくラジアン値を使う
        h = b * Math.sin(rajiC);
        
        //面積を求める 計算式　S = a * h / 2
        S = a * h / 2 ;
        
        //dの計算　角度が90度の時　sqrt( a*a + b*b ) 平方根
        //Lの計算
        double x = b * Math.cos(rajiC);
        double y = a - x ;
        d = Math.sqrt( h * h + y * y );
        L = a + b + d ;
        
        System.out.println( S + " " + L + " " + h );
        
        
        
        
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> staff(n+1, 0);
  for ( int i = 2; i <= n; i++ ) {
    int a;
    cin >> a;
    staff[a]++;
  }
  for ( int i = 1; i <= n; i++ ) {
    cout << staff[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4036
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

class Problem
{
private:
	// Variables
	int k, s;
	
public:
	// Methods
	void input ()
	{
		cin >> k >> s;
	}
	
	void process ()
	{
		
	}
	
	void output ()
	{
		int S = min(s, 2 * k);
		int O = max(0, s-k);
		int count = 0;
		for (int l=O; l<=S; ++l)
		{
			int b = max(l-k, 0);
			int e = min(l, k);
			for (int x=b; x<=e; ++x)
			{
				if (0 <= l-x && l-x <= k)
				{
					++count;
				}
			}
		}

		cout << count << endl;
	}
};

int main ()
{
	Problem problem;
	problem.input();
	problem.process();
	problem.output();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
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;
}

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

inline long long mul(long long a, long long b, long long m) {
    a = mod(a, m); b = mod(b, m);
    if (b == 0) return 0;
    long long res = mul(mod(a + a, m), b>>1, m);
    if (b & 1) res = mod(res + a, m);
    return res;
}

int main() {
    long long ans;
    int N, K;
    cin >> N >> K;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    COMinit();
    long long MAX_sum = 0;
    for(int i = K - 1; i < N; i++) {
        MAX_sum = (MAX_sum + mul(A.at(i) , COM(i, K - 1) , MOD)) % MOD;
    }
    long long MIN_sum = 0;
    for(int i = 0; i < N - K + 1; i++) {
        MIN_sum = (MIN_sum + mul(A.at(i) , COM(N - i - 1, K - 1) , MOD)) % MOD;
    }
    ans = MAX_sum - MIN_sum;
    if(ans < 0)
        ans += MOD;
    cout << ans << endl;
}

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

using namespace std;

map <long long,long long> dp;

const long long MOD = 1e9+7;

long long calc(long long x){
	if (dp.find(x) != dp.end())
        return dp[x];
	if (x == 0)
        return dp[0]=1;
	if (x == 1)
	return dp[1] = 2;
	return dp[x] = (calc(x / 2) + calc((x - 1) / 2) + calc((x - 2) / 2)) % MOD;
}

int main() {
	long long n;
	cin >> n;
	cout << calc(n) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
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 gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    vector<int> P(N);
    vector<int> Q(N);
    vector<int> x(N);
    for(int i=0;i<N;i++){
        cin >> P[i];
        x[i] = i+1;
    }
    for(int i=0;i<N;i++){
        cin >> Q[i];
        
    }
    int a,b;
    int cnt=0;
    do{
        bool s=true;
        bool t=true;
        for(int i=0;i<N;i++){
            if(x[i]!=P[i]) s=false;
            if(x[i]!=Q[i]) t=false;
        }
        if(s) a=cnt;
        if(t) b=cnt;
        cnt++;
    }while(next_permutation(x.begin(),x.end()));
    cout << abs(a-b) << endl;
    return 0;
}


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

using namespace std;

int main()
{
  string S;
  cin >> S;
  int ret = 114514;
  for(int i = 'a'; i <= 'z'; i++) {
    if(count(begin(S), end(S), i) == 0) continue;
    int beet = 0;

    string T = S;
    while(count(begin(T), end(T), i) != T.size()) {
      string Q;
      for(int j = 0; j < T.size() - 1; j++) {
        if(T[j] == i || T[j + 1] == i) Q += (char)i;
        else Q += T[j];
      }
      ++beet;
      swap(Q, T);
    }
    ret = min(ret, beet);
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 40) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z, K;
    cin >> x >> y >> z >> K;
    vector<ll> a(x), b(y), c(z);
    for(int i = 0; i < x; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < y; i++) {
        cin >> b[i];
    }
    for(int i = 0; i < z; i++) {
        cin >> c[i];
    }
    sort(all(a));
    sort(all(b));
    sort(all(c));
    reverse(all(a));
    reverse(all(b));
    reverse(all(c));
    priority_queue<ll, vector<ll>, greater<ll>> q;
    for(int i = 0; i < x; i++) {
        for(int j = 0; j < y; j++) {
            for(int k = 0; k < z; k++) {
                ll sum = a[i] + b[j] + c[k];
                if(q.size() == K && q.top() > sum) {
                    break;
                }
                q.push(sum);
                if(q.size() > K) {
                    q.pop();
                }
            }
        }
    }
    vector<ll> v;
    while(!q.empty()) {
        v.push_back(q.top());
        q.pop();
    }
    reverse(all(v));
    for(int i = 0; i < K; i++) {
        cout << v[i] << endl;
    }
}


Measured memory_bytes: 1020
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	ll N; cin >> N;
	vector<ll> a(N); rep(i, N) cin >> a[i];

	ll sum = 0;
	vector<ll> c(N);
	rep(i, N) { 
		sum += a[i];
		if (i == 0) c[i] = a[i];
		else c[i] = a[i] + c[i - 1];
	}

	ll mi = 1e15;
	rep(i, N-1) {
		ll x = c[i];
		ll y = sum - x;
		ll ans = abs(x - y);
		mi = min(mi, ans);
	}

	cout << mi << endl;
}

Measured memory_bytes: 3328
N, M = map(int, input().split())
A, B = [], []

for _ in range(N):
  A.append(list(map(int, input().split())))

for _ in range(M):
  B.append(int(input()))

for n in range(N):
  x = 0
  for m in range(M):
    x += A[n][m] * B[m]
  print(x)


Measured memory_bytes: 6008
n = int(input())
x = list(enumerate(map(int, input().split())))
x.sort(key=lambda x:x[1])
ans = [""]*n
for i in range(n):
  if (n+1)//2 >= i+1: ans[x[i][0]] = x[(n+1)//2][1]
  else: ans[x[i][0]] = x[(n+1)//2-1][1]

print("\n".join(map(str, ans)))

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

int main (){
    int N;
    cin >> N;
    vector<int> list(N,0);
    int A;

    for(int i = 1;i < N; i++){
        cin >> A;
        list.at(A - 1)++;
    }



    for(int i = 0;i < N; i++){
        cout << list.at(i) << endl;
    }
    
}

Measured memory_bytes: 4028
n, x, y = map(int, input().split())
x -= 1
y -= 1

ans = [0] * n

for j in range(n):
  for i in range(j):
    d = min(j-i, abs(x-i)+1+abs(j-y))
    ans[d] += 1

print( "\n".join( [str(d) for d in ans[1:]] ))


Measured memory_bytes: 3188
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int n;
    cin>>n;
    int a[n+3],b[n+3];
    f(i,1,n)
    {
        cin>>a[i]>>b[i];
    }
    int delta=0;
    rf(i,n,1)
    {
        int val=a[i]+delta;
        if(val%b[i]!=0)
        {
            if(val<b[i])
            {
                delta+=(b[i]-val);
            }
            else
            {
                int m=val/b[i];
                m=(m+1)*b[i];
                delta+=(m-val);
            }
        }
    }
    cout<<delta<<endl;
    return 0;

}





































Measured memory_bytes: 1792
q,h,s,r = map(int,input().split())
n = int(input())
a = n//2
b = n%2
x = min(q*8,h*4,s*2,r)
if b==0:
    print(x*a)
else:
    y = min(q*4,h*2,s)
    print(x*a+y)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();

        if (K == 1) {
            System.out.println(0);
            return;
        }
        int T = sc.nextInt();
        if (T == 1) {
            System.out.println(K - 1);
            return;
        }
        int[] a = new int[T];

        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }

        int fIndex = 0;
        int sIndex = 1;
        if (a[0] < a[1]) {
            fIndex = 1;
            sIndex = 0;
        }

        for (int i = 0; i < K / 2; i++) {

            for (int j = 0; j < a.length; j++) {
                if (a[j] > a[fIndex]) {
                    sIndex = fIndex;
                    fIndex = j;
                } else if (a[j] > a[sIndex] && j != fIndex) {
                    sIndex = j;
                }
            }

            if (a[sIndex] == 0) {
                System.out.println(a[fIndex] - 1);
                return;
            }

            a[fIndex]--;
            a[sIndex]--;
        }
        System.out.println(0);
    }
}

Measured memory_bytes: 10068
from collections import deque

N, *AB = map(int, open(0).read().split())

E = [set() for _ in range(N + 1)]
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
    E[a].add((b, i))
    E[b].add((a, i))

A = [0] * (N - 1)
Q = deque([1])
while Q:
    p, v = divmod(Q.popleft(), N + 1)
    c = 0
    for u, i in E[v]:
        E[u].remove((v, i))
        c += 1 + (c + 1 == p)
        Q.append(c * (N + 1) + u)
        A[i] = c

print(max(A))
print("\n".join(map(str, A)))

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

int main(void){
	char x[128];
	
	while(scanf("%s", x)!=EOF){
		
		for(int i = 9; i > 0; i--){
			char s[128];
			strcpy(s,x);
			for(int j = 0; j < i; j++){
				s[j] = x[j]+x[j+1]-'0';
				if(s[j]-'0'>9)s[j]-=10;
			}
			strcpy(x,s);
//			puts(x);
		}
		printf("%c\n", x[0]);
	}
	
	return 0;
}

Measured memory_bytes: 980
s = list(map(int,list(input())))
a = 0
b = 1
counta = 0
countb = 0
for binary in s:
    if binary != a:
        counta += 1
    a += 1
    if a == 2:
        a = 0
for binary in s:
    if binary != b:
        countb += 1
    b += 1
    if b == 2:
        b = 0
print(counta if counta < countb else countb)

Measured memory_bytes: 4652
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

//using namespace std;
using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up) for (auto countName = left; countName < right; countName += up)
#define REP(countName, end) for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down) for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end) for (auto countName = end; countName >= 0; countName--)

auto solve1(int n, int m)
{
    std::vector<std::vector<int>> h(n);
    auto ans = 0;

    REP(i, n)
    {
        int height;
        cin >> height;
        h[i].push_back(height);
    }

    REP(i, m)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        h[a].push_back(b);
        h[b].push_back(a);
    }

    REP(i, n)
    {
        bool flag = true;
        if (h[i].size() == 1)
        {
            ++ans;
            continue;
        }
        else
        {
            rep(k, 1, (int)h[i].size(), 1)
            {
                if (h[h[i][k]][0] >= h[i][0])
                {
                    flag = false;
                    break;
                }
            }

            if (flag)
            {
                //cout << i << " good" << endl;
                ++ans;
            }
            else
            {
                //cout << i << " wrong" << endl;
            }
        }
    }
    
    /*
    cout << "n : " << n << " m : " << m << endl;
    REP(i, n)
    {
        REP(k, (int)h[i].size())
        {
            cout << h[i][k] << " ";
        }
        cout << endl;
    }
    */

    return ans;
}

int main(void)
{
    int n, m;
    cin >> n >> m;
    std::cout << solve1(n, m) << std::endl;
    return 0;
}

Measured memory_bytes: 9376
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open System

let rec cartesian lst n = 
    match (lst, n) with
        | ([], _) -> []
        | (_,  0) -> []
        | (_,  1) -> [for x in lst -> [x]]
        | _       -> [for x in lst do for y in cartesian lst (n-1) -> [x]@y]


type Light(noIn:int, pIn:int, patternIn:int array) =
    let no = noIn
    let p = pIn
    let pattern = patternIn

    member this.IsOn(switches:bool list) = 
        //trueのみカウント
        //正確にはfun x -> x=trueだが面倒なのでidで代用
        let count = [for p in pattern -> switches.[p]] |> List.filter(id) |> List.length
        ((p+count) % 2 = 0)


[<EntryPoint>]
let main argv = 
    
    let inputs = stdin.ReadLine().Split(' ') |> Array.map int

    let numOfSwitches = inputs.[0]
    let numOfLights = inputs.[1]

    let switchPattern : int array array = Array.create numOfLights (Array.create 1 0)

    for i = 0 to numOfLights - 1 do
        switchPattern.[i] <- (stdin.ReadLine().Split(' ') |> Array.map (fun s -> int s - 1)).[1..]

    let ps = stdin.ReadLine().Split(' ') |> Array.map int

    //ライトの生成
    let lights = [for i in 0..(numOfLights-1) -> new Light(i, ps.[i], switchPattern.[i])]

    //パターンを総当たりで数える
    let count = cartesian [false; true] numOfSwitches 
                |> List.filter(fun x -> lights |> List.forall(fun y -> y.IsOn x))
                |> List.length
            
    printfn "%d" count

    0 // return an integer exit code


Measured memory_bytes: 16728
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.La;
		Console.WriteLine("{0}",s[0]*s[1]);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27568
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;


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

   vector< vector<int> > arr;
   arr.resize(n+1);
   arr[0].resize(3);
   arr[0][0] = arr[0][1] = arr[0][2] = 0;
   for (int i=1; i<n+1; i++) {
      arr[i].resize(3);
      for (int j=0; j<3; j++) {
         scanf("%d", &arr[i][j]);
      }
   }

   for (int i=1; i<n+1;i++) {
      if( (arr[i][0]-arr[i-1][0]) < abs(arr[i][1]-arr[i-1][1]) + abs(arr[i][2]-arr[i-1][2]) ) {
         printf("No\n");
         return 0;
      } else if ( (arr[i][0]-arr[i-1][0]) % 2 == 0 && (abs(arr[i][1]-arr[i-1][1]) + abs(arr[i][2]-arr[i-1][2])) % 2 != 0 ) {
         printf("No\n");
         return 0;
      } else if ( (arr[i][0]-arr[i-1][0]) % 2 != 0 && (abs(arr[i][1]-arr[i-1][1]) + abs(arr[i][2]-arr[i-1][2])) % 2 == 0 ) {
         printf("No\n");
         return 0;
      }
   }

   printf("Yes\n");

   return 0;
}

Measured memory_bytes: 5760
#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;
    int ans = 0;
    rep(i,50001) {
        if (i * 108 / 100 == n) ans = i;
    }
    if (ans == 0) {
        cout << ":(" << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
vector<int> adj[100001];
int arr[100001];

int bfs(int s) {
	if(adj[s].empty()) return 1;
	for(int child : adj[s]) {
		if(arr[s]<=arr[child]) return  0;
	}
//	cout<<"src is:"<<s<<"\n";
	return 1;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m, a, b;
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>arr[i];
	while(m--) {
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	int res = 0;
	for(int i=1;i<=n;i++) {
		int x = bfs(i);
		res+=x;
	}
	cout<<res;
}



Measured memory_bytes: 9120
def main():
    A, B, M = map(int, input().split(' '))
    a_list = list(map(int, input().split(' ')))
    b_list = list(map(int, input().split(' ')))
    result = min(a_list) + min(b_list)
    for _ in range(M):
        x, y, c = map(int, input().split(' '))
        if result > a_list[x - 1] + b_list[y - 1] - c:
            result = a_list[x - 1] + b_list[y - 1] - c
    print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 18736
#include<bits/stdc++.h>
using namespace std;
 
template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " "<<a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }

 
#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}
#define fr first
#define sc second
 
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
const int INF = 1 << 30;

typedef long long int64;

int main(){
  int N, K;
  cin >> N >> K;
  vector< int > Need(N, -1);
  for(int i = 0; i < K; i++){
    int A, B;
    cin >> A >> B;
    Need[A - 1] = B - 1;
  }
  // dp[i][j][k]: i日目一昨日のパスタj,昨日のパスタk
#define vi vector
  vi < vi < vi < int > > > dp( N, vi < vi < int > >( 3, vi< int >( 3, 0)));
  for(int i = 0; i < 3; i++){
    if(Need[0] == -1 || Need[0] == i){
      for(int j = 0; j < 3; j++){
        if(Need[1] == -1 || Need[1] == j){
          dp[1][i][j] = 1;
        }
      }
    }
  }
  for(int i = 2; i < N; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        if(dp[i - 1][j][k] == 0) continue;
        for(int l = 0; l < 3; l++){
          if(j == k && k == l) continue;
          if(Need[i] == -1 || Need[i] == l){
            (dp[i][k][l] += dp[i - 1][j][k]) %= 10000;
          }
        }
      }
    }
  }
  int ret = 0;
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      (ret += dp[N - 1][i][j]) %= 10000;
    }
  }
  cout << ret << endl;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  string s;
  cin >> s;
  int n = s.size();
  if (s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  } else {
    s[0] = 'a';
  }
  int l, r;
  l = 2;
  r = n - 2;
  if (r < l)
    swap(r, l);
  int cnt = 0;
  for (int i = l; i <= r; i++) {
    if (s[i] == 'C') {
      cnt++;
      s[i] = 'c';
    }
  }
  dump(l, r, cnt);
  if (cnt != 1) {
    cout << "WA" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A' || s[i] == 'C')
      continue;
    if ('a' <= s[i] && s[i] <= 'z')
      continue;
    cout << "WA" << endl;
    return 0;
  }
  cout << "AC" << endl;
  return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;


int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    int s=0;
    rep(i,n){
        cin>>a[i];
        s =s^a[i];
    }
    rep(i,n){
        cout<<(s^a[i])<<endl;
    }
    return 0;
}

Measured memory_bytes: 4052
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
//public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> graph[n+1];
  int a,b;
  for(int i=0;i<m;i++){
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  int ans[n+1];
  for(int i=0;i<n+1;i++) ans[i] = 0;
  ans[0] = -1;
  ans[1] = -1;
  queue<int> q;
  q.push(1);
  while(!q.empty()){
    int now = q.front();
    q.pop();
    for(int i=0;i<graph[now].size();i++){
      int next = graph[now][i];
      if(ans[next] == 0){
        ans[next] = now;
        q.push(next);
      }
    }
  }
  bool flag = true;
  for(int i=0;i<n+1;i++){
    if(ans[i] == 0) flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else{
    cout << "No" << endl;
    return 0;
  }
  for(int i=2;i<n+1;i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 10444
#include <iostream>
#include <vector>

inline void swap(int &a, int &b)
{
	int tmp = a;
	a = b;
	b = tmp;
}
int main()
{
	int a[100], t = 0,count=0;
	std::cin >> t;
	for (int i = 0; i < t; i++)
	{
		std::cin >> a[i];
	}
	int flag = 1;
	while (flag)
	{
		flag = 0;
		for (int i = t - 1; i != 0; i--)
		{
			if (a[i] < a[i - 1])
			{
				swap(a[i], a[i - 1]); count++;
				flag = 1;
			}
		}
	}
	for (int i = 0; i < t; i++)
	{
		if (i) std::cout << " ";
		std::cout << a[i];
	}
	std::cout << std::endl << count << std::endl;

}

Measured memory_bytes: 3092
#import collections
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''
#import copy
#import numpy as np

n, k, s = map(int, input().split())
ans = [s+1 if s != 10**9 else 1 for i in range(n)]
#print(ans)
for i in range(k):
    ans[i]=s
for i in ans:
    print(i)


Measured memory_bytes: 8068
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-9
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	string S;
	scan(N>>K>>S);
	vint A;
	int now=1;
	int ans=0;
	rep(i,N-1){
		if(S[i]==S[i+1]){
			now++;
			ans++;
		}
		else{
			A.push_back(now);
			now=1;
		}
	}
	int twonum=max((int)A.size()-1,0);
	int onenum=min((int)A.size(),2);
	//prin(twonum);
	//prin(onenum);
	ans+=2*min(K,twonum);
	K-=min(K,twonum);
	ans+=min(K,onenum);
	if(ans>=N) ans=N-1;
	prin(ans);
	return 0;
}


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

typedef long long ll;

int h, a;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> h >> a;
    if (h % a) {
        cout << h / a + 1 << endl;
    } else {
        cout << h / a << endl;
    }

    return 0;
}



Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
l2=sorted(l)

l3=[]
for i in range(n):
    l3.append(l[i]-l2[i])

z=l3.count(0)
if n-z==0 or n-z==2:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const ll maxx=1e18;
int n;
ll all=1;
ll ar[200000]; 
int main() {
	scanf("%d",&n);
	rep(i,0,n){
		cin>>ar[i];
		if(ar[i]==0){
			all=0;
			break;
		}	
	}
	rep(i,0,n){
		if(all==0){
			printf("0");
			return 0;
		}else{
			if(maxx/ar[i]<all){
				printf("-1");
				return 0;
			}else{
				all*=ar[i];
			}
		}
	}
	cout<<all; 

} 

Measured memory_bytes: 4524
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
vi link(N),size(N,1);
ll find(ll x)
{
    while(x!=link[x]) x=link[x];
    return x;
}
bool same(ll i,ll j)
    {return find(i)==find(j);}
void unite(ll a,ll b)
{
    a=find(a);
    b=find(b);
    if(size[a]<size[b]) swap(a,b);
    size[a]+=size[b];
    link[b]=a;
}
vi v[N];
ll total[N];
void solve(){
    ll n,a,b;
    cin>>n;
    rep(i,0,n-1){
        cin>>a>>b;
        v[a].pb(b);
        // v[b].pb(a);
    }
    rep(i,1,N-1) link[i]=i;
    rep(i,1,N-1){
        if(v[i].empty()) continue;
        // if(link[v[i][0]]==0) link[v[i][0]]=v[i][0];
        rep(j,1,sz(v[i])-1) if(!same(v[i][0],v[i][j])) unite(v[i][0],v[i][j]);
    }
    // rep(i,1,5) cout<<link[i]<<" ";
    rep(i,1,N-1){
        total[find(i)]++;
    }
    ll ans=0;
    rep(i,1,N-1){
        if(v[i].empty()) continue;
        ans+=total[find(v[i][0])];
    }
    ans-=n;
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 6784
import java.util.*;

public class Main {

    int INF = 1 << 28;
    boolean[][] map;
    int MAX = 21;
    int dx[] = {-1,0,1,0};
    int dy[] = {0,-1,0,1};

    void run() {
       Scanner sc = new Scanner(System.in);
       while(true) {
            int n = sc.nextInt();
            if( n==0 ) break;

            map = new boolean[MAX][MAX];
            for(int i=0;i<n;i++) map[sc.nextInt()][sc.nextInt()] = true;

            int m = sc.nextInt();
            int x = 10, y = 10;
            int cnt = 0;
                for(int i=0;i<m;i++) {
               char c = sc.next().charAt(0);
                int l = sc.nextInt();
                int d;
                if( c == 'W' ) d = 0;
                else if( c == 'N' ) d = 3;
                else if( c == 'E' ) d = 2;
                else d = 1;
                for(int j=0;j<l;j++) {
                   x += dx[d];
                   y += dy[d];
                   if( map[x][y] ) {
                        cnt++;
                        map[x][y] = false;
                   }
                }
             }
           System.out.println( (cnt == n? "Yes": "No") );
        }
    }

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

}
  

Measured memory_bytes: 42024