akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

ll dp[200002][5];

int main(){
    ll l;
    cin >> l;
    VE a(l);
    VE now(5);
    REP(i, 5)now[i] = 0;
    REP(i, l)cin >> a[i];
    REP(i, l){
        ll base = mod;
        REP(j, 5){
            base = min(base, now[j]);
            ll add = 0;
            if((j == 0) || (j == 4)){add = a[i];}
            if((j == 1) || (j == 3)){add = (a[i] == 0 ? 2 : a[i] % 2);}
            if(j == 2){add = (a[i] % 2 ? 0 : 1);}

            now[j] = base + add;
        }
    }
    ll res = mod;
    REP(i, 5)res = min(res, now[i]);
    print(res);
}


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

int main(void) {
    int a, b, c, d, p, q, r, s;
    cin >> a >> b >> c >> d;
    cin >> p >> q >> r >> s;

    int sum1 = a + b + c + d;
    int sum2 = p + q + r + s;
    
    if (sum1 > sum2)
		cout << sum1 << endl;
	else
		cout << sum2 << endl;

    return 0;
}

Measured memory_bytes: 3084
import java.util.NoSuchElementException;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int[] n_a_b_c_d = Stream.of(sc.nextLine().split(" "))
                    .mapToInt(Integer::parseInt)
                    .toArray();
            int n = n_a_b_c_d[0];
            float a = n_a_b_c_d[1];
            int b = n_a_b_c_d[2];
            float c = n_a_b_c_d[3];
            int d = n_a_b_c_d[4];
            int pab = (int)Math.ceil(n / a) * b;
            int pcd = (int)Math.ceil(n / c) * d;
            System.out.println(Integer.min(pab, pcd));
        } catch (NoSuchElementException | NumberFormatException e) {
            System.out.println(e);
        }
    }
}



Measured memory_bytes: 32128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''
import fractions

def main():
    A, B = list(map(int, input().split()))

    gcd = fractions.gcd(A, B)
    print(int(A*B/gcd))


if __name__ == '__main__':
    main()

Measured memory_bytes: 5052
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

const ll MOD = 1000000007;

struct mint {
    ll x;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
    }
    mint operator-() const {
        return mint(-x);
    }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t / 2);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

ostream &operator<<(ostream &os, const mint &a) {
    return os << a.x;
}

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    --K;
    if(W==1) {
        cout << 1 << endl;
        return 0;
    }
    vec<vec<int>> to(W, vec<int>(W, 0));

    rep(i, 1 << (W - 1)) {
        bool flag = true;
        for (int j = 1; j <= W - 1; ++j)
            if ((i & (1 << j)) && (i & (1 << (j - 1)))) flag = false;
        if (!flag) continue;

        rep(j, W-1) {
            if (i & (1 << j)) {
                to[j][j + 1] += 1;
                to[j + 1][j] += 1;
            } else {
                if(j==0) to[j][j] += 1;
                else if (!(i & (1 << (j-1)))) to[j][j] += 1;
                if(j==W-2) to[j+1][j+1]+=1;
            }
        }
    }

    vec<vec<mint>> dp(H + 1, vec<mint>(W, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= H; ++i)
        rep(j, W) {
            dp[i][j] += dp[i - 1][j] * to[j][j];
            if (j + 1 < W) dp[i][j] += dp[i - 1][j + 1] * to[j + 1][j];
            if (j != 0) dp[i][j] += dp[i - 1][j - 1] * to[j - 1][j];
        }

    cout << dp[H][K] << endl;
}

Measured memory_bytes: 256
//BFTの典型的な問題（多点スタート）
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  int dx[4] = {1, 0, 0, -1};
  int dy[4] = {0, 1, -1, 0};
  vector<string> fi(H);

  //マスの読み込み
  for(int i = 0; i < H;i++){
    cin >> fi.at(i);
  }

  //多点スタートとして扱う問題
  //使用するデータ構造は2つ　①vector<int> distance()→今回は全スタート地点の移動距離を格納するのでvector<vector<int>>
  //②queue<int> que→今回は、(i,j)を格納するのでqueue<pair<int,int>>にしておく。
  
  //初期化
  vector<vector<int>> dist(H, vector<int>(W, -1));//頂点が訪問済みかも含めて-1で初期化しておく
  using pir=pair<int, int>;
  queue<pir> que;
  for (int i = 0; i < H;i++){
    for (int j = 0; j < W;j++){
      if(fi[i][j]=='#'){
        dist[i][j] = 0;
        que.push(pir(i, j));

      }
    }
  }

  //BFSのスタート
  while(!que.empty()){
    auto cur = que.front();
    que.pop();
    //4方向について調べていく
    for (int i = 0; i < 4;i++){

      int nx = cur.first + dx[i];
      int ny = cur.second+dy[i];
      //範囲外だったら
      if(nx<0||nx>=H||ny<0||ny>=W){
        continue;
      }
      //未探索だったら
      if(dist[nx][ny]==-1){
        dist[nx][ny] = dist[cur.first][cur.second] + 1;
        que.push(pir(nx, ny));
      }
    }
  }

  int tmp = 0;
  for (int i = 0; i < H;i++){
    for (int j = 0; j < W;j++){
      tmp = max(tmp, dist[i][j]);
    }
  }
  cout << tmp << endl;
  return 0;
}


