akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){
    int i, n;
    int m = 100000; 
    
    scanf("%d", &n);
    for(i=1; i<=n; i++) {
        m = (m * 1.05);
        if(m%1000 > 0) {
            m = m/1000 * 1000 + 1000;
        }
    }
    printf("%d\n", m);
    
    return 0;
}



Measured memory_bytes: 2040
N = gets.to_i
A = gets.split(' ').map{|x| x.to_i}
s = 0
for x in A
  s = s + x.abs
end

l = Array.new(N)
r = Array.new(N)

l[0] = false
for i in 0...N-1
  l[i+1] = (A[i] < 0 && !l[i]) || (A[i] > 0 && l[i])? true : false
end

r[N-1] = false
for j in 0...N-1
  i = N - j - 1
  r[i-1] = (A[i] < 0 && !r[i]) || (A[i] > 0 && r[i])? true : false
end

ans = -10000000000000000000
for i in 0...N
  f = l[i] != r[i]? true : false
  if (A[i] < 0 && f == true) || (A[i] > 0 && f == false)
    ans = s
  else
    ans = [ans, s - 2 * A[i].abs].max
  end
end

p ans
  


Measured memory_bytes: 13460
n = int(input())
lis = list(map(int, input().split()))

cnt1 = 0
cnt2 = 0
cnt4 = 0
for i in lis:
    if i % 4 == 0:
        cnt4 += 1
    elif i % 2 == 0:
        cnt2 += 1
    else:
        cnt1 += 1

if cnt1 - cnt4 > 1:
    print("No")
elif cnt1 - cnt4 == 1:
    if cnt2 == 0:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int y, m, d;
  char c1, c2;
  cin >> y >> c1 >> m >> c2 >> d;
  if (m <= 4)
    cout << "Heisei" << endl;
  else
    cout << "TBD" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int d = b - a - 1;
    if(d % 2 == 0)cout << "Borys" << endl;
    else cout << "Alice" << endl;
    
}

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

int main(){
  int n;
  cin >> n;
  int n1=n/1000;
  int n2=n/100-n1*10;
  int n3=n/10-n1*100-n2*10;
  int n4=n-n1*1000-n2*100-n3*10;
  if(n1+n2+n3+n4==7){
    cout << n1 << '+' << n2 << '+' << n3 << '+' << n4 << '=' << 7 << endl;
    return 0;
  }
  if(n1+n2-n3+n4==7){
    cout << n1 << '+' << n2 << '-' << n3 << '+' << n4 << '=' << 7 << endl;
    return 0;
  }
  if(n1+n2+n3-n4==7){
    cout << n1 << '+' << n2 << '+' << n3 << '-' << n4 << '=' << 7 << endl;
    return 0;
  }
  if(n1-n2+n3+n4==7){
    cout << n1 << '-' << n2 << '+' << n3 << '+' << n4 << '=' << 7 << endl;
    return 0;
  }
  if(n1-n2-n3+n4==7){
    cout << n1 << '-' << n2 << '-' << n3 << '+' << n4 << '=' << 7 << endl;
    return 0;
  }
  if(n1+n2-n3-n4==7){
    cout << n1 << '+' << n2 << '-' << n3 << '-' << n4 << '=' << 7 << endl;
    return 0;
  }
  if(n1-n2+n3-n4==7){
    cout << n1 << '-' << n2 << '+' << n3 << '-' << n4 << '=' << 7 << endl;
    return 0;
  }
  if(n1-n2-n3-n4==7){
    cout << n1 << '-' << n2 << '-' << n3 << '-' << n4 << '=' << 7 << endl;
    return 0;
  }
}
  


Measured memory_bytes: 256
n,k = map(int,input().split())

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

mod = 10**9+7
ans = 0
for i in range(n):
  a = 0
  b = 0
  for j in range(n):
    if j < i and ls[j] < ls[i]:
      a += 1
    if  ls[j] < ls[i]:
      b += 1
  a = b-a
  ans += (a+b*k)*k-b*(1+k)*k//2
  
  ans %= mod
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  10000005

