akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

const int MAX_N = 200000;
const int MOD = 1000000007;

int n;

long long fac[MAX_N + 1];
long long inv[MAX_N + 1], ifac[MAX_N + 1];
long long ans[MAX_N + 1], sub_ans[MAX_N + 1];
long long sz[MAX_N + 1];

vector<int> g[MAX_N];

long long mod_inv(long long a)
{
  long long r = 1;
  long long n = MOD - 2;
  while (n) {
    if (n & 1) {
      r = (r * a) % MOD;
    }
    a = (a * a) % MOD;
    n /= 2;
  }
  return r;
}

long long comb(int n, int r)
{
  long long ret = 1;
  ret = (ret * fac[n]) % MOD;
  ret = (ret * ifac[r]) % MOD;
  ret = (ret * ifac[n - r]) % MOD;
  return ret;
}

int getSize(int v, int p = -1)
{
  int ret = 1;
  
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i] != p) {
      ret += getSize(g[v][i], v);
    }
  }
  sz[v] = ret;
  return sz[v];
}

long long dfs1(int v, int p = -1)
{
  long long ans = 1;
  int tmp_size = sz[v] - 1;
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i] != p) {
      long long tmp = comb(tmp_size, sz[g[v][i]]);
      long long tmp2 = dfs1(g[v][i], v);
      ans = (ans * tmp) % MOD;
      ans = (ans * tmp2) % MOD;
      tmp_size -= sz[g[v][i]];
    }
  }
  return sub_ans[v] = ans;
}

long long dfs2(int v, int p = -1)
{
  if (p != -1) {
    long long tmp = ans[p];
    long long dup = comb(n - 1, sz[v]);
    tmp = (tmp * mod_inv(dup)) % MOD;
    tmp = (tmp * comb(n - 1, n - sz[v])) % MOD;
    ans[v] = tmp;
  }
  for (int i = 0; i < g[v].size(); i++) {
    if (g[v][i] != p) {
      dfs2(g[v][i], v);
    }
  }
}

int main()
{
  scanf("%d", &n);
  
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  inv[1] = 1;
  fac[0] = ifac[0] = 1;
  fac[1] = ifac[1] = 1;
  for (int i = 2; i <= n; i++) {
    fac[i] = (fac[i - 1] * i) % MOD;
    inv[i] = (inv[MOD % i] * (MOD - MOD / i)) % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
  }
  
  getSize(0);
  ans[0] = dfs1(0);
  dfs2(0);
  
  for (int i = 0; i < n; i++) {
    printf("%lld\n", ans[i]);
  }
  
  return 0;
}

Measured memory_bytes: 23284
#include<bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, K;
string S;

int main() {
	cin >> N >> K >> S;
	S[K - 1] -= 'A' - 'a';
	cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */


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

    string s; cin >> s;

    if(s[0]=='S') cout << "Cloudy" << endl;
    else if(s[0]=='C') cout << "Rainy" << endl;
    else cout << "Sunny" << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = stoi(s);
    int a = n / 100;
    int b = n % 100;
    bool f = false, g = false;
    if(1 <= a && a <= 12) f = true;
    if(1 <= b && b <= 12) g = true;
    if(f && g) cout << "AMBIGUOUS" << endl;
    else if(f) cout << "MMYY" << endl;
    else if(g) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if not n:
        break
    d = {k:[] for k, v in enumerate(range(7))}
    for _ in range(n):
        age = int(input())
        if age >= 10 and age < 20:
            d[1].append(1)
        elif age >= 20 and age < 30:
            d[2].append(1)
        elif age >= 30 and age < 40:
            d[3].append(1)
        elif age >= 40 and age < 50:
            d[4].append(1)
        elif age >= 50 and age < 60:
            d[5].append(1)
        elif age >= 60:
            d[6].append(1)
        else:
            d[0].append(1)
    for k, v in d.items():
        print(sum(v))

Measured memory_bytes: 15472
def get_ints
  gets.split.map(&:to_i)
end

while true
  n, m = get_ints
  break if n == 0 and m == 0

  nums = Array.new(m){|i| [i + 1, 0] }.reverse
  n.times do
    gets.strip.split.each_with_index do |c, i|
      if c == '1'
        nums[-(i + 1)][1] += 1
      end
    end
  end

  puts nums.sort_by.with_index{|(_, c), i| [c, i] }.reverse.map{|i, _| i }.join(' ')
end

Measured memory_bytes: 6120
h, w = gets.chomp.split(' ').map(&:to_i)
s = []
h.times { s << gets.chomp.each_char.to_a }

def search(i, j, h, w, s)
  direction = [ [1, 0], [0, 1], [0, -1], [-1, 0] ]
  direction.any? do |d|
    (0...h).cover?(i + d[0]) &&
        (0...w).cover?(j + d[1]) &&
        s[i + d[0]][j + d[1]] == '#'
  end
end

0.upto(h-1) do |i|
  0.upto(w-1) do |j|
    next unless s[i][j] == '#'
    unless search(i, j, h, w, s)
      puts 'No'
      exit
    end
  end
end

puts 'Yes'


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int n,m;
vector<vector<int>> G;
vector<bool> seen(100010);

void dfs(int v){
    seen[v]=true;
    for(auto nv : G[v]){
        if(seen[nv]) continue;
        dfs(nv);
    }
}

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

    G.resize(n);
    rep(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        x--,y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    int ans=0;

    rep(i,n){
        if(seen[i]) continue;
        dfs(i);
        ans++;
    }

    cout<<ans<<endl;
}


 

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, m;
string s, t;

int32_t main(){_
   
   int r;
   cin >> r;
   
   L pi = acosl(-1);


   cout << fixed << setprecision(15);

   cout<<2*pi*r;


   return 0;
}


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

int main() {
  int N,M;
  scanf("%d %d", &N ,&M);
  int a[M],b[M];
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &a[i],&b[i]);
  }

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

  for (int i = 0; i < M; ++i){
    ++c[a[i]-1];
    ++c[b[i]-1];
  }

  for (int i = 0; i < N; ++i){
    cout << c[i] << endl;
  }

  

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