Measured memory_bytes: 13456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		Deque<Integer> tmp=new ArrayDeque<Integer>();
		String s=sc.next();
		int counter=0;
		for(int i=0; i<s.length(); i++) {
			if(s.charAt(i)=='1') {
				if(tmp.size()>0) {
					if(tmp.peek()==0) {
						tmp.remove();
						counter++;
					}
					else {
						tmp.push(1);
					}
				}
				else {
					tmp.push(1);
				}
			}
			else if(s.charAt(i)=='0') {
				if(tmp.size()>0) {
					if(tmp.peek()==1) {
						tmp.remove();
						counter++;
					}
					else {
						tmp.push(0);
					}
				}
				else {
					tmp.push(0);
				}
			}
		}
		pl(counter*2);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 26452
#include <stdio.h>
int main(void) {
  int N,i,j,count = 0;
  scanf("%d",&N);
  for(i = 0; i <= N / 4; i++) {
    for(j = 0; j <= N / 7; j++) {
      if(4 * i + 7 * j == N) {
        count++;
      }
    }
  }
  if(count != 0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  string a, b;
  cin >> a >> b;
  string c = a + b;
  if (sqrt(stod(c)) - floor(sqrt(stod(c))) == 0)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}



Measured memory_bytes: 3732
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	int n;
	cin >> n;
	if (!cin) return false;

	vi a(n), b(n), c(n - 1);

	for (int i = 0; i < n; ++i) {
		int num;
		cin >> num;
		a[i] = num - 1;
	}
	for (int i = 0; i < n; ++i) {
		int num;
		cin >> num;
		b[i] = num;
	}
	for (int i = 0; i < n - 1; ++i) {
		int num;
		cin >> num;
		c[i] = num;
	}
	ll sol = 0;

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

	cout << sol << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N;
    cin >> N;
    vector<Pll> Ps(N);
    for(int i=0;i<N;i++){
        cin >> Ps[i].first >> Ps[i].second;
    }

    sort(Ps.begin(),Ps.end());

    map<Pll,ll>mp;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            mp[Pll(Ps[j].first-Ps[i].first,Ps[j].second-Ps[i].second)]++;    
        }
    }
    ll ans=1;
    ll tmp=0;
    for(auto e : mp){
        tmp=max(tmp,e.second);
        
    }

    cout << N-tmp << endl;



    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INT long long int
#define MOD (INT)(1e9)+7
using namespace std;

INT h, w, c[10][10], a[220][220], ans;

