akhauriyash/Code-Regression huggingface dataset:
END { load __FILE__ unless $stdin.eof? }

n = gets.to_i
stones = gets.chomp.chars.map! { |c| c == 'W' }

cnt = 0
loop do
  ptr_w = stones.index { |s| s } || n
  ptr_r = stones.rindex { |s| !s } || -1
  break if ptr_w >= ptr_r
  cnt += 1
  stones = stones[(ptr_w + 1)...ptr_r]
  n = stones.size
end

puts cnt


Measured memory_bytes: 30592
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  auto s = readln.chomp.to!(char[]);
  if (s[0] != 'A') {
    writeln("WA");
    return;
  }
  if (s.count('A') != 1 || s.count('C') != 1) {
    writeln("WA");
    return;
  }
  foreach (c; s) {
    if (c != 'A' && c != 'C') {
      if ('A' <= c && c <= 'Z') {
        writeln("WA");
        return;
      }
    }
  }
  if (s[2 .. ($ - 1)].count('C') != 1) {
    writeln("WA");
    return;
  }

  writeln("AC");

}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

int main() {
  int n;
  cin >> n;
  vector<long> a(n);
  for(int i=0;i<n;i++){
    cin >>  a.at(i);
  }
  vector<long> dp(n,10000000000);
  dp.at(0)=0;
  for(int i=0;i<n-1;i++){
    dp.at(i+1) = min(dp.at(i+1),dp.at(i)+abs(a.at(i)-a.at(i+1)));
    if(i<n-2)dp.at(i+2) = min(dp.at(i+2),dp.at(i)+abs(a.at(i)-a.at(i+2)));
  }
  cout << dp.at(n-1) << endl;
}


Measured memory_bytes: 1792
n, k = gets.chomp.split(' ').map(&:to_i)
list = gets.chomp.split(' ').map(&:to_i)

N_MAX = 100_000_000

time = N_MAX * 3
0.upto(n - k).each do |i|
  l = i
  r = i + k - 1

  time_1 = list[l].abs + (list[r] - list[l]).abs
  time_2 = list[r].abs + (list[r] - list[l]).abs
  time = [time, time_1, time_2].min
end
puts time


Measured memory_bytes: 12036
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    ll a,b,n; cin >> a >> b >> n;
    ll x = b-1;
    if(n < b-1) x = n;
    cout << a*x/b << endl;


    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 3612
//#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define int long long
#define ll long long
#define str string
#define db double
#define ac() cout<<"Yes"<<endl;
#define wa() cout<<"No"<<endl;
#define ddd cout<<"---debug---"<<endl;
#define ff(a,b) for(signed long long (a)=1;(a)<=(b);(a)++)
#define fff(a,b) for(signed long long (a)=0;(a)<(b);(a)++)
#define re readdd()
#define pr(a) printtt(a)
#define pee puts("");
#define eee putchar(' ');
#define pss(a) push_back(a)
#define ps(a) push(a)
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}//
int ppow(int a,int b,int mod){a%=mod;//
int ans=1%mod;while(b){if(b&1)ans=(long long)ans*a%mod;
a=(long long)a*a%mod;b>>=1;}return ans;}
int readdd(){int x=0,f=1;char c=getchar();//
while(!isdigit(c)&&c!='-')c=getchar();
if(c=='-')f=-1,c=getchar();
while(isdigit(c))x=x*10+c-'0',c=getchar();
return f*x;}
void printtt(int x){if(x<0)putchar('-'),x=-x;
if(x>=10)printtt(x/10);putchar(x%10+'0');}
bool addd(int a,int b){return a>b;};
//
const int maxm=2e5+5;
int a[maxm];
signed main(){
    int k=re,n=re;
    ff(i,n)a[i]=re;
    int mi=0;
    for(int i=2;i<=n;i++){
        mi=max(mi,a[i]-a[i-1]);
    }
    mi=max(mi,a[1]+k-a[n]);
    cout<<k-mi;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        while (n-- > 0) {
            Circle a = new Circle(sc.nextDouble(), sc.nextDouble(), sc.nextDouble());
            Circle b = new Circle(sc.nextDouble(), sc.nextDouble(), sc.nextDouble());
            double dx = b.x - a.x;
            double dy = b.y - a.y;
            double r = a.r + b.r;
            double d = Math.sqrt(dx * dx + dy * dy);
            if (d > r) {
                System.out.println(0);
            } else {
                if (a.r < b.r && d + a.r < b.r) {
                    System.out.println(-2);
                } else if (a.r > b.r && d + b.r < a.r) {
                    System.out.println(2);
                } else {
                    System.out.println(1);
                }
            }
        }
    }

    static class Circle {
        double x;
        double y;
        double r;

        Circle(double x, double y, double r) {
            this.x = x;
            this.y = y;
            this.r = r;
        }
    }
}




