akhauriyash/Code-Regression huggingface dataset:
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: usize = sc.read();
    let ss: Vec<char> = sc.chars();
    let mut count: usize = 0;
    if ss[0] == '0' {
        count += 1;
    }
    let mut s = 0;
    let mut i = 1;
    let mut result = 1;
    while i < n {
        if ss[i - 1] == '1' && ss[i] == '0' {
            count += 1;
            if count > k {
                while ss[s] == '1' {
                    s += 1;
                }
                while ss[s] == '0' {
                    s += 1;
                }
                i = std::cmp::max(i, s);
                count -= 1;
            }
        }
        result = std::cmp::max(result, i - s + 1);
        i += 1;

    }
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(256 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 8572
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    bool tak = true;
    while(1){
        if(tak){
            c -= b;
            if(c <= 0){
                cout << "Yes" << endl;
                break;
            }
        }
        else{
            a -= d;
            if(a <= 0){
                cout << "No" << endl;
                break;
            }
        }
        tak = !tak;
    }

    return 0;
}

Measured memory_bytes: 3068
#include<stdio.h>
int main()
{
  char s[3][4]={};
  scanf("%s", &s[0]);
  scanf("%s", &s[1]);
  scanf("%s", &s[2]);
  printf("%c%c%c", s[0][0],s[1][1],s[2][2]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, sum = 0;
    cin >> n;
    int l[n * 2];
    for (int i = 0; i < n * 2; ++i)
        cin >> l[i];
    sort(l, l + n * 2);
    for (int i = 0; i < n * 2; i += 2)
        sum += l[i];
    cout << sum;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

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

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

ll mod_pow(ll x, ll n) {
    ll a = 1;
    while (n) {
        if (n%2) a = a*x%INF;
        x = x*x%INF;
        n/=2;
    }
    return a;
}

map<long, int> prime;
int main(){
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int tmp = M;
    for(int i=2; i*i <= M; i++) {
        while(tmp%i == 0) {
            tmp/=i;
            prime[i]++;
        }
    }
    if (tmp != 1) prime[tmp]++;
    ll ans = 1;
    for(auto x: prime) {
        int bi = x.second;
        ll t = bi + N - 1;
        ll tans = 1;
        for (int i = 0; i < bi; i++) {
            tans *= t - i;
            tans %= INF;
        }
        if (tans < 0) cout << tans << endl;
        for (int i = 1; i <= bi; i++) {
            tans *= mod_pow(i, INF-2);
            tans %= INF;
        }
        ans *= tans;
        ans %= INF;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    string s;
    string ans="Yes";
    cin >> s;
    for(int i=0; i<s.length(); i++){
        if(i%2==0 && s[i]=='L'){
            ans="No";
        }
        if(i%2==1 &&s[i]=='R'){
            ans="No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    row_input = input()
    row_input = row_input.split()
    A = int(row_input[0])
    B = int(row_input[1])

    if B % A == 0:
        print(A+B)
    else:
        print(B-A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
    int face_a[6] = {},face_b[6] = {},dice[6][7] = { {1,2,4,3,1,2,4},{0,3,5,2,0,3,5},{0,1,5,4,0,1,5},{0,4,5,1,0,4,5},{0,2,5,3,0,2,5},{1,3,4,2,1,3,4} };
    for(int i=0;i<6;i++){
      cin >> face_a[i];
    }
    for(int i=0;i<6;i++){
        cin >> face_b[i];
    }
    int a =0;
    while(true){
        if(face_b[0] == face_a[a])break;
        a +=1;
    }
    int b=0;
    while(true){
        if(face_b[1] == face_a[b])break;
        b +=1;
    }
    int c=0;
    while(true){
        if(dice[a][c] == b)break;
        c +=1;
    }
    if(face_a[dice[a][c+1]] == face_b[2] && face_a[dice[a][c+3]] == face_b[3] && face_a[dice[a][c+2]] == face_b[4])cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



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

#define all(x) (x).begin(),(x).end()

#define MOD 1000000007

using namespace std;

bool comp( pair<int,int>a, pair<int, int>b ){
	return a.first < b.first;
}

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

	vector< pair<int, int> > a(n);
	for( int i=0; i<n; i++ ){
		cin >> a[i].first;
		a[i].second = i+1;
	}

	sort( all(a), comp );

	for( int i=0; i<n-1; i++ )	cout << a[i].second << " ";
	cout << a[n-1].second << endl;

	return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>

int main(){
    int t[4][14];
    int n,i,j,c;
    char m,d;
    for(i=0;i<4;i++){
        for(j=0;j<14;j++){
            t[i][j]=0;
        }
    }
    scanf("%d",&c);
    for(i=0;i<c;i++){
        scanf("%c",&d);
        scanf("%c %d",&m,&n);
        if(m=='S'){
            t[0][n]=1;
        }
        else if(m=='H'){
            t[1][n]=1;
        }
        else if(m=='C'){
            t[2][n]=1;
        }
        else if(m=='D'){
            t[3][n]=1;
        }
    }
    for(j=1;j<14;j++){
        if(t[0][j] != 1){
            printf("S %d\n",j);
        }
    }
    for(j=1;j<14;j++){
        if(t[1][j] != 1){
            printf("H %d\n",j);
        }
    }
    for(j=1;j<14;j++){
        if(t[2][j] != 1){
            printf("C %d\n",j);
        }
    }
    for(j=1;j<14;j++){
        if(t[3][j] != 1){
            printf("D %d\n",j);
        }
    }
    return 0;
}


Measured memory_bytes: 2100
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

from collections import defaultdict

s = ns()
d = defaultdict(int)
d[0] += 1
k = 1
n = 0
for i in range(len(s))[::-1]:
    n += int(s[i])*k%2019
    n%=2019
    d[n] += 1
    k = (k*10)%2019

ans = 0

for j in d.values():
    if j > 1:
        ans += j*(j-1)//2

print(ans)

Measured memory_bytes: 9576
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
long long gcd(long long a, long long b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
int main() {
	long long n, a = 0; string s; cin >> s;
	if (s[0] != 'A') { cout << "WA" << endl; cin >> n; return 0; }
	for (int h = 1; h < s.size(); h++) {
		if (h == 1 || h == s.size() - 1) { 
			if (s[h] >= 'A'&&s[h] <= 'Z') { 
				cout << "WA" << endl; cin >> n; return 0;
			}
		}
		else {
			if (s[h] >= 'A'&&s[h] <= 'Z' && s[h] != 'C') {
				cout << "WA" << endl; cin >> n; return 0;
			}
			if (s[h] == 'C') { a++; }
		}
	}
	if (a == 1) {
		cout << "AC" << endl;
	}
	else {
		cout << "WA" << endl;
	}
	cin >> n;
}

Measured memory_bytes: 256
X, Y = map(int, input().split())
n, mod = divmod(X + Y, 3)


def modinv(a, mod=10 ** 9 + 7):
    return pow(a, mod - 2, mod)


def combination(n, r, mod=10 ** 9 + 7):
    r = min(r, n - r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i + 1, mod) % mod
    return res


if mod != 0 or not (X <= 2 * Y and Y <= 2 * X):
    print(0)
else:
    r = Y - n
    print(combination(n, r))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 102;
int a[N], n, c[N];

int main() {
    scanf("%d", &n);
    for(int i=1;i<=n;i++) {
        scanf("%d", &a[i]); c[a[i]] ++;
    }

    sort(a+1,a+1+n);
    if (a[n] == 1) {
        return !printf("%s\n", n==2 ? "Possible" : "Impossible");
    }
    if (a[n-1] != a[n]) {
        return !printf("Impossible\n");
    }
    for(int i=1;i<=a[n]+1;i++) {
        //printf("# %d\n", max(a[n]+1-i, i-1));
        c[max(a[n]+1-i, i-1)] --;
        if(c[max(a[n]+1-i, i-1)] < 0) return !printf("Impossible\n");
    }

    for(int i=1;i<=a[n];i++){
        //printf("i=%d\n", i);
        if(c[i] && i<=(a[n]+1)/2) return !printf("Impossible\n");
    }
    printf("Possible\n");
}
/*
# # # # # #
*/


Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        x: i64,
        y: i64,
    }

    let mut ans = std::i64::MAX;
    if x <= y {
        // 最初にも最後にも B を押さない
        ans = ans.min(y - x);
    }
    if -x <= y {
        // 最初に B を押し最後に B を押さない
        ans = ans.min(y + x + 1);
    }
    if x <= -y {
        // 最初に B を押さず最後に B を押す
        ans = ans.min(-y - x + 1);
    }
    if -x <= -y {
        // 最初にも最後にも B を押す
        ans = ans.min(-y + x + 2);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2116
#include <iostream>
using namespace std;
int main() {
  int a;
  cin >> a;
  int ans = 0;
  int num = a;
  for(int j=1; j<=num; ++j){
    if(j%2!=0){
      //cout << endl << j << ":";
      int tmp = 0;
      for(int i=1; i<=j; ++i ){
        if( j%i == 0 ){
          tmp += 1;
          //cout << i << ",";
        }
      }
      if(tmp == 8){
        //cout << j << endl;
        ans += 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  int a[100][100];
  int b[100];
  int c[100];
  int i,j;
  for(i = 0; i < n;i++){
    for(j = 0;j < m;j++){
      cin >> a[i][j];
    }
  }
  for(i = 0;i < m;i++){
    cin >> b[i];
  }

  for(i = 0;i < n;i++){
    for(j = 0; j < m;j++){
      c[i] += a[i][j]*b[j];
    }
    cout << c[i] << endl;
  }
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  ll f[242], x;
  for(ll i = 0; i < 242; i++)
    f[i] = (i - 120) * (i - 120) * (i - 120) * (i - 120) * (i - 120);
  scanf("%lld", &x);
  for(int i = 0; i < 242; i++) {
    for(int j = 0; j < 242; j++) {
      if(f[i] - f[j] == x) {
        printf("%d %d\n", i - 120, j - 120);
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3828
#include<stdio.h>
int main()
{
  int n;
  double a,sum=0,ans;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
    scanf("%lf",&a);
    sum+=1.0/a;
  }
  ans=1.0/sum;
  printf("%lf ",ans);
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s.at(i)+n > 'Z') printf("%c",s.at(i)+(n-26));
        else printf("%c",s.at(i)+n);
    }
    cout << endl;
}

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

// 辺の長さがA, Bの平行四辺形内での軌道の長さ
ll reflect(ll A, ll B) {
    if (A > B) swap(A, B);

    ll ref = B / A;
    if (B % A == 0) {
        return (ref * 2 - 1) * A;
    } else {
        return ref * 2 * A + reflect(B % A, A);
    }
}

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

    cout << N + reflect(X, N - X) << endl;
    return 0;
}


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

const int MX = 400010;
vector<vector<int>> adj(MX+1);

//adding edge utility
void add_edge(vector<vector<int>> &ref, int start, int end, bool dir) {

    ref[start].push_back(end);
    if(!dir) {
        ref[end].push_back(start);
    }
    
}    

std::vector<bool> vis(MX+1,false);
std::vector<ll> comp;

//DFS
void dfs(int v) {
    vis[v] = true;
    comp.push_back(v);
    for(auto u: adj[v]) {
        if(!vis[u]) {
            dfs(u);
        }
    }
    return;
}

// CONNECTED COMPONENTS
void find_comps(int n) {
    // std::vector<ll> arr;
    ll ans = INT_MIN;
    for(int i = 0; i < n; i++) {
        if(!vis[i]) {
            comp.clear();
            dfs(i);
            // for(auto u: comp) {
            //     cout << u << ' ';
            // }
            // cout << '\n';
            // arr.push_back(comp.size());
            ans = max(ans,(ll)comp.size());
        }
    }
    cout << ans << '\n';
    // for(auto it: arr) {
    //     cout << it << '\n';
    // }
}


//testing
int32_t main(){
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
        // for debug in error.txt
        freopen("error.txt", "w", stderr);
    #endif
    int t = 1;
    while(t--) {
        ll n, m;
        cin >> n >> m;
        while(m--) {
            int s,d;
            cin >> s >> d;
            s--,d--;
            add_edge(adj,s,d,0);
        }
        find_comps(n);
    }
}

Measured memory_bytes: 33008
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 200000 + 10;
const int MOD = 998244353;

inline int inc(int a, int b) { return (a + b >= MOD) ? (a + b - MOD) : (a + b); }
inline int dec(int a, int b) { return (a >= b) ? (a - b) : (a + MOD - b); }
inline int mul(int a, int b) { return 1LL * a * b % MOD; }

inline int power(int x, int k) {
	int tmp = 1;
	while(k) {
		if(k & 1) tmp = mul(tmp,x);
		x = mul(x,x);
		k >>= 1;
	}
	return tmp;
}

int n, arr[2][maxn], mi[maxn], f[maxn], lis[maxn], im[maxn], inv2;
char s[maxn];

inline int get_num(int l, int r, int kd) {
	int tmp = dec(arr[kd][r],mul(mi[r - l + 1],arr[kd][l - 1]));
	return tmp;
}

inline int LCP(int l1, int r1, int l2, int r2, int kd) {
	int len = min(r1 - l1 + 1,r2 - l2 + 1);
	int l = 0, r = len, tmp = 0;
  while(l <= r) {
    int mid = (l + r) >> 1;
		int t1 = get_num(l1,l1 + mid - 1,kd);
		int t2 = get_num(l2,l2 + mid - 1,0);
		if(t1 == t2) l = mid + 1, tmp = mid;
		else r = mid - 1;
	}
	return tmp;
}

inline int calc(int x) {
	int now = get_num(1,x,0);
	int flag = 1;
	for(int i = x + 1, kd = 1;i <= n;i += x, kd = 1 - kd) {
		int len = LCP(1,x,i,i + x - 1,kd);
		if(len == x) continue;
		if(!kd) {
			if(s[len + 1] == '0') flag = 1;
			else flag = 0;
			break;
		}
		else {
      if(s[len + 1] == '1') flag = 1;
			else flag = 0;
			break;
		}
	}
	now = inc(now,flag);
	return now;
}

int main() {
  scanf("%d%s", &n, s + 1);
  arr[0][0] = arr[1][0] = 0;
	for(int i = 1;i <= n;i ++) {
		arr[0][i] = inc(mul(2,arr[0][i - 1]),s[i] - '0');
		arr[1][i] = inc(mul(2,arr[1][i - 1]),!(s[i] - '0'));
	}
	inv2 = power(2,MOD - 2);
	mi[0] = 1; for(int i = 1;i <= n;i ++) mi[i] = mul(mi[i - 1],2);
	im[0] = 1; for(int i = 1;i <= n;i ++) im[i] = mul(im[i - 1],2);
	int Ans = 0, lcnt = 0;
	for(int i = 1;i * i <= n;i ++) {
		if(n % i == 0) {
			if((n / i) & 1) lis[++ lcnt] = i;
			if((n / i != i) && (i & 1)) lis[++ lcnt] = n / i;
		}
	}
	sort(lis + 1,lis + lcnt + 1);
	for(int i = 1;i <= lcnt;i ++) {
		f[i] = calc(lis[i]);
		for(int j = 1;j < i;j ++) {
			if(lis[i] % lis[j] == 0) f[i] = dec(f[i],f[j]);
		}
		Ans = inc(Ans,mul(f[i],mul(2,lis[i])));
	}
	printf("%d\n", Ans);
	return 0;
}


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

int main()
{

  int x,y,z,res;

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

  if(x<1 || y>1000000000) exit(2);

  if(x<y){
    z=x;
    x=y;
    y=z;
  }

  res = x%y;
  while(res!=0){
    x=y;
    y=res;
    res = x%y;
  }
  printf("%d\n",y);

  return 0;
}



Measured memory_bytes: 2124
#include <stdio.h>


int main(void) {

	// 1_6-C Official House

	int i,j,k;

	int b,f,r,v,n;
	int rooms[4][3][10];
	for(i=0; i<4; i++){
		for(j=0; j<3; j++){
			for(k=0; k<10; k++){
				rooms[i][j][k] = 0;
			}
		}
	}
	scanf("%d\n",&n);

	for(i=0; i<n; i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		b--;
		f--;
		r--;
		rooms[b][f][r] = rooms[b][f][r] + v;
	}

	for(i=0; i<4; i++){
		for(j=0; j<3; j++){
			for(k=0; k<10; k++){
				printf(" %d",rooms[i][j][k]);
			}
			putchar('\n');
		}
		if(i<3){
			for(j=0; j<20; j++){
				putchar('#');
			}
			putchar('\n');
		}
	}
        return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int n, m, x, i, j, k, ans=1e9;
int a[15][15], b[15], c[15];
void dfs(int k, int v){
	int i, j, s;
	if(v >= ans) return;
	if(k > n){
		for(j=1; j<=m; j++){
			s = 0;
			for(i=1; i<=n; i++){
				s += a[i][j] * b[i];
			}
			if(s < x) return;
		}
		ans = v;
	}
	else{
		for(i=0; i<=1; i++){
			b[k] = i;
			dfs(k+1, v+c[k]*i);
		}
	}
}
int main(){
	scanf("%d%d%d", &n, &m, &x);
	for(i=1; i<=n; i++){
		scanf("%d", &c[i]);
		for(j=1; j<=m; j++){
			scanf("%d", &a[i][j]);
		}
	}
	dfs(1, 0);
	if(ans < 1e9) printf("%d\n", ans);
	else printf("-1\n");
	return 0;
}

Measured memory_bytes: 1732
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		String c = scan.next();
		char[] c1 = c.toCharArray();
		int ans = c1[0] + 1;
		
		System.out.print((char)ans);
	}

}


Measured memory_bytes: 35652
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T & a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T & a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<class T> void getVector(vector<T> & v) {
	for (int i = 0; i < v.size(); ++i)
		cin >> v[i];
}

int main() {
	double a, b;
	cin >> a >> b;
	vector<double> ans = { a * b,2 * (a + b) };
	say(ans);
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

ll fac[500010], ans;

ll power(int x, int n) {
    ll res = 1, now = x;
    for (;n;n>>=1,now=now*now%mod) if (n&1) res = res*now%mod;
    return res;
}

ll nCr(int n, int r) {
    return fac[n]*power(fac[r], mod-2)%mod*power(fac[n-r], mod-2)%mod;
}

ll nPr(int n, int r) {
    return fac[n]*power(fac[n-r], mod-2)%mod;
}

int main() {
    ios_base::sync_with_stdio(0);
    int n, m; cin >> n >> m;

    fac[0] = 1;
    for (int i=1;i<=m;i++) fac[i] = fac[i-1]*i%mod;

    for (int i=0;i<=n;i++) {
        ll now = (i&1? mod-1: 1)*nCr(n, i)%mod;
        now = now*nPr(m, i)%mod;
        now = now*nPr(m-i, n-i)%mod*nPr(m-i, n-i)%mod;
        ans += now;
        if (ans>=mod) ans -= mod;
    }

    cout << ans << endl;
}


Measured memory_bytes: 7416
import sys
def input():
    return sys.stdin.readline()[:-1]

class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)


    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

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

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

inf=float("inf")
n,m=map(int,input().split())
p=list(map(int,input().split()))
xy=[list(map(int,input().split())) for i in range(m)]

uf=WeightedUnionFind(n+1)
cnt=0
for i in range(m):
    uf.union(xy[i][0],xy[i][1],0)
for i in range(n):
    if uf.same(i+1,p[i]):
        cnt+=1
print(cnt)

Measured memory_bytes: 105580
// JOI - Prelim  0524
// 星座探し
use std::fmt::Debug;
use std::str::FromStr;
use std::collections::*;

// std input(line)
fn read_line<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

fn sub() -> bool
{
    let ms = read_line();
    let m = ms[0];
    if m == 0 {
        return false;
    }
    let mut m_xys = Vec::with_capacity(m);
    let mut base_x = 0;
    let mut base_y = 0;
    for i in 0..m {
        let mut line: Vec<i64> = read_line();
        if i == 0 {
            base_x = line[0];
            base_y = line[1];
        }
        else {
            line[0] -= base_x;
            line[1] -= base_y;
            m_xys.push(line);
        }
    }
    let ns = read_line();
    let n = ns[0];
    let mut n_xys = HashSet::with_capacity(n);
    for _i in 0..n {
        let ns: Vec<i64> = read_line();
        n_xys.insert(ns);
    }

    if m == 1 {
        // 例外:探したい星が1つのみ
        assert!(m_xys.is_empty());
        for n_xy in &n_xys {
            println!("{} {}", n_xy[0] - base_x, n_xy[1] - base_y);
            return true;
        }
    }

    let mut matchs = Vec::new();
    for n_xy in &n_xys {
        if !m_xys.iter().all(|m_xy| {
            matchs.clear();
            matchs.push(n_xy[0] + m_xy[0]);
            matchs.push(n_xy[1] + m_xy[1]);
            n_xys.contains(&matchs)
        }) {
            continue;
        }
        println!("{} {}", n_xy[0] - base_x, n_xy[1] - base_y);
    }

    return true;
}

fn main()
{
    loop {
        if !sub() {
            return;
        }
    }
}


Measured memory_bytes: 5060
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
#include <numeric>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)


void solve(){
  int n,d;
  cin >> n >> d;
  double x[15][15];
  rep(i,n){
    rep(j,d){
      cin >> x[i][j];
    } 
  }
  
  int count = 0;
  for(int i=0; i<n; i++){
    for(int k=0; k<n; k++){
    double sum = 0;
    rep(j,d){
      sum += pow((x[k][j] - x[i][j]), 2); 
    }
      //cout << i << " " << k << ":" << sum << endl;
    if(sum - pow((int)sqrt(sum),2) < 0.00001 && i!=k){
      count++; 
      //cout << i << " " << k << endl;
    }
    }
  }
  cout << count/2 << endl;
}

int main(){
  solve();
  return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> L(N);
	for (int i = 0; i < N; i++) {
		cin >> L[i];
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (L[i] != L[j]) {
				for (int k = j + 1; k < N; k++) {
					if (L[i] != L[k] && L[j] != L[k]) {
						vector<int> temp(3);
						temp[0] = L[i];
						temp[1] = L[j];
						temp[2] = L[k];
						sort(temp.begin(), temp.end());
						if (temp[2] < temp[0] + temp[1]) {
							ans++;
						}
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;



}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>

void main()
{
    int A,B,C,K;
    int i;
    int Z=0;

    scanf("%d %d %d %d", &A, &B, &C ,&K);

    if((A < 0) || (B < 0) || (C < 0)){
        printf("[ERROR]\n");
    }

    if(!((K >= 1) && (K <= (A+B+C)) && ((A+B+C)<=(2000000000)))){
        printf("[ERROR]\n");
    }

    if(A >= K) A = K;
    Z += A;
    K = K - A;
    if(B >= K) B = K;
    // 何もしない
    K = K - B;
    if(C >= K) C = K;
    Z -= C;

    printf("%d\n", Z);
}


Measured memory_bytes: 1732
#include<stdio.h>
int main(void)
{
	int n,i,age;
	
	while (1) {
		scanf("%d", &n);
		if (n == 0)break;
		int age_count[7] = {0};
		for (i = 0; i < n; i++) {
			scanf("%d", &age);

			if (age < 10)
				age_count[0]++;
			else if (age >= 10 && age < 20)
				age_count[1]++;
			else if (age >= 20 && age < 30)
				age_count[2]++;
			else if (age >= 30 && age < 40)
				age_count[3]++;
			else if (age >= 40 && age < 50)
				age_count[4]++;
			else if (age >= 50 && age < 60)
				age_count[5]++;
			else
				age_count[6]++;
		}
		for (i = 0; i < 7; i++) {
			printf("%d\n", age_count[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 600
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_c

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};
vector<ll> a;
vector<ll> b;
vector<ll> c;
vector<ll> d;

ll N, M, Q;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}
ll ans;

// dfsは終了条件をまず考える
// その後に各ステップで何やって再帰につなげるか

void dfs(vector<ll> A) {
  if (A.size() == N+1) {
    ll now = 0;
    rep(i, Q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }

  A.push_back(A.back());
  while (A.back() <= M) {
    dfs(A);
    A.back()++;
  }
}

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

  cin >> N >> M >> Q;
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  rep(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i] ;
  dfs(vector<ll>(1,1));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3660
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nf = lambda: map(float, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)


a,b,c = nm()

if c -a -b < 0: 
    print('No')
    exit(0)

#print(a,b,c)
if (c - a -b ) **2 - 4 * (a*b) > 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
ans = 0
exist = False
if N == 1:
  x = 0
else:
  x = 10 ** (N - 1)
for i in range(x, 1000):
  s = str(i)
  f = True
  for j in range(M):
    if int(s[sc[j][0] - 1]) != sc[j][1]:
      f = False
      break
  if f:
    ans = i
    exist = True
    break
print(ans if exist else -1)

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 n;
  cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int cnt=0;
  while(1){
    bool ans=false;
    rep(i,n){
      if(a[i]%2==1)ans=true;
      a[i]/=2;
    }
    if(ans)break;
    cnt++;
  }
  cout<<cnt<<endl;
}
    

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<ctime>
#include<cstdlib>
#include<numeric>
#include<typeinfo>
#include<cstdio>
#include<cctype>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
const int inf=1e8;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009

int main(void){
	int n,q,i;
	cin>>n>>q;
	queue<string> name;
	queue<int> time;
	loop(i,0,n){
		int temp1;
		string temp2;
		cin>>temp2>>temp1;
		name.push(temp2);
		time.push(temp1);
	}
	int sum=0;
	while(!time.empty()){
		if(time.front()>q){
			sum+=q;
			int front1=time.front()-q;
			time.pop();
			time.push(front1);
			string front2=name.front();
			name.pop();
			name.push(front2);
		}else{
			sum+=time.front();
			string front2=name.front();
			cout<<front2<<" "<<sum<<"\n";
			name.pop();
			time.pop();
		}
	}
}

Measured memory_bytes: 5656
use std::io::{BufRead, Write};

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut writer = std::io::BufWriter::new(stdout.lock());

    let (x, y): (usize, usize) = {
        let mut buf = String::new();
        reader.read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };

    for i in 0..(x + 1) {
        if i * 2 + (x - i) * 4 == y {
            writeln!(writer, "Yes").unwrap();
            return;
        }
    }
    writeln!(writer, "No").unwrap();
}

Measured memory_bytes: 2160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	int n, min = 1000000, num, ans = 0;

	std::cin >> n;

	for (size_t i = 0; i < n; i++)
	{
		std::cin >> num;
		if (min > num) {
			ans++;
		}
		min = std::min(min, num);
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    N, A, B, C = map(int, input().split())
    l_list = [int(input()) for i in range(N)]

    INF = 10 ** 9

    def dfs(current_bamboo_index, a, b, c):
        if current_bamboo_index == N:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30 if a * b * c > 0 else INF
        stuff_a = dfs(current_bamboo_index + 1, a + l_list[current_bamboo_index], b, c) + 10
        stuff_b = dfs(current_bamboo_index + 1, a, b + l_list[current_bamboo_index], c) + 10
        stuff_c = dfs(current_bamboo_index + 1, a, b, c + l_list[current_bamboo_index]) + 10
        unused = dfs(current_bamboo_index + 1, a, b, c)
        return min(stuff_a, stuff_b, stuff_c, unused)

    print(dfs(0, 0, 0, 0))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n := nextInt()
	a := make([]int, n)
	height := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	for i := 1; i < n; i++ {
		if a[i-1] > a[i] {
			height[i] = a[i-1] - a[i]
			a[i] = a[i-1]
		}
	}

	sum := 0
	for i := 0; i < n; i++ {
		// fmt.Fprintf(out, "%d\n", height[i])
		sum += height[i]
	}

	fmt.Fprintf(out, "%d\n", sum)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func quickSort(val []int) []int {
	if len(val) < 2 {
		return val
	}

	pivot := val[0]

	left := []int{}
	right := []int{}

	for _, v := range val[1:] {
		if pivot > v {
			left = append(left, v)
		} else {
			right = append(right, v)
		}
	}

	left = quickSort(left)
	right = quickSort(right)

	ret := append(left, pivot)
	ret = append(ret, right...)

	return ret
}


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

int main(){
    int N;
    cin >> N;
    int A[N], B[N], C[N - 1];
    cins(A, A + N);
    cins(B, B + N);
    cins(C, C + N - 1);
    int ans = accumulate(B, B + N, 0);
    for(int i = 0; i < N - 1; i++){
        if(A[i] + 1 == A[i + 1]){
            ans += C[A[i] - 1];
        }
    }
    cout << ans << endl;
}


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

int main() {
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.length()/2; i++){
        if(s.at(i) != s.at(s.length()-1-i))ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

	//------------------------------------------

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}
	//------------------------------------------
	static long lcm (long a, long b) {
		long temp;
		long c = a;
		c *= b;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return (long)(c/b);
	}

	//------------------------------------------



	public void exec() throws Exception{
		final String C = sc.next();
		out.println((char)(C.charAt(0)+1));
	}
}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	struct LR
	{
		public long L, R;
	}

	static void Main()
	{
		var h = Console.ReadLine().Split().Select(long.Parse).ToArray();
		long n = h[0], x = h[1], d = h[2];

		if (d == 0) { Console.WriteLine(x == 0 ? 1 : n + 1); return; }
		if (d < 0) { d = -d; x = -x; }

		var map = new Dictionary<long, List<LR>>();
		for (long i = 0; i <= n; i++)
		{
			var l = i * (i - 1) / 2;
			var r = n * (n - 1) / 2 - (n - i) * (n - i - 1) / 2;

			var a = i * x;
			var m = a % d;
			if (m < 0) m += d;
			a = (a - m) / d;

			if (!map.ContainsKey(m)) map[m] = new List<LR>();
			map[m].Add(new LR { L = a + l, R = a + r });
		}

		var c = 0L;
		foreach (var lrs in map.Values)
		{
			var M = long.MinValue;
			foreach (var lr in lrs.OrderBy(s => s.L))
			{
				c += Math.Max(0, lr.R - Math.Max(M, lr.L - 1));
				M = Math.Max(M, lr.R);
			}
		}
		Console.WriteLine(c);
	}
}


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

const int N = 505;

int a[N][N];

int main(){
	int k, n;
	scanf("%d",&k);
	if (k == 1){
		printf("1\n");
		printf("1\n");
		return 0;
	}
	n = (k + 3) / 4 * 2;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (i & 1) a[i][j] = (i + j) % n;
			else a[i][j] = n + (i + j) % n;
		}
	}
	printf("%d\n", n);
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (a[i][j] >= k) printf("%d", a[i][j] - n + 1);
			else printf("%d", a[i][j] + 1);
			printf(" ");
		}
		printf("\n");
	}
	return 0;
} 

Measured memory_bytes: 2176
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b = input().split()
    x = int(a + b)

    def judge():
        for i in range(10001):
            if i ** 2 == x:
                return True
        return False

    if judge():
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 68948
A, B, C = map(int, input().split())
binary = [1, 2, 4, 8, 16, 32, 64, 128, 256]
K = int(input())
flg = False
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i + j + k == K:
        if A*binary[i] < B*binary[j] and B*binary[j] < C*binary[k]:
          flg = True
if flg:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 9196
#include<cstdio>
#include<cmath>
 
//#include<iostream>
using namespace std;
 
int main(){
int i=0, j, ar[11];

	while( scanf("%d" , &j)!= EOF){
		if(j!=0)	ar[++i]=j;
		else 		printf("%d\n",ar[i--]);
	}

    return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>
#include <cassert>
#include <stdlib.h>
#include <string.h>
#include <sstream>
#include <iostream>
#include <math.h>
#include <time.h>
#include <unistd.h>
#include <algorithm>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <string>
#include <iomanip>
 
#ifdef LOCAL_CODE
	#define DEBUG(x) cerr << "[" << #x << '=' << x << "]" << endl;
#else
	#define DEBUG(x) do {} while(0);
#endif
 
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define PER(i, N) for(int i = (N)-1; i >= 0; i--)
#define REP(i, N) for(int i = 0; i < (int)(N); i++)
using namespace std;
typedef long long ll;
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }

template <typename T, typename U> std::istream&operator>>(std::istream&i, pair<T,U>&p) {i >> p.first >> p.second; return i;}
template<typename T>std::istream&operator>>(std::istream&i,vector<T>&t) {for(auto&v:t){i>>v;}return i;}
template <typename T, typename U> std::ostream&operator<<(std::ostream&o, const pair<T,U>&p) {o << p.first << ' ' << p.second; return o;}
template<typename T>std::ostream&operator<<(std::ostream&o,const vector<T>&t) {if(t.empty())o<<'\n';for(size_t i=0;i<t.size();++i){o<<t[i]<<" \n"[i == t.size()-1];}return o;}
template<typename T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using maxheap = priority_queue<T, vector<T>, less<T>>;
template<typename T> T gcd(T a,T b) { if (a<b) swap(a,b); return b?gcd(b,a%b):a; }

ll n,m,k;//A,B,C,D;
void solve(istream& cin, ostream& cout) {
	cin>>n;
	vector<ll> A(n);
	cin>>A;
	ll ans = 1;
	REP(i, n) {
		if(A[i] == 0) {
			cout << 0 <<endl;
			return;
		}
	}
	REP(i, n) {
		if(ans > (ll)1e18/A[i]) {
			ans = -1;
			break;
		}
		ans = ans*A[i];

		if(ans > (ll)1e18) {
			ans = -1;
			break;
		}
	}
	cout <<ans<<endl;
}


int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	solve(cin, cout);
	/*
	{
		istringstream instr("2\n2\n14");
		solve(instr, cout);
	}
 */
	return 0;
}


Measured memory_bytes: 3992
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n;
    cin >> n;
    vector<pair<double,string>> oto(n);
    rep(i,n) cin >> oto[i].first >> oto[i].second;
    double ans=0;
    rep(i,n){
        if(oto[i].second == "BTC")
            oto[i].first *= 380000.0;
        ans += oto[i].first;
    }
    cout << ans << endl;
    return 0;
}



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

#define int long long

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

string s;

signed main() {
    cin >> s;
    int ans = s.size();
    for (int i = 0; i < s.size() - 1; i++) {
        if (s[i] != s[i + 1]) {
            int cur = max(i + 1, (int)s.size() - i - 1);
            ans = min(ans, cur);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <iostream>

using namespace std;

typedef long long ll;
const int MAXN = 3010;
const ll INF  = 10e17+1;

int n, a[MAXN];
ll f[MAXN][MAXN];

int main()
{
	scanf("%d",&n);
	for(int i = 1; i <= n; i++)
		scanf("%d",&a[i]);
	for(int l = 0; l < n; l++){
		for(int i = 1, j = i + l; j <= n; i++, j++){
			if((n - l) & 1) f[i][j] = max(f[i+1][j] + a[i], f[i][j-1] + a[j]);
			else f[i][j] = min(f[i+1][j] - a[i], f[i][j-1] - a[j]);
		}
	}
	printf("%lld\n",f[1][n]);
	return 0;
}

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

int main(){
    int N,K;
    string S;
    cin >> N >> K >> S;
    if(S[K-1] == 'A') {
        S[K-1] = 'a';
    }
    else if(S[K-1] == 'B') {
        S[K-1] = 'b';
    }
    else {
        S[K-1] = 'c';
    }
    cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
    
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    string str;
    cin >> str;
    vector<int> n(4, 0);
    REP(i, str.size()){
        if(str[i] == 'N') n[0]++;
        if(str[i] == 'S') n[1]++;
        if(str[i] == 'E') n[2]++;
        if(str[i] == 'W') n[3]++;
    }
    
    if(n[0] > 0){
        if(n[1] < 1){
            cout << "No" << endl;
            return 0;
        }
    }
    if(n[1] > 0){
        if(n[0] < 1){
            cout << "No" << endl;
            return 0;
        }
    }
    if(n[2] > 0){
        if(n[3] < 1){
            cout << "No" << endl;
            return 0;
        }
    }
    if(n[3] > 0){
        if(n[2] < 1){
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
def yn(a,b,c):
    ans = "NO"
    for i in range(a*b):
        if a * i % b == c:
            ans = "YES"

    return ans

def main():
    a , b , c = map(int, input().split())
    print(yn(a,b,c))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38640