akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const int mod=1000000007;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

// int gcd(int a, int b){
//   if (a%b==0){
//     return(b);
//   }
//   else{
//     return(gcd(b,a%b));
//   }
// }


// ll memo[2020][2020];
// int meke_comb(){
//   for(int i = 0; i < 2020; i++){
//     for(int j = 0; j < i+1; j++){
//       if(j == 0 || j == i) memo[i][j] = 1;
//       else{
// 	memo[i][j] = (memo[i-1][j-1]+memo[i-1][j]);
//       }
//     }
//   }
//   return 0;
// }


// int fact(int n){
//   int ans;
//   if(n==1 || n == 0) return 1;
//   ans = n*fact(n-1);
//   return ans;
// }

// int comb(int n, int k){
//   return fact(n) / (fact(n-k)*fact(k));
// }




int main(){
  int N;
  bool f = true;
  cin >> N;
  map<string,int> wmap;
  char c;
  string s;
  rep(i,N){
    cin >> s;
    wmap[s]++;
    if((wmap[s] > 1 || s[0] != c) && i != 0) f = false;
    c = s.at(s.size()-1);
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#define _GLIBCXX_DEBUG
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

using Graph = vector<vector<int>>;
//再帰とかグラフを使うときは予めNの最大値のグローバル配列を取っておく


//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

bool E[2005][2005];
vector<bool> seen;
typedef pair<int, int> P;
typedef tuple<int, int, int> Tu;
//typedef pair<string, int> P;
int D[2005];
//頂点状態を表すcolor[]において、0は未訪問、1は訪問中、2は完了を表す。
int color[101];
int find_time = 0;

queue<long long> Q;

long long lunlun(long long K,long long time) {
    long long now = Q.front();
    Q.pop();
    time++;
    if (time == K) return now;
    if(now%10 != 0)Q.push(now * 10 + now%10 - 1);
    Q.push(now * 10 + now % 10);
    if(now%10 != 9)Q.push(now * 10 + now%10 + 1);
    //cout << now << endl;
    lunlun(K, time);
}

int main() {
    long long K; cin >> K;
    for (int i = 1; i <= 9; i++) Q.push(i);
    long long ans = lunlun(K, 0);
    cout << ans << endl;

}


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

using ll=long long;
using P=pair<int, int>;
const ll INF=1LL<<60;
const ll MOD=1e9+7;

int main(){
    while(1){
        int R, C; cin >> R >> C;
        if(R==0 && C==0) break;
        vector<vector<int>> data(R, vector<int>(C));
        for(int i=0; i<R; i++){
            for(int j=0; j<C; j++){
                cin >> data[i][j];
            }
        }
        int res=0;
        for(int bits=0; bits<(1<<R); bits++){
            int sum=0;
            vector<vector<int>> change=data;
            for(int i=0; i<R; i++){
                if(bits & (1<<i)){
                    for(int j=0; j<C; j++){
                        change[i][j]=!change[i][j];
                    }
                }
            }
            for(int i=0; i<C; i++){
                int cnt0=0, cnt1=0;
                for(int j=0; j<R; j++){
                    if(change[j][i] == 0) cnt0++;
                    else cnt1++;
                }
                sum+=max(cnt0, cnt1);
            }
            res=max(res, sum);
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3564
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(n)]

ans = 0
for i in range(n):
    count = c
    for j in range(m):
        count += b[j]*a[i][j]
    if count > 0 :
        ans += 1

print(ans)


Measured memory_bytes: 9096
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] g = new int[n];
        for (int i = 0; i < m; i++) {
            int l = sc.nextInt()-1;
            int r = sc.nextInt()-1;
            g[l]++;
            if(r < n-1) g[r+1]--;
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if(0 < i) g[i] += g[i-1];
            if(g[i] == m) ans++;
        }
        System.out.println(ans);
        sc.close();

    }

}


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

const int maxn = 3e3;
int n, mod, C[maxn + 3][maxn + 3], S[maxn + 3][maxn + 3];

inline int func(int x) {
	return x < mod ? x : x - mod;
}

int qpow(int a, int b, int m = mod) {
	int c = 1;
	for (; b; b >>= 1, a = 1ll * a * a % m) {
		if (b & 1) c = 1ll * a * c % m;
	}
	return c;
}

void prework(int n) {
	for (int i = 0; i <= n; i++) {
		C[i][0] = C[i][i] = 1;
		for (int j = 1; j < i; j++) {
			C[i][j] = func(C[i - 1][j - 1] + C[i - 1][j]);
		}
	}
	for (int i = 0; i <= n; i++) {
		S[i][0] = 0, S[i][i] = 1;
		for (int j = 1; j < i; j++) {
			S[i][j] = (1ll * S[i - 1][j] * j + S[i - 1][j - 1]) % mod;
		}
	}
}

int main() {
	scanf("%d %d", &n, &mod);
	prework(n + 1);
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		int x = i & 1 ? mod - C[n][i] : C[n][i], s = 0;
		x = 1ll * x * qpow(2, qpow(2, n - i, mod - 1)) % mod;
		for (int j = 0; j <= i; j++) {
			int y = qpow(2, (n - i) * j);
			y = 1ll * y * S[i + 1][j + 1] % mod;
			s = func(s + y);
		}
		ans = (ans + 1ll * x * s) % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 69376
#include<iostream>

using namespace std;

int gcd(int, int);

int main() {
	int n;
	cin >> n;
	long long sum = 0;
	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= n;j++) {
			for (int k = 1;k <= n;k++) {
				sum += gcd(gcd(i, j), k);
			}
		}
	}
	cout << sum << "\n";
	return 0;
}