int main()
{
    cin>>h>>w;
    for(int i = 0 ; i < 10 ; i++ ) for(int j = 0 ; j < 10 ; j++ ) cin>>c[i][j];
    for(int i = 0 ; i < h ; i++ ) for(int j = 0 ; j < w ; j++ )cin>>a[i][j];
    for(int k = 0 ; k < 10 ; k++ )
        for(int i = 0 ; i < 10 ; i++ )
            for(int j = 0 ; j < 10 ; j++ )
                if( c[i][j] > c[i][k] + c[k][j] )
                    c[i][j] = c[i][k] + c[k][j];
    for(int i = 0 ; i < h ; i++ ) for(int j = 0 ; j < w ; j++ )
        if( a[i][j] >= 0 ) ans += c[a[i][j]][1];
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
	string s, m;
	int cnt = 0, k, n;
	cin >> s >> k;
	for (int i = 0; i < k; i++)
	{
		cin >> m;
		m = m + m;
		n = m.find(s);
		if (n >= 0)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define sizeOf(A) (sizeof(A))/(sizeof(A[0]))
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
#define fileio freopen("template.in", "r", stdin), freopen("template.out", "w", stdout);
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    fastio;
    //fileio;

    char x;
    cin >> x;
    if (isupper(x)) {
        cout << 'A' << "\n";
    } else {
        cout << 'a' << "\n";
    }
    return 0;
}


Measured memory_bytes: 3604
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    H,W,K = map(int, readline().split())
    S = [readline().strip() for j in range(H)]

    white = []
    for line in S:
        white.append(line.count("1"))
    white_total = sum(white)

    if white_total <= K:
        print(0)
        exit()

    # 横線の決め方を全探索
    ans = 10**5
    for pattern in range(2**(H-1)):
        # 初期化
        impossible = False
        x = 0
        ly = bin(pattern).count("1")
        y = [[0]*W]*(ly + 1)
        line = 0
        for i in range(H):
            y[line] = [y[line][j] + int(S[i][j]) for j in range(W)]
            if (pattern >> i) & 1:
                line += 1

        # 各列の値を加算していく
        count = [0]*(ly + 1) 
        for col in zip(*y):
            # Kより大きい値を加算する場合は不成立
            if any(a > K for a in col):
                impossible = True
                break
            for i, a in enumerate(col):
                count[i] += a
                # 和がKより大きければカット数を増やす
                if count[i] > K:
                    x += 1
                    count = list(col) 
                    break
            if x + ly > ans:
                impossible = True
                break
        if impossible:
            x = 10**6

        ans = min(ans, x + ly)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 200005
#define INF 1000000000
#define MOD 1000000007
#define print(cs) printf("Case %lld: ",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b)
{
    return ((a*b)/__gcd(a,b));
}
vector<ll>v;
ll mov(ll val,ll n)
{
    ll i,j,k,l,r=0;
    for(i=0; i<n; i++)
    {
        k=ceil(v[i]/(double)val)-1;
        k=max(k,0LL);
        r+=k;
    }
    return r;
}
int main()
{
    ll i,j,k,l,n,m,r,lo=1,hi=0,mid;
    in(n);
    in(k);
    v.resize(n);
    for(i=0; i<n; i++)
    {
        in(v[i]);
        hi=max(hi,v[i]);
    }
    ll ans;
    while(lo<=hi)
    {
        mid=lo+(hi-lo)/2;
        if(mov(mid,n)<=k)
        {
            ans=mid;
            hi=mid-1;
        }
        else lo=mid+1;
    }
    out(ans);
    endl;
}


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

int main(){
  //入力
  int n, k;	cin >> n >> k;
  vector<int> p(n);	rep(i,n) cin >> p[i];
  //期待値
  vector<double> e(n);	rep(i,n) e[i] = (1.0+p[i])/2.0;
  //期待値の最大値を求める
  double sum = 0;
  double ans = 0;
  queue<double> q;
  rep(i,n){
    sum += e[i];
    q.push(e[i]);
    //k以下ならスルー
    if(q.size() < k) continue;
    //k以上なら消去
    if(q.size()>k){
      sum -= q.front();
      q.pop();
    }
    //期待値の最大値
    ans = max(ans, sum);
  }
  //出力
  printf("%.10f", ans);
  return 0;
}

Measured memory_bytes: 4224
#include <iomanip>
#include <iostream>
#include <vector>
using namespace std;
int x[200010];
int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
    s[i] = x[i];
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    if (x[i] < s[n / 2])
      cout << s[n / 2] << endl;
    else
      cout << s[n / 2 - 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
import bisect

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()

count = 0
for j in range(n):
    i = bisect.bisect_left(A, B[j])
    k = bisect.bisect(C, B[j])
    count += (i * (n - k))

print(count)

Measured memory_bytes: 23328
// E - This Message Will Self-Destruct in 5s

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int A[200000];
unordered_map<int, int> cnt;

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

	for (int i=0; i<N; i++) {
		cin >> A[i];
	}

	ll ans = 0;
	for (int i=0; i<N; i++) {
		ans += cnt[i - A[i]];
		cnt[i + A[i]]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 19292
#include <stdio.h>

int main(){
int a, b, c;
    int tmp;
    scanf("%d %d %d", &a, &b, &c);
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    if(b>c){
        tmp=b;
        b=c;
        c=tmp;
    }
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

Measured memory_bytes: 2720
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int A,B,C; cin>>A>>B>>C;
    int diff=max({A,B,C})*3-(A+B+C);
    if(diff%2==0)
        cout<<diff/2<<endl;
    else
        cout<<(diff+3)/2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <set>

#define N 1000000

typedef long long ll;

using namespace std;

int prime[N + 1];
int D[N + 1];
int used[N + 1];

int main() {
    for (int i = 0; i <= N; ++i) {
        prime[i] = 1;
        D[i] = i;
        used[i] = 0;
    }
    prime[0] = prime[1] = 0;

    int p = 2;
    while (p < sqrt(N)) {
        for (int i = p * 2; i <= N; i += p) {
            prime[i] = 0;
            D[i] = p;
        }

        for (int i = p + 1; i <= N; ++i) {
            if (prime[i] == 1) {
                p = i;
                break;
            }
        }
    }

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int A;
        cin >> A;

        set<int> s;
        while (A != D[A]) {
            s.insert(D[A]);
            A = A / D[A];
        }
        s.insert(A);
        for (auto it = s.begin(); it != s.end(); ++it) {
            ++used[*it];
        }
    }

    bool pairwise = true;
    bool setwise = true;

    for (int i = 2; i <= N; ++i) {
        if (used[i] >= 2) {
            pairwise = false;
        }
        if (used[i] >= n) {
            setwise = false;
        }
    }

    if (pairwise) {
        cout << "pairwise coprime" << endl;
    }
    else if (setwise) {
        cout << "setwise coprime" << endl;
    }
    else {
        cout << "not coprime" << endl;
    }

    return 0;
}

Measured memory_bytes: 14800
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  ll a, b;

  while (cin >> a >> b) {
    cout << a / __gcd(a, b) * b << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  ll  long long
#define  pii pair<ll,ll>
#define  pll pair<ll , ll>
#define  debug cout << "this far" << endl;
#define  For(i, n) for(int i = 0; i < (n); ++i)
#define  lsb(x) ((x) & (-x))
#define  PI acos(-1)
#define  line cout << endl;
#define  getbit(n, i) (((n) & (1LL << (i))) != 0)
#define  resetbit(n, i) ((n) & (~(1LL << (i))))
#define  setbit(n, i) ((n) | (1LL << (i)))
#define  togglebit(n, i) ((n) ^ (1LL << (i)))
#define  gap " "
#define printall(container) for(auto val  : container) cout << val << gap ; line ; 
using namespace std;
const int N = 2e5 + 10;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x, k, d;
    cin >> x >> k >> d;
    ll cnt = (abs(x)) / d;
    if (cnt > k) {
        if (x < 0) x += k * d;
        else x -= (k * d);
        cout << abs(x) << endl; 
    }
    else {
        if (x < 0) x += d * cnt;
        else x -= cnt * d;
        k -= cnt;
        ll tmpx;
        if (x > 0) tmpx = x - d;
        else tmpx = x + d;
        if (k % 2) cout << abs(tmpx) << endl;
        else cout << abs(x) << endl;
    }
}

Measured memory_bytes: 3640
using Primes
function main()
    n::Int=myread(Int)
    a::Vector{Int}=myreads(Int)
    cnt::Dict{Int,Int}=Dict{Int,Int}()
    for i=a
        for j=keys(factor(i))
            if haskey(cnt,j)
                cnt[j]+=1
            else
                cnt[j]=1
            end
        end
    end
    if all(x->x==1,values(cnt))
        println("pairwise coprime")
    else
        g::Int=a[1]
        for i=a
            g=gcd(g,i)
        end
        if g==1
            println("setwise coprime")
        else
            println("not coprime")
        end
    end
end

# ----------input function----------
sread()=chomp(readline())
sreads(sp=" ")=split(readline(),sp)
myread(ty)=parse(ty,sread())
myreads(ty)=parse.(ty,sreads())
main()

Measured memory_bytes: 305908
#include <iostream>
using namespace std;
int main(void){
    
  int N,A;
  cin >> N;
  
  for(int i=0;i<1000000;i++){
      A=i*i;
      
    if (A>N){
        cout << (i-1)*(i-1) << endl;
        break;
        
    }
  }
  
}


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


int main(){
  int N;cin>>N;
  int sum=0;
  int S=N;
  for(int i=0;S!=0;i++){
    sum+=S%10;
    S/=10;
  }
  if(sum%2!=0&&N>=10&&sum<10){
    if(sum==9){
      cout<<18<<endl;
    }else if(sum==7){
      cout<<16<<endl;
    }else if(sum==5){
      cout<<14<<endl;
    }else if(sum==3){
      cout<<12<<endl;
    }else if(sum==1){
      cout<<10<<endl;
    }
  }else{
  cout<<sum<<endl;
}
}

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

int main(){
    int n,mx=0;
    cin >> n;

    int A1[n];
    int A2[n];
    for(int i=0;i<n;++i) cin >> A1[i];
    for(int i=0;i<n;++i) cin >> A2[i];

    for(int i=0;i<n;++i){
        int cnt = 0;
        for(int l=0;l<=n;++l){
            if(l<=i){
                cnt+=A1[l];
            }else{
                cnt+=A2[l-1];
            }
        }
        if(mx < cnt) mx = cnt;
    }

    cout << mx;
    return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto G = new long[][](N);
    foreach (_; 0 .. N - 1)
    {
        long a, b;
        scan(a, b);
        a--, b--;
        G[a] ~= b;
        G[b] ~= a;
    }
    long[2] cnt2;
    auto visited = new bool[](N);
    auto d2 = new long[](N);
    void dfs1(long v, long dist)
    {
        if (visited[v])
            return;
        visited[v] = true;
        d2[v] = dist & 1;
        cnt2[dist & 1]++;
        foreach (w; G[v])
            dfs1(w, dist + 1);
    }

    dfs1(0, 0);

    auto ans = new long[](N);
    long[3] cnt3;
    cnt3[0] = 1;

    foreach (i; 0 .. N)
    {
        if (N / 3 < cnt2[0] && N / 3 < cnt2[1])
        {
            ans[i] = (cnt3[1 + d2[i]]++) * 3 + (1 + d2[i]);
            if (N < ans[i])
                ans[i] = (cnt3[0]++) * 3;
        }
        foreach (j; 0 .. 2)
            if (cnt2[j] <= N / 3)
            {
                if (d2[i] == j)
                    ans[i] = (cnt3[0]++) * 3;
                if (d2[i] == (j + 1) % 2)
                {
                    ans[i] = (cnt3[1]++) * 3 + 1;
                    if (N < ans[i])
                        ans[i] = (cnt3[2]++) * 3 + 2;
                    if (N < ans[i])
                        ans[i] = (cnt3[0]++) * 3;
                }
            }
        if (N < ans[i])
        {
            writeln(-1);
            return;
        }
    }
    ans.map!text().join(' ').writeln();
}


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

int main() {
  ll k, n;
  cin >> k >> n;
  vector<ll> a(n);
  ll maxD = 0;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    ll dis;
    if (i == 0)
      dis = a[0] + k - a[n - 1];
    else
      dis = a[i] - a[i - 1];
    maxD = max(dis, maxD);
  }
	cout<<k-maxD<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=34e4,M=18,mo=1e9+7;

int c[N*M];
int be[N],en[N];
int n,a,b,f,p,oo;
int m2[N];

/*
inline void solve(int k,int w,int a,int b)
{
	if(w==1){
		be[k]=a; en[k]=b;
		return;
	}
	int u=w/2,v=w-u;
	solve()
}
*/

inline void solve(int k,int w,int a,int b)
{
	if(w==1){
		be[k]=++oo; en[k]=++oo;
		c[oo]=b; c[oo-1]=a;
		return;
	}
	int s1=w,s2=0;
	fd(i,w,1)if((a&m2[i])!=(b&m2[i])){
		s2=i; break;
	}
	int gs=0,e=(a&m2[s2])>0,js=0;
	int aa=a^(a&m2[w])^(a&m2[s2]);
	aa=aa^(((a&m2[w])>0)*m2[s2]);
	int bb=b^(b&m2[w])^(b&m2[s2]);
	bb=bb^(((b&m2[w])>0)*m2[s2]);
	
	fo(i,1,w-1)gs=gs+((aa&m2[i])>0);
	
	if(gs%2==1)js=0;else js=1;
	int q=++p;
	solve(q,w-1,aa,js);
	int r=++p;
	solve(r,w-1,js,bb);
	
	int len=1<<w-1;
	be[k]=oo+1;
	fo(i,1,len){
		c[++oo]=c[be[q]+i-1];
		c[oo]=c[oo]^(((c[oo]&m2[s2])>0)*m2[w]);
		c[oo]=c[oo]^(c[oo]&m2[s2]);
		if(e)c[oo]=c[oo]|m2[s2];
	}
//	oo=oo+len/2;
	fo(i,1,len){
		c[++oo]=c[be[r]+i-1];
		c[oo]=c[oo]^(((c[oo]&m2[s2])>0)*m2[w]);
		c[oo]=c[oo]^(c[oo]&m2[s2]);
		if(!e)c[oo]=c[oo]|m2[s2];
	}
	en[k]=oo;
}

int main()
{
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	m2[1]=1;
	fo(i,2,n)m2[i]=m2[i-1]<<1;
	f=a;b=b^a;
	a=0; 
	int kk=0;
	for(int y=b;y;y>>=1)kk=(kk+((y%2)));
	if(kk%2==0){
		puts("No");
		return 0;
	}
	p=1;
	solve(1,n,a,b);
	int len=1<<n;
	puts("Yes");
	fo(i,1,len){
		printf("%d ",f^c[be[1]+i-1]);
	}
}

Measured memory_bytes: 13824
//	Author : amnptl 
//	   Godbless
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define NeedForSpeed() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD (1000000007); // 1e9+7
int main()
{
	NeedForSpeed();
	int n; cin>>n; string s; cin>>s; map<char,vector<int>> m;
	for(int i=0; i<n; i++) m[s[i]].push_back(i);
	ll ans = 1; ans *= (int)m['R'].size(); ans *= (int)m['G'].size(); ans *= (int)m['B'].size();
	for(int i=0; i<n; i++)
	{
		for(int j=1; (i+2*j)<n; j++)
		{
			int a1 = i; int a2 = i+j; int a3 = i+2*j;
			if(s[a1]!=s[a2] && s[a1]!=s[a3] && s[a2]!=s[a3])
				ans--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>
#include <ctype.h>
int main() {
  int n,k;
  scanf("%d%d",&n,&k);
  char s[n];
  scanf("%s",s);
  for(int i=0;i<=n;i++){
    if(i==k){
      s[i-1]=tolower(s[i-1]);
    }
  }
  printf("%s",s);

  return 0;
}


Measured memory_bytes: 128
#include <string>
 #include <vector>
 #include <algorithm>
 #include <iostream>
 #include <cstdio>
 #include <cstdlib>
 #include <cmath>
 #include <queue>
 #include <map>
 #define INF 100000000
 
 using namespace std;
 typedef long long ll;
 
 ll num[21]={0};
 
 long long int kai(ll n){
 if(num[n]!=0)return num[n];
 else{
 num[n]=n*kai(n-1);
 return num[n];
 }
 }
 
 int main(){
 int n;
 num[0]=num[1]=1;
 cin>>n;
 cout<<kai(n)<<endl;
 }
 

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

int main()
{
     string s;
     string s1; 
     int n;
     cin>>n;
     cin>>s;
     for(int i=0; i<s.size(); i++)
    {
        if(s[i]+n <= 90)
            cout<<char(s[i]+n);
        else
            cout<<char(s[i]+n-90+64);
        
    }
     
     
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  printYesNo((abs(b - a) <= d && abs(c - b) <= d) || abs(c - a) <= d);
  return 0;
}

Measured memory_bytes: 256
import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

void main() {
	long x, k, d;
	readf("%s %s %s", &x, &k, &d);

	if (x < 0) {
		x = -x;
	}

	if (x / d > k) {
		x = x - d * k;
	} else {
		k = (k - x / d) % 2;
		x = x % d;
		if (k == 1) {
			assert(d > x);
			x = -(x - d);
		}
	}

	writeln(x);
}


Measured memory_bytes: 2820
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


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

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
        a.at(i) --;
    }

    vector<int> osita(n);
    int now = 0;
    
    for(int i = 0;;i ++){
        if(now == 1){
            cout << i << endl;
            break;
        }

        if(osita.at(now) == 1){
            cout << -1 << endl;
            break;
        }

        osita.at(now) = 1;
        now = a.at(now);
    }
}


Measured memory_bytes: 1792
#include <stdio.h>


int main()
{
	int N;
	scanf("%d", &N);
	int a[N+1];
	int i = 0;
	while (i < N)
		scanf("%d", &a[i++]);
	i = 0;
	int max = 0;
	int max_index;
	while (i < N)
	{
		if (a[i] > max)
		{
			max = a[i];
			max_index = i;
		}
		i++;
	}
	i = 0;
	int second = 0;
	int sec_index;
	while (i < N)
	{
		if (i != max_index && a[i] > second)
		{
			second = a[i];
			sec_index = i;
		}
		i++;
	}
	i = 0;
	while (i < N)
	{
		// printf("%d ", a[i]);
		if (i != max_index)
			printf("%d\n", a[max_index]);
		else if (i == max_index)
			printf("%d\n", a[sec_index]);
		i++;
	}
	return (0);
}


Measured memory_bytes: 2304
X,Y,Z,K=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
z=list(map(int,input().split()))

L=[xx+yy for xx in x for yy in y ]
L=sorted(L,reverse=True)

if K > X*Y:
  LL=[l+zz for l in L for zz in z]
  [print(i) for i in sorted(LL,reverse=True)]   
else:
  LL=[l+zz for l in L[:K] for zz in z]
  LL=sorted(LL,reverse=True)
  [print(ll) for k,ll in zip(range(K),LL)]

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

ll gcd(ll a, ll b){
    ll r = a%b;
    if(r==0)   return b;
    return gcd(b, r);
}

int main(){

    ll n;   cin >> n;
    vector<ll> v(n);
    for(ll i=0; i<n; i++)  cin >> v.at(i);
    sort(v.begin(), v.end());
    ll ans = gcd(v.at(0), v.at(1));
    for(ll i=0; i<n; i++){
        ans = gcd(v.at(i), ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import numpy as np
H,W=[int(x) for x in input().split()]
h,w=[int(x) for x in input().split()]

M=np.zeros((H,W))

for n in range(h):
    print
    M[n]=1
for m in range(w):
        M.T[m]=1
        
print(len(M[M==0]))


Measured memory_bytes: 12436
use proconio::input;
use proconio::marker::Chars;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
    't', 'u', 'v', 'w', 'x', 'y', 'z',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
    'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
];
#[allow(unused)]
fn main() {
    input!(N: usize, D: i64);
    let mut ans: usize = 0;
    for _ in 0..N {
        input!((x, y): (i64, i64));
        if x * x + y * y <= D * D {
            ans += 1;
        }
    }

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


Measured memory_bytes: 4868
import kotlin.math.abs

fun main(args: Array<String>) {
    val s = readString()

    val a = s.count { it == 'a' }
    val b = s.count { it == 'b' }
    val c = s.count { it == 'c' }

    val ans = when {
        a == 1 && b == 1 && c == 1
                || a == 0 && b == 1 && c == 1
                || a == 1 && b == 0 && c == 1
                || abs(a - b) <= 1 && abs(b - c) <= 1 && abs(c - a) <= 1 -> "YES"
        else -> "NO"
    }
    println(ans)
}

// read
fun readString() = readLine()!!

Measured memory_bytes: 37196
import math

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

B = [str(N - i) for i in range(math.ceil(N / 2)) if A[N - i - 1] == 1]
C = [0] * math.floor(N / 2) + A[math.floor(N / 2):]

for i in range(math.floor(N / 2), 0, -1):
    count = 0
    for j in range(i, N + 1, i):
        count += C[j - 1]
    if not count % 2 == A[i - 1]:
        B.append(str(i))
        C[i - 1] = 1

print(len(B))
if not len(B) == 0:
    print(" ".join(B))


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<ll>>;



int main(){
  ll N,Q; cin>>N>>Q;
  Graph Tree(N+1);
  rep(i,N-1){
    ll a,b; cin>>a>>b;
    Tree.at(a).push_back(b);
    Tree.at(b).push_back(a);
  }
  vector<ll> dist(N+1,-1);
  map<ll,ll> parent;
  dist.at(1) = 0;
  ll H_MAX = 0;
  queue<ll> que;
  que.push(1);
  while(!que.empty()){
    ll v = que.front();
    que.pop();
    for(auto nv: Tree.at(v)){
      if(dist.at(nv)!=-1)continue;
      dist.at(nv)=dist.at(v)+1;
      que.push(nv);
      H_MAX = max(H_MAX,dist.at(nv));
      parent[nv] = v;
    }
  }
  vector<ll> X(N+1,0);
  rep(i,Q){
    ll p,x; cin>>p>>x;
    X.at(p)+=x;
  }
  vector<set<ll>> m(H_MAX+1);
  rep1(i,N+1)m.at(dist.at(i)).insert(i);
  rep1(i,H_MAX+1){
    for(auto v: m.at(i)){
    //  cout<<v<<endl;
      X.at(v) += X.at(parent[v]);
    }
  }
  
  rep1(i,N+1)cout<<X.at(i)<<endl;
}


Measured memory_bytes: 49280
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<tuple<string, int, int>> a;
  for (int i = 1; i <= n;i++){
    string s;
    int p;
    cin >> s >> p;
    p = -p;
    a.push_back(tie(s, p, i));
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n;i++){
    cout << get<2>(a.at(i)) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	char c;
	cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
		cout << "vowel";
	}
	else {
		cout << "consonant";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int N=3010;
int w[2],s[2],e,f,anss,answ;
bool fw[N],fs[N];
double ans=-1;
int main(){
	scanf("%d%d%d%d%d%d",w+0,w+1,s+0,s+1,&e,&f);
	w[0]*=100;w[1]*=100;
	fw[0]=fs[0]=1;
	for (int i=1;i<=f;++i){
		if (i>=w[0]) fw[i]|=fw[i-w[0]];
		if (i>=w[1]) fw[i]|=fw[i-w[1]];
		if (i>=s[0]) fs[i]|=fs[i-s[0]];
		if (i>=s[1]) fs[i]|=fs[i-s[1]];
	}
	for (int sn=0;sn<=f;++sn) if (fs[sn])
		for (int wn=(sn?(sn-1)/e+1:1)*100;wn+sn<=f;wn+=100) if (fw[wn]){
			if (double(sn)/wn>ans) ans=double(sn)/wn,answ=wn,anss=sn;
		}
	printf("%d %d",anss+answ,anss);
	return 0;
}

Measured memory_bytes: 256
def roll(l, command):
    '''
    return rolled list

    l : string list
    command: string
    '''
    res = []
    i = -1
    if command =='N':
        res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]]
    if command =='S':
        res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]]
    if command =='E':
        res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]]
    if command =='W':
        res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]]

    return res

