akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun insertionSort(A: Array<Int>, n: Int, g: Int): Int {
    var cnt = 0
    for (i in g until n) {
        val v = A[i]
        var j = i - g
        while (j >= 0 && A[j] > v) {
            A[j + g] = A[j]
            j = j - g
            cnt++
        }
        A[j + g] = v
    }
    return cnt
}

fun shellSort(A: Array<Int>, n: Int): Int {
    var cnt = 0
    val G = mutableListOf<Int>()
    var g = 1
    while (g <= n) {
        G.add(g)
        g += g * 3
    }
    G.reverse()
    println(G.size)
    println(G.joinToString(" "))
    for (i in 0 until G.size) {
        cnt += insertionSort(A, n, G[i])
    }
    println(cnt)
    A.forEach { println(it) }
    return cnt
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val list = mutableListOf<Int>()
    (1..n).forEach {
        list.add(scanner.nextInt())
    }
    list.toTypedArray()
    shellSort(list.toTypedArray(), n)
}


Measured memory_bytes: 356696
#import<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL i,j,k,m,n,w[100005];
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	for(cin>>n;n--;)
	{
		cin>>k;
		if(k%2<1&&k%3&&k%5)return cout<<"DENIED",0;
	}
	cout<<"APPROVED";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <random>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <complex>
#include <functional>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < int(b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> int(a);)
#define all(v) v.begin(),v.end()
#define trav(x, v) for(auto &x : v)
#define sz(v) int((v).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double ld;

void fail(){
	puts("No");
	exit(0);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<vi> a(3, vi(n));
	trav(v, a) trav(x, v) cin >> x;
	vi perm(n);
	bool sign[2] = {};
	rep(i,0,n){
		int ix = (a[0][i]-1)/3;
		if(a[1][i] != 3*ix+2) fail();
		if(min(a[0][i], a[2][i]) != 3*ix+1
			|| max(a[0][i],a[2][i]) != 3*ix+3) fail();
		sign[i&1] ^= a[0][i] > a[2][i];
		perm[i] = ix;
		if((i+ix)&1) fail();
	}
	int numofcycles[2] = {};
	vector<bool> vis(n);
	rep(i,0,n) if(!vis[i]){
		++numofcycles[i&1];
		int j = i;
		do {
			vis[j] = 1;
			j = perm[j];
		} while(j != i);
	}
	int nn[2] = {n/2+(n&1), n/2};
	if(sign[0] != (nn[1]+numofcycles[1])%2
		|| sign[1] != (nn[0]+numofcycles[0])%2)
		fail();
	puts("Yes");
}

Measured memory_bytes: 1912
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val s = sc.next()
    println(problem126a(n, k, s))
}

fun problem126a(n: Int, k: Int, s: String): String {
    return s.mapIndexed { index, c -> if (index == k - 1) c.toLowerCase() else c }.joinToString("")
}

Measured memory_bytes: 29592
n = gets.to_i
t,a = gets.split(" ").map!{|i| i.to_i}
h = gets.split(" ").map!{|j| j.to_i}
dif = 5000;num = nil
n.times do |u|
  b = t.to_f - 0.006*h[u]
  if (b - a).abs < dif
   dif = (b-a).abs 
   num = u+1
  end
end
puts num 


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> D(110);

  for(int i=0; i<N; i++) cin >> D.at(i);

  vector<int> number(110);
  for(int i=0; i <N; i++) {
    number.at(D.at(i))++;
  }
  
  int count =0;
  for(int i =1; i<=100; i++) {
    if(number.at(i)>0) count++;
  }
 
  cout << count  << endl;
}

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

bitset<4000009> bits;

int main()
{
    int n,a;
    cin>>n;
    bits.reset();
    bits[0]=1;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        bits|=(bits<<a);
    }
    int cnt=0;
    for(int i=0;i<=4000000;i++)
    {
        if(bits[i])cnt++;
    }
    cnt=(cnt+2)/2;
    for(int i=0;i<=4000000;i++)
    {
        if(bits[i])
        {
            cnt--;
            if(cnt==0)
            {
                cout<<i<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H,W;
  cin >> H >> W;
  string S[H];
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0, bombs = 0; j < W; j++, bombs = 0) {
      if (S[i][j] != '#') {
        bombs += i && j && S[i-1][j-1] == '#';
        bombs += i && S[i-1][j] == '#';
        bombs += i && j+1 < W && S[i-1][j+1] == '#';
        bombs += j && S[i][j-1] == '#';
        bombs += j+1 < W && S[i][j+1] == '#';
        bombs += i+1 < H && j && S[i+1][j-1] == '#';
        bombs += i+1 < H && S[i+1][j] == '#';
        bombs += i+1 < H && j+1 < W && S[i+1][j+1] == '#';
        S[i][j] = '0'+bombs;
      }
      cout << S[i][j];
    }
    cout << '\n';
  }
}

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