Measured memory_bytes: 28308
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	string s;
	cin >> s;
	int n = s.length();
	int ans = INF;
	for (int i = 0; i <= n-3; i++) {
		int x = (s[i] - '0');
		int y = (s[i + 1] - '0');
		int z = (s[i + 2] - '0');
		int a = 100 * x + 10 * y + z;
		ans = min(ans, abs(753 - a));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3652
from itertools import product
from sys import maxsize

n, a, b, c = [int(i) for i in input().split()]
l = [int(input()) for _ in range(n)]

min = maxsize
pattern = [0, 1, 2, 3]
for pt in product(pattern, repeat=n):
    mp = 0
    length = [999] + [0] * 3
    for i, k in zip(pt, l):
        if i:
            if length[i]:
                mp += 10
            length[i] += k

    if length.count(0) > 0:
        continue

    mp += abs(a - length[1]) + abs(b - length[2]) + abs(c - length[3])

    if mp < min:
        min = mp

print(min)


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

int main()
{
    int k,x;
    cin >> k >> x;
    cout << ((500 * k >= x) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int ctoi(char);

int main()
{
	int i, j, a[10];
	char num[16];

	while(scanf("%s", num) != EOF){

		for(i=0; i<10; i++)
			a[i] = ctoi(num[i]);

		for(j=8; j>=0; j--){
			for(i=0; i<=j; i++)
				a[i] = (a[i] + a[i+1]) % 10;
		}

		printf("%d\n", a[0]);

	}
	return 0;
}

int ctoi(char c)
{
	int i;
	for(i=0; i<10; i++){
		if(c == '0' + i)
			return i;
	}
	return -1;
}

	

Measured memory_bytes: 540
import sys
input = sys.stdin.readline


def main():
    A, B, C, K = map(int, input().split())
    if K <= A:
        print(K*1)
        exit()
    if K <= A+B:
        print(A)
        exit()
    if K <= A+B+C:
        print(A-(K-A-B)*1)
        exit()


if __name__ == '__main__':
    main()


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

using ll=long long; 

ll cnt2=0;
ll cnt5=0;

void solve(){
	cnt2=0;cnt5=0;
	ll n;
	cin>>n;
	if(n%2==1){
		cout<<0<<endl;
		return;
	}
	ll n5=n;
	ll ruijo5=1;
	ll ruijo2=1;
	ll ruijocnt5=0;
	ll ruijocnt2=0;
	ll n2=n;
	while(n5!=0){
		n5/=5;
		//cnt5+=n5;
		ruijo5*=5;
		ruijocnt5++;
	}
	ruijo5/=5;
	ruijo5*=2;
	if(ruijo5>n){
		ruijo5/=5;
		ruijocnt5--;
	}
	ruijocnt5--;
	while(n2!=0){
		n2/=2;
		//cnt2+=n2;
		ruijo2*=2;
		ruijocnt2++;
	}
	ruijo2/=2;
	ruijocnt2--;

	//cout<<ruijo5<<endl;
	//cout<<ruijo2<<endl;
	//ll max5jo=n/ruijo5*ruijo5;
	//ll max2jo=n/ruijo2*ruijo2;
	//cout<<max5jo<<endl;
	//cout<<max2jo<<endl;
	//cout<<ruijocnt5<<endl;
	//cout<<ruijocnt2<<endl;
	n2=n;
	n5=n;
	while(ruijocnt2>0){
		cnt2+=(n2/ruijo2);
		ruijo2/=2;
		ruijocnt2--;
	}
	while(ruijocnt5>0){
		cnt5+=(n5/ruijo5);
		ruijo5/=5;
		ruijocnt5--;
	}
	cout<<min(cnt2,cnt5)<<endl;
	//cout<<min(cnt2, cnt5)<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using P = pair<int, int>;
#define mrep(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) mrep(i, 0, n)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int main() {
    st num;
    cin >> num;
    ll sum = 0;
    rep(i, num.size()){
        int dig = num.at(i) - '0';
        sum += dig;
    }
    if(sum % 9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3740
import java.util.HashSet;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String inputString=sc.nextLine();
		String[] inputstrArray = inputString.split(" ");
		int input1 = Integer.parseInt(inputstrArray[0]);
		int input2 = Integer.parseInt(inputstrArray[1]);
		int input3 = Integer.parseInt(inputstrArray[2]);

		HashSet<Integer> set = new HashSet<Integer>();
		set.add(input1);set.add(input2);set.add(input3);

		switch(set.size()) {
		case 1:
		System.out.println("No");
		break;
		case 2:
		System.out.println("Yes");
		break;
		case 3:
		System.out.println("No");
		break;

		}
	}
}

Measured memory_bytes: 23764
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  int f=1;
  a[0]--;
  for(int i=1;i<n;i++){
    if(a[i-1]>a[i]){
      f=0;
      break;
    }
    if(a[i-1]<a[i]){
      a[i]--;
    }
  }
  if(f){
    printf("Yes");
  }else{
    printf("No");
  }
  
  return 0;
}


Measured memory_bytes: 512
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int N;
  int A[2][100] = {0};
  cin >> N;
  rep(i, N) {
    int a;
    cin >> a;
    A[0][i] = a;
  }
  rep(i, N) {
    int a;
    cin >> a;
    A[1][i] = a;
  }

  int maxCount = 0;
  rep(i, N) {
    int sum = 0;
    for(int first = 0; first <= i ; first++) {
      sum += A[0][first];
      // DEBUG(first);
    }
    
    // DEBUG(sum);
    for(int second = i; second < N ; second++) {
      sum += A[1][second];
      // DEBUG(second);
    }

    // DEBUG(sum);
    maxCount = max(sum, maxCount);
  }
  cout << maxCount << endl;
}


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

using namespace std;

#define MOD 1000000007
typedef unsigned long long ULL;
typedef long long LL;
bool checker(LL a, LL b){
    if( abs(a) < abs(b)){
        return true;
    }else{
        return false;
    }
}
bool rchecker(LL a, LL b){
    return !checker(a,b);
}
bool MinusCheck(int mem_of_plus, int mem_of_minus, int K, int N){
    if( N == K && mem_of_minus % 2 == 1){
        return true;
    }
    if( mem_of_plus + mem_of_minus - mem_of_minus % 1 < K){
        return true;
    }
    
    if( mem_of_plus == 0 && K % 2 == 1){
        return true;
    }
    return false;
}
int main(){
    LL *A;
    LL *minus;
    LL *plus;
    LL *calc;
    int mem_of_plus,mem_of_minus,mem_of_calc;
    int K,N;
    int i,j,pos;
    LL ans;
    LL a;
    int count;
    LL bef;
    cin >> N >> K;
    A = new LL[N];
    plus = new LL[N];
    minus = new LL[N];
    calc = new LL[N];

    mem_of_plus = mem_of_minus = 0;
    for(i=0;i<N;i++){
        cin >> a;
        if( a >= 0 ){
            plus[mem_of_plus++] = a;
        }else{
            minus[mem_of_minus++] = a;
        }
        A[i] = a;
    }
    //どうあがいてもマイナス
    if( 
        MinusCheck(mem_of_plus, mem_of_minus, K,N) == true ){
        ans = 1;
        sort(A,A+N,checker);
        for(i=0;i<K;i++){
            ans = ans * A[i];
            ans %= MOD;
            if( ans < 0 ){
                ans += MOD;
            }
        }
    }else{
        sort(minus,minus+mem_of_minus);
        sort(plus,plus + mem_of_plus,std::greater<LL>());
        if(K % 2 == 1){
            i=2;
        }else{
            i=1;
        }
        mem_of_calc = 0;
        for(;i<mem_of_plus;i+=2){
            calc[mem_of_calc++] = plus[i-1] * plus[i];
        }
        for(i=1;i<mem_of_minus;i+=2){
            calc[mem_of_calc++] = minus[i-1] * minus[i];
        }
        sort(calc,calc + mem_of_calc,std::greater<LL>());
        if(K % 2 == 1){
            ans = plus[0];
        }else{
            ans = 1;
        }
        for(i=0;i<K/2;i++){
            ans = ans * (calc[i] % MOD);
            ans %= MOD;
            if( ans < 0 ){
                ans += MOD;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7480
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<pair<int, int> > stones;
        for(int i = 1; i <= N; ++i) {
            int c;
            cin >> c;
            if(stones.empty()) stones.push_back(make_pair(c, 1));
            else {
                if(i % 2 == 0) {
                    if(stones.back().first == c) ++stones.back().second;
                    else {
                        stones.back().first = c;
                        ++stones.back().second;
                        if(stones.size() >= 2) {
                            stones[stones.size()-2].second += stones.back().second;
                            stones.pop_back();
                        }
                    }
                }
                else {
                    if(stones.back().first == c) ++stones.back().second;
                    else stones.push_back(make_pair(c, 1));
                }
            }
        }
        int sum = 0;
        for(int i = 0; i < stones.size(); ++i) {
            if(stones[i].first == 0) sum += stones[i].second;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 908
A, B, C = map(int, input().split())
count = 0
fA = A
fB = B
while A%2 == 0 and B%2 == 0 and C%2 == 0:
    hA = A/2
    hB = B/2
    hC = C/2
    A = hB + hC
    B = hA + hC
    C = hA + hB
    count += 1
    if A == fA and B == fB:
        count = -1 
        break

print(count)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	vector<int> goo (n);
	int s = 0;
	cinv (goo);
	for (auto& x: goo) s += x;
	hm <int, int> kek;
	for (auto& x: goo) {
		++kek[x];
	}
	int q;
	cin >> q;
	while (q--) {
		int a, b;
		cin >> a >> b;
		s -= a * kek[a];
		s += b * kek[a];
		kek[b] += kek[a];
		kek[a] = 0;
		cout << s << '\n';
	}








}

Measured memory_bytes: 7852
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;

ll t=1;

void solve()
{
   cin>>n;
   c=0;
   for(ll i=1;i<n;i++)
   {
       for(ll j=1;j<n;j++)
       {
           if(i*j<n)c++;
           else break;
       }
   }
   cout<<c;
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    
   //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

Measured memory_bytes: 3648
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int ans = 0, g = 0;
		for(int i = 0; i < s.length(); i++)
			if(s.charAt(i) == 'g') {
				if(g == 0)
					g++;
				else {
					g--;
					ans++;
				}
			}
			else {
				if(g == 0) {
					ans--;
					g++;
				}
				else
					g--;
			}
		System.out.println(ans);
	}

}

Measured memory_bytes: 25556
#include <iostream>
using namespace std;
int mx(int x,int y,int z)
{
    if(x >= y && x >= z) return x;
    else if(y >= z && y >= x) return y;
    else return z;
}
void lz(int &x, int &y, int &z, int &cnt)
{
    if((x%2 == 0 && y%2 == 0 && z%2 == 0) || (x%2 != 0 && y%2 != 0 && z%2 != 0))
    {
        cnt--;
    }
    else if((x%2 == 0 && y%2 == 0) || (x%2 != 0 && y%2 != 0))
    {
        x++;
        y++;
    }
    else if((x%2 == 0 && z%2 == 0) || (x%2 != 0 && z%2 != 0))
    {
        x++;
        z++;
    }
    else if((y%2 == 0 && z%2 == 0) || (y%2 != 0 && z%2 != 0))
    {
        y++;
        z++;
    }
}
int main()
{
    int x,y,z;
    cin >> x >> y >> z;
    int cnt = 1;
    //cout << Max;
    lz(x, y, z, cnt);
    int Max = mx(x,y,z);
    cnt += (Max-x + Max-y + Max-z)/2;
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N;
  char str[101] = {};
  scanf("%d", &N);
  scanf("%s", str);

  int excess_close = 0;
  int excess_open = 0;
  int depth = 0;

  for (int i = 0; i < N; i++) {
    if (str[i] == '(') {
      depth++;
      excess_open++;
    } else if (str[i] == ')') {
      if (depth > 0) {
	depth--;
	excess_open--;
      }
      else {
	excess_close++;
      }
    }
    //    printf("%c d %d o %d c%d\n", str[i], depth, excess_open, excess_close);
  }

  for (int i = 0; i < excess_close; i++) {
    printf("(");
  }
  printf("%s", str);
  for (int i = 0; i < excess_open; i++) {
    printf(")");
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
using namespace std;

typedef long long ll;
typedef short int sh;

const int inf=0x3f3f3f3f;
const int MAX=2e5+10;
const int mod=1e9+7;

int main()
{
    int n;
    while(cin>>n)
        cout<<((n+1)*n>>1)<<endl;
    return 0;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> n >> a >> b >> c >> d;
     rep(m,n){
         if(c*(n-1-m)-d*m<=b-a && b-a<=-1*c*m+(n-1-m)*d){
             Cout("YES");
             return 0;
         }
     }
       Cout("NO");
return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int x, y;
	bool ans = false;
	cin >> x >> y;

	for (int i = 0; i < x + 1; i++) {
		int k = x - i;
		if (i * 4 + k * 2 == y ) {
			ans = true;
		}
	}

	if (ans) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 3560
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        new Program().SolveC();
    }

    Scanner sc = new Scanner();
    void Solve()
    {
        int w = sc.NextInt();
        int h = sc.NextInt();
        int n = sc.NextInt();
        int maxX = w;
        int minX = 0;
        int maxY = h;
        int minY = 0;
        for (int i = 0; i < n; i++)
        {
            int x = sc.NextInt();
            int y = sc.NextInt();
            int a = sc.NextInt();
            if (a == 1) minX = Math.Max(minX, x);
            if (a == 2) maxX = Math.Min(maxX, x);
            if (a == 3) minY = Math.Max(minY, y);
            if (a == 4) maxY = Math.Min(maxY, y);
        }
        int ans = (maxX - minX) * (maxY - minY);
        if (ans <= 0) wl(0);
        else wl(ans);
        rk();
    }
    void SolveC()
    {
        int N = sc.NextInt();
        int T = sc.NextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) A[i] = sc.NextInt();
        int maxDiff = 0;
        int minV = A[0];
        int ans = 0;
        for (int i = 1; i < N; i++)
        {
            if (maxDiff < A[i] - minV)
            {
                maxDiff = A[i] - minV;
                ans = 0;
            }
            if (maxDiff == A[i] - minV)
            {
                ans++;
            }
            minV = min(minV, A[i]);
        }
        wl(ans);
        rk();
    }
    // ------------------------------------- //
    void wl(string v) { Console.WriteLine(v); }
    void wl(int v) { Console.WriteLine(v); }
    void rk() { Console.ReadKey(); }
    int max(int v1, int v2) { return Math.Max(v1, v2); }
    int min(int v1, int v2) { return Math.Min(v1, v2); }
    long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
    long lcm(long a, long b) { return a / gcd(a, b) * b; }
}
class Scanner
{
    public Scanner() { }
    private string[] buff = null;
    private int bIndex = 0;
    public string Next()
    {
        if (buff == null || bIndex >= buff.Length)
        {
            buff = Console.ReadLine().Split(' ');
            bIndex = 0;
        }
        return buff[bIndex++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
class Pair<T, K>
{
    public Pair() { }
    public Pair(T f, K s)
    {
        first = f;
        second = s;
    }
    public T first {get; set;}
    public K second {get; set;}
}


Measured memory_bytes: 12248
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(' ').map { it.toLong() }

    val s = LongArray(n + 1)
    for (i in 0 until n) {
        s[i + 1] = s[i] + a[i]
    }

    s.groupBy { it }
            .values
            .map { it.size.toLong() }
            .map { it * (it - 1) / 2 }
            .sum()
            .let { println(it) }
}


Measured memory_bytes: 110752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  string s, t; cin >> s >> t;
  
  int k = N-1;
  while(k >= 0 && s.substr(N-1-k) != t.substr(0,k+1)) k--;
  
  cout << 2*N-k-1 << endl;
}


Measured memory_bytes: 256
import itertools
n = int(input())
l = [int(x) for x in range(1, 99)]
c = list(itertools.combinations_with_replacement(l, 3))

ans = [0]*(10**4)

for x, y, z in c:
    a = x**2 + y**2 + z**2 + x*y + y*z + z*x
    if a <= 10**4:
        s = {x, y, z}
        if len(s) == 1:
            ans[a-1] += 1
        elif len(s) == 2:
            ans[a-1] += 3
        elif len(s) == 3:
            ans[a-1] += 6
for i in range(n):
    print(ans[i])

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

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

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; }


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

    if( b-a==c-b ) cout << "YES" << endl;
    else cout << "NO" << endl;

}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int x;
    cin >> x;
    if (x == 7 || x == 5 || x == 3) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}

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

int main(){
  int n;
  cin>>n;
  bool flag=false;
  if(n%10==9){
    flag=true;
    }
  else if(n/10==9){
    flag=true;
    }
  if(flag) cout<<"Yes";
  else cout<<"No";
  cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <cstring>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

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

int main(void){
	int n;
	while(cin >> n && n){
		stack<PII> stone;
		int a;
		cin >> a;
		if(a) stone.push({1, 1});
		else stone.push({1, 0});
		REP(i, n-1){
			cin >> a;
			if(i%2 == 0 && a != stone.top().second){
				PII b = stone.top();
				stone.pop();
				if(stone.size()) stone.top().first += b.first+1;
				else stone.push({b.first+1, a});
			}else if(a != stone.top().second){
				stone.push({1, a});
			}else{
				stone.top().first++;
			}

		}
		int res = 0;
		while(stone.size()){
			PII b = stone.top();
			stone.pop();
			if(b.second == 0) res += b.first;
		}
		cout << res << endl;
	}
}

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

int count(const string &S) {
    int res = 0;
    for (int i = 0; i+1 < S.size(); ++i) {
        if (S[i] == 'A' && S[i+1] == 'B') ++res;
    }
    return res;
}

int N;
vector<string> S;

long long solve() {
    long long res = 0;
    for (int i = 0; i < N; ++i) res += count(S[i]);

    int a = 0, b = 0, c = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i][0] == 'B' && S[i].back() == 'A') ++a;
        else if (S[i].back() == 'A') ++b;
        else if (S[i][0] == 'B') ++c;
    }
    long long add = 0;
    if (b + c == 0) add = max(0, a-1);
    else add = a + min(b, c);

    res += add;
    return res;
}