def spin(l):
    '''
    return right sppined list

    l : string list
    '''

    i = -1
    res = [l[i+1], l[i+3], l[i+5], l[i+2], l[i+4], l[i+6]]

    return res

def check_all(upper, front, faces):
    orig_faces = faces[:]

    #change upper face
    for i in range(6):
        if 1 <= i <= 3:
            faces = roll(faces, "N")
        elif i == 4:
            pass
            faces = orig_faces[:]
            faces = roll(faces, "W")
        elif i == 5:
            faces = orig_faces[:]
            faces = roll(faces, "E")


        # spin 4 times
        for _ in range(4): #spin 3 times
            faces = spin(faces)
            if (faces[0] == upper and (faces[1] == front)):
                return faces[2]

if __name__ == "__main__":
    faces = input().split()
    n = int(input())

    for _ in range(n):

        question = list(input().split())
        answer = check_all(question[0], question[1], faces)

        print(answer)



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

int max(int,int);

int main(int argc, char** argv) {
    int size;
    scanf("%d\n", &size);
    if(size < 2 || size > 200000)
        return (EXIT_FAILURE);
    int array[size];
    
    for(int i = 0; i < size; i++){
        scanf("%d", &array[i]);
        if(array[i]<1 || size > 100000000)
            return(EXIT_FAILURE);
    }
    
    int j = 1;
    int i = j - 1;
    int maxLoc = 0;
    int minLoc = 0;
    int profit = array[j] - array[i];
    for(;j < size; j++){
        i = j - 1;
        if(array[i]>=array[j]){
            if(profit<=0)
                profit = max(profit, array[j]-array[i]);
            if(array[minLoc]>array[j])
                minLoc = j;
        }
        else{
            if(array[j]>array[maxLoc])
                maxLoc = j;
            profit = max(profit, array[j] - array[minLoc]);
        }
    }
    
    
    printf("%d\n", profit);
    
    return (EXIT_SUCCESS);
}