int main(){
    vector<int> answers(1001,0);
    for(int i=1;i<=1000;i++){
        for(int j=i+1;j<=1000;j++){
            int s=((j+i)*(j-i+1))/2;
            if(s<=1000){
                answers.at(s)+=1;
            }
        }
    }
    int n;
    cin >> n;
    while(n!=0){
        cout << answers.at(n) << endl;
        cin >> n;
    }
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define lld double
#define vi vector<ll>
#define pii pair<int,int>
#define piii pair<pii, ll>
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define ppb pop_back
#define d0(x) cout<<x<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<x<<" "<<y<<"\n"
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define d5(x,y,z,w,s) cout<<x<<" "<<y<<" "<<z<<" "<<w<<" "<<s<<endl
using namespace std;
const ll mod = 1e9+7;


vi nbr[200001];bool isv[200001];vi ch[200001];int N;int H[200001];bool isu[200001];

int ans[200001];

bool dfs1(int x,int h)
{
    if(isv[x])return 0;
    isv[x]=1;H[x]=h;
    for(int j=0;j<nbr[x].size();j++)
    {
        int y = nbr[x][j];
        if(dfs1(y,1-h))
            ch[x].pb(y);
    }
    return 1;
}

void f(int a1,int hh)
{
    int i=1;int j=1;

    while((i<=N)&&(j<=N))
    {
        if((j%3!=a1)||isu[j])
        {
            j++;continue;
        }
        if((H[i]!=hh)||(ans[i]!=-1))
        {
            i++;continue;
        }
        ans[i]=j;isu[j]=1;i++;j++;
    }
}

void f1()
{
    int i=1;int j=1;
    while(i<=N && j<=N)
    {
        if(isu[j])
        {
            j++;continue;
        }
        if(ans[i]!=-1)
        {
            i++;continue;
        }
        ans[i]=j;isu[j];i++;j++;
    }
}
int main()
{
    cin>>N;

    assert(N<=200000);

    for(int i=1;i<N;i++)
    {
        int x,y;cin>>x>>y;
        nbr[x].pb(y);
        nbr[y].pb(x);
    }

    for(int i=1;i<=N;i++)
    {
        isv[i] = 0; ans[i]=-1;
    }

    dfs1(1,0);

    int cnt=0;
    for(int i=1;i<=N;i++)
        if(H[i]==0)cnt++;

    for(int i=1;i<=N;i++)isu[i]=0;

    int tmp = ((2*cnt<=N)?0:1);

    if(tmp==1)
    {
        cnt = N-cnt;
    }

    if(cnt>=(N+2)/3)
    {
        f(1,tmp);
        f(0,tmp);
        f1();
    }
    else
    {
        f(0,tmp);
        f1();
    }

    for(int i=1;i<=N;i++)
        d0(ans[i]);

    d1("");
}

Measured memory_bytes: 33664
MOD = 10 ** 9 + 7
h, w, k = [int(x) for x in input().split()]
dp = [[0] * w for _ in range(h+1)]
dp[0][0] = 1
for i in range(h):
    for b in range(1 << (w-1)):
        ok = True
        for s in range(w-2):
            if b >> s & 1 and b >> (s+1) & 1:
                ok = False
        if ok:            
            for j in range(w):
                if j > 0 and b >> (j-1) & 1:
                    dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % MOD
                elif j+1 < w and b >> j & 1:
                    dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD
                else:
                    dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD

print(dp[h][k-1])

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

int main()
{

	int N;
	string s;

	cin >> N;
	cin >> s;

	int couB = N - count(s.begin(),s.end(),'R');
	int couR = N - couB;

	if(couB < couR){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type, less<int>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e6+10, mod=1e9+7;


int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int x,k;
	cin>>k>>x;
	for(int i=x-k+1;i<=x+k-1;i++) cout<<i<<" ";
}
// check for any potential overflow before submitting



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

int main() {
	ll N,r=0;
	cin >> N;
	vector<ll> d(N+1,1);

	for(int i=2; i<=N; ++i)
		for(int j=i; j<=N; j+=i)
			++d.at(j);

	rep(i,N)
		r += d.at(i+1)*(i+1);
	cout << r << endl;
}

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

int N;
int d[102];

int main()
{
    cin >> N;
    rep(i, N) cin >> d[i];

    int num[102] = {0};

    rep(i, N) num[d[i]]++;

    int res = 0;
    rep(i, 102)
    {
        if (num[i])
            res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#define MOD 1000000007
#define pb push_back
using namespace std;

double dp[303][303][303];
int cnt[4];

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

	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		cnt[x]++;
	}

	for (int c = 0; c <= n; c++) {
		for (int b = 0; b <= n; b++) {
			for (int a = 0; a <= n; a++) {
				if (a + b + c > n || a + b + c == 0) continue;
				dp[a][b][c] += 1.0 * n / (a + b + c);
				if (a) dp[a][b][c] += 1.0 * a / (a + b + c) * dp[a - 1][b][c];
				if (b) dp[a][b][c] += 1.0 * b / (a + b + c) * dp[a + 1][b - 1][c];
				if (c) dp[a][b][c] += 1.0 * c / (a + b + c) * dp[a][b + 1][c - 1];
			}
		}
	}

	cout << fixed << setprecision(12) << dp[cnt[1]][cnt[2]][cnt[3]];

	return 0;
}

Measured memory_bytes: 217344
use std::io::*;
use std::str::FromStr;

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let mut ans: Vec<i32> = (0..s.len()).map(|_| 0).collect();

    let mut count = 0;
    for (i, &x) in s.iter().enumerate() {
        if x == 'R' {
            count += 1;
        } else {
            ans[i] += (count) / 2;
            ans[i - 1] += (count + 1) / 2;
            count = 0;
        }
    }

    let mut count = 0;
    let mut l_index = 0;
    for (i, &x) in s.iter().enumerate() {
        if x == 'L' {
            count += 1;
            l_index = if l_index == 0 { i } else { l_index };
        } else {
            if l_index > 0 {
                ans[l_index] += (count + 1) / 2;
                ans[l_index - 1] += (count) / 2;
                count = 0;
                l_index = 0;
            }
        }
    }
    ans[l_index] += (count + 1) / 2;
    ans[l_index - 1] += (count) / 2;

    for x in ans {
        print!("{} ", x);
    }
    println!("",);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    vector<string> s(n);
    for (auto&& ss : s) {
        cin >> ss;
    }

    int64_t ans = 0;
    for (auto d : irange(0L, n)) {
        bool ok = true;
        for (auto i : irange(0L, n)) {
            for (auto j : irange(0L, n)) {
                if (s[(i + d) % n][j] != s[(j + d) % n][i]) {
                    ok = false;
                    break;
                }
            }
            if (!ok) {
                break;
            }
        }

        if (ok) {
            ans += n;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
  
  int a , b, c;

  scanf("%d %d %d",&a,&b,&c);

  int temp = b;
  b = a;
  a = c;
  c = temp;
  

  printf("%d %d %d",a,b,c);

  return 0;

}

Measured memory_bytes: 128
n,k = map(int, input().split()) 
aa = [0] * n
for i in range(k):
    d = input()
    a = list(map(int, input().split())) 
    for j in range(len(a)):
        b = a[j]
        aa[b-1] = aa[b-1] + 1
bb = 0
for i in range(len(aa)):
    if aa[i] == 0:
        bb = bb + 1
print(bb)

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

int main(){
    vector<int> c(6);
    for(int i = 0; i < 6; i++) cin >> c.at(i);

    vector<int> city(4,0);
    for(int i = 0; i < 6; i++) city.at(c.at(i) - 1)++;

    int count1 = 0, count2 = 0;
    for(int i = 0; i < 4; i++)
    {
        if (city.at(i) == 2) count2++;
        if (city.at(i) == 1) count1++;
    }
    if (count1 == 2 && count2 == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

def cul(n,x):
    l=len(x)
    b=[x[i] for i in range(l)]
    b.pop(n)
    tmp=b[0]
    for i in range(1,l-1):
        tmp=gcd(tmp,b[i])
    return tmp

import sys
p=40
N=int(input())
if p>N: p=N
a=list(map(int,input().split()))

ans=0
for i in range(p):
    s=cul(i,a[:p])
    if s>ans: ans=s

print(ans)

Measured memory_bytes: 14076
#include<iostream>
using namespace std;
void write(int[], int);
int main() {
	int n, a[1010];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 1; i < n; i++) {
		write(a, n);
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v) {
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
	}
	write(a, n);
	return 0;
}

void write(int a[], int n) {
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i != n - 1) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
}

Measured memory_bytes: 1164
sd = input()
t = input()

n = len(sd)
m = len(t)
s = []

# sd を後ろから見ていき、 t の入りそうな場所を探す
for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        # 1文字ずつ順に入りうるか調べ、最後まで入るなら "?" を "a" に置き換えて出力
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")


Measured memory_bytes: 38384
#n=int(input())
n,k=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

trans=[1]
dic={}
bef=1
dic[bef]=0
for i in range(n):
    trans.append(al[bef-1])
    bef=trans[-1]
    if dic.get(bef,-1)>=0:
        st=dic[bef]
        ed=i
        break
    dic[bef]=i+1
pattern=trans[st:ed+1]
until_num=st
if k<st:
    ans=trans[k]
else:
    ans=pattern[(k-st)%(ed-st+1)]
print(ans)


Measured memory_bytes: 39228
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  rep(snip_i, n) cin >> v.at(snip_i);
  sort(v.begin(), v.end());
  double ans = v.at(0);
  rep2(i, 1, n){
    ans = (ans + v.at(i))/2;
  }
  cout << fixed << setprecision(7) << ans << endl;
  return 0;
}

Measured memory_bytes: 3844
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n, m;
    cin >> n >> m;
    vector<ll> p(m);
    vector<string> s(m);

    rep(i,0,m) cin >> p[i] >> s[i];
    rep(i,0,m) --p[i];

    vector<ll> ac(n);
    vector<ll> wa(n);

    ll sum_ac(0), sum_wa(0);
    rep(i,0,m)
    {
        if (ac[p[i]] != 0) continue; 

        if ("AC" == s[i])
            ac[p[i]]++, sum_wa+=wa[p[i]];

        if ("WA" == s[i])
            wa[p[i]]++;
    }

    rep(i,0,n) sum_ac+=ac[i];
    //rep(i,0,n) sum_wa+=wa[i];

    cout << sum_ac << " " << sum_wa << endl;

    return 0;
}


Measured memory_bytes: 8064
from sys import stdin 
n = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
a = sorted(a)
t = 1
c = 0
answer = 0
for i in range(n):
    if a[i] == t:
        c += 1
    else:
        if c > t:
            answer += c-t
        elif c < t:
            answer += c
        c = 1
        t = a[i]
if c > t:
    answer += c-t
elif c < t:
    answer += c
print(answer)

Measured memory_bytes: 14244
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


ll s[100009];
ll t[100009];

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

	int A, B, Q;
	cin >> A >> B >> Q;
	for (int i = 0; i < A; i++) cin >> s[i];
	for (int i = 0; i < B; i++) cin >> t[i];
	

	sort(s, s + A);
	sort(t, t + B);
	queue<ll> ansque;

	for (int i = 0; i < Q; i++) {
		ll pos; cin >> pos;
		int nearestA, nearestB;
		nearestA = int(upper_bound(s, s + A, pos) - s); 
		nearestB = int(upper_bound(t, t + B, pos) - t);
		// cout << nearestA << " " << nearestB << " ";

		ll ans = LLINF;

		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < 2; j++) {
				if (0 <= nearestA - i && nearestA - i < A && 0 <= nearestB - j && nearestB - j < B) {
					ll tmpAns = abs(s[nearestA - i] - t[nearestB - j]) + min(abs(pos - s[nearestA - i]), abs(pos - t[nearestB - j]));
					ans = min(ans, tmpAns);
				}
			}
		}
		ansque.push(ans);
	}
 
	while (!ansque.empty()) {
		cout << ansque.front() << endl;
		ansque.pop();
	}

	return 0;
}

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