void solve()
{
    ll x=7;
    ll k;
    cin>>k;
    rep(i,1,k+10)
    {
        if(x%k==0)
        {
            cout<<i<<endl;
            return;
        }
        x=x*10;
        x%=k;
        x=(x+7)%k;
    }
    cout<<-1<<endl;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

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

using namespace std;


int H, W;
char getElement(vector<string> S, int h, int w){
    if( h >= 0 && h < H && w >= 0 && w < W ){
        return S[h][w];
    } else {
        return '0';
    }
}

int main(int argc, char const *argv[])
{
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++)
    {
        cin >> S[i];
    }

    for(int h = 0; h < H; h++){
        string s = "";
        for(int w = 0; w < W; w++){
            if(S[h][w] == '#') {
                s.append("#");
                continue;
            } else {
                int cnt = 0;
                if(getElement(S,h-1,w) == '#') cnt++;
                if(getElement(S,h-1,w-1) == '#') cnt++;
                if(getElement(S,h-1,w+1) == '#') cnt++;
                if(getElement(S,h,w-1) == '#') cnt++;
                if(getElement(S,h,w+1) == '#') cnt++;
                if(getElement(S,h+1,w) == '#') cnt++;
                if(getElement(S,h+1,w-1) == '#') cnt++;
                if(getElement(S,h+1,w+1) == '#') cnt++;

                s.append(to_string(cnt));
            }
        }
        cout << s << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3700
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n;
	cin >> n;
	vector<int>A(n), B(n);
	rep(i, n)cin >> A[i] >> B[i];
	ll btn = 0;
	for (int i = n - 1; i >= 0; i--) {
		if ((A[i] + btn) % B[i] != 0)btn += ll((B[i] * ceil(double(A[i] + btn) / double(B[i]))) - (A[i]+ btn));
	}
	cout << btn << endl;
	return 0;
}



Measured memory_bytes: 4060
n, k = map(int, input().split())

mod = 1000000007

def pow(x, n):
    ret = 1
    while n > 0:
        if (n & 1) == 1:
            ret = (ret * x) % mod
        x = (x * x) % mod
        n //= 2
    return ret

fac = [1]
inv = [1]
for i in range(n * 2):
    fac.append(fac[-1] * (i + 1) % mod)
    inv.append(pow(fac[-1], mod - 2))

def cmb(n, k):
    if k < 0 or k > n:
        return 0
    return (fac[n] * inv[k] * inv[n - k]) % mod

x = max(0, n - k - 1)
ret = cmb(n * 2 - 1, n - 1)
for i in range(x):
    ret = (ret - cmb(n, i + 1) * cmb(n - 1, i)) % mod
print(ret)



Measured memory_bytes: 118700
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int now = 0, ans = 0;
    rep(i, 0, n){
        if(now + a[i] > x){
            int tmp = (now + a[i]) - x;
            now = a[i] - tmp;
            ans += tmp;
        }else{
            now = a[i];
        }
    }
    o(ans);
}

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  int n;
  int i,j,out;
  int result;
  int judge[1000000];
  for(i=2;i<1000000;i++) judge[i]=-1;
  for(i=2;i<1000000;i++)
    {
      if(judge[i]==0) continue;
      else
	{
	  judge[i]=1;
	  for(j=i+i;j<1000000;j+=i) judge[j]=0;
	}
    }
  while(scanf("%d",&n)!=EOF)
    {
      result=0;
      for(i=2;i<=n;i++) result+=judge[i];
      printf("%d\n",result);
    }
  return 0;
}

Measured memory_bytes: 4504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    multiset<int> cnt;
    cnt.insert(vec.at(0));
    for(int i = 1;i < N;i++) {
        auto itr = cnt.lower_bound(vec.at(i));
        if(itr == cnt.begin()) {
            cnt.insert(vec.at(i));
        }
        else {
            --itr;
            itr = cnt.erase(itr);
            cnt.insert(vec.at(i));
        }
    }
    cout << cnt.size() << endl;
}

Measured memory_bytes: 5376
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      long[] H = new long[n];
      for(int i=0;i<n;i++){   
         H[i]=sc.nextInt();
      }
      Arrays.sort(H); 
      long ans = 0;
      for(int i=0;i<n-k;i++){  
        ans+=H[i];
      }
      System.out.println(ans);
    }
}

Measured memory_bytes: 61964
K = int(input())
arr = list(range(1, 10))
i = 0
while len(arr) < K:
    num = arr[i]
    last = list(filter(lambda x: 0 <= x <= 9, [num%10-1, num%10, num%10+1]))
    arr.extend(num*10 + t for t in last)
    i += 1
# print(arr)
print(arr[K-1])

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

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

    int N;
    cin >> N;
    string S;
    cin >> S;

    int sum = 0;
    for (int i=1; i<N; ++i) {
        vector<int> cnt1(26, 0), cnt2(26, 0);
        // 0..i-1 , i .. N-1
        for (int j=0; j<i; ++j) {
            cnt1[S[j]-'a'] = 1;
        }
        for (int j=i; j<N; ++j) {
            cnt2[S[j]-'a'] = 1;
        }
        int t = 0;
        for (int j=0; j<26; ++j) {
            t += (cnt1[j] > 0 && cnt2[j] > 0) ? 1 : 0;
        }
        sum = max(sum, t);
    }

    cout << sum << endl;

    return 0;
}

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

ans = 0

def main(n):  
    if n >= 10000:
        ans = n-10000+1 + 900 + 9
        if n == 100000:
            ans -= 1
        return ans

    if n>=1000:
        ans = 909
        return ans

    if n >= 100:
        ans = n - 100 + 1 + 9
        return ans

    if n >= 10:
        ans = 9
        return ans

    if n>= 1:
        ans = n
        return ans

print(main(n))

Measured memory_bytes: 3064
#include <stdio.h>
  