int gcd(int a, int b) {
	int work;
	if (b > a) {
		work = a;
		a = b;
		b = work;
	}
	while (a % b != 0) {
		work = a % b;
		a = b;
		b = work;
	}
	return b;
}

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

int main(){
    int n; cin >> n;
    vector<int> v(n);
    for( int i = 0 ; i < n; ++i ) cin >> v[i];
    if( n < 3 ) cout << 0 << endl;
    else {
        sort( v.begin() , v.end() );
        int ans = 0;
        for( int i = 0 ; i + 2 < n ; ++i ){
            for( int j = i + 1 ; j + 1 < n ; ++j ){
                for( int k = j + 1 ; k < n ; ++k ){
                    if( v[i] == v[j] || v[i] == v[k] || v[j] == v[k] ) continue;
                    if( v[i] + v[j] > v[k] ) ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
class Dictionary:
    def __init__(self, data={}):
        self.data = data
    def insert(self, x):
        self.data[x] = 0
    def find(self, x):
        if x in self.data:
            return 'yes'
        else:
            return 'no'
n = int(input())
d = Dictionary()
s = [list(input().split()) for i in range(n)]
for i in s:
    if i[0] == 'insert':
        d.insert(i[1])
    else:
        print(d.find(i[1]))


Measured memory_bytes: 248116
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void solve(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll sm = 0;
  forn(i, n) cin >> a[i], sm += a[i];
  ll ans = sm;
  ll cur = 0;
  forn(i, n){
    cur += a[i];
    sm -= a[i];
    setmin(ans, abs(cur - sm));
  }
  cout << ans;

}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

k (k-1) (k-1)

2 6 3
4 6 5
6 6 7
7 7 7

*/

Measured memory_bytes: 4836
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
b = [v-k for k,v in enumerate(a)]
c = Counter(b[1:])
now = 0
ans = 0
for i in b[:-1]:
  search = now - i
  if search in c:
    ans += c[search]
  c[i] -= 1
  now -= 2
print(ans)

Measured memory_bytes: 133192
a  = int(input())
b = int(input())
c = int(input())
x = int(input()) 
ans = 0 
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if x == i*500 + j*100 + k*50 :
                ans+=1
print(ans)

Measured memory_bytes: 9172
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll D[200010], T[200010];
    cin >> N;
    rep(i,0,N) cin >> D[i];
    cin >> M;
    rep(i,0,M) cin >> T[i];
    map<ll,ll> dd, tt;
    rep(i,0,N) dd[D[i]]++;
    rep(i,0,M) tt[T[i]]++;
    for(auto &e: tt){
        if(e.second > dd[e.first]){
            print("NO");
            return 0;
        }
    }
    print("YES");

}

Measured memory_bytes: 28416
def main():
    S = input()
    if S == 1:
        return 1
    dp_1 = [0] * len(S)
    dp_2 = [0] * len(S)
    if S[0] != S[1]:
        dp_1[1] = 2
    dp_1[0] = 1
    dp_2[1] = 1
    for i, v in enumerate(S):
        if i < 2:
            continue
        dp_1[i] = dp_2[i-1] + 1
        if v != S[i-1]:
            dp_1[i] = max(dp_1[i], dp_1[i-1] + 1)
        dp_2[i] = dp_1[i-2] + 1
        if i >= 4 and S[i-1:i+1] != S[i-3:i-1]:
            dp_2[i] = max(dp_2[i], dp_2[i-2] + 1)
    return max(dp_1[-1], dp_2[-1])
print(main())


Measured memory_bytes: 45916
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define maxn 100001
#define pb push_back
using namespace std;
void solve(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    int dp[n+1];
    dp[0]=0,dp[1]=0,dp[2]=(abs(a[1]-a[0]));
    for(int i=3;i<=n;i++)
    dp[i]=min(dp[i-1]+(abs(a[i-2]-a[i-1])),dp[i-2]+(abs(a[i-1]-a[i-3])));
    cout<<dp[n];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 4396
n,c = map(int,input().split())

dll = []
for _ in range(c):
    dl = list(map(int,input().split()))
    dll.append(dl)

cll = []
for _ in range(n):
    cl = list(map(int,input().split()))
    cll.append(cl)


d_sum = [[0 for i in range(c)] for j in range(3)]

for i in range(c):
    for j in range(n):
        for k in range(n):
            d_sum[(j+k) % 3][i] += dll[cll[j][k]-1][i]

import itertools
c_set = [i for i in range(c)]
c_list = list(itertools.permutations(c_set, 3)) 

ans = float("inf")  
for c1, c2, c3 in c_list:
    tmp = d_sum[0][c1] + d_sum[1][c2] + d_sum[2][c3]
    if ans > tmp:
        ans = tmp

print(ans)

Measured memory_bytes: 46428
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define endl "\n"
#define ar array
#define deb(x) cout << #x << " = " << x << endl
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll N = 2e5 + 1;

template <class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
inline ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
struct comp
{
    bool operator()(const pair<ll, ll> &x, const pair<ll, ll> &y) const
    {
        return x.first < y.first;
    }
};
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll pwr(ll x, ll n)
{
    if (n == 0)
        return 1;
    if (n & 1)
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    else
        return pwr(mul(x, x), n / 2);
}
ll modInv(ll n)
{
    return pwr(n, mod - 2);
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}
int main()
{
    IOS;
    int t = 1;
    //  cin >> t;
    while (t--)
    {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        ll ans = a * c;
        ans = max(ans, b * c);
        ans = max(ans, b * d);
        ans = max(ans, a * d);
        cout << ans << endl;
    }
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  // 数字ごとの件数
  map<int, int> mp;
  rep(i, n) {
    int aa = a.at(i);
    mp[aa]++;
  }
  vector<P> c;
  for (auto mpp : mp) {
    c.emplace_back(mpp.second, mpp.first);
  }
  sort(c.begin(), c.end());
  int res = 0;
  int cnt = c.size();
  int i = 0;
  while (cnt > k && i < c.size()) {
    cnt--;
    res += c.at(i).first;
    i++;
  }
  cout << res << endl;
  return 0;
}


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

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

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

    if x == y:
      return

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

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

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

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

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

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

  def num_members(self,x):
    return abs(self.parents[self.find(x)])

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

N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
  a,b = map(int, input().split())
  uf.union(a-1,b-1)
ans = uf.roots()
print(ans)



Measured memory_bytes: 88016
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int T = sc.nextInt();
        int A = sc.nextInt();
        int[] H = new int[N];
        double[] t = new double[N];
        double min = 1000;
        int ans = 0;

        for(int i=0; i<N; i++){
            t[i] = T - sc.nextInt() * 0.006;
            min = Math.min(min, Math.abs(A - t[i]));
            if(min==Math.abs(A-t[i])){
                ans = i + 1;
            }
        }
        System.out.println(ans);
    }
}

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

int main(){
    int N, M, cnt=0;
    cin >> N >> M;
    int a[M][2];
    queue<int> q;
    for(int i=0; i<M; i++){
        cin >> a[i][0] >> a[i][1];
    }
    for(int i=0; i<M; i++){
        int visit[N+1] = {};
        int path[N+1][N+1] = {};
        visit[1]++;
        q.push(1);
        for(int j=0; j<M; j++){
            if(j != i){
                path[a[j][0]][a[j][1]]++;
                path[a[j][1]][a[j][0]]++;
            }
        }

        while(!q.empty()){
            int tmp = q.front();
            q.pop();
            for(int j=1; j<=N; j++){
                if(path[tmp][j] == 0) continue;

                if(visit[j] == 0){
                    visit[j]++;
                    q.push(j);
                }
            }
        }

        for(int j=1; j<=N; j++){
            if(visit[j] == 0){
                cnt++;
                break;
            }
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;

class Program {

    static void Main (string[] args) {
        string[] str = Console.ReadLine ().Split (' ');
        int N = int.Parse (str[0]);
        long K = long.Parse (str[1]);
        string[] str2 = Console.ReadLine ().Split (' ');
        int[] list = new int[N];
        long[] lastwhen = new long[N];
        for (int i = 0; i < N; i++) {
            list[i] = int.Parse (str2[i]) - 1;
            lastwhen[i] = -1;
        }
        lastwhen[0] = 0;

        long now = 0;
        int nowplace = 0;

        while (now < K) {
            now++;
            nowplace = list[nowplace];
            if (lastwhen[nowplace] == -1) {
                lastwhen[nowplace] = now;
            } else {
                long leftover = (K - now) % (now - lastwhen[nowplace]);
                while (leftover > 0) {
                    nowplace = list[nowplace];
                    leftover--;
                }
                break;
            }
        }

        Console.WriteLine (nowplace + 1);
    }
}
//dotnet run --project test

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

int main(){
    int i;
    int cache=0;
    int x1,x2,x3,x4,x5;
    int arr[5];
    scanf("%d",&x1);
    scanf("%d",&x2);
    scanf("%d",&x3);
    scanf("%d",&x4);
    scanf("%d",&x5);

    arr[0] = x1;
    arr[1] = x2;
    arr[2] = x3;
    arr[3] = x4;
    arr[4] = x5;

    for(i=0;i<5;i++){
        if(arr[i]== 0){
            cache = i+1;
            break;
        }
    }
    printf("%d",cache);
    return 0;
}


Measured memory_bytes: 1732
//bcw0x1bd2 {{{
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define SZ(x) ((int)((x).size()))
#define ALL(x) begin(x),end(x)
#define REP(i,x) for (int i=0; i<(x); i++)
#define REP1(i,a,b) for (int i=(a); i<=(b); i++)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;

#ifdef DARKHH
#define FILEIO(name)
#else
#define FILEIO(name) \
  freopen(name".in", "r", stdin); \
  freopen(name".out", "w", stdout);
#endif

#ifdef DARKHH
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
  int c=0;
  while ( *s!=',' || c!=0 ) {
    if ( *s=='(' || *s=='[' || *s=='{' ) c++;
    if ( *s==')' || *s==']' || *s=='}' ) c--;
    cerr<<*s++;
  }
  cerr<<"="<<head<<", ";
  _dump(s+1,tail...);
}

#define dump(...) do { \
  fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
  _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
  s<<"[";
  for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
  s<<"]";
  return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif
// }}}
// Let's Fight! ~OAO~~

const int MXN = 100005;
const int MOD = 1000000007;

int N,ip[MXN];
int cnt[MXN],x[MXN];
int dp[MXN];

int main() {
  IOS;
  
  int cur = 1;
  int cc = 1;
  cin>>N;
  REP1(i,1,N) {
    cin>>ip[i];
    if (ip[i] >= cur) {
      cnt[cc]++;
      cur += 2;
    } else {
      cnt[cc]++;
      cc++;
    }
  }

  dp[N] = 1;
  cur = 0;
  REP1(i,1,N) {
    cur += cnt[i];
    x[i] = cur;
    cur--;
  }
  for (int i=N-1; i>=1; i--) {
    dp[i] = 1LL * dp[i+1] * x[i] % MOD;
  }
  cout<<dp[1]<<endl;

  return 0;
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;

        vllvll v(10, vll(10));
        rep(i, 1, N+1) {
                string x = to_string(i);
                ll head = x.front() - '0';
                ll tail = x.back() - '0';
                v[head][tail]++;
        }

        ll ans = 0;
        rep(i, 0, 10) {
                rep(j, 0, 10) {
                        ans += v[i][j] * v[j][i];
                }
        }

        cout << ans << endl;
}

Measured memory_bytes: 3696
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    bool b = false;
    for (int k = 0; k < 3; ++k) {
        if (N % 10 == 7) {
            b = true;
        }
        N /= 10;
    }
    if (b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N = int(input())
    A = list(map(int, input().split()))
    # print(A)
    ans = 1000
    kabu = 0
    for i in range(N-1):
        if A[i] < A[i+1]:
            kabu += ans//A[i]
            ans = ans % A[i]
        else:
            ans += kabu * A[i]
            kabu = 0
    
    print(ans+kabu*A[N-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 9480
n = int(input())
d = {}
s = 0
for i in range(n):
    a, b = map(int, input().split())
    if b not in d:
        d.update({b:a})
    else:
        d[b] += a
    s += a
key = list(d.keys())
key.sort(reverse = True)
ans = True
for k in key:
    if k < s:
        ans = False
        break
    s -= d[k]
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 110408
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(a) (a).begin(),(a).end()
#define PI 3.141592653589793238
#define INF 1050000000
#define INFL (long long)(4e18)

using vi = vector<int>;

template<class T>
struct Edge {
    int to;
    T cost;
    Edge() {};
    Edge(int to, T cost) : to(to), cost(cost) {};
};

template<class T>
class Graph {
    int n;
    bool directed;
    vector<vector<Edge<T>>> edges;
public:

    Graph(int n, bool directed) :n(n), directed(directed), edges(vector<vector<Edge<T>>>(n)){};
    Graph() {};

    void add(int from,int to, T cost) {
        edges[from].emplace_back(to, cost);
        if(!directed){
            edges[to].emplace_back(from,cost);
        }
    }

    int size() {
        return n;
    }
};


int main() {

    long long X;

    cin >> X;

    int ans = 0;

    long long int N = 100;

    while(N<X){
        N=floor(N*1.01);
        ans++;
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main() {
  int n, m; cin >> n >> m;
  vector<vector<char>> a(n, vector<char>(n)), b(m, vector<char>(m));

  REP(y, n)REP(x, n) cin >> a[y][x];
  REP(y, m)REP(x, m) cin >> b[y][x];

  REP(i, n-m+1)REP(j, n-m+1){
    bool f = true;
    REP(y, m)REP(x, m) f &= a[i + y][j + x] == b[y][x];
    if(f){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

//dp[i][j][k],i番目の高さで,左からj列目、k：見ている箇所の左側に橋がかかっている。
lli dp[110][10];

signed main(){

	lli h,w,k;
	cin>>h>>w>>k;
	dp[0][0]=1;

	REP(i,1,h+1){
		REP(bit,0,(1LL)<<(w-1)){
			if(DEBUG)cout<<"bit="<<bit<<endl;
			
			//cout<<endl;
			bool ok=false;
			REP(j,0,w){
				//cout<<(bit&(1LL<<j))<<" ";
				if(bit&(1LL<<j) && bit&(1LL<<(j+1))){
					ok=true;
					break;
				}
			}
			if(ok)continue;
			REP(j,0,w+1){
				bool flag=false;
				if(bit&(1LL<<j)){
					dp[i][j+1] += dp[i-1][j];
					dp[i][j]   += dp[i-1][j+1];
					flag=true;
				}
				else{
					dp[i][j] += dp[i-1][j];
				}

				dp[i][j]%=MOD;
				dp[i][j+1]%=MOD;
				if(flag)j++;
			}
		}
	}

	if(DEBUG){
		cout<<"show"<<endl;
		REP(i,0,h+1){
			REP(j,0,w){
				cout<<dp[i][j]%MOD<<" ";
			}
			cout<<endl;
		}
	}

	cout<<dp[h][k-1]%MOD<<endl;

	return 0;
 
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 200111;
int n;
int a[maxn];
unordered_map<int,int> mp;
int st[maxn], stn;
bool check(int B)
{
	mp.clear();
	for (int i=2; i<=n; i++)
	{
		if (a[i]<=a[i-1])
		{
			while (stn>0&&st[stn-1]>a[i])
			{
				stn--;
				mp[st[stn]] = 0;
			}
			if (stn==0||st[stn-1]!=a[i])
			{
				st[stn++] = a[i];
			}
			int x = a[i];
			mp[x]++;
			if (B<=1) return false;
			while (mp[x]>=B) mp[x]=0, mp[--x]++;
			if (x<=0) return false;
		}
	}
	return true;
}
int main()
{
	geti(n);
	for (int i=1; i<=n; i++)
	{
		geti(a[i]);
	}
	int l = 1, r= n;
	while (l<=r)
	{
		int mid = l+r>>1;
		if (check(mid)) r = mid-1;
		else l = mid+1;
	}
	cout<<l<<endl;
	return 0;
}


Measured memory_bytes: 9032
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
ll pow10(ll x){
    ll res=1;
    REP(i,x){
        res*=10;
    }
    return res;
}
int f(ll x){
    int res=0;
    while(x){
        res+=x%10;
        x/=10;
    }
    return res;
}
double calc(ll x){
    return (double)x/f(x);
}
int main(){
    int n;
    cin>>n;
    vl vec;
    REPR(i,15){
        REPR(j,999){
            if(!j){
                continue;
            }
            ll p=j*pow10(i)-1;
            vec.pb(p);
        }
    }
    sort(all(vec));
    vec.erase(unique(all(vec)),vec.end());
    set<ll> se;
    double mi=1e18;
    REPR(i,vec.size()-1){
        if(mi>=calc(vec[i])){
            mi=calc(vec[i]);
            se.insert(vec[i]);
        }
    }
    for(auto itr:se){
        if(!n){
            break;
        }
        n--;
        cout<<itr<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
 
const int MAX = 1000000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int64_t N, K, Max = 0, Min = 0, ans;
    cin >> N >> K;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(ALL(A));
    if (K == 1) {
        cout << 0 << endl;
        return 0;
    }
    else if (K == N) {
        cout << A.at(N - 1) - A.at(0) << endl;
        return 0;
    }
    sort(ALL(A));
    COMinit();
    for (int i = K - 1; i < N; i++){
        Max = (Max + (COM(i, K - 1) * A.at(i)) % 1000000007) % 1000000007;
    }
    reverse(ALL(A));
    for (int i = K - 1; i < N; i++){
        Min = (Min + (COM(i, K - 1) * A.at(i)) % 1000000007) % 1000000007;
    }
    ans = (Max - Min) % 1000000007;
    while(ans < 0) {
        ans += 1000000007;
    }
    cout << ans << endl;
}



Measured memory_bytes: 24448
<?php
list($N, $K) = explode(" ", trim(fgets(STDIN)));

$count = [];
While ($str = trim(fgets(STDIN))) {
    list($a, $b) = explode(" ", $str);

    $count[$a] = isset($count[$a]) ? $count[$a] + $b : $b;
}

ksort($count);

$sum = 0;
foreach ($count as $key => $val) {
    $sum += $val;
    if ($K <= $sum) {
        echo $key;
        break;
    }
}

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

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int L,R,d;
  cin>>L>>R>>d;
  if(L%d==0 && R%d==0)
   cout<<(R/d)-(L/d)+1;
  else
   cout<<(R/d)-(L/d);
  
  return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int BinaryToNo(char s[])
{
	int ans;
	
	ans = (s[0] - '0') * 16 + (s[1] - '0') * 8 + (s[2] - '0') * 4 + (s[3] - '0') * 2 + (s[4] - '0');
	
	return (ans);
}

int main(void)
{
	char str[1000];
	char code1[32][12] = {
		"101", "000000", "000011", "10010001", "010001", "000001", "100101", "10011010",
		"0101", "0001", "110", "01001", "10011011", "010000", "0111", "10011000",
		"0110", "00100", "10011001", "10011110", "00101", "111", "10011111", "1000",
		"00110", "00111", "10011100", "10011101", "000010", "10010010", "10010011", "10010000"
	};
	char code2[32] = {
		'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
		'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
		'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
		'Y', 'Z', ' ', '.', ',', '-', 39, '?'
	};
	int i;
	int code;
	char str2[1000];
	char *p;
	
	
	while (fgets(str, 1000, stdin) != NULL){
		str2[0] = '\0';
		str[strlen(str) - 1] = '\0';
		for (i = 0; i < strlen(str); i++){
			switch (str[i]){
			  case ' ':
			  	code = 0;
				break;
				
			  case 39:
			  	code = 1;
				break;
				
			  case ',':
			  	code = 2;
				break;
				
			  case '-':
			  	code = 3;
				break;
				
			  case '.':
			  	code = 4;
				break;
				
			  case '?':
			  	code = 5;
				break;
				
			  default:
			  	code = str[i] - 'A' + 6;
				break;
			}
			strcat(str2, code1[code]);
		}
		
		if (strlen(str2) % 5 != 0){
			for (i = 0; i < strlen(str2) % 5; i++){
				strcat(str2, "0");
			}
		}
		
		
		p = str2;
		while (*p != '\0'){
			printf("%c", code2[BinaryToNo(p)]);
			
			p += 5;
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 520
#include <stdio.h>

int main(void)
{
  long long int n,k,length = 0,notloop = 0,now = 1,dupl = -1,l_c = 1;

  scanf("%lld %lld",&n,&k);

  long long int a[n],l[n];
  int c[n];
  
  for(long long int i=0; i<n; i++){
    scanf("%lld",&a[i]);
    c[i] = -1;
  }
  c[0] = 0;
  l[0] = 1;
  
  for(long long int i=0; i<k; i++){
    now = a[now - 1];
    c[now - 1]++;
    l[l_c] = -1;
    if(c[now - 1] == 1){
      dupl = now;
      break;
    }
    else
      l[l_c++] = now;
  }
  if(dupl == -1)
    printf("%lld\n",now);
  else{
    for(long long int i=0; i<n; i++){
      if(l[i] == dupl)
        notloop = i;
      if(l[i] == -1){
        length = i - notloop;
        break;
      }
    }
    if(length == 0)
      length = n - notloop;
    printf("%lld\n",l[(k-notloop)%length+notloop]);
  }
  return 0;
}


Measured memory_bytes: 5244
#include<stdio.h>
int main()
{
	int A,B,MAX=1;
	scanf("%d%d",&A,&B);
	if(A==B)
	printf("Draw");
	else if(A>B)
	{
		if(B==1) printf("Bob");
		else printf("Alice");
	}
	else
	{
		if(A==1) printf("Alice");
		else printf("Bob");
	}
	return 0;
} 

Measured memory_bytes: 128
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename F, typename... R>void input(F& f, R&... r) { cin >> f; input(r...); }
template<typename F, typename... R>void input(vector<F>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

int main() {
    int W, H, x, y; input(W, H, x, y);
    double ans;
    ans = (ll)W * H / 2.0;
    if (W % 2 == 0 && H % 2 == 0 && W / 2 == x && H / 2 == y) {
        printf("%.10f 1\n", ans);
    }
    else {
        printf("%.10f 0\n", ans);
    }
    getchar(); getchar();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int n, k;
int main(){
  cin >> n >> k;
  int ans = 0;
  rep(i, n){
    int x;
    cin >> x;
    ans += 2*min(k-x, x);
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  string a[110];
  cin >> h >> w;
  for (int i = 0; i < h; i++) cin >> a[i];
  for (int i = 0; i < 2 * h; i++) {
    if (i % 2 == 0) cout << a[i / 2] << endl;
    else cout << a[(i - 1) / 2] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    string S,T,U;
    cin>>S>>T;
    int A,B;
    cin>>A>>B;
    cin>>U;
    if(S==U){
        A--;
    }else{
        B--;
    }
    cout<<A<<" "<<B<<endl;

    return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2



int d[MAX];
vector<int> V[MAX];
int tt=0;
queue<int> Q;

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

  int u,k,v;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      V[u].push_back(v);
    }
  }

  Q.push(0);
  d[0]=tt;

  while(!Q.empty()){
    v=Q.front(); Q.pop();
    for(int i=0;i<V[v].size();i++){
      if(d[V[v][i]]==-1) {
        Q.push(V[v][i]);
        d[V[v][i]]=d[v]+1;

      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<d[i]<<endl;
  }
}



Measured memory_bytes: 3112
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int a = sc.nextInt();	   
	    int answer = a + a*a + a*a*a;
	    System.out.println(answer);	    
	    sc.close();

	}

}


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

#define rep(i,N) repv(i,0,N)
#define reps(i,N) repvs(i,0,N)
#define repv(i,a,b) for(int i=a;i<b;i++)
#define repvs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define debug(a) if(isDebugMode) cout<<#a<<"="<<a<<","
#define debug2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b
#define debug3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c
#define debug4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d
#define debugarr(arr,N){if(isDebugMode){ rep(i,N+1)\
	{if(arr[i]==INF)printf("INF ");\
		else cout<<arr[i]<<" ";} cout<<endl;}}
#define debugarr2(arr,N,M){if(isDebugMode) rep(i,N+1){rep(j,M+1)\
	{if(arr[i][j]==INF)printf(" INF");\
		else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define show(a) cout<<a<<endl;

auto chmax =[](int &a,int b){a=max(a,b);};
auto chmin =[](int &a,int b){a=min(a,b);};

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

bool isDebugMode=true;
//--------------------------------------//
int n,k;

int main(){
	cin>>n>>k;
	int a=0,b=0;
	reps(i,n){
		if(i%k==0) a++;
		else if(k%2==0&&i%k==(k/2)) b++;
	}
	ll ans=pow(a,3)+pow(b,3);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
import java.io.DataInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.function.IntBinaryOperator;
import java.util.stream.IntStream;

public class Main {

	class Operation implements Comparable {
		int B, C;

		Operation (int B, int C) {
			this.B = B;
			this.C = C;
		}

		@Override
		public int compareTo(Object o) {
			return C - ((Operation)o).C;
		}
	}

	public static void main(String[] args) throws Exception {
		int N = in.i(), M = in.i();
		int[] amountOfGate = new int[N+1];
		for (int i = 1; i <= M; i++) {
			amountOfGate[in.i()-1] += 1; // L_i
			amountOfGate[in.i()  ] -= 1; // R_i
		}

		int acc = 0;
		int num = 0;
		for (int i : amountOfGate ) {
			acc += i;
			if (acc == M)
				num++;
		}
		out.println(num);
	}

	static PrintStream out = System.out;
	static FastReader in = new FastReader();
}

class FastReader {
	final private int BUF_SIZE = 1 << 16;
	private DataInputStream din = new DataInputStream(System.in);
	private byte[] buffer = new byte[BUF_SIZE];
	private int bufferPointer, bytesRead;

	String s() throws IOException {
		return s(64);
	}

	String s(int capacity) throws IOException {
		byte[] buf = new byte[capacity];
		int cnt = 0, c;
		while ((c = c()) != -1) {
			if (c == '\n') break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	int i() throws IOException {
		int ret = 0;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	long l() throws IOException {
		long ret = 0;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		return neg ? -ret : ret;
	}

	double d() throws IOException {
		double ret = 0, div = 1;
		byte c = c();
		while (c <= ' ') c = c();
		boolean neg = (c == '-');
		if (neg) c = c();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = c()) >= '0' && c <= '9');
		if (c == '.')
			while ((c = c()) >= '0' && c <= '9')
				ret += (c - '0') / (div *= 10);
		return neg ? -ret : ret;
	}

	private void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUF_SIZE);
		if (bytesRead == -1) buffer[0] = -1;
	}

	byte c() throws IOException {
		if (bufferPointer == bytesRead) fillBuffer();
		return buffer[bufferPointer++];
	}
}



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

string seq;

void init(){
    cin >> seq;
}

void solve(){
    int ans = 0;
    for( int i = 0; i < seq.size(); ++i ){
        if( seq[ i ] == 'g' )
            ans += i & 1;
        else
            ans -= not ( i & 1 );
    }
    cout << ans << endl;
}

signed main(){
    ios::sync_with_stdio( 0 );
    init();
    solve();
    return 0;
}


Measured memory_bytes: 512
input_line = input()
str = ""

for i in range(0,len(input_line)):
  if input_line[i] == '0':
    str += "0"
  elif input_line[i] == '1':
    str += "1"
  elif input_line[i] == 'B':
    str = str[:-1]
else:
  print(str)

Measured memory_bytes: 38256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		double x, h, h2 = 0;

		while(true){
			x = sc.nextInt();
			h = sc.nextInt();
			if(x == 0 && h == 0) break;

			h2 = Math.sqrt(Math.pow(x / 2, 2) + Math.pow(h, 2));

			System.out.println(x * x + 2 * x * h2);
		}
	}
}

Measured memory_bytes: 11000
#include <stdio.h>
int main(void)
{
        int a,b,l,S;
        scanf("%d",&a);
        scanf("%d",&b);
        S=a*b;
        l=2*(a+b);
        printf("%d",S);
        printf(" ");
        printf("%d",l);
        printf("\n");
        return 0;
}

Measured memory_bytes: 2672