int main(){
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++)cin>>s[i];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='#')cout<<'#';
            else{
                int cnt=0;
                for(int x1=-1;x1<=1;x1++){
                    for(int x2=-1;x2<=1;x2++){
                        if(i+x1<0||i+x1>=h||j+x2<0||j+x2>=w)continue;
                        if(s[i+x1][j+x2]=='#')cnt++;
                    }
                }
                cout<<cnt;
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int64_t n,k;
    cin>>n>>k;
    vector<pair<int64_t,int64_t>> p(n);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        p[i]=make_pair(a,b);
    }
    sort(p.begin(),p.end());
    int64_t ans;
    rep(i,n){
        k -= p[i].second;
        //cout<<k<<endl;
        if(k<=0){
            ans = p[i].first;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
using namespace std;
#define LL long long
int n;
char s[10+5];
map<LL,int> mp;
LL ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		sort(s+1,s+11);
		LL val=0;
		for(int j=1;j<=10;j++)
		val=val*26+s[j]-'a';
		ans+=mp[val];
		mp[val]++;
	}
	printf("%lld",ans); 
}

Measured memory_bytes: 6528
p = [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381]
n = gets.to_i
puts p[0..n-1].join("\s")

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cassert>
#include <string>
#include <cstring>
#include <bitset>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int dp [N][2];
vvi g (N);