int main() {
    while (cin >> N) {
        S.resize(N);
        for (int i = 0; i < N; ++i) cin >> S[i];
        cout << solve() << endl;
    }
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n],c=0;
	vector<int>v;
	for(int i=0;i<n;i++){
	cin>>a[i];
	v.push_back(a[i]);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
	{
		for(int j=i+1;j<v.size();j++)
		{
				for(int k=j+1;k<v.size();k++)
				{
					if((v[i]!=v[j])&&(v[j]!=v[k])&&(v[i]+v[j]>v[k]))
					c++;
				}
		}
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    cin >> N;
    int b = 0;
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        if (c == 'P') b |= 1;
        if (c == 'W') b |= 2;
        if (c == 'G') b |= 4;
        if (c == 'Y') b |= 8;
    }
    cout << (b == 15 ? "Four" : "Three") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main () {

    int n, k;

    string s;

    cin>>n>>k>>s;

    if(s[k-1]=='A')s[k-1]='a';

    if(s[k-1]=='B')s[k-1]='b';

    if(s[k-1]=='C')s[k-1]='c';

    cout <<s<<endl;

} 

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

int main () {
	int x, y;
	
	while(1){
    	cin >> x >> y;
    	if ( x == 0 && y == 0 ){ 
			break;  
		}
		
		if(x < y) {
			cout << x << " " << y << endl;
		}else{
			cout << y << " " << x << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3044
N,A,B=map(int,input().split())
if N>A*B or N<A+B-1:
  print(-1)
  exit()
P=[[] for i in range(B)]
for i in range(N):
  P[i//A].append(i+1)
P=P[::-1]
for i in range(B):
  if len(P[i])==0:
    P[i].append(P[-((N-i-1)//A+1)][-1])
    del P[-((N-i-1)//A+1)][-1]
  else:
    break
Q=[]
for i in range(B):
  for j in range(len(P[i])):
    Q.append(P[i][j])
print(*Q)

Measured memory_bytes: 126360
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int R,C,k;cin>>R>>C>>k;
    map<pair<int,int>,ll> item;
    vin r(k),c(k);vll v(k);
    rep(i,k){
        cin>>r[i]>>c[i]>>v[i];
        item[mp(r[i],c[i])]=v[i];
    }
    vector<vector<vector<ll>>> dp(R+1, vector<vector<ll>>(C+1, vector<ll>(4)));
    rep(i,R)rep(j,C){
        rep(l,4)dp[i+1][j+1][l]=dp[i+1][j][l];
        rep(l,4)dp[i+1][j+1][0]=max(dp[i+1][j+1][0],dp[i][j+1][l]);
        if(item.count(mp(i+1,j+1))){
            rep(l,3)dp[i+1][j+1][l+1]=max(dp[i+1][j+1][l+1],dp[i+1][j][l]+item[mp(i+1,j+1)]);
            rep(l,4)dp[i+1][j+1][1]=max(dp[i+1][j+1][1],dp[i][j+1][l]+item[mp(i+1,j+1)]);
        }
    }
    ll ans=(ll)0;
    rep(i,4)ans=max(ans,dp[R][C][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 652276
n=int(input())
a=0
table=[]
while a<n:
	s=int(input())
	table.append(s)
	a+=1

maxv=-10**9
minv=table[0]
for i in range(1,n,1):
	if maxv<table[i]-minv:
		maxv=table[i]-minv
	if minv>table[i]:
		minv=table[i]
print(maxv)


Measured memory_bytes: 13592
n,m = map(int,input().split())

lst1 = [list(map(int,input().split())) for i in range(n)]
lst2 = [list(map(int,input().split())) for i in range(m)]

ans = []
for x,y in lst1:
    res = 10**9
    for i,seq in enumerate(lst2):
        a = seq[0]
        b = seq[1]
        if res > abs(a-x)+abs(b-y):
            ct = i
            res = abs(a-x)+abs(b-y)
    ans.append(ct)

for i in ans:
    print(i+1)

Measured memory_bytes: 39536
#include <iostream>
using namespace std;
const int MOD = 1000000000 + 7;
#define MAXN 100007

long long ans[MAXN];

int main() {
    ans[0] = 1;
    for( int i = 1; i <= 100000; i++ ) {
        ans[i] = (ans[i-1] % MOD * i ) % MOD;
    }
    int n;
    while( cin >> n ) {
        cout << ans[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <list>
#include <vector>
#include <queue>
#include <bitset>
#include <cctype>
#include <algorithm>


typedef long long ll;
#define nn cout << '\n'
#define rep(n) for(int i = 0; i < n; i++)
#define repi(n) for(int i = 0; i <n; i++)

using namespace std;


void testcase() {
	int n, k; cin >> n >> k;
	vector<pair<int,int>> v(n);
	for (int i = 1; i <= n; i++) {
		int x; cin >> x;
		v[i - 1] = make_pair(x,i);
	}
	sort(v.begin(), v.end());
	ll sum = 0;
	for (int i = 0; i < k; i++) {
		sum += v[i].first;
	}

	cout << sum;


}


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

	int x = 1;
	rep(x) {
		testcase();
		nn;

	}
	return 0;
}

/*

*/

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    string s;
    cin >> s;

    int res = 0;
    int l = s.size();
    for(int i=0; i<(1<<(l-1)); i++) {
        int seq = l-1;
        int a = 1, mul = 1;
        while(true) {
            res += (s[seq--]-'0')*mul;
            if(!(a&i)) mul *= 10;
            else mul = 1;
            a <<= 1;
            if(seq<0) break;
        }
    }

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

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
from functools import lru_cache
import sys
sys.setrecursionlimit(2147483647)

@lru_cache(None)
def up(i):
    if i == 0: 
        return 0
    res1 = res2 = float("inf")
    res1 = up(i- 1)
    if i -2 >=0:
        res2 = up(i -2)
    return min(abs(A[i-2] - A[i]) + res2,abs(A[i-1] - A[i]) + res1)

print(up(N-1))
    


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

#define  int        long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int n;
    cin>>n;
    cout<< (1000- n%1000)%1000;
}

Measured memory_bytes: 3644
#include <cstdio>
using namespace std;

constexpr int MOD = 1000000007;

int main() {
	int N;
	scanf("%d%*c", &N);
	bool S[N * 2];
	char c;
	for(int i = 0; i < N * 2; i++) {
		scanf("%c", &c);
		S[i] = (c == 'B');
	}

	long long ans = 1;
	int acc = 0;
	for(int i = 0; i < N * 2; i++) {
		if((acc & 1) ^ S[i]) {
			acc++;
		} else {
			if(acc == 0) {
				printf("0\n");
				return 0;
			}
			ans *= acc--;
			ans %= MOD;
		}
	}
	if(acc != 0) {
		printf("0\n");
		return 0;
	}

	for(int i = 2; i <= N; i++) {
		ans *= i;
		ans %= MOD;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
# D - Wall

from scipy.sparse.csgraph import floyd_warshall

H, W = map(int, input().split())
c = []
for _ in range(10):
    c.append(list(map(int, input().split())))
A = []
for _ in range(H):
    A.append(list(map(int, input().split())))
    
dist_matrix = floyd_warshall(c)

ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] != -1:
            ans += int(dist_matrix[A[h][w]][1])
            
print(ans)

Measured memory_bytes: 14056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005,INF=1<<30;

int main(){
    
    int N;cin>>N;
    if(N%2==0) cout<<0.5<<endl;
    else cout<<setprecision(25)<<double((N+1)/2)/double(N)<<endl;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<String> set = new HashSet<>();
		for(int i = 0; i < n; i++){
			set.add(sc.next());
		}
		System.out.println(set.size());
	}
}


Measured memory_bytes: 78436
#include <stdio.h>
#include <math.h>

int main(void)
{
	int d, sd;
	long s = 0;
	while (scanf("%d", &d) != EOF){
		sd = 0;
		s = 0;
		while (sd != 600 - d){
			sd += d;
			s += d * pow(sd, 2);
		}
		
		printf("%ld\n", s);
	}
	
	return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
const int M=200001;
int a,b;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b;
	if(a%b==0)cout<<-1<<endl;
	else cout<<a<<endl;


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	double t1[7] = {35.5,37.5,40,43,50,55,70}, t2[7] = {71,77,83,89,105,116,148};
	double R1,R2;
	while(cin>>R1>>R2){
		int c1=7,c2=7;
		for(int i=6;i>=0;i--){
			if(R1<t1[i]) c1 = i;
			if(R2<t2[i]) c2 = i;
		}
		int c = max(c1,c2);
		if(c==0) puts("AAA");
		else if(c==1) puts("AA");
		else if(c==2) puts("A");
		else if(c==3) puts("B");
		else if(c==4) puts("C");
		else if(c==5) puts("D");
		else if(c==6) puts("E");
		else puts("NA");
	}
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =998244353;
const ll inf =1e18;
using namespace std;

ll n;
ll cnt[101010];
bool flag;
int main(){
    cin>>n;
    REP(i, 0, n){
        ll d;
        cin>>d;

        cnt[d]++;
        if(i==0 && d==0) flag=true;
    }

    if(!flag || cnt[0]!=1){
        cout<<0<<endl;
        return 0;
    }

    ll ans=1, sum=0, i=0;
    while(sum<n){
        if(cnt[i]<=0){
            ans=0;
            break;
        }
        else if(i>0 && cnt[i-1]>1){
            REP(j, 0, cnt[i]){
                ans*=cnt[i-1];
                ans%=mod;
            }
        }

        sum+=cnt[i];
        i++;
    }

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

Measured memory_bytes: 1024
def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    ans = 0
    for x in range(1, N+1):
        if (K-1)*x + 1 >= N:
            ans = x
            break
    print(ans)
main()

Measured memory_bytes: 83828
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

//ll dp[110][110][310];
ll dp[110][410][110];

int main(){
    ll N, W; cin >> N >> W;
    ll w1, v1; cin >> w1 >> v1;
    dp[1][1][1] = v1;
    FOR(i, 1, N){
        ll w, v; cin >> w >> v;
        w -= w1-1;
        REP(j, 410) REP(k, 105){
            if(j >= w) dp[i+1][j][k+1] = max(dp[i][j][k+1], dp[i][j-w][k]+v);
            else dp[i+1][j][k] = dp[i][j][k];
        }
    }
    ll ans = 0;
    REP(i, 410) REP(k, i+1){
       if(k*(w1-1) + i <= W) ans = max(ans, dp[N][i][k]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 36604
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned int uint;
typedef unsigned long long ulint;
constexpr lint mod = 1e9+7;

template<typename T>
struct ST{
  using F = function<T(T, T)>;
  int size_ = 1;
  vector<T> node;
  T initial;
  F query_, update_;
  ST(int n, T initial, F query, F update){
    while(size_ < n) size_ *= 2;
    node.resize(2*size_-1, initial);
    query_ = query;
    update_ = update;
  }
  void nodes(){
    rep(i, node.size()) cout << node[i] << endl;
    return;
  }
  void build(vector<T> v){
    rep(i, v.size()) node[i+size_-1] = v[i];
    rrep(i, size_ - 1) node[i] = query_(node[2*i+1], node[2*i+2]);
    return;
  }
  void update(int j, T x){
    j += size_-1;
    node[j] = update_(node[j], x);
    while(j > 0){
      j = (j-1)/2;
      node[j] = query_(node[2*j+1], node[2*j+2]);
    }
    return;
  }
  T query(int l, int r){
    l += size_-1;
    r += size_-1;
    T ql = node[l], qr = node[r];
    while(l < r-1){
      if(l % 2 == 1) ql = query_(ql, node[l+1]);
      if(r % 2 == 0) qr = query_(node[r-1], qr);
      l = (l-1)/2;
      r = (r-1)/2;
    }
    return query_(ql, qr);
  }
};

int main() {
  int n, q;
  string s;
  cin >> n >> s >> q;
  auto f = [](int a, int b){return a | b;};
  auto g = [](int a, int b){return b;};
  ST<int> st(n, 0, f, g);
  vector<int> v(n);
  rep(i, n) v[i] = 1 << (s[i] - 'a');
  st.build(v);
  rep(i, q){
    int c;
    cin >> c;
    if(c == 1){
      int j;
      char x;
      cin >> j >> x;
      st.update(j-1, 1 << (x - 'a'));
    }
    else if(c == 2){
      int l, r, tmp;
      cin >> l >> r;
      tmp = st.query(l-1, r-1);
      cout << __builtin_popcount(tmp) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 8836