akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>

using namespace std;

#define x first
#define y second
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define all(x) x.begin(),x.end()
#define SZ(x) int(x.size())
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = b-1; i >= a; i--)
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define ll long long
#define inf 1000000007
#define mod 1000000007
#define N 100005

template<typename U, typename V> void Min(U &a, const V & b){if(a > b)a = b;}
template<typename U, typename V> void Max(U &a, const V & b){if(a < b)a = b;}
template<typename U, typename V> void add(U &a, const V & b){a = (a + b) % mod;} 
template<typename U> U gcd(U a, U b){
	if(a == 0)return b;
    if(b == 0)return a;
	if(a >= b)return gcd(a-b, b);
	else return gcd(a, b - a);
} 
int pow(int a, int b){
    int ans = 1;
    while(b){
        if(b & 1)ans = 1LL * ans * a % mod;
        a = 1LL * a * a % mod;
        b >>= 1;
    }
    return ans;
}

char s[N << 1];
int main(){
    int T, m, n, i, j, k, K;
    scanf("%d%s", &n, s);
    if(s[0] == 'W'){
        puts("0");return 0;
    }
    int x = 1, l = 1, r = 0, ans = 1;
    rep(i, 1, n *2){
        if(s[i] == s[i-1])x ^= 1;
        if(x == 1)l++;
        else r++;
        if(x == 0){
            if(l < r){
                puts("0");
                return 0;
            }
            ans = 1LL * ans * (l - r + 1) % mod;
        }
    }
    if(l != r){
        puts("0");
        return 0;
    }
    rep(i, 1, n+1)ans = 1LL * ans * i % mod;
    printf("%d\n", ans);
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//mint型にキャスト
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(ll n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main(){
  ll n,m,k;
  cin>>n>>m>>k;
  mint ans=0;
  init();
  for(ll i=0;i<n;i++){
      for(ll j=0;j<m;j++){
            ans+=mint(m)*mint((n-i)*(n-i-1)/2)*COM(n*m-2,k-2);
      }
  }
   for(ll i=0;i<m;i++){
      for(ll j=0;j<n;j++){
            ans+=mint(n)*mint((m-i)*(m-i-1)/2)*COM(n*m-2,k-2);
      }
  }

  cout<<ans<<"\n";
}

Measured memory_bytes: 50476
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    System.out.println(S.equals("Sunny") ? "Cloudy" : S.equals("Cloudy") ? "Rainy" : "Sunny");
  }
}

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

int main() {
    int64_t N ;
    cin >> N;
    vector<int64_t> A(N);
    map<int64_t,int64_t> m;
    for ( int64_t i = 0; i < N; ++i){
        cin >> A[i];
        m[A[i]] = m[A[i]] + 1;
    }
    int64_t sum = 0;
    for ( auto p : m ){
        int64_t val = p.first;
        int64_t num = p.second;
        sum = sum + val * num;
    }
    int64_t Q;
    cin >> Q;
    vector<int64_t> B(Q),C(Q);
    for ( int64_t i = 0; i < Q; ++i){
        cin >> B[i] >> C[i];
        int64_t num = m[B[i]];
        m[B[i]] = 0;
        m[C[i]] = m[C[i]] + num;
        sum = sum - B[i] * num + C[i] * num;
        cout << sum << endl;
    }
    
    /*int64_t sum = 0;
    for ( auto p : m ){
        int64_t val = p.first;
        int64_t num = p.second;
        sum = sum + val * num;
    }
    
    cout << sum << endl;*/
    return 0;
}

Measured memory_bytes: 11260
N = input()
x = map(int,raw_input().split(" "))


v = {}
for q in x:
    if not q in v:
        v[q] = 0
    v[q] += 1


ans = 0
for key in v.keys():
    val = v[key]
    
    if val < key:
        ans += val
    elif val > key:
        ans += val - key
print ans
        


Measured memory_bytes: 15944
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