int add (int a, int b) {
  a += b;
  while (a >= MOD) a -= MOD;
  return a;
}

int mult (int a, int b) {
  i64 res = 1LL * a * b;
  if (res >= MOD) res %= MOD;
  return res;
}

void dfs (int node = 0, int p = -1) {
  i64 res_a = 1, res_b = 1;
  GO (to, g[node]) {
    if (to != p) {
      dfs (to, node);
      res_a = mult (res_a, dp[to][0] + dp[to][1]);
      res_b = mult (res_b, dp[to][0]);
    }
  }
  dp[node][0] = add (dp[node][0], res_a);
  dp[node][1] = add (dp[node][1], res_b);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  F0R (i, n - 1) {
    int st, et;
    cin >> st >> et;
    --st; --et;
    g[st].eb(et);
    g[et].eb(st);
  }
  dfs ();
  cout << add (0, dp[0][0] + dp[0][1]) << '\n';
  return 0;
}


Measured memory_bytes: 13440
package main

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

const mod int64 = 1000003
const size int = 40

func main() {
  f := make([]int64,mod)
  f[0] = 1
  for i:=int64(1);i<mod;i++ { f[i] = (f[i-1]*i)%mod }
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  q := input.NextInt()
  for k:=0;k<q;k++ {
    x,d,n := input.NextInts()
    if x == 0 { fmt.Println(0);continue }
    if d == 0 { fmt.Println(pow(x,n));continue }
    j := ((mod-x)*inv(d))%mod
    if n > j { fmt.Println(0);continue }
    y := (x*inv(d))%mod
    m := (f[y+n-1]*inv(f[y-1]))%mod
    fmt.Println((m*pow(d,n))%mod)
  }
}