bool inRange(int x, int low, int high){
  return (low <= x && x <= high);
}
int main(){
  int A, B, C, D, delta;
  cin >> A >> B >> C >> D;
  if (D < A || B < C){
    delta = 0;
  }
  else {
    if (C < A){
      delta = min(D-A, B-A);
    }
    else {
      delta = min(B-C, D-C);
    }
  }
  cout << delta << endl;
  return 0;
}


Measured memory_bytes: 256
#define LOCAL

#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

// From Errichto's Youtube stream
#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__) << "] "

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////

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

    int N, M;
    cin >> N >> M;

    int d = abs(N - M);
    if (d > 1) {
        cout << 0 << "\n";
    } else {
        int result = d == 1 ? 1 : 2;

        for (int i = 1; i <= N; i++) {
            result = (int64)result * i % (1000000007);
        }

        for (int i = 1; i <= M; i++) {
            result = (int64)result * i % (1000000007);
        }

        cout << result << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
	char a[11],b[11],c[11],*d;
	int e,f,n,m=0,i,j,k;
	scanf("%s%d",a,&n);
	e=strlen(a);
	for(i=1;i<=n;i++){
		scanf("%s",b);
		if((d=strstr(b,a))!=NULL)m++;
		else{
			f=1;
			while(f<=e){
				for(k=f,j=0;b[k]!='\0';k++)c[j++]=b[k];
				for(k=0;k<f;k++)c[j++]=b[k];
				if((d=strstr(c,a))!=NULL){
					m++;
					break;
				}
				f++;
			}
		}
	}
	printf("%d\n",m);
	return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n, a[N], b[N], ans;
ll sa, sb;
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		sa += a[i];
	}
	for (int i = 1; i <= n; ++i) {
		scanf("%d", b + i);
		sb += b[i];
	}
	if (sa < sb) {
		puts("-1");
		return 0;
	}
	ll d = 0;
	multiset<int> S;
	for (int i = 1; i <= n; ++i) {
		if (a[i] > b[i]) {
			S.insert(a[i] - b[i]);
		}
	} 
	for (int i = 1; i <= n; ++i) {
		if (a[i] < b[i]) {
			ans++;
			if (d >= b[i] - a[i]) {
				d -= b[i] - a[i];
			} else {
				a[i] += d;
				d = 0;
				while (a[i] < b[i]) {
					int x = *S.rbegin();
					S.erase(S.find(x));
					ans++;
					d += x;
					int tmp = min(d, (ll)b[i] - a[i]);
					a[i] += tmp;
					d -= tmp;
				}
			}
		}
	} 
	cout << ans;
}

Measured memory_bytes: 3584
"use strict";

main(require("fs").readFileSync("/dev/stdin", "utf8"));

function main(input) {
  const [n, k] = input.trim().split("\n").map(Number);

  let ans = 1;
  for (let i = 0; i < n; i++) {
    if (ans <= k) {
      ans *= 2;
    } else {
      ans += k;
    }
  }
  console.log(ans);
}