int main(){
  int H, W; cin >> H >> W;
  string S[H];
  rep(i,H) cin >> S[i];
  vector<vector<int>> n(H,vector<int>(W,0));
  
  rep(i,H) {
    int cnt = 0;
    rep(j,W){
      if (S[i][j]=='.' && cnt==0){
        int j0 = j;
        while (j0<W && S[i][j0]=='.') cnt++, j0++;
        n[i][j] = cnt;
      }
      else if (S[i][j]=='.') n[i][j] = cnt;
      else cnt = 0;
    }
  }

  rep(j,W) {
    int cnt = 0;
    rep(i,H){
      if (S[i][j]=='.' && cnt==0){
        int i0 = i;
        while (i0<H && S[i0][j]=='.') cnt++, i0++;
        n[i][j] += cnt;
      }
      else if (S[i][j]=='.') n[i][j] += cnt;
      else cnt = 0;
    }
  }

  int ans = 0;
  rep(i,H) rep(j,W) chmax(ans, n[i][j]);
  cout << ans-1 << endl;


  
  // cout << fixed << setprecision(10);
  
  return 0;
}


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

int main() {
  string S;
  cin >> S;

  for (int bit = 0; bit < (1 << 3); bit++) {
    int number = S[0] - '0';

    string formula;
    formula.push_back(S[0]);

    for (int i = 0; i < 3; i++) {
      if (bit & (1 << i)) {
        number += (S[i + 1] - '0');
        formula += "+";
        formula.push_back(S[i + 1]);
      } else {
        number -= (S[i + 1] - '0');
        formula += "-";
        formula.push_back(S[i + 1]);
      }
    }

    formula += "=7";

    if (number == 7) {
      cout << formula << endl;
      return 0;
    }
  }
}

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

int N, K;

struct two_dimension_bit {
    vector<vector<int>> bit;
    int N, M;
    
    two_dimension_bit(int N, int M): bit(N + 1, vector<int>(M + 1)), N(N), M(M) { }
    
    int sum(int i, int j) { //(1, 1)から(i, j)までの累積和
        if(i <= 0 || j <= 0) return 0;
        int s = 0;
        for(int x = i; x > 0; x -= x & -x) {
            for(int y = j; y > 0; y -= y & -y) {
                s += bit[x][y];
            }
        }
        return s;
    }
    
    void add(int i, int j, int n) { //(i, j)にnを加える
        for(int x = i; x <= N; x += x & -x) {
            for(int y = j; y <= M; y += y & -y) {
                bit[x][y] += n;
            }
        }
    }
};

int main() {
    cin >> N >> K;
    two_dimension_bit black(K, K), white(K, K);
    for (int i = 0; i < N; i++) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        bool flag = (c == 'B');
        if ((x / K + y / K) % 2) flag = !flag;
        if (flag) {
            black.add(x % K + 1, y % K + 1, 1);
        } else {
            white.add(x % K + 1, y % K + 1, 1);
        }
    }
    int ans = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            int tmp = black.sum(K, K)
            + 2 * black.sum(i, j) - black.sum(K, j) - black.sum(i, K)
            + white.sum(K, j) + white.sum(i, K) - 2 * white.sum(i, j);
            tmp = max(tmp, N - tmp);
            ans = max(tmp, ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8192
import java.util.Scanner;

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

    int A = scanner.nextInt();
    int B = scanner.nextInt();
    for (int i = 1; i <= 3; i++) {
      if (i != A && i != B) System.out.println(i);
    }
  }
}


Measured memory_bytes: 22100
import sys
for line in sys.stdin:
    h, w = map(int, line.rstrip('\n').split(' '))
    if h == 0 and w == 0: break
    for y in range(h):
        row = ''
        for x in range(w):
            if (x % 2,y % 2) in ((0, 0), (1, 1)):
                row += '#'
            else:
                row += '.'
        print row
    print ''