func pow(b,n int64) int64 {
  if n == 0 { return 1 }
  if n%2 == 0 {
    h := pow(b,n/2)
    return (h*h)%mod
  }
  return (b*pow(b,n-1))%mod
}
func inv(n int64) int64 {
  if n == 1 { return 1 }
  k := make([]int64,size)
  a,b,u := mod,n,size
  for i:=0;i<size;i++ {
    k[i],a,b = a/b,b,a%b
    if b == 0 { u = i;break }
  }
  var y0,y1 int64 = 1,-k[0]
  for i:=1;i<u;i++ { y0,y1 = y1,y0-k[i]*y1 }
  for y1 < 0 { y1 += mod }
  return y1%mod
}

type Input struct {
  reader *bufio.Reader
}
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  n,_ := strconv.Atoi(i.NextLine())
  return n
}
func(i *Input) NextInts() (int64,int64,int64) {
  s := strings.Split(i.NextLine()," ")
  x,_ := strconv.ParseInt(s[0],10,64)
  y,_ := strconv.ParseInt(s[1],10,64)
  z,_ := strconv.ParseInt(s[2],10,64)
  return x,y,z
}

Measured memory_bytes: 15616
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
#ifdef DEBUG
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; return o; }
#ifdef USE_COUT
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#else
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#endif
template<class T> inline void dump2D(T &d, size_t sizey, size_t sizex) { ostream&o=
#ifdef USE_COUT
  cout;
#else
  cerr;
#endif
  for(size_t i = 0; i < sizey; i++) { for(size_t j = 0; j < sizex; j++) o << d[i][j] << " "; o << endl; }
}
#else
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); return o; }
#define dump(...) (42)
#define dump2D(...) (42)
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
/// }}}--- ///


int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int ok = 1;
  string s; cin >> s;
  if(s[0] != 'A') ok = 0;
  int cnt = 0;
  for(int i = 2; i <= s.size()-2; i++) {
    dump(s[i]);
    if(s[i]=='C')cnt++;
    else if('A'<=s[i]&&s[i]<='Z')ok = 0;
  }
  if('A'<=s[1]&&s[1]<='Z')ok = 0;
  if('A'<=s.back()&&s.back()<='Z')ok = 0;
  if(cnt!=1) ok = 0;
  if(ok) cout << "AC" << endl;
  else cout << "WA" << endl;
  return 0;
}



Measured memory_bytes: 256
D,G = map(int,input().split())
G = G/100
P = []; C = []
for i in range(D):
  p,c = map(int,input().split())
  P.append(p)
  C.append(c/100)