int max(int a, int b){
    if(a > b)
        return a;
    return b;
}



Measured memory_bytes: 2564
// inputに入力データ全体が入る
function Main(input) {
  chars = input.split("");
  
	if(chars[0] == chars[1] && chars[0] == chars[2] && chars[0] == chars[3]){
       console.log("No");
	}else{

      //chars[i]は後から変わるので、先に定数として定義
      var letter = chars[0];
      //最初のアルファベットなので消していい
      chars.splice(0,1);
      var replaced = input.replace(letter, '');
      var search = replaced.search(letter);

      //最初のアルファベットと同じやつがないか探して、あったら消す
      chars.splice(search,1);
      replaced = replaced.replace(letter, '');
      search = replaced.search(letter);

      //残りの２文字が一緒だったらYes、一緒じゃない場合はNo
      if(chars[0] == chars [1]) 
        console.log("Yes");
      else console.log("No");
    }
}
  
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7372
w,h,n=map(int,input().split())
xmin, xmax, ymin, ymax = 0, w, 0, h
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > xmin:
            xmin = x
    elif a == 2:
        if x < xmax:
            xmax = x
    elif a == 3:
        if y > ymin:
            ymin = y
    else:
        if y < ymax:
            ymax = y

if xmax-xmin < 0 or ymax-ymin < 0:
    print(0)
    exit()