Measured memory_bytes: 4212
#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 N; cin>>N;
    vint h(N);
    REP(i,N) cin>>h[i];

    int ans=0;
    while(true){
        bool ok=true;
        bool f=false;
        REP(i,N){
            if(h[i]>0){
                h[i]--;
                f=true;
                ok=false;
            }
            else{
                if(f){ 
                    ans++;
                    f=false;
                }
            }
        }
        if(f) ans++;
        if(ok) break;
    }
    cout<<ans<<endl;
 
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
view = [True] * n
for j in range(m):
    a, b = map(int, input().split())
    a -=1
    b -=1
    if h[a] < h[b]:
        view[a] = False
    elif h[a] > h[b]:
        view[b] = False
    elif h[a] == h[b]:
        view[a] = False
        view[b] = False

print(view.count(True))

Measured memory_bytes: 20124
// C - 755
#include <bits/stdc++.h>
using namespace std;

int N;//limit value
int Digit;//limit number of digit
int Count;//anser

void dfs(int x, int depth){
	if(x > N) return;//exceeded value limit?

	set<int> s;
	for(int a=x; a && s.size()<3; a/=10) s.insert(a%10);
	if(s.size() == 3) Count++;//{3,5,7}.size()==3

	if(depth >= Digit) return;//limit of digits?

	dfs(x*10+3, depth+1);
	dfs(x*10+5, depth+1);
	dfs(x*10+7, depth+1);
}

int main(){
	string s; cin>>s;
	Digit = s.size();
	N = stoi(s);
	dfs(0, 0);
	cout<< Count <<endl;
}

Measured memory_bytes: 256
# CODE FESTIVAL 2016 予選 C: B – K個のケーキ / K Cakes
K, T = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

max_index = a.index(max(a))

print(max(a[max_index] - 1 - (K - a[max_index]), 0))

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

int main() {
  int N, Y;
  cin >> N >> Y;
  
  bool ans = false;
  int x, y, z;
  
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      if (N-i-j >= 0) {
        int sum = 10000*i + 5000*j + 1000*(N-i-j);
        if (sum == Y) {
          ans = true;
          x = i;
          y = j;
          z = N-i-j;
          break;
        }
      }
    }
  }
  
  ans ? (cout << x << " " << y << " " << z << endl)
    : (cout << -1 << " " << -1 << " " << -1 << endl);
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using ll = long long;

using namespace std;
int n;
const int maxN = 405;
ll dp[maxN][maxN];
ll INF = 1e18 + 5;
// dp[i][j] - cost of combining element i and j into 1 vertex
int main(int argc, char *argv[]) {
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    auto sum = [&] (int L, int R) {
        ll res = 0;
        for (int i = L; i <= R; ++i)
            res += a[i];
        return res;
    };
    for (int L = n; L >= 0; --L) {
        for (int R = L; R < n; ++R) {
            if (L == R) {
                dp[L][R] = 0;
            }
            else {
                dp[L][R] = INF;
                ll s = sum(L, R);
                for (int i = L; i <= R - 1; ++i) {
                    dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + s);
                }
            }
        }
    }
    printf("%lld\n", dp[0][n-1]);
    return 0;
}

Measured memory_bytes: 1536
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")
#include"bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long
#define ends ' '
#define endl '\n'
#define pb emplace_back
#define x first
#define y second
#define pii pair<int, int>
#define sz(x) (int)(x).size()

void solve() {
    int n;
    cin >> n;

    vector<pii> v(n);

    for(int i = 0; i < n; ++i) {
        cin >> v[i].x >> v[i].y;
    }

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

    multiset<int> a, b;

    int ans = 0;

    for(int i = 0; i < n; ++i) {
        int t1 = v[i].x+v[i].y;
        int t2 = v[i].x-v[i].y;

        if(i) {
            int u = *a.begin();
            ans = max(ans, t1-u);
            int v = *b.begin();
            ans = max(ans, t2-v);
        }
        a.insert(t1);
        b.insert(t2);
    }
    cout << ans;

}

int32_t main() {

	IOS;

    int t = 1;
    while(t--) {
        solve();
    }
		
	return 0;
}

Measured memory_bytes: 25116
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
                int answer = 0;
		int digit = n/100;
		n = n - digit*100;
                if(digit*10+ digit >= n){
			answer = digit*100+ digit*10 + digit;
		}else{
			answer = (digit+1)*100+ (digit+1)*10 + digit+1;
		}
		System.out.println(answer);
	}
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const ll inf=1e18;
const int maxn=55;
const int maxm=2500;
ll dp[maxn][maxm<<1];
ll c[maxn],d[maxn];