m = 10**3
for k in range(2**D):
  R = list(range(D))[::-1]
  point = G
  prob = 0
  for d in range(D):
    if k%(2**(d+1)) >= 2**d:
      p = P[d]; c = C[d]
      point -= (d+1)*p + c
      prob += p
      R.remove(d)
  for r in R:
    if point > 0:
      p = P[r]
      if point/(r+1) <= p:
        prob += -(-point//(r+1))
        point = 0
      else:
        point -= (r+1)*p + C[r]
        prob += p
  if m >= prob:
    m = prob
print(int(m))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, k;
    cin >> n >> k;
    vint a(n);
    rep(i, n) cin >> a[i];

    ll ok = 1e9, ng = 0;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        bool f = true;
        int c = 0;
        rep(i, n) c += (a[i] + (mid - 1)) / mid - 1;
        if (c <= k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  
  cin >> str;
  int count = 0;
  int length = str.size();
  for (int i = 0 ; i < length ; i++) {
  	if (str[i] == '1'){
      count++;
    }
  }
  
  cout << count << endl;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <numeric>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 1e9;
constexpr int mod = 1000000007;
class mint {
public:
    long long x;
    constexpr mint(long long x=0) : x((x%mod+mod)%mod) {}
    constexpr mint operator-() const {
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    constexpr mint inv() const {
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
};
ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
}

ll sum(ll l, ll r) {
    return (l+r)*(r-l+1)/2;
}

int main() {
    int n, k; cin >> n >> k;
    mint ans;
    for (int i = k; i <= n+1; ++i) {
        ll l = sum(0, i-1), r = sum(n-i+1, n);
        ans += r-l+1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3192
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>

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

int main()
{
	int L;
	scanf("%d",&L);
	int now=1,t=0;
	while(now<=L) now<<=1,t++;
	vector <PP> edge;
	for(int i=0;i+1<t;i++)
	{
		edge.push_back(PP(P(i,i+1),1<<i));
		edge.push_back(PP(P(i,i+1),0));
	}
	int zan=1<<(t-1);
	for(int i=t-2;i>=0;i--)
	{
		if(L>>i&1)
		{
			edge.push_back(PP(P(i,t-1),zan));
			zan+=1<<i;
		}
	}
	printf("%d %d\n",t,edge.size());
	for(int i=0;i<edge.size();i++)
	{
		P p=edge[i].first;
		printf("%d %d %d\n",p.first+1,p.second+1,edge[i].second);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <cassert>
#include <complex>
using namespace std;

long dist[300][300];
long dist2[300][300];

struct edge {
    int f, t;
    long c;
    bool operator <(const edge e) const {
        return c < e.c;
    }
    bool operator >(const edge e) const {
        return c > e.c;
    }
};

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> dist[i][j];
            dist2[i][j] = dist[i][j];
        }
    }
    
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (dist[i][j] != dist2[i][j]) {
                cout << -1 << endl;
                return 0;
            }
        }
    }

    long ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            bool use = true;
            for (int k = 0; k < n; k++) {
                if (k == i || k == j) continue;
                if (dist[i][k] + dist[k][j] == dist[i][j]) use = false;
            }
            if (use) {
                ans += dist[i][j];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[4][15];
char st[7]="SCHD";
char nm[17]=".23456789TJQKA";
int d[20];
char in[4];
pair<int,int>p[10];
int calc(){
	bool flash=true;
	for(int i=0;i<5;i++)for(int j=i+1;j<5;j++)
		if(p[i].second!=p[j].second)flash=false;
	bool st=true;
	for(int i=0;i<4;i++)if(p[i].first+1!=p[i+1].first)st=false;
	bool st2=true;
	for(int i=0;i<4;i++)if(p[i].first!=i+1)st2=false;
	if(p[4].first!=13)st2=false;
	if(st2)st=true;
	if(st&&flash&&p[0].first==9)return d[8];
	if(st&&flash)return d[7];
	if(p[0].first==p[3].first||p[1].first==p[4].first)return d[6];
	if((p[0].first==p[1].first&&p[2].first==p[4].first)||(p[0].first==p[2].first&&p[3].first==p[4].first))return d[5];
	if(flash)return d[4];
	if(st)return d[3];
	if(p[0].first==p[2].first||p[1].first==p[3].first||p[2].first==p[4].first)return d[2];
	if((p[0].first==p[1].first&&p[2].first==p[3].first)||
	(p[0].first==p[1].first&&p[3].first==p[4].first)||
	(p[1].first==p[2].first&&p[3].first==p[4].first))return d[1];
	for(int i=0;i<4;i++)if(p[i].first==p[i+1].first)return d[0];
	return 0;
}
int main(){
	int a;
	bool tc=false;
	while(~scanf("%d",&a)){
		if(tc)printf("\n");
		for(int i=0;i<4;i++)for(int j=0;j<13;j++)
			scanf("%d",&c[i][j]);
		for(int i=0;i<4;i++)c[i][13]=c[i][0];
		for(int i=0;i<9;i++)scanf("%d",d+i);
		while(a--){
			int ks=0;
			for(int i=0;i<5;i++){
				scanf("%s",in);
				for(int j=1;j<=13;j++){
					if(in[0]==nm[j])p[i].first=j;
				}
				for(int j=0;j<4;j++){
					if(in[1]==st[j])p[i].second=j;
				}
				ks+=c[p[i].second][p[i].first];
			//	printf("(%d %d) ",p[i].first,p[i].second);
			}
			std::sort(p,p+5);
			int sc=calc();
			printf("%d\n",ks*sc);
		}
		tc=true;
	//	printf("\n");
	}
}

Measured memory_bytes: 1036
#include <algorithm>
#include <iostream>
#include<queue>
#include<cstring>
using namespace std;
const int inf = 0x3f3f3f3f;
typedef pair<int, int> pii;
int G[1005][1005];
int cost[1005][1005];
int n,m;
int stx, sty, edx, edy;
int op[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};

void show(void){
    for (int i = 1; i <= n;i++){
        for (int j = 1; j <= m;j++){
            if(cost[i][j]==inf)
                cout << "- ";
            else
                cout << cost[i][j] << " ";
        }
        cout << endl;
    }
}


int main(){
    memset(cost, 0x3f, sizeof(cost));
    memset(G, -1, sizeof(G));
    cin >> n >> m >> stx >> sty >> edx >> edy;
    for (int i = 1; i <= n;i++){
        for (int j = 1; j <= m;j++){
            char c;
            cin >> c;
            if(c=='.')
                G[i][j] = 0;
        }
    }

    deque<pii> dq;

    dq.push_front({stx, sty});
    cost[stx][sty] = 0;

    while(!dq.empty()){
        
        pii t = dq.front();
        int cur = cost[t.first][t.second];
        dq.pop_front();

        for (int i = 0; i < 4;i++){
            int tx = t.first + op[i][0];
            int ty = t.second + op[i][1];
            if(!G[tx][ty] && cur<cost[tx][ty]){
                dq.push_front({tx, ty});
                cost[tx][ty] = cur;
            }
        }

        int r1 = max(t.first - 2, 1);
        int r2 = min(t.first + 2, n);
        int c1 = max(t.second - 2, 1);
        int c2 = min(t.second + 2, m);

        for (int i = r1; i <= r2;i++){
            for (int j = c1; j <= c2;j++){
                if(!G[i][j] && cur+1 < cost[i][j]){
                    dq.push_back({i, j});
                    cost[i][j] = cur + 1;
                }
            }
        }         
    }

    //show();
        
    if(cost[edx][edy]!=inf)
        cout << cost[edx][edy] << endl;
    else
        cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 11536
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int a, b, c, d;
   cin >> a >> b >> c >> d;
   int l = max(a, c);
   int r = min(b, d);
   int ans = max(0, r - l);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int i;
    int n;
	int max;
	cin >> n;
	max = n / 4;

	for (i = 0; i <= max; i++) {
		if ((n - i * 4) % 7 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<int> vi;
const int INF = 1LL << 58;
const int MOD = 1000000007;
const int MAX_N = 200100;

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int H, W, K;
    cin >> H >> W >> K;
    int C[11][1001];
    for (int i = 1; i <= H; i++)
    {
        string S;
        cin >> S;
        for (int j = 1; j <= W; j++)
        {
            if (S.at(j - 1) == '0')
                C[i][j] = 0;
            else if (S.at(j - 1) == '1')
                C[i][j] = 1;
        }
    }
    REP(i, H)
    C[i][0] = 0;

    REP(i, W)
    C[0][i] = 0;

    for (int i = 1; i <= H; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            C[i][j] = C[i][j] + C[i - 1][j] + C[i][j - 1] - C[i - 1][j - 1];
        }
    }

    int ans = INF;
    for (int bit = 0; bit < (1 << H - 1); ++bit)
    {
        int tmp[11][1001];
        int idx = 0;
        int befidx = 0;
        REP(i, H - 1)
        {
            if (bit & (1 << i))
            {
                for (int j = 0; j <= W; j++)
                {
                    tmp[idx][j] = C[i + 1][j] - C[befidx][j];
                }
                idx++;
                befidx = i + 1;
            }
        }
        for (int j = 0; j <= W; j++)
            tmp[idx][j] = C[H][j] - C[befidx][j];
        int tmpans = idx;
        int tmpw = 0;
        for (int i = 1; i < W; i++)
        {
            REP(j, idx + 1)
            {
                if (tmp[j][i] - tmp[j][tmpw] > K)
                {
                    if (i - 1 == tmpw)
                    {
                        tmpans += INF;
                    }
                    else
                        tmpans++;
                    tmpw = i - 1;
                    break;
                }
            }
        }
        REP(j, idx + 1)
        {
            if (tmp[j][W] - tmp[j][tmpw] > K)
            {
                if (W - 1 == tmpw)
                {
                    tmpans += INF;
                }
                else
                    tmpans++;
                break;
            }
        }
        ans = min(ans, tmpans);
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n+1);
	REP(i,n){
		cin >> a[i];
	}
	vector<int> ans(n+1,0);
	
	for (int i = n; i >= 1 ; --i) {
		int count = 0;
		for (int j = 1; j*i <= n; ++j) {
			count += ans[j*i];
		}
		if(count % 2 == a[i]){
			ans[i] = 0;
		}else{
			ans[i] = 1;
		}
	}
	
	int hako = 0;
	REP(i,n){
		if(ans[i] == 1) hako++;
	}
	
	cout << hako << endl;
	
	REP(i,n){
		if(ans[i] != 0)
		cout << i << " ";
	}
	cout << endl;
    return 0;
}



Measured memory_bytes: 2432
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 1000005;
const ll MOD = 998244353;

int n,N,tot;
int pr[MAXN];
int mob[MAXN];

ll ans;
ll cnt[MAXN];
ll sum[MAXN];

bool mark[MAXN];

int main()
{
	scanf("%d",&n);
	for (int a,i = 1;i <= n;i++)
	{
		scanf("%d",&a);
		cnt[a]++;
	}
	N = 1000000;
	mob[1] = 1;
	for (int i = 2;i <= N;i++)
	{
		if (!mark[i])
		{
			mob[i] = -1;
			pr[++tot] = i;
		}
		for (int j = 1;j <= tot && i * pr[j] <= N;j++)
		{
			mark[i * pr[j]] = 1;
			if (i % pr[j] == 0)
			{
				mob[i * pr[j]] = 0;
				break;
			}
			mob[i * pr[j]] = -mob[i];
		}
	}
	for (int i = 1;i <= N;i++)
		for (int j = 1;j * i <= N;j++)
			(sum[i] += cnt[i * j] * j) %= MOD;
	for (int i = 1;i <= N;i++)
		(sum[i] *= sum[i]) %= MOD;
	for (int i = 1;i <= N;i++)
		for (int j = 1;j * i <= N;j++)
			(ans += sum[i * j] * i % MOD * mob[j] % MOD * j % MOD * j) %= MOD;
	for (int i = 1;i <= N;i++)
		(ans -= cnt[i] * cnt[i] % MOD * i) %= MOD;
	(ans *= (MOD + 1) / 2) %= MOD;
	for (int i = 1;i <= N;i++)
		(ans += (cnt[i] * (cnt[i] - 1) / 2) % MOD * i) %= MOD;
	printf("%lld\n",(ans + MOD) % MOD);
	return 0;
}

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

using namespace std;

int main()
{
    long long n,k,sum =0;
    cin>>n>>k;
    long long a[n];
    for(long long i=0;i<n;i++)
        cin>>a[i];
    if(k>=n)
        cout<<0;
        else{

	long long z = sizeof(a)/sizeof(a[0]);

    sort(a, a+z);
    for(long long i=0;i<(n-k);i++)
        sum = sum+a[i];
    cout<<sum;
	}


    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  ll n;
  cin >> n;

  ll sum = 0;
  for(ll r = 1; r * r <= n; r++){
    if(n % r != 0) continue;
    ll m = n / r - 1;
    if(m > 0 && (n / m) == (n % m)) sum += m;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    S = list(input())
    ls = len(S)

    rr = [0] * (ls + 1)
    ll = [0] * (ls + 1)

    for i in range(ls):
        if S[i] == '<':
            ll[i+1]=ll[i]+1
    for i in reversed(range(ls)):
        if S[i] == '>':
            rr[i]=rr[i+1]+1


    ans = 0
    for i in range(ls + 1):
        ans += max(ll[i], rr[i])
    print(ans)


resolve()

Measured memory_bytes: 97584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int main()
{
    int h;
    int w;
    cin >> h >> w;

    rep(i,1 ,w + 2)
    {
        cout << '#';
    }
    cout << endl;
    rep(i,1,h)
    {
        string s;
        cout << '#';
        cin >> s;
        cout << s;
        cout << "#" << endl;
    }
    rep(i,1, w + 2)
    {
        cout << '#';
    }
    cout << endl;

}

Measured memory_bytes: 256
a, b = map(int, input().split())
def trans(x):
    if x%2 == 0:
        if x%4 == 0:
            return 0^x
        else:
            return 1^x
    else:         
        if (x+1)%4 == 0:
            return 0
        else:
            return 1
print(trans(a-1)^trans(b)) 

Measured memory_bytes: 3060
/*
Problem :
Algorithm :
Status :
*/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define DEBUG printf("Passing Line %d in Function [%s].\n",__LINE__,__FUNCTION__);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 505;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};

int n,ans;
int dis[MAXN][MAXN],w[MAXN][MAXN];
deque<pii> q;

bool check(int x,int y){
    return x >= 1 && x <= n && y >= 1 && y <= n;
}

void bfs(int x,int y){
    ans += --dis[x][y];
    w[x][y] = 0;
    while(!q.empty())
        q.pop_back();
    q.push_back(make_pair(x,y));
    while(!q.empty()){
        int x = q.front().first;
        int y = q.front().second;
        q.pop_front();
        for(int i = 0;i < 4;i++){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(!check(nx,ny))
                continue;
            if(dis[nx][ny] > dis[x][y] + w[nx][ny]){
                dis[nx][ny] = dis[x][y] + w[nx][ny];
                if(w[nx][ny])
                    q.push_back(make_pair(nx,ny));
                else
                    q.push_front(make_pair(nx,ny));
            }
        }
    }
}

int main(){
    // freopen("data.in","r",stdin);
    // freopen("data.out","w",stdout);
    scanf("%d",&n);
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            dis[i][j] = min(min(i,n - i + 1),min(j,n - j + 1));
            w[i][j] = 1;
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            int pos;
            scanf("%d",&pos);
            int x = (pos - 1) / n + 1;
            int y = (pos - 1) % n + 1;
            bfs(x,y);
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

int main()
{
  double a;
  cin >> a;
  cout << a * 2 * M_PI << endl;
  return 0;
}


Measured memory_bytes: 3788