int main(void) {
    int k, x;

    scanf("%d%d", &k, &x);

    for (int i = x - k + 1; i <= x + k - 1; i++ ) {
        printf("%s%d", i == x - k + 1 ? "" : " ", i);
    }
    putchar('\n');

    return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
h,w,m = map(int,input().split())
y_dic = defaultdict(int)
x_dic = defaultdict(int)
bom_dic = set()
for _ in range(m):
    y,x = map(int,input().split())
    y_dic[y]+=1
    x_dic[x]+=1
    bom_dic.add((y,x))
y_max = max(y_dic.values())
x_max = max(x_dic.values())
y_max_indexes = [key for key,value in y_dic.items() if value==y_max]
x_max_indexes = [key for key,value in x_dic.items() if value==x_max]
for y_index in y_max_indexes:
    for x_index in x_max_indexes:
        if (y_index,x_index) not in bom_dic:
            print(y_max+x_max)
            exit()
            
print(y_max+x_max-1)

Measured memory_bytes: 186436
#!/usr/bin/env python

ta, tb, tc = map(int, input().split())
k = int(input())

def dfs(s):
    a = ta
    b = tb
    c = tc
    if len(s) == k:
        #print(s)
        for i in range(k):
            if 'A' == s[i]:
                a *= 2
            elif 'B' == s[i]:
                b *= 2
            elif 'C' == s[i]:
                c *= 2
        if c > b > a:
            print('Yes')
            exit(0)
        return
    dfs(s+'A')
    dfs(s+'B')
    dfs(s+'C')

dfs('')

print('No')


Measured memory_bytes: 9200
N = gets.to_i
T,A = gets.split.map(&:to_i)
H = gets.strip.split.map(&:to_i)
a = Array.new
for i in 0..N-1
    a[i] = (T-H[i] * 0.006-A).abs
end
puts a.index(a.min) + 1

Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
typedef long long ll;
using namespace std;
ll intpow(int n,int m){
    if(m==0)return 1;
    return n*intpow(n,m-1);
}
int main(){
    string s;
    cin >> s;
    int cnt0=0;
    int cnt1=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0')cnt0++;
        if(s[i]=='1')cnt1++;
    }
    cout << 2*min(cnt0,cnt1) <<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 1e6 + 9, M = 1e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7;
const ll inf = 1e18;

int ans[N];

int main() {
  fastIO;
#ifdef LOCAL
  freopen("input.in", "rt", stdin);
#endif
  string str;
  cin >> str;
  vector<pair<char, int>> vv;
  char last = '?';
  int cnt = 0;
  for (int i = 0; i < (int)str.size(); ++i) {
    if(last == str[i]) {
      ++cnt;
    } else {
      if(last != '?')
        vv.push_back({last, cnt});
      last = str[i];
      cnt = 1;
    }
  }
  if(cnt > 0)
    vv.push_back({last, cnt});
  for (int i = 1; i < (int)vv.size(); ++i) {
    if(vv[i].first == 'L' && vv[i-1].first == 'R') {
      string str(vv[i-1].second - 1, '0');
      for(auto it: str)
        cout << it << ' ';
      cout << ((vv[i-1].second+1) / 2) + ((vv[i].second) / 2) << ' ';
      cout << ( (vv[i].second + 1) / 2) + (vv[i-1].second / 2) << ' ';
      str =  string(vv[i].second - 1, '0');
      for(auto it: str)
        cout << it << ' ';
      ++i;
    } else {
      string str(vv[i-1].second, '0');
      for(auto it: str)
        cout << it << ' ';
    }
  }
  return 0;
}


Measured memory_bytes: 1480
#include <stdio.h>

int main(int argc, char *args[])
{
	int x[10001]; 
	int c;
	int i;

	for( i=0; i<=10000; i++ ) {
		scanf("%d", &x[i]);

		if( x[i] == 0 ) {
			break;
		}

	}

	for( c=0; c < i; c++ ) {
		printf("Case %d: %d\n", c+1, x[c]);
	}

	return 0;
}

Measured memory_bytes: 636
S = gets.chomp
n = S.size

def f(s, i)
  $ans << s
  return if i <= 0
  a = String.new(s)
  a[i,0] = "+"
  $ans << a
  f(s, i-1)
  f(a, i-1)
end

$ans = []
(n-1).downto(0) do |i|
  f(S, i)
end
puts $ans.uniq.map { |a| eval(a) }.inject(:+)

Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 



int main(){
    int n,q;cin >> n >> q;
    vector<LL> s(n),t(n),x(n),d(q);
    vector<pair<LL,P>> v(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> t[i] >> x[i];
        v[i]=mp(x[i],mp(s[i],t[i]));
    }
    sort(ALL(v));
    for (int i = 0; i < q; i++) {
        cin >> d[i];
    }
    vector<vector<LL>> vp(q+1),vm(q+1);
    for (int i = n-1; i >= 0; i--) {
        int l = lower_bound(ALL(d),v[i].sc.fs-v[i].fs)-d.begin();
        int r = lower_bound(ALL(d),v[i].sc.sc-v[i].fs)-d.begin();
        vp[l].pb(v[i].fs);
        vm[r].pb(v[i].fs);
    }
    multiset<LL> st;
    for (int i = 0; i < q; i++) {
        for (int j = 0; j < vp[i].size(); j++) {
            st.insert(vp[i][j]);
        }
        for (int j = 0; j < vm[i].size(); j++) {
            st.erase(st.find(vm[i][j]));
        }
        if(st.empty()) cout << -1 << endl;
        else cout << *st.begin() << endl;
    }
    return 0;
}


Measured memory_bytes: 40456
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
using namespace std;

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

int main() {
	int n, m, p;
	while(cin >> n >> m >> p, n||m||p) {
		int sum = 0, win = 0;
		rep(i, n) {
			int x;
			cin >> x;
			if(i+1 == m) {
				win = x;
			}
			sum += x;
		}
		if( win == 0 ) cout << 0 << endl;
		else {
			sum = 100 * sum - 100 * sum * p / 100;
			cout << sum / win << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
process.stdin.resume();
process.stdin.setEncoding("utf8");
var lines = [];
var reader = require("readline").createInterface({
	input: process.stdin,
	output: process.stdout
});
reader.on("line", (line) => {
	lines.push(line);
});
reader.on("close", () => {
	var s = lines[0], n=[];
	for(var i=0;i<s.length;i++){
		n.push("x");
	}
	console.log(n.join(""));
});

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) begin(n),end(n)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int x,a,b;
	cin >> x >> a >> b;

	if(a >= b) cout << "delicious" << endl;
	else if(b - a <= x) cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
struct edge{ll u, v ; ll cost; };
int V, E;
int N;
vector<edge> es;
vector<ll> vx, vy;
ll llabs(ll x){
  return x >= 0 ? x : - x;
}
// union - find tree !!!!!!!!!!!!!!!!!!!!!!!!!
vector<int> par; //oya
vector<int> rnk; //ki no hu ka sa

// n要素で初期化
void init(int n){
    par.resize(n);
    rnk.resize(n);
    FOR(i, 0, n){
        //最初は全部が根
        //par mean 親
        par[i] = i;
        rnk[i] = 0;
    }
}

//木の根を求める
int find(int x){
    //根なら根の番号を返す
    if(par[x] == x) return x;
    // 途中経過の親も根にしとく
    else return par[x] = find(par[x]);
}

//xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(rnk[x] < rnk[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(rnk[x] == rnk[y]) rnk[x]++;
    }
    return;
}

bool isSame(int x, int y){
    return find(x) == find(y);
}


bool comp(edge& e1, edge& e2){
  return e1.cost < e2.cost;
}

ll kruskal(){
  sort(es.begin(), es.end(), comp);
  init(V);
  ll res = 0;
  FOR(i,0,E){
    edge e = es[i];
    if(!isSame(e.u, e.v)){
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main(){
  cin >> N;
  vx.resize(N);
  vy.resize(N);
  es.resize(2*(N-1));
  FOR(i,0,N){
    ll x, y;
    cin >> x >> y;
    vx[i] = x;
    vy[i] = y;
  }
  int ind[N];
  FOR(i,0,N){
    ind[i] = i;
  }
  sort(ind, ind + N, [](int i, int j){
    return vx[i] < vx[j];
  });
  FOR(i,0,N-1){
    edge e;
    e.u = ind[i+1];
    e.v = ind[i];
    e.cost = vx[e.u] - vx[e.v];
    es[2 * i] = e;
  }
  sort(ind, ind + N, [](int i, int j){
    return vy[i] < vy[j];
  });
  FOR(i,0,N-1){
    edge e;
    e.u = ind[i+1];
    e.v = ind[i];
    e.cost = vy[e.u] - vy[e.v];
    es[2 * i + 1] = e;
  }
  V = N;
  E = 2 * (N - 1);
  ll ans = kruskal();
  cout << ans << endl;
  return 0;
}

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

using namespace std;
int main() {
  int N;
  int t[100010],x[100010],y[100010];
  cin>>N;
  for(int i=0;i<N;++i) cin>>t[i+1]>>x[i+1]>>y[i+1];
  int T,X,Y;
  t[0]=x[0]=y[0]=0;
  bool f;
  for(int i=0;i<N;i++){
      T=t[i+1]-t[i];
      X=abs(x[i+1]-x[i]);
      Y=abs(y[i+1]-y[i]);
      f=false;
      if(T>=X+Y){
          if((T+X+Y)%2==0){
             f=true;
          }
      }
      if(!f){
          cout<<"No"<<endl;
          return 0;
      }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        String str = new Scanner(System.in).nextLine();
        for(int i = str.length() - 1;i >= 0;i--){
            System.out.print("" + str.charAt(i));
        }
        System.out.println();
    }
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    rep(i, 1000)
    {
        c -= b;
        if (c <= 0)
        {
            OP("Yes");
            return 0;
        }
        a -= d;
        if (a <= 0)
        {
            OP("No");
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3636
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
using namespace std;
string s, t;
set<string> S;
 
void Work()
{
    int lens = s.size();
    int lent = t.size();
    for(int i = 0; i < lens; i++)
    {
        if(s[i] == '?' || s[i] == t[0])
        {
            string tmp = s;              
            for(int j = 0; j < i; j++)
                if(tmp[j] == '?')
                    tmp[j] ='a';    
            bool can = false;
            for(int j = 0; j < lent; j++)    
            {
 
                if(tmp[i+j]!= '?' && tmp[i+j] != t[j])  
                    break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can)
            {
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';//处理匹配后的字符
                S.insert(tmp);  
            }
        }
    }
    if(S.size() == 0) cout << "UNRESTORABLE" << endl;
    else cout << *S.begin() << endl;
}
int main()
{
    cin >> s >> t;
    Work();
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>=13){
    cout<<b<<endl;
  }
  else if(6<=a&&a<=12){
    cout<<b/2<<endl;
  }
  else{
    cout<<0<<endl;
  }
  return(0);
}


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

typedef long long ll;
typedef pair<int, int> ii;

int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    for (double i = 1; i <= 1251; i++)
        if ((int)(i * 0.08) == a && b == (int)(i * 0.1)) {
            printf("%d\n", (int)i);
            return 0;
        }
    printf("-1\n");

    return 0;
}


Measured memory_bytes: 256
/*  ex9_2
    urah  */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
void pop(node **first){
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
}


int main(void){
    char string[MAX_LEN];
    //最初のノードの指す先
    node *first = NULL;
    // 取り除いた回数
    int count = 0;

    scanf("%s", string);

    for (int i=0; i<strlen(string); i++){
        if (first != NULL && first->elem != string[i]){
            pop(&first);
            count += 2;
        } 
        else {
            push(&first, string[i]);
        }
    }

    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 4848
import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def Main():
    n = read_int()
    h = read_int_list()
    maxh = 0
    cur = 0
    for i in h:
        if maxh < cur:
            maxh = cur
        cur = i
        if maxh >= i + 2:
            print('No')
            break
    else:
        print('Yes')

if __name__ == '__main__':
    Main()

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

int main() {
    string gt = "GREATER", ls = "LESS", eq = "EQUAL";
    string a, b; cin >> a >> b;
    if (a.size() == b.size()) {
        if (a[0] < b[0]) cout << ls << endl;
        else if (a[0] > b[0]) cout << gt << endl;
        else cout << eq << endl;
    } else if (a.size() < b.size()) {
        cout << ls << endl;
    } else {
        cout << gt << endl;
    }
}


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

int main(){
  ll mod=1e9+7,ans=1;
  int n;
  int x;
  string s1,s2;
  cin>>n>>s1>>s2;
  if(s1[0]==s2[0]){
    ans=3;
    x=1;
  }
  else{
    ans=6;
    x=2;
  }
  int y=x;
  for(int i=y;i<n;i++){
    if(s1[i]==s2[i]){
      if(x==1){
        ans*=2;
        ans%=mod;
      }
      x=1;
    }
    else{
      if(x==1){
        ans*=2;
        ans%=mod;
      }
      else{
        ans*=3;
        ans%=mod;
      }
      x=2;
      i++;
    }
  }
  cout<<ans<<endl;
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
#define ALL(a)  (a).begin(),(a).end()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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

// constant
// -----------------------------------------------------------------------------
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl

ll factorial(int x) {
    ll res = 1;
    while(x > 1) {
        res = (res * x) % MOD;
        x--;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N, M; cin >> N >> M;
    if (abs(N - M) == 1) {
        cout << (factorial(N) * factorial(M)) % MOD << "\n";
    } else if (N == M) {
        cout << ((factorial(N) * factorial(M)) * 2) % MOD << "\n";
    } else {
        cout << 0 << "\n";
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<complex>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
typedef double D;
const ll inf = 5555555555555555555;
const ll mod = 1000000007;
const D pi = acos(-1);
const D EPS = 1e-10;

ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

ll grid[555][555], mo[4][33], conv[33][33], cou[4];
int main(void) {
  ll c;
  cin >> n >> c;

  rep(i, c) {
	rep(j, c) {
	  cin >> conv[i + 1][j + 1];
	}
  }

  FOR(i,1, n+1) {
	FOR(j,1,n+1) {
	  cin >> grid[i][j];
	  mo[(i + j) % 3][grid[i][j]]++;
	  cou[(i + j) % 3]++;
	}
  }

  ans = inf;

  rep(i, 3) FOR(j, 1, c + 1) FOR(k, 1, c + 1)  FOR(m, 1, c + 1) {
	if (j == k || k == m || m == j) continue;
	tmp = 0;
	FOR(h, 1, c + 1) {
	  if (j == h) continue;
	  tmp += conv[h][j] * mo[0][h];
	}
	FOR(h, 1, c + 1) {
	  if (k == h) continue;
	  tmp += conv[h][k] * mo[1][h];
	}
	FOR(h, 1, c + 1) {
	  if (m == h) continue;
	  tmp += conv[h][m] * mo[2][h];
	}
	ans = min(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
//cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);

struct node{
    int key;
    node *parent,*left,*right;
};

node *root,*NIL;

void insert(int k){
    node *y=NIL;
    node *x=root;
    node *z;

    z=(node*)malloc(sizeof(node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }

    z->parent=y;

    if(y==NIL){
        root=z;
    }else{
        if(z->key<y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}

node *treeminimum(node *x){
    while(x->left!=NIL){
        x=x->left;
    }
    return x;
}

node *find(node *u,int k){
    while(u!=NIL&&u->key!=k){
        if(k<u->key){
            u=u->left;
        }else{
            u=u->right;
        }
    }
    return u;
}

node *treesuccessor(node *x){                       //次節点（入力されたノードの次に中間順巡次に訪れる場所）を求める
    if(x->right!=NIL) return treeminimum(x->right);
    node *y=x->parent;
    while(y!=NIL&&x==y->right){
        x=y;
        y=y->parent;
    }
    return y;
}

void treedelete(node *z){
    node *y;//削除する対象
    node *x;//yの子
    //削除する接点を求める
    if(z->left==NIL||z->right==NIL) y=z;
    else y=treesuccessor(z);
    //yの子を決める
    if(y->left!=NIL){
        x=y->left;
    }else{
        x=y->right;
    }

    if(x!=NIL){
        x->parent=y->parent;
    }

    if(y->parent==NIL){
        root=x;
    }else{
        if(y==y->parent->left){
            y->parent->left=x;
        }else{
            y->parent->right=x;
        }
    }
    if(y!=z){
        z->key=y->key;
    }
    free(y);
}

void preorder(node *u){
    if(u==NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

void inorder(node *u){
    if(u==NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

int main() {
    int n,x;
    string s;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>s;
        if(s=="insert"){
            scanf("%d",&x);
            insert(x);
        }else if(s=="find"){
            scanf("%d",&x);
            node *t=find(root,x);
            if(t!=NIL){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }else if(s=="delete"){
            scanf("%d",&x);
            treedelete(find(root,x));
        }else if(s=="print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    return 0;
}






Measured memory_bytes: 21916
#include "bits/stdc++.h"
#define all(v) (v).begin(), (v).end()
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define int long long
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(),(v).end()
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
	int ans = 1;
	for (; b; b >>= 1, a = a * a % mod)
		if (b & 1)
			ans = ans * a % mod;
	return ans;
}

vector<int> v;
int tr[500000]; int n,k;
void add(int x){
	for(int i=x;i<=v.size();i+=i&-i)tr[i]++;
}
inline int gao(int x){int ans=0;
	for(int i=x;i>0;i-=i&-i)ans+=tr[i];
	return ans;
}
int que(int l,int r){
	return gao(r)-gao(l-1);
}
int a[500000],b[300000];
inline int che(int mid){
	int ans=0;
	rep(i,1,n){
		if(b[i]==0){
			if(mid>=0)ans+=n-1;
		}
		else if(b[i]>0){
			int p=(mid/b[i]);
			if(mid<0 && mid%b[i] != 0 )p--;
			//cout<<i<<" p:"<<p<<endl;
			p=upper_bound(all(v),p)-v.begin();
			ans+=que(1,p);
			if(b[i]*b[i]<=mid)ans--;
		}
		else {
			int p = (mid / b[i]) ;
			if(mid < 0 && mid % b[i] != 0 )p ++ ;
			p=lower_bound(all(v),p)-v.begin()+1;
	//		cout << i << " p:" << p << endl;
			ans += que(p,v.size());
			if(b[i]*b[i]<=mid)ans--;
		}
	//	cout<<i<<" "<<b[i]<<" "<<ans<<endl;
	}
	//cout<<mid<<"----------------"<<ans<<endl;
	return ans/2;

}
signed main()
{
	//cout<<((int)(-1.5));
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,1,n)cin>>a[i],b[i]=a[i],v.pb(a[i]);
	sort(all(v));v.erase(unique(all(v)),v.end());
	//cout<<v.size()<<endl;
	rep(i,1,n)a[i]=lower_bound(all(v),a[i])-v.begin()+1,add(a[i]);
	int L=-1e18,R=1e18; int ans=0;
	//cout<<che(124564)<<endl;
	while(L<=R){
		int mid = L+R>>1;
		//cout<<mid<<" "<<che(mid)<<endl;
		if(che(mid)<k)L=mid+1;
		else ans=mid,R=mid-1;
	}
	cout<<ans<<endl;


	getchar();
	getchar();
}

/*

 4 6

 1  2  3   4 

*/

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

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

  int dummy = n;

  int sum = 0;

  for(int i = 1; dummy != 0; i++){
    sum += dummy % 10;
    dummy /= 10;
  }

  if(n % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;

}


Measured memory_bytes: 256
from collections import Counter

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

AC = Counter(A)
BC = Counter(B)
if N < max((AC + BC).values()):
    print('No')
    exit()

curA = 0
curB = 0
while curA < N:
    a = A[curA]
    if a == B[curA]:
        while a == B[curB] or A[curB] == B[curA]:
            curB += 1
            curB %= N
        B[curA], B[curB] = B[curB], B[curA]
    curA += 1

print('Yes')
print(*B)


Measured memory_bytes: 191316
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

int a[2'000];
int x[2'000], y[2'000];

int main()
{
    int n, z, w;
    cin >> n >> z >> w;
    for (int i = 0; i < n; i++) {
        cin >> a[n - 1 - i];
    }

    for (int i = 0; i < n; i++) {
        if (i == n - 1) {
            x[i] = abs(a[0] - w);
            y[i] = abs(a[0] - z);
        } else {
            x[i] = abs(a[0] - a[i + 1]);
            y[i] = abs(a[0] - a[i + 1]);
        }
        for (int j = 0; j < i; j++) {
            x[i] = max(x[i], y[j]);
            y[i] = min(y[i], x[j]);
        }
    }
    cout << x[n - 1] << endl;
}

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

using namespace std;

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

string s;

bool check(char a, char b) {
  int n = (a - '0') * 10 + (b - '0');

  return (n > 0) && (n < 13);
}
int main(void) {
  cin >> s;

  if (check(s[0],s[1]) && check(s[2],s[3])) {
    printf("AMBIGUOUS\n");
  } else if ((!check(s[0],s[1])) && (!check(s[2],s[3]))) {
    printf("NA\n");
  } else if (check(s[0],s[1])) {
    printf("MMYY\n");
  } else {
    printf("YYMM\n");
  }

  return 0;
}

Measured memory_bytes: 256
import math
a, b, h, m = map(int, input().split())

angle_m = 6 * m
angle_h = 30 * h + 0.5 * m
angle = abs(angle_m - angle_h)
if angle > 180:
  angle = 360 - angle

ans = math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(angle)))
print('{:.20f}'.format(ans))

Measured memory_bytes: 9516
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// 約数列挙：nの約数を昇順に返す。
vector<long long> enumDivisors(long long n){
    vector<long long> ret;
    for(long long i=1; i*i<=n; i++){
        if(n%i == 0){
            ret.push_back(i);
            if(n/i != i) ret.push_back(n/i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main(){
    Init();
    ll n; cin >> n;
    ll allGcd = -1;
    vi a(n);
    rep(i, n){
        cin >> a[i];    
        if(i == 0) allGcd = a[i];
        else allGcd = __gcd(allGcd, a[i]);
    }

    vector<bool> used(1000001, false);
    bool pc = true;
    rep(i, n){
        auto eDiv = enumDivisors(a[i]);
        for(auto &num: eDiv){
            if(num <= 1) continue;
            if(used[num]){
                pc = false;
                break;
            }
            else{
                used[num] = true;
            }
            if(!pc) break;
        }
        if(!pc) break;
    }

    if(pc) cout << "pairwise coprime" << endl;
    else if(!pc && allGcd == 1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}

Measured memory_bytes: 11052
N, M, *xy = map(int, open(0).read().split())
boxes = [1] * N
is_red = [0] * N
is_red[0] = 1

for x, y in zip(*[iter(xy)] * 2):
    x -= 1
    y -= 1
    boxes[x] -= 1
    boxes[y] += 1
    if is_red[x]:
        if boxes[x] == 0:
            is_red[x] = 0
        is_red[y] = 1
print(sum(is_red))


Measured memory_bytes: 31724
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){

  rep(i,5){
    int tmp;
    cin >> tmp;
    if(tmp == 0){
      cout << i+1 << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define flash                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0)
int main()
{

    flash;
    long long n, k, cnt1 = 0, cnt2 = 0, ans = 0, y;
    cin >> n >> k;

    for (int i = 1; i <= n; i++)
    {
        if (i % k == 0)
            cnt1++;
    }

    ans = cnt1 * cnt1 * cnt1;

    if (k % 2 == 0)
    {
        for (int i = 1; i <= n; i++)
        {

            if (i % k == k / 2)
                cnt2++;
        }
    }

    ans += cnt2 * cnt2 * cnt2;

    cout << ans << endl;
    return 0;
}


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

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(void)
{
    int N,K,i,H[1000000];

    long long int sum=0;

    scanf("%d %d",&N,&K);

    for(i=0; i<N; i++){
        scanf("%d",&H[i]);
    }

    qsort(H,N,sizeof(int),compare_int);

    for(i=K; i<N; i++){
        sum += H[i];
    }

    printf("%lld\n",sum);

    return 0;
}

Measured memory_bytes: 3708
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
ll pow1(ll a,int b)
{
    ll res=1;
    while(b)
    {
        if(b%2)
            res=res*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return res;
}
int main()
{
    int n;
    ll ans;
    cin>>n;
    ans=pow1(10,n);
    ans=(((ans-pow1(9,n)+mod)%mod-pow1(9,n)+mod)%mod+pow1(8,n))%mod;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3612
# encoding: utf-8
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
def mysub(a, b): return a - b if a > b else b - a
 
import heapq
 
pq = []
d = [0] * N
prev = [None] * N
 
heapq.heappush(pq, (0, 0))
for i in range(1, N): d[i] = 10 ** 9 + 7
 
while len(pq) > 0:
    Qu, u = heapq.heappop(pq)
    if Qu > d[u]: continue
    for i in range(1, min(K + 1, N - u)):
        v = u + i
        cost = mysub(h[u], h[v])
        if Qu + cost < d[v]:
            d[v] = Qu + cost
            heapq.heappush(pq, (Qu + cost, v))
            prev[v] = u
 
print(d[-1])

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

const int lim = 2000006;

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

    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;

    if(x2-x1==0)
    {
    	cout<<x1-(y2-y1)<<' '<<y2<<' '<<x1-(y2-y1)<<' '<<y1;
    	return 0;
    }
    double d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
    double m = 1.0*(y2-y1)/(x2-x1);
    int e = round(sqrt(d/(1+m*m)));

    int ay3 = round(y2 + e);
    int ax3 = round(x2 - m*(ay3-y2));

    int cross = (x1-x2)*(ay3-y2) - (ax3-x2)*(y1-y2);
    if(cross>0)
    {
    	ax3 = 2*x2 - ax3;
    	ay3 = 2*y2 - ay3;
    }
    cout<<ax3<<' '<<ay3<<' '<<x1+ax3-x2<<' '<<y1+ay3-y2;

    return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
a = [list(map(int,input().split())) for _ in range(h)]
n = 10
for k in range(n):
    for i in range(n):
        for j in range(n):
            c[i][j] = min(c[i][j],c[i][k]+c[k][j])
ans = 0
for i in a:
    for j in i:
        if j!=-1: ans += c[j][1]
print(ans)

Measured memory_bytes: 40412
n = gets.to_i
pn = gets.split().map(&:to_i)

ans = 0
(pn.length-2).times do |i|
  if pn[i]<pn[i+1] && pn[i+1]<pn[i+2]
    ans += 1
  elsif pn[i]>pn[i+1] && pn[i+1]>pn[i+2]
    ans += 1
  end
end

puts ans

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

int main() {
    string s;
    cin >> s;
    for ( int i = 0; i<s.size(); i++) {
        if (s[i-1] == s[i]) {
            cout << "Bad" << '\n';
            return 0;
        }
    }
    cout << "Good" << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<ll> a(n);
    int negative_cnt = 0, zero_cnt = 0;
    ll sum = 0;
    int mine = INF;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        if(a[i] == 0)   ++zero_cnt;
        if(a[i] < 0){
            ++negative_cnt;
            a[i] = abs(a[i]);
        }
        sum += a[i];
        chmin(mine, (int)a[i]);
    }
    if(zero_cnt || negative_cnt % 2 == 0){
        cout << sum << endl;
        return 0;
    }
    cout << sum - 2 * mine << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int dir[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
const int INF = 1e9;

int main() {
    int h, w, k, x1, y1, x2, y2; cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
    --x1, --y1, --x2, --y2;
    char MP[h][w] = {};
    int dis[h][w] = {};
    for (int i = 0; i < h; i++) 
        for (int j = 0; j < w; j++)
            cin >> MP[i][j], dis[i][j] = INF;
    queue<pair<int, int>> que;
    dis[x1][y1] = 0;
    que.push({x1, y1});
    while (!que.empty()) {
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        for (int i = 0; i < 4; i++) {
            int nx = x, ny = y;
            int nd = dis[x][y] + 1;
            for (int j = 1; j <= k; j++) {
                nx += dir[i][0];
                ny += dir[i][1];
                if (nx < 0 or ny < 0 or nx >= h or ny >= w or MP[nx][ny] == '@' or dis[nx][ny] < nd)
                    break;
                if (dis[nx][ny] > nd) {
                    dis[nx][ny] = nd;
                    que.push({nx, ny});
                }
            }
        }
    }
    int ans = dis[x2][y2];
    cout << (ans == INF ? -1 : ans);
}

Measured memory_bytes: 9244
n=int(input())
csf=[list(map(int,input().split())) for _ in range(n-1)]
#n=100000
#csf=[[1,0,1] for _ in range(n-1)]
for i in range(n-1):
    t=0
    for j in range(i,n-1):
        t=max(csf[j][1],t+(-t)%csf[j][2])+csf[j][0]
    print(t)
print(0)

Measured memory_bytes: 3188
import java.util.Scanner;

class Main {
    	public static void main(String[] args) {
        	Scanner sc = new Scanner(System.in);
	        int a = sc.nextInt();
	        int b = sc.nextInt();
	        int c = sc.nextInt();
	         
	        double x = c * Math.PI /180;
	         
	        double y = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(x));
	        double z = b * Math.sin(x);
	        double w = b * Math.sin(x) * a /2;
	         
	        System.out.println(w);
	        System.out.println(y + a + b);
	        System.out.println(z);
    	}
}

Measured memory_bytes: 17176
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
struct atom{
	int c0,c1;
	inline bool operator<(const atom&rhs)const{return 1ll*c1*rhs.c0<1ll*rhs.c1*c0;}
};
set<pair<atom,int>>S;
int g[N],s0[N],s1[N],p[N],v[N],n,i,vv[N],xb,z,rk[N];
long long ans;
vector<int>e[N];
int gfa(int x){return g[x]==x?x:g[x]=gfa(g[x]);}
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
int main(){
	scanf("%d",&n);
	for(i=2;i<=n;++i)scanf("%d",p+i),e[p[i]].push_back(i);
	for(i=1;i<=n;++i)scanf("%d",v+i),g[i]=i,s0[i]=v[i]==0,s1[i]=v[i]==1;
	for(i=2;i<=n;++i)S.insert(make_pair((atom){s0[i],s1[i]},i));
	for(i=2;i<=n;++i){
		int x=S.begin()->second,y=p[x];S.erase(S.begin());g[x]=y;
		rk[x]=i;
		y=gfa(y);
		if(y>1){
			S.erase(make_pair((atom){s0[y],s1[y]},y));
			s0[y]+=s0[x];s1[y]+=s1[x];
			S.insert(make_pair((atom){s0[y],s1[y]},y));
		}
	}
	q.push(make_pair(1,1));
	for(i=1;i<=n;++i){
		int x=q.top().second;q.pop();vv[i]=v[x];
		for(int y:e[x])q.push(make_pair(rk[y],y));
	}
	for(i=1;i<=n;++i)if(vv[i]==0)ans+=z;else ++z;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 29184