class edge
{
	public:
		int to,money,t;
		edge(int v,int a,int b)
		{
			to=v;
			money=a;
			t=b;
		}
};
vector<edge> v[maxn];
bool in[maxn];
queue<int> q;
void push(int x)
{
	if(in[x]) return ;
	in[x]=1;
	q.push(x);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	rept(i,1,50)
		rept(j,0,maxm)
				dp[i][j]=inf;
	int n,m,xx;
	cin>>n>>m>>xx;
	rep(i,0,m)
	{
		int x,y,a,b;
		cin>>x>>y>>a>>b;
		v[x].pb(edge(y,a,b));
		v[y].pb(edge(x,a,b));
	}
	rept(i,1,n) cin>>c[i]>>d[i];
	for(int i=0;;i++)
	{
		if(i*c[i]+xx>=maxm)
		{
			dp[1][maxm]=i*d[1];
			break;
		}
		else dp[1][i*c[1]+xx]=i*d[1];
	}
	push(1);
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		in[x]=0;
		rep(i,0,v[x].size())
		{
			int to=v[x][i].to,money=v[x][i].money,t=v[x][i].t;
			rept(j,money,maxm)
			{
				if(dp[to][j-money]>dp[x][j]+t)
				{
					dp[to][j-money]=dp[x][j]+t;
					push(to);
				}
			}
			rep(j,0,maxm)
			{
				if(c[to]+j<maxm)
				{
					if(dp[to][c[to]+j]>dp[to][j]+d[to])
					{
						push(to);
						dp[to][c[to]+j]=dp[to][j]+d[to];
					}
				}
				else
				{
					if(dp[to][maxm]>dp[to][j]+d[to])
					{
						push(to);
						dp[to][maxm]=dp[to][j]+d[to];
					}
				}
			}
		}
	}
	rept(i,2,n)
	{
		ll ans=inf;
		rept(j,0,maxm) ans=min(ans,dp[i][j]);
		cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 4776
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!(usize; n);
    let mut b = a.clone();
    b.sort();
    let mut map = BTreeMap::new();
    for i in 0..n {
        map.insert(b[i],i);
    }

    let mut res = 0;
    for i in 0..n {
        let bi = map[&a[i]];
        let d = (bi as isize - i as isize).abs();
        if d%2 == 1 {
            res += 1;
        }
    }
    println!("{}", res/2);
}


Measured memory_bytes: 12668
#include <cstdio>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); i++)

const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char get_char() {
  if (ci - cn == cm) {
    fread(cn, 1, cm, stdin);
    ci = cn;
  }
  return *ci++;
}
inline int get_int() {
  int A = 0;
  if (ci - cn + 16 > cm)
    while ((ct = get_char()) >= '0') A = A * 10 + ct - '0';
  else
    while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
  return A;
}

int cnt[1001][1001];

int main() {
  int N = get_int(), K = get_int();
  rep(i, N) {
    int x = get_int(), y = get_int(), b;
    char c = get_char();
    get_char();
    if(c=='W')y += K;
    b = x / K % 2 == y / K % 2 ? 1 : -1;
    if(b > 0) cnt[0][0]++;
    int nx = x % K + 1, ny = y % K + 1;
    cnt[nx][0] -= b;
    cnt[0][ny] -= b;
    cnt[nx][ny] += b * 2;
  }
  rep(i, K + 1)rep(j, K)cnt[i][j + 1] += cnt[i][j];
  rep(j, K + 1)rep(i, K)cnt[i + 1][j] += cnt[i][j];
  int ans = 0;
  rep(i, K)rep(j, K)ans = std::max(ans, std::max(cnt[i][j], N - cnt[i][j]));
  printf("%d", ans);
}


Measured memory_bytes: 5580
#include <iostream>
 
using namespace std;
 
int main()
{
    int t,flag=0;
    cin>>t;
    int num[t];
    for(int i=0;i<t;i++)
    {
        cin>>num[i];
        if(num[i] != i+1)
        {
            flag +=1;
        }
    }
    if(flag>2)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
}