Measured memory_bytes: 7500
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int p[100005], q[100005];
long long sum[100005];
int main() {
  int w, h;
  long long ans = 0;
  scanf("%d%d", &w, &h);
  for (int i = 0; i < w; ++i) {
    scanf("%d", &p[i]);
    ans += p[i];
  }
  for (int i = 0; i < h; ++i) {
    scanf("%d", &q[i]);
  }
  sort(p, p + w);
  sum[0] = p[0];
  for (int i = 1; i < w; ++i) {
    sum[i] = sum[i - 1] + p[i];
  }
  for (int i = 0; i < h; ++i) {
    int u = lower_bound(p, p + w, q[i]) - p;
    if (u > 0) {
      ans += sum[u - 1];
    }
    ans += ((long long)(w - u + 1)) * q[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n, q, l, r, ans, a[100005],b[100005], count=0;
    string s;
    cin >> n >> q >> s;
    a[0]=0;
    for(int i=1; i<s.size(); i++) {
        if(s.at(i)=='C' && s.at(i-1)=='A') count++;
        a[i]=count;
    }
    for(int i=0; i<q; i++) {
        cin >> l >> r;
        b[i]=a[r-1]-a[l-1];
    }
    for(int i=0; i<q; i++) cout << b[i] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int par[100000], rnk[100000];

void init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rnk[i] = 0;
    }
}

int root (int i) {
    return i == par[i] ? i : par[i] = root(par[i]);
}

bool same(int i, int j) {
    return root(i) == root(j);
}

void unite(int i, int j) {
    i = root(i);
    j = root(j);
    if (rnk[i] < rnk[j]) {
        par[i] = j;
    } else {
        par[j] = i;
        if (rnk[i] == rnk[j]) rnk[i]++;
    }
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m; cin >> n >> m;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        p[i] = a - 1;
    }
    
    init(n);
    
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--; b--;
        unite(a, b);
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (same(p[i], i)) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

int main(){
  int H, W, i, j;
  for( i =0;; i++){
    cin >> H >> W;
    if( H == 0 && W == 0) break;
    for( i = 0; i < H; i++){
      for( j = 0; j < W; j++){
        if( i % 2 == 0 && j % 2 == 0 ) cout << "#";
        else if( i % 2 == 0 && j % 2 != 0 ) cout << ".";
        else if( i % 2 != 0 && j % 2 == 0 ) cout << ".";
        else if( i % 2 != 0 && j % 2 != 0 ) cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}


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

ll GCD(ll a,ll b){
    if(a>b){
        return GCD(b,a);
    }
    else{
    ll r=b%a;
    while(r!=0){
        b=a;
        a=r;
        r=b%a;
    }
    return a;
    }
}

int main(){
    ll n;cin>>n;
    ll an=0;
    rep(i,1,n+1){
        rep(j,1,n+1){
            rep(k,1,n+1){
                ll A=GCD(i,j);
                an+=GCD(k,A);
            }
        }
    }
    cout<<an<<endl;
}
    









Measured memory_bytes: 3636
n = int(input())
p = list(map(int, input().split()))
# result_list = [0]*n
result = 1
com_val = p[0]

for i in range(1, n):
    if com_val < p[i]:
        continue
    else:
        result += 1
        com_val = p[i]

print(result)


Measured memory_bytes: 24744
N = int(input())
As = list(map(int, input().split()))

Mat = [[float('inf')] * (N - 1) + [N] for d in range(20)]
prev = [-1] * 20

for i, A in enumerate(As):
    binA = format(A, 'b').zfill(20)
    for d in range(20):
        if binA[d] == '1':
            if prev[d] != -1:
                Mat[d][prev[d]] = i
            prev[d] = i

minM = list(map(min, *Mat))

for i in reversed(range(N - 1)):
    minM[i] = min(minM[i], minM[i + 1])

print(sum(minM) - N * (N - 1) // 2)


Measured memory_bytes: 51580
#include<stdio.h>
int main(){
    int i,n,cnt=0;
    scanf("%d",&n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(i%2==0&&a[i]%2==1){
            cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 1728
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
stS = [v for v in input()[:-1]]
stT = [v for v in input()[:-1]]

ans = "YES"
# T=U,A=D
T = "U"
A = "D"
m = sr
# print("U")
for s, t in zip(stS, stT):
    #print("m->", m)
    if s == T:
        m -= 1
        if m <= 0:
            ans = "NO"
            print(ans)
            exit()
    if t == A:
        if m < H:
            m += 1

T = "D"
A = "U"
m = sr
# print("D")
for s, t in zip(stS, stT):
    #print("m->", m)
    if s == T:
        m += 1
        if m > H:
            ans = "NO"
            print(ans)
            exit()
    if t == A:
        if m > 1:
            m -= 1

T = "R"
A = "L"
m = sc
# print("R")
for s, t in zip(stS, stT):
    #print("m->", m)
    if s == T:
        m += 1
        if m > W:
            ans = "NO"
            print(ans)
            exit()
    if t == A:
        if m > 1:
            m -= 1
T = "L"
A = "R"
m = sc
# print("L")
for s, t in zip(stS, stT):
    #print("m->", m)
    if s == T:
        m -= 1
        if m <= 0:
            ans = "NO"
            print(ans)
            exit()
    if t == A:
        if m < H:
            m += 1
print(ans)


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

int main() {
  int N;
  cin >>N;
  vector<long long>A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  
  long long ans=1LL;
  for(int i=0;i<N;i++){
    if(A.at(i)==0LL) ans=0LL;
  }
  if(ans){
    for(int i=0;i<N;i++){
      if(A.at(i)>1000000000000000000LL/ans){
        ans=-1LL;
        break;
      }
      else
        ans*=A.at(i);
    }
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 3972
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
i = 0
while (i < n-1):
 if a[i] == i+1:
  ans  +=1
  a[i],a[i+1] = a[i+1],a[i]
 i += 1
if a[n-1] == n:
 ans +=1
print(ans)

Measured memory_bytes: 13880
n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
if k in a:
    print("POSSIBLE")
elif k>max(a):
    print("IMPOSSIBLE")
else:
    x=a[0]
    for i in range(1,n):
        x=gcd(x,a[i])
    if k%x==0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

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

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}




int main() {
  long long n,a,b,p,ans,k,daisu;
  cin>>n>>a>>b;
 p=1000000007;
  ans=0;
  k=1;
  
    // 3^45 mod. 1000000007 を計算してみる
   // cout << modpow(2, 1000000000, 1000000007) << endl;
  ans=modpow(2,n,p);
  for(long long i=1; i<a+1; i++){
    daisu=modinv(i,p);
    k=k*daisu%p;
    daisu=(n+1-i)%p;
    k=k*daisu%p;
  }
  ans=ans+p-k;
  
  
  
  k=1;
  for(long long i=1; i<b+1; i++){
    daisu=modinv(i,p);
    k=k*daisu%p;
    daisu=(n+1-i)%p;
    k=k*daisu%p;
  }
  ans=ans+p-k-1;
  ans=ans%p;

  cout<<ans;
}

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

Measured memory_bytes: 3060
import java.util.Deque;
import java.util.ArrayDeque;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[][] xyhs = new int[n][3];
        
        for (int i = 0; i < n; i++) {
            String[] line = br.readLine().split(" ");
            xyhs[i][0] = Integer.parseInt(line[0]);
            xyhs[i][1] = Integer.parseInt(line[1]);
            xyhs[i][2] = Integer.parseInt(line[2]);
        }
        
        int a = 0;
        int b = 1;
        outer: for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (xyhs[i][0] != xyhs[j][0] && xyhs[i][1] != xyhs[j][1] && xyhs[i][2] != 0 && xyhs[j][2] != 0) {
                    a = i;
                    b = j;
                    break outer;
                }
            }
        }
        
        int cx = 0;
        int cy = 0;
        int h = 0;
        if (n == 1) {
            cx = xyhs[0][0];
            cy = xyhs[0][1];
            h = xyhs[0][2];
        }
        else {
            outer: for (int i = 0; i <= 100; i++) {
                for (int j = 0; j <= 100; j++) {
                    
                    if (Math.abs(xyhs[a][0]-i) + Math.abs(xyhs[a][1]-j) + xyhs[a][2] == Math.abs(xyhs[b][0]-i) + Math.abs(xyhs[b][1]-j) + xyhs[b][2]) {
                        cx = i;
                        cy = j;
                        h = xyhs[a][2] + Math.abs(xyhs[a][0]-i) + Math.abs(xyhs[a][1]-j);
                        if (n > 1) {
                            for (int k = 0; k <= n-1; k++) {
                                if (Math.max(h - Math.abs(xyhs[k][0]-cx) - Math.abs(xyhs[k][1]-cy), 0) == xyhs[k][2]) {
                                    if (k == n-1) break outer;
                                }
                                else {
                                    break;
                                }
                            }
                        }//System.out.println(cx + " " + cy + " " + h);
                    }
                }
            }
        }
        //System.out.println(xyhs[0][2]);
        System.out.println(cx + " " + cy + " " + h);
    }
}


Measured memory_bytes: 22996
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26208
import heapq

n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for _ in range(n)]
jobs.sort()

i = 0
works = []
reward = 0
for d in range(m):
  while i < n and jobs[i][0] <= d + 1:
    heapq.heappush(works, -jobs[i][1])
    i += 1
  if works:
    reward -= heapq.heappop(works)
print(reward)

Measured memory_bytes: 20672
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
pre=sum(A)

for i in range(N):
  if B[i]<=A[i]:
    A[i]-=B[i]
  else:
    A[i+1]=max(0, A[i+1]-B[i]+A[i])
    A[i]=0
print(pre-sum(A))

Measured memory_bytes: 24172
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;


long long a[2005][2005]={0};

int main()
{
  int n,k;
  scanf("%d %d",&n,&k);
  for(int i=0;i<=n+2;i++)
  {
  a[i][0]=1;
    for(int j=1;j<=i;j++)
    a[i][j]=(a[i-1][j-1]+a[i-1][j])%1000000007;
  }

   int t=n-k+1;long long ans;
  for(int i=1;i<=k;i++)
  {
  if(n-k+1>=i&&t>0)
  {
    ans=a[n-k+1][i]*a[k-1][i-1]%1000000007;
 
  }
   else
   ans=0;
   

   printf("%lld\n",ans);
  }



}

Measured memory_bytes: 30208
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ABC057BSolve solve = new ABC057BSolve();
		solve.main();
	}
}

class ABC057BSolve {
	
	Point[] checkPoints;
	Point[] students;
	int N;
	int M;
	
	ABC057BSolve() {
		Scanner cin = new Scanner(System.in);
		this.N = cin.nextInt();
		this.M = cin.nextInt();
		this.students = new Point[N];
		this.checkPoints = new Point[M];
		for (int i = 0; i < N; i++) {
			int a = cin.nextInt();
			int b = cin.nextInt();
			students[i] = new Point(a, b);
		}
		for (int i = 0; i < M; i++) {
			int c = cin.nextInt();
			int d = cin.nextInt();
			checkPoints[i] = new Point(c, d);
		}
	}
	
	void main() {
		for (Point student : students) {
			int point = 0;
			int min = Integer.MAX_VALUE;
			for (int i = M - 1; i >= 0; i--) {
				int distance = distance(student, checkPoints[i]);
				if (min >= distance) {
					min = distance;
					point = i + 1;
				}
			}
			System.out.println(point);
		}
	}
	
	int distance(Point a, Point b) {
		return Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
	}
	
	class Point {
		int x;
		int y;
		
		Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
	
}


Measured memory_bytes: 22740
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int *a=new int[n];
	int odd=0;
	int fou=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		if(a[i]&1!=0)
			odd++;
		else if(a[i]%4==0)
			fou++;
	}
	if(fou>=odd||(odd==fou+1&&odd+fou==n))
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 640
N = int(input())
a = [int(x) for x in input().split()]

M = max(a)

C = [0] * (M + 1)

for i in range(N):
    C[a[i]] += 1 

ans = 0

for i in range(1,M):
    wa = C[i - 1] + C[i] + C[i + 1]
    ans = max(ans, wa)

if M <= 1:
    ans = N

print(ans)

Measured memory_bytes: 19924
;; F - Tree and Constraints

(defun main ()
  (let* ((n (read))
         (ab (loop repeat (1- n) collect (cons (read) (read))))
         (m (read))
         (uv (loop repeat m collect (cons (read) (read)))))
    (princ (solve n ab m uv))))

(defun make-adjacency-list (n edges)
  (let ((adj (make-array n :initial-element nil)))
    (loop for i from 0
          for edge in edges
          for a = (1- (car edge))
          for b = (1- (cdr edge))
          do (setf (aref adj a) (cons (cons b i) (aref adj a)))
             (setf (aref adj b) (cons (cons a i) (aref adj b))))
    adj))

(defun empty-set (n-elem)
  (make-array n-elem :element-type 'bit :initial-element 0))

(defun find-paths (m uv n adj)
  (labels ((dfs (u v parent)
             (if (eql u v)
                 (empty-set (1- n))
                 (loop for (a . i) in (aref adj u)
                       for p = (and (not (eql a parent))
                                    (dfs a v u))
                       when p do (setf (bit p i) 1)
                                 (return p)))))
    (loop for (u . v) in uv
          collect (dfs (1- u) (1- v) nil))))

(defun coloring (n paths union sign)
  (if paths
      (+ (coloring n (cdr paths) union sign)
         (coloring n (cdr paths) (bit-ior union (car paths)) (- sign)))
      (* sign (ash 1 (- (1- n) (count 1 union))))))

(defun solve (n ab m uv)
  (let* ((adj (make-adjacency-list n ab))
         (paths (find-paths m uv n adj)))
    (coloring n paths (empty-set (1- n)) 1)))

(main)


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

//π M_PI
//deg = rad*180/M_PI

int main() {
    string s;
    cin >> s;
    rep(i, s.length()) {
        cout << "x";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#import numpy
import math

def pita(a, b, angle):
    return math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(angle)))

a, b, h, m = map(int, input().split())

h_angle = h*30 + m*(1/2)
m_angle = m*6

#print(h_angle, m_angle)

angle = abs(h_angle - m_angle)

print(pita(a, b, angle))

Measured memory_bytes: 9516
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <list>
#include <stack>
#include <set>
#include <cctype>

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

#define ll long long
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)


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

	ll n, k;
	cin >> n >> k;

	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}

	ll ans = 0;
	FOR(i, 1, n + 1) {
		if (i - 1 >= k) {
			ans += n / i * (i - k);
			ans += max(0LL, (n%i) - k + 1);
		}
	}
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MOD = 1e9+7;
#define REP(i,n) for (int i = 0; i < (N); ++i)
#define ar array
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

	int N;
	cin >> N;
	int ans = 0;

	for (int i = 0; i <= N; i++) {
		ans = ans + i; 
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3464
#include <bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
#define M 1000000007
#define boost
#define push_back push
#define pop_back pop
#define fo(i,n)   for (size_t i = 0; i < n; i++)
#define fo1(i,n)   for (size_t i = 1; i <= n; i++)
template<class _T>inline void read(_T &_a)
{
    bool f=0; char _c=getchar(); _a=0;
    while(_c<'0'||_c>'9'){ if(_c=='-') f=1; _c=getchar(); }
    while(_c>='0'&&_c<='9'){ _a=(_a<<3)+(_a<<1)-'0'+_c; _c=getchar(); }
    if(f) _a=-_a;
}
int price[100001];
int dp[100001];

int cost(int x){
    
    if(x==1)
    return dp[x]=0;

    if(x==2)
   return dp[x]= abs(price[2]-price[1]);

   
  if(dp[x]!=-1)
  return dp[x];

   
 return dp[x]= std ::min(cost(x-1)+ abs(price[x]-price[x-1]),cost(x-2)+abs(price[x]-price[x-2])) ;
   
   
}
//ll T;

int main()
{  
   /* ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
      for(read(T);T;--T)*/
   {
    memset(dp,-1,sizeof(dp));
    int n ; read(n);

    fo1(i,n)
    read(price[i]);

    cout<<cost(n);
   }

return 0;
}

Measured memory_bytes: 6764
#include <iostream>
#define N_MAX 200000
using namespace std;

int main() {
    int N, T, t[N_MAX], ans = 0;
    cin >> N >> T;
    for(int i=0; i<N; i++) cin >> t[i];
    for(int i=0; i<N; i++) {
        if(i < N-1 && t[i+1]-t[i] < T) {
            ans += t[i+1] - t[i];
        } else {
            ans += T;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int main(void)
{
	int n,m,i,j,k,cnt;
	int a[10001],b[10001],flg[501];
	scanf("%d",&n);
	scanf("%d",&m);
	while(!(n==0 && m==0)){
		for(i=1;i<=m;i++){
			scanf("%d %d",&a[i],&b[i]);
	//		printf("a=%d b=%d\n",a[i],b[i]);
		}
		for(i=1;i<=n;i++){
			flg[i]=0;
		}
		flg[1]=-1;
		for(i=1;i<=m;i++){
			if(a[i]==1){
	//			printf("b=%d\n",b[i]);
				flg[b[i]]=1;
			}
		}
		for(i=1;i<=n;i++){
			if(flg[i]==1){
				for(j=1;j<=m;j++){
					if(i==a[j] && flg[b[j]]==0){
						flg[b[j]]=2;
					}
					if(i==b[j] && flg[a[j]]==0){
						flg[a[j]]=2;
					}
				}
			}
		}
		cnt=0;
		for(i=1;i<=n;i++){
			if(flg[i]==1 || flg[i]==2){
	//			printf("flg%d=%d\n",i,flg[i]);
				cnt++;
			}
		}
		printf("%d\n",cnt);
		scanf("%d %d",&n,&m);
	}
	return 0;
}

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

using namespace std;

int main(){
	int N;
	cin >> N;
	vector<int> a(N+1);
	for(int i = 1; i <= N; i++){
		cin >> a[i];
	}
	int count = 0;
	int button = 1;
	
	while(1){
		if(button == 2){
			cout << count << endl;
			return 0;
		}
		button = a[button];
		count++;
		if(count >= N + 1) break;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
N = int(input())
C = [0] * (N - 1)
S = [0] * (N - 1)
F = [0] * (N - 1)
for i in range(N - 1):
    C[i], S[i], F[i] = map(int, input().split())

ans = [0] * (N - 1)
for i in range(N - 1):
    for j in range(i, N - 1):
        r = ans[i] % F[j]
        ans[i] += F[j] - r if (r != 0) else 0
        ans[i] = max(ans[i], S[j])
        ans[i] += C[j]
    print(ans[i])
print(0)


Measured memory_bytes: 3188
import sys


def sum(tree, i):
    s = 0
    while i > 0:
        s += tree[i]
        i -= i & -i
    return s


def add(tree, size,  i, x):
    while i <= size:
        tree[i] += x
        i += i & -i


def range_sum(tree, l, r):
    return sum(tree, r) - sum(tree, l)


def main():
    n, q = map(int, sys.stdin.buffer.readline().split())

    bit = [0] + list(map(int, sys.stdin.buffer.readline().split()))
    for i in range(1, n+1):
        if i + (i & -i) < n + 1:
            bit[i + (i & -i)] += bit[i]

    for y in sys.stdin.buffer.readlines():
        q, p, x = map(int, y.split())
        if q:
            print(range_sum(bit, p, x))
        else:
            add(bit,n, p+1, x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	string S;
	cin >> S;

	if (S[0] == 'S') {
		co("Cloudy");
	}
	if (S[0] == 'C') {
		co("Rainy");
	}
	if (S[0] == 'R') {
		co("Sunny");
	}

	Would you please return 0;
}

Measured memory_bytes: 256
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1], M = ip[2];
	auto a = readAs!(int[]);
	auto b = readAs!(int[]);
	ulong res = a.reduce!min + b.reduce!min;
	foreach(i; 0..M) {
		auto ip2 = readAs!(int[]), x = ip2[0], y = ip2[1], c = ip2[2];
		auto tmp = a[x-1] + b[y-1] - c;
		if(tmp < res) res = tmp;
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 8356
// AOJ 0290: Microorganism Power Generation
// 2017.10.27 bal4u@uu

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

int bm[14], bw[14], m, w;
int tbl[14][14];
int dp[14][4100];

int main()
{
	int i, j, k, d, x, lim;

	while (scanf("%d%d", &m, &w) && m > 0) {
		for (i = 0; i < m; i++) scanf("%d", bm + i);
		for (j = 0; j < w; j++) scanf("%d", bw + j);

		memset(tbl, 0, sizeof(tbl));
		for (i = 0; i < m; i++) for (j = 0; j < w; j++) {
			d = bm[i] - bw[j]; if (d < 0) d = -d;
			x = d * (d - 30) * (d - 30);
			tbl[i][j] = x;
		}

		memset(dp, -1, sizeof(dp));
		dp[0][0] = 0;
		lim = 1 << w;
		for (i = 0; i < m; i++) {
			for (k = 0; k < lim; k++) if (dp[i][k] >= 0) {
				if (dp[i+1][k] < dp[i][k]) dp[i+1][k] = dp[i][k];
				for (j = 0; j < w; j++) {
					if (k & (1<<j)) continue;
					d = k | (1<<j);
					x = dp[i][k] + tbl[i][j];
					if (dp[i+1][d] < x) dp[i+1][d] = x;
				}
			}
		}

		for (x = 0, i = 0; i < lim; i++) if (dp[m][i] > x) x = dp[m][i];
		printf("%d\n", x);
	}
	return 0;
}

Measured memory_bytes: 2016
#include<iostream>
int main() {
	using std::cin;
	using std::cout;
	int len;
	cin >> len;
	int* arr = new int[len];
	for (int i = 0; i < len; i++)
		cin >> arr[i];

	for (int j = 0; j < len; j++) {
		if (j)
			cout << " ";
		cout << arr[j];
	}
	cout << "\n";
	for (int i = 1; i < len; i++) {
		int j = i - 1;
		int temp = arr[i];
		while(j >= 0 && temp<arr[j]) {
			arr[j + 1] = arr[j];
			j--;
		}
		arr[j+1] = temp;
		for (int j = 0; j < len; j++) {
			if (j)
				cout << " ";
			cout << arr[j];
		}
		cout << "\n";
	}
	return 0;
}



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

int main() {
  int S;
  cin >> S;
  
  if (S == 111) {
    cout << 999 << endl;
  } else if (S == 191) {
    cout << 919 << endl;
  } else if (S == 119) {
    cout << 991 << endl;
  } else if (S == 911) {
    cout << 199 << endl;
  } else if (S == 991) {
    cout << 119 << endl;
  } else if (S == 199) {
    cout << 911 << endl;
  } else if (S == 999) {
    cout << 111 << endl;
  } else if (S == 919) {
    cout << 191 << endl;
  }
}


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

int main() {
  long N;
  cin >> N;
  vector<int> vec(N);
  
  for (long i=0;i<N; i++) {
    cin >> vec[i];
  }
  long long sum=0;
  for (int i=1;i<N;i++) {
    if (vec[i-1]>vec[i]) {
      sum+=vec[i-1]-vec[i];
      vec[i]=vec[i-1];
    }
  }
  cout << sum << endl;
  
}

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

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

using namespace std;
using ll = long long;

struct PrimeNumbers {
    int max;
    vector<bool> is_prime; // i-th element is true iff i is prime (i <= max). (e.g. is_prime = {false, false, true, true, false} for max = 4)
    vector<int> primes; // The list of prime numbers less than or equal to max. (e.g. primes = {2, 3} for max = 4)
    vector<int> minimum_factor; // The list of the minimum factors of the integers less than or equal to max. (e.g. minimum_factor = {0, 1, 2, 3, 2} for max = 4)

    PrimeNumbers(int max): max(max) {
        is_prime = vector<bool>(max + 1, true);
        is_prime.at(0) = is_prime.at(1) = false;
        for(int i = 0; i <= max; ++i) minimum_factor.emplace_back(i);

        for(int i = 2; i * i <= max; ++i)
            if(is_prime.at(i))
                for(int j = i * i; j <= max; j += i) {
                    is_prime.at(j) = false;
                    if(minimum_factor.at(j) == j) minimum_factor.at(j) = i;
                }
        for(int i = 2; i <= max; ++i)
            if(is_prime.at(i)) primes.emplace_back(i);
    }

    // Return the list of the prime factors of n. (2 <= n < (max + 1)^2)
    // (e.g. prime_factorization(24) = {2, 2, 2, 3})
    // Use a fast algorithm for n <= max.
    template<typename T>
    vector<T> prime_factorization(T n) {
        vector<T> factors;
        try {
            if(n < 2 || n / (max + 1) >= (max + 1)) throw "The argument of prime_factorization() is out of range.";
        } catch(char const* str) {cout << str << endl;}

        if(n <= max) {
            while(n != 1) {
                factors.emplace_back(minimum_factor.at(n));
                n /= minimum_factor.at(n);
            }
        } else {
            for(int p: primes) {
                if(n == 1) return factors;
                while(n % p == 0) {
                    factors.emplace_back(p);
                    n /= p;
                }
            }
            if(n != 1) factors.emplace_back(n);
        }

        return factors;
    }
};

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

    PrimeNumbers pm(1000);

    int n;
    cin >> n;
    vector<int> a(n);
    int a_max = 0;
    rep(i, n) {
        cin >> a.at(i);
        a_max = max(a_max, a.at(i));    
    }

    PrimeNumbers pn(a_max);
    unordered_set<int> factors;
    vector<int> n_factors(a_max + 1);

    for(int i: a) {
        factors.clear();
        for(int p: i != 1 ? pn.prime_factorization(i) : vector<int>(1, 1)) factors.emplace(p);
        for(int p: factors) n_factors.at(p)++;
    }

    bool pairwise_coprime = true;

    for(int i = 2; i <= a_max; ++i) {
        if(n_factors.at(i) == n) {
            printf("not coprime\n");
            return 0;
        }
        if(n_factors.at(i) > 1) pairwise_coprime = false;
    }

    if(pairwise_coprime) printf("pairwise coprime\n");
    else printf("setwise coprime\n");

    return 0;
}

Measured memory_bytes: 15892
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<string>
#include<cstdlib>
#include<vector>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 n, x, m;
    cin >> n >> x >> m;

    vector<vector<i64>> doubling(64, vector<i64>(m,-1));
    vector<vector<i64>> sum(64,vector<i64>(m,0));
    rep(i,m){
        doubling[0][i] = i * i % m;
        sum[0][i] = i;
    }
    rep(i,63){
        rep(j,m){
            doubling[i + 1][j] = doubling[i][doubling[i][j]];
            sum[i + 1][j] = sum[i][j] + sum[i][doubling[i][j]];
        }
    }
    i64 ans = 0;
    i64 now = x;
    for(i64 i = 63; i >= 0; i--){
        if(n & ((i64)(1) << i)){
            ans += sum[i][now];
            now = doubling[i][now];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 104204
# ABC134
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    A = list(map(int, [input() for _ in range(n)]))
    SA = sorted(A)
    ma, ma2 = SA[-1], SA[-2]
    ans = (ma if i != ma else ma2 for i in A)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef map<int, int> mint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


int mod(int a, int b){return (a%b+b)%b;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b){ll ans=1; rep(i, b){ans=ans*a%MOD;} return ans;}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}




int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m;
    cin >> n >> m;

    vector<pint> demand(m);


    rep(i, m){
        int a, b;
        cin >> a >> b;
        demand[i] = make_pair(b, a);
    }

    sort(ALL(demand));


    int removed = -1;
    int ans = 0;

    rep(i, m){
        int a=demand[i].second, b=demand[i].first;
        if(a <= removed)  continue;
        removed = b-1;
        ans++;

    }

    ppp(ans);

    return 0;
}


Measured memory_bytes: 1024
using static System.Math;
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var m = int.Parse(line[0]);
        var n = int.Parse(line[1]);
        if (n == 1) { Console.WriteLine(getMax1(m)); goto exit; }
        if (n == 2) { Console.WriteLine(getMax2(m)); goto exit; }
        var map = new bool[n];
        line = Console.ReadLine().Trim().Split(' ');
        for (int i = 0; i < n; i++)
            if (line[i] == "0") map[i] = true;
        var ans = getMax3(map, n);
        for (int i = 1; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < n; j++)
                if (line[j] == "1") map[j] = true;
                else map[j] = false;
            ans += getMax3(map, n);
        }
        Console.WriteLine(ans);
        exit:;
    }
    static int getMax2(int m)
    {
        var ans = 0;
        for (int i = 0; i < m; i++)
        {
            var s = Console.ReadLine().Trim();
            if (s == "0 0" | s == "1 1") ans++;
            else ans += 2;
        }
        return ans;
    }
    static int getMax1(int m)
    {
        var ans = int.Parse(Console.ReadLine().Trim());
        for (int i = 1; i < m; i++)
        {
            var t = int.Parse(Console.ReadLine().Trim());
            if (t == 0) ans++;
        }
        return ans;
    }
    static int getMax3(bool[] map, int n)
    {
        var c = map.Count(x => x == true);
        var c1 = c;
        if (map[0]) c1--;
        else c1++;
        var c2 = c;
        if (map[n - 1]) c2--;
        else c2++;
        var ans = Max(c1, c2);
        var b0 = c1;
        if (map[n - 1]) b0--;
        else b0++;
        for (int i = 1; i < n - 1; i++)
        {
            var t = b0;
            if (map[i]) t--;
            else
            {
                t++;
                ans = Max(ans, t);
                break;
            }
        }
        return ans;
    }
}



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

int main() {
  int HowMuch = 0, OneCoinExist = 0;
  cin >> HowMuch >> OneCoinExist;
  if(HowMuch % 500 != 0 && HowMuch % 500 - OneCoinExist > 0){
    cout << "No" << endl;
  } else {
    cout << "Yes" <<endl;
  }
}

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

using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
#define debug(x) cout << x << endl
#define vout(v) rep(i, v.size()) cout << v[i] << " ";
#define INF INT_MAX

int R;

int main() {
	cin >> R;
	cout << 2.0 * 3.14159265358979323846 * (double)R;

	return 0;
}

Measured memory_bytes: 3788
#include<stdio.h>

int main(){
  int N,a[100],flag=1,i,j,tmp,n=0;

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

  i =0;
  while(flag){
    flag =0;
    for(j = N-1;j > i;j--){
      if(a[j] < a[j-1]){
	tmp = a[j];
	a[j] = a[j-1];
	a[j-1] = tmp;
	flag = 1;
	n++;
      }
    }
    i++;
  }
  for(i = 0;i<N-1;i++)
    printf("%d ",a[i]);
  printf("%d\n%d\n",a[N-1],n);

  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main (void){
  int a, b;
  scanf ("%d %d", &a, &b);
  if (a > b)
    printf ("a > b\n");
  else if (a < b)
    printf ("a < b\n");
  else if (a == b)
    printf ("a == b\n");
  return 0;
}

Measured memory_bytes: 580
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n ,m;
  cin >> n >> m;
  if(n==m) cout <<"Yes\n";
  else cout <<"No\n";
}


Measured memory_bytes: 256
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int area1 = int.Parse(input[0]) * int.Parse(input[1]);
    int area2 = int.Parse(input[2]) * int.Parse(input[3]);
    Console.WriteLine(Math.Max(area1, area2));
  }
}

Measured memory_bytes: 11092