ans = (xmax-xmin) * (ymax-ymin)
print(ans)


Measured memory_bytes: 3064
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int n; cin >> n;
	cout << 1-n << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
typedef long long ll;
typedef long double ld;
long long dx[] = {1,0,-1,0};
long long dy[] = {0,1,0,-1};
long long dx8[] = {1,1,0,-1,-1,-1,0,1};
long long dy8[] = {0,1,1,1,0,-1,-1,-1};
long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};

map<int,map<int,int>> m;
map<int,map<int,bool>> is_edge;

int adj(int s,int t){
    if(is_edge[s][t])return m[s][t];
    else return -1;
}

signed main(){
    ll V,E;
    cin >> V >> E;
    ll s,t,d;
    FOR(i,0,E){
        cin >> s >> t >> d;
        m[s][t] = d;
        is_edge[s][t] = true;
    }
    ll DP[(1<<V)][V];
    FOR(i,1,(1<<V))FOR(j,0,V){
        DP[i][j] = 1000000;
        if((1<<j)&i){
            int last = i^(1<<j);
            if(last){
                FOR(k,0,V){
                    if((1<<k)&last && adj(k,j) != -1){
                        DP[i][j] = min(DP[i][j],DP[last][k]+adj(k,j));
                    }
                }
            }
            else if(i == 1)DP[i][j] = 0;
        }
    }
    ll ans = 20000;
    FOR(i,0,V)if(adj(i,0) != -1)ans = min(ans,DP[(1<<V)-1][i]+adj(i,0));
    if(ans == 20000)cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 6948
def slove():
    import sys
    input = sys.stdin.readline
    n, q = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    lr = [list(map(int, input().rstrip('\n').split())) for _ in range(q)]
    l = [0] * n
    cnt = 0
    for i in range(1, n):
        if s[i] == "C" and s[i-1] == "A":
            cnt += 1
        l[i] = cnt
    for ln, rn in lr:
        print(l[rn-1] - l[ln-1])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 64604
#include<iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N];
  int n, u, k, v;

  cin >> n;

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) M[i][j] = 0;
  }

  for ( int i = 0; i < n; i++ ) {
    cin >> u >> k;
    u--;
    for ( int j = 0; j < k; j++ ) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      if ( j ) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3148
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,x] <- getIntList
    xs <- map (abs . (flip (-) x)) <$> getIntList
    print $ foldl1' gcd xs

Measured memory_bytes: 2940
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        s: String,
    };

    let numbers = s.chars().map(|n| n as i32 - 48).collect::<Vec<i32>>();

    for i in 0..(1usize << s.len()) {
        let mut ans = 0;
        for (j, num) in numbers.iter().enumerate() {
            if i & (1 << j) == 0 {
                ans -= num;
            } else {
                ans += num;
            }
        }
        if ans == 7 {
            for (j, num) in numbers.iter().enumerate() {
                print!("{}", num);
                if j == 3 {
                    continue;
                }
                if i & (1 << j+1) == 0 {
                    print!("-");
                } else {
                    print!("+");
                }
            }
            println!("=7");
            return ;
        }
    }
}


Measured memory_bytes: 2184
#include<stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
	i++;
	t=A[i];
	A[i]=A[j];
	A[j]=t;
      }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;
  return i+1;
}

int main(){
  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  q=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2120
import sys
input = sys.stdin.readline
def main():
    X,Y = map(int, input().split())
    for i in range(0,X+1):
        if (i*2 + (X-i)*4) == Y:
            print("Yes")
            break
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 9180