Measured memory_bytes: 256
N, M, C = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
for i in range(N):
    t = C
    for j in range(M):
        t += a[i][j] * b[j]
    if t > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

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

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif

    string a;
    while (cin >> a) {
        string s(a.size(), 'x');
        cout << s << endl;
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


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

int dp[3000][3000][2];
string s, t;
int longest_common(int i, int j)
{
	if(i >= s.size() || j >= t.size())
		return 0;
	if(dp[i][j][0] >= 0)
		return dp[i][j][0];
	if(s[i] == t[j])
	{
		// cout << i << " " << j <<"\n";
		dp[i][j][0] = 1 + longest_common(i+1,j+1);
		dp[i][j][1] = 0;
		return dp[i][j][0];
	}
	else
	{
		int k1, k2;
		k1 = longest_common(i+1,j);
		k2 = longest_common(i,j+1);
		// cout << k1 << " " << k2 << " " << i << " " << j << "\n";
		if(k1 > k2)
		{
			dp[i][j][0] = k1;
			dp[i][j][1] = 1;
		}
		else
		{
			dp[i][j][0] = k2;
			dp[i][j][1] = 2;
		}
		return dp[i][j][0];
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	for (int i = 0; i < 3000; ++i)
	{
		for (int j = 0; j < 3000; ++j)
		{
			dp[i][j][0] = -1;
		}
	}
	// memset(s1, '0', 3000);
	cin >> s >> t;
	// cout << s1;
	int k = longest_common(0, 0);
	// cout << k;

	if(!k)
		cout << "";
	int i = 0, j = 0;
	while(k && (i < s.size() &&  j < t.size()))
	{
		if(dp[i][j][1] == 0)
		{
			cout << s[i];
			i+=1;
			j+=1;	
			k--;
		}
		else
		{
			if(dp[i][j][1] == 1)
				i+=1;
			if(dp[i][j][1] == 2)
				j+=1;
		}
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  string s;
  cin >> s;
  if (s.size() >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 764
using System;

namespace teisyutusensei
{
    class Program
    {
        static void Main(string[] args)
        {
            ////?????????????????????
            string dmmy1 = Console.ReadLine();
            int n1 = int.Parse(dmmy1);
 
            string[] dmmySP = new string[n1];
            char del = ' ';

            string dmmy2 = Console.ReadLine();
            dmmySP = dmmy2.Split(del);
            int[] data1 = new int[n1];

            for (int i = 0; i < n1; i++)
            {
                data1[i] = int.Parse(dmmySP[i]);
            }
            ////?????????????????????
            string dmmy3 = Console.ReadLine();
            int n2 = int.Parse(dmmy3);

            string[] dmmySP2 = new string[n2];

            string dmmy4 = Console.ReadLine();
            dmmySP2 = dmmy4.Split(del);
            int[] data2 = new int[n2];

            int count = 0;

            for (int i = 0; i < n2; i++)
            {
                data2[i] = int.Parse(dmmySP2[i]);

                int left = 0;
                int right = n1;
                int mid = 0;

                while (left < right)
                {
                    mid = (left + right) / 2;

                    if (data1[mid] == data2[i])
                    {
                        count++;
                        break;
                    }
                    else if (data2[i] < data1[mid])
                    {
                        right = mid;
                    }
                    else
                    {
                        left = mid + 1;
                    }
                }

            }

            Console.WriteLine(count);
            Console.ReadLine();

        }
    }

}

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

int main(void) {
    ll N,K;
    cin >> N >> K;
    if(K==0) {
        cout << N*N << endl;
        return 0;
    }
    ll res = 0;
    for(int i=K; i<N; i++) {
        res += N-i;
        int elm = 0;
        while(true) {
            elm++;
            int diff = ((N-i)/elm) - i;
            if(diff <= 0) break;
            res += diff;
        }
    }
    cout << res << endl;
    return 0;
}


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

class DisjointSet {
public:
    vector<int> p, rank;

    DisjointSet(int n) {
        p.resize(n, 0);
        iota(p.begin(), p.end(), 0);
        rank.resize(n, 0);
    }

    int root(int x) {
        return (p[x] == x ? x : root(p[x]));
    }

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

    void unite(int x, int y) {
        int xroot = root(x), yroot = root(y);
        if (rank[xroot] < rank[yroot]) {
            p[xroot] = yroot;
        } else {
            p[yroot] = xroot;
            if (rank[xroot] == rank[yroot]) rank[xroot] ++;
        }
    }
};

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

    int n, q, com, x, y;
    cin >> n >> q;

    DisjointSet obj(n);
    while (q --) {
        cin >> com >> x >> y;
        if (com == 0) {
            obj.unite(x, y);
        } else {
            cout << (int)obj.same(x, y) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<P> vp;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,K;
    cin >> n >> K;
    vector<ll> x(n),y(n);
    vector<ll> u(n),v(n);
    rep(i,n){
        cin >> x[i] >> y[i];
        u[i] = x[i],v[i] = y[i];
    }
    zip(x),zip(y);
    ll ans = (1LL << 62);
    rep(i,len(x)-1){
        srep(j,i+1,len(x)){
            rep(k,len(y)-1){
                srep(l,k+1,len(y)){
                    int res = 0;
                    rep(m,n){
                        if(x[i] <= u[m] && u[m] <= x[j] && y[k] <= v[m] && v[m] <= y[l]){
                            res++;
                        }
                    }
                    if(res >= K){
                        ans = min(ans,(x[j]-x[i])*(y[l]-y[k]));
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

ll gcd(ll a, ll b);

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

  vector<ll> a(n);
  rep(i, n) cin >> a.at(i);

  vector<ll> migi(n);
  vector<ll> hidari(n);
  migi.at(n-1)= a.at(n-1);
  hidari.at(0)= a.at(0);

  rep(i, n-1){
    hidari.at(i+1) = gcd(a.at(i+1), hidari.at(i));
  }

  rep(i, n-1){
    migi.at(n-i-2) = gcd(a.at(n-i-2), migi.at(n-i-1));
  }

  //rep(i,n) cout << hidari.at(i) << endl;

  ll max = 0;
  rep(i,n){
    ll left, right;
    ll now;
    if(i==0) now = migi.at(1);
    else if(i==n-1) now = hidari.at(n-2);
    else now = gcd(migi.at(i+1), hidari.at(i-1));
    if(now>=max) max = now;
  }

  cout << max;
}

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


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  
  if(n<=6) cout<<1<<endl;
  else{
    ll ans=n/11*2;
    if(n%11!=0){
      if(n%11>6) ans+=2;
      else ans++;
    }
    
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
// #include <bitset>
const int oo=2139063143;
const int N=2010;
const int P=1000000007;
using namespace std;
typedef long long LL;
typedef double db;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
	if (x< 0) putchar('-'),x=-x;
	if (x>=10) print(x/10);
	putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
int del(int x) { return x>=P?x-P:x; }
void add(int &x,int y) { x=del(x+y); }
int ksm (int a,int b)
{
	int ans=1;
	while (b)
	{
		if (b&1) ans=(LL)ans*a%P;
		a=(LL)a*a%P,b>>=1;
	}
	return ans;
}
int jc[N*N],inv[N*N];
void init (int n)
{
	jc[0]=1;
	for (int i=1; i<=n; i++)
		jc[i]=(LL)i*jc[i-1]%P;
	inv[n]=ksm (jc[n],P-2);
	for (int i=n-1; i>=0; i--)
		inv[i]=(LL)(i+1)*inv[i+1]%P;
}
int C(int n,int m) { return n< m?0:(LL)jc[n]*inv[m]%P*inv[n-m]%P; }
int f[N][N];
int main ()
{
	// freopen (".in","r",stdin);
	// freopen (".out","w",stdout);
	int n,k; sc(n),sc(k);
	if (k==1||n==1) return pr(1),0;
	init (n*k);
	f[0][0]=1;
	for (int i=1; i<=n; i++)
		for (int j=0; j<=i; j++)
		{
			f[i][j]=f[i-1][j];
			if (j) add(f[i][j],(LL)f[i][j-1]*(n-j+1)%P*C(n*k-i-(k-1)*(j-1)-1,k-2)%P);
		}
	pr(f[n][n]);

	return 0;
}

Measured memory_bytes: 46464
n,m=map(int,input().split())
l=[-1]*n
check=False

for i in range(m):
    s,c=map(int,input().split())
    if n!=1 and s==1 and c==0:
        break
    if l[s-1]==-1 or l[s-1]==c:
        l[s-1]=c
    else:
        break
    if i==m-1:
        check=True
if n!=1 and l[0]==-1:
    l[0]=1

if m!=0 and check:
    for num in l:
        if num==-1:
            print(0,end='')
        else:
            print(num,end='')
    print()
elif n==1 and m==0:
    print(0)
elif m==0:
    print(10**(n-1))
else:
    print(-1)

Measured memory_bytes: 38384
import java.util.Scanner;

//ABC111-B

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

		int x = Integer.parseInt(sc.next());
		int ans = 0;

		if(x <= 111){
			ans = 111;
		}else if(x <= 222){
			ans = 222;
		}else if(x <= 333){
			ans = 333;
		}else if(x <= 444){
			ans = 444;
		}else if(x <= 555){
			ans = 555;
		}else if(x <= 666){
			ans = 666;
		}
		else if(x <= 777){
			ans = 777;
		}
		else if(x <= 888){
			ans = 888;
		}
		else if(x <= 999){
			ans = 999;
		}


			System.out.println(ans);
	}
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int n, k, ans = 0;
  cin >> n >> k;
  vector<int> x(n);

  arep(i, x) cin >> i;

  sort(all(x));

  rep(i, 0, k) ans += x[i];

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll N,C; cin >> N >> C;
  vector<ll> x(N); vector<ll> v(N);
  
  for(ll i = 0; i < N; i++){
    cin >> x[i] >> v[i];}
  
  vector<ll> sumA(N); sumA[0] = v[0];
  for(ll i = 1; i < N; i++   ){ sumA[i] = sumA[i-1] + v[i];}
  
  vector<ll> sumB(N); sumB[N-1] = v[N-1];
  for(ll i = N-2; i >= 0; i--){ sumB[i] = sumB[i+1] + v[i];}
  
  vector<ll> dirA(N); dirA[0] = v[0];
  for(ll i = 0; i < N-1; i++){
    dirA[i+1] = dirA[i] + v[i+1];}
  
  
  vector<ll> dirB(N); dirB[N-1] = v[N-1];
  for(ll j = N-2; j >= 0; j--){
    dirB[j] = dirB[j+1]+v[j];}
  
  for(ll i = 0; i < N; i++){ 
    dirA[i] -= x[i];}
  
  for(ll j = N-1; j >= 0; j--){ 
    dirB[j] -= ( C-x[j]);}
  
  vector<pair<ll,ll>> maxA(N);
  maxA[0] = make_pair(dirA[0],0);
  
  for(ll i = 0; i < N-1; i++){
    if( dirA[i+1]  > maxA[i].first){
      maxA[i+1] = make_pair(dirA[i+1],i+1);}
    else{
      maxA[i+1] = maxA[i];}
  }
  
  vector<pair<ll,ll>> maxB(N);
  maxB[N-1] = make_pair(dirB[N-1],N-1);
  
  for(ll j = N-2; j >= 0; j--){
    if( dirB[j] > maxB[j+1].first){ 
      maxB[j] = make_pair(dirB[j],j);}
    else{
      maxB[j] = maxB[j+1];}
  }
  
  
  ll ans = 0LL;
  
  for(ll a = 0;  a < N; a++){
    // 左回りで何番目(0-indexed)までの寿司を獲りに行くかを考える(折り返し込み)
    ll res = sumA[a];  res -= 2*x[a];
     if(maxB[a+1].first > 0 && a < N-1){res += maxB[a+1].first;}
    
    ans = max(ans, res);}
  
  for(ll b = N-1; b >= 0; b--){
    //　右回りで何番目(0-indexed)までの寿司を獲りに行けるかを考える(折り返し込み）
    ll res = sumB[b]; res -= 2*(C-x[b]);
     if(maxA[b-1].first > 0 &&   b > 0){res += maxA[b-1].first;}
    
    ans = max(ans, res);}

  
  for(ll i = 0; i < N; i++){ ans = max(ans, dirA[i]); ans = max(ans, dirB[i]);}
  cout << ans << endl;
  
  
  return 0;}
    
    
    
    
    

Measured memory_bytes: 8064
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def main():
    N = 50
    K = int(input())

    L = [49] * N

    D, M = divmod(K, N)

    L = list(map(lambda x: x + D, L))

    for i in range(M):
        for j in range(N):
            if i == j:
                L[j] += N
            else:
                L[j] -= 1

    print(N)
    print(" ".join(list(map(str, L))))


main()


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

long long n;
map<long long, long long> mp;

bool solve();

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++mp[a];
  }
  if(solve())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

bool solve() {
  if(mp.size() != 2 && mp.size() != 1) return 0;
  long long x = 0, y = 0, xnum = 0, ynum = 0;
  for(auto m : mp) {
    x = y;
    xnum = ynum;
    y = m.first;
    ynum = m.second;
  }
  if(x == 0)
    return y * 2 <= n || y == n - 1;
  else {
    if(x > y) {
      swap(x, y);
      swap(xnum, ynum);
    }
    if(y - x != 1) return 0;
    n -= xnum;
    y -= xnum;
    assert(n == ynum);
    return y * 2 <= n && y > 0;
  }
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int in(){int x; scanf("%d",&x); return x;}
static const int MAX = 100;


int main(){
  int A = in(), B = in(), C = in(), X = in();
  int count = 0;

  rep(i, A+1){
    rep(j, B+1){
      rep(k, C+1){
        if(500*i + 100*j + 50*k == X) count++;
      }
    }
  }
  cout << count << endl;
}

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

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public int[] A;

        public void Run()
        {
            {
                N = Input.ReadInt();
                A = Input.ReadIntArray();
            }

            int ret = 0;
            for (int i = 0; i < N; i++)
            {
                int a = A[i];
                while (a % 2 == 0)
                {
                    a /= 2;
                    ret++;
                }
            }

            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 12128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

ll digitSum(ll n) {
    ll sum = 0;
    while (n) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main() {
    int n;
    cin >> n;
    ll mind = 1e9;
    for (int a = 1; a < n; a++) {
        int b = n - a;
        mind = min(mind, digitSum(a) + digitSum(b));
    }
    cout << mind << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
#define INF 2000000000
#define REP(i,b,n) for(int i = (b); i < n; i++)
#define rREP(i,b,n) for(int i = n; i >= b; i--)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const string lowercase = "abcdefghijklmnopqrstuvwxyz";
const string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int gcd(int a, int b){return b ? gcd(b, a % b): a;}

int main()
{
    /*
    dp[i][j]: s[0:i]にabc[0:j]が存在する場合の数
    dp[0][0] = 1
    dp[i][j] = dp[i-1][j] + dp[i-1][j-1] * K
        where K = 3 for s[i] == '?'
                = 1 for s[i] == abc[j]
                = 0 for else
    */
    string s; cin >> s;
    ll ans;
    ll dp[100001][4];
    const string abc = "ABC";
    const int d = 1000000007;
    REP(i,0,s.length()+1){
        REP(j,0,4){
            if(i == 0){
                if(j == 0) dp[i][j] = 1;
                else dp[i][j] = 0;
            }
            else{
                int k;
                if(s[i-1] == '?') k = 3;
                else k = 1;
                dp[i][j] = k * dp[i-1][j];

                if(j>0){
                    if(s[i-1] == '?' || s[i-1] == abc[j-1]) dp[i][j] += dp[i-1][j-1];
                }
            }
            dp[i][j] %= d;
        }
    }
    cout << dp[s.length()][3] << endl;
    return 0;
}


Measured memory_bytes: 3584