akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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


const ll INF = 1e18;
const ll MOD = 2019;
const ll MX = 1000001;

namespace Modop {
    ll modAdd(ll a, ll b) {
        return (a + b) % MOD;
    }
    
    ll modSub(ll a, ll b) {
        return (((a - b) % MOD) + MOD) % MOD;
    }
    
    ll modMul(ll a, ll b) {
        return ((a % MOD) * (b % MOD)) % MOD;
    }

    ll modExp(ll base, ll power) {
        if (power == 0) {
            return 1;
        } else {
            ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
            if (power % 2 == 1) cur = cur * base;
            cur = cur % MOD;
            return cur;
        }
    }
    
    ll modInv(ll a) {
        return modExp(a, MOD - 2);
    }
    
    ll modDiv(ll a, ll b) {
        return modMul(a, modInv(b));
    }
}

using namespace Modop;



string S;
ll ans = 0;

void solve() {
    cin >> S;
    reverse(S.begin(), S.end());
    map<ll, ll> cnts;
    
    cnts[0]++;
    
    ll cur = 0;
    for(int i = 0; i < (int)S.size(); i++) {
        cur += modMul(modExp(10, i), (S[i] - '0')); cur %= MOD;

        ans += cnts[cur]++;
    }
    
    cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 3824
import java.util.*;

public class Main{
	private static Scanner sc=new Scanner(System.in);
	
	public static void main(String[] args){
		int n=readInt();
		long a;
		long s[]=new long[n+1];
		for(int i=0;i<n;i++){
			a=readLong();
			if(i==0)s[i]=a;
			else s[i]=s[i-1]+a;
		}
		s[n]=0;
		HashMap<Long,Long> mp = new HashMap<Long,Long>();
		for(int i=0;i<n+1;i++){
			Long t=mp.get(s[i]);
			if(t==null)mp.put(s[i],(long)1);
			else mp.put(s[i],t+1);
		}
		long ans=0;
		for(Long x:mp.keySet()){
			long c=mp.get(x);
			ans+=c*(c-1)/2;
		}
		System.out.println(ans);
	}
	
	private static int readInt(){
		return Integer.parseInt(sc.next());
	}
	private static long readLong(){
		return Long.parseLong(sc.next());
	}
}

Measured memory_bytes: 53968
#include <bits/stdc++.h>
using namespace std;
//屈辱だがキッズの回答をまねた
int main() {
  int N,ret,count;
  cin>> N ;
  vector<int> a(N);
  count=0;
  vector<int> s(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    if(i>(N/2-1)){s.at(i)=a.at(i);
    count+=s.at(i);}
    }
int num,sum,st,en;

  for(int i=N/2;i>0;i--){
    sum=0;
    //cout<<"index: "<<i<<endl;
    for(int j=2*i;j<N+1;j+=i){
      //cout<<"check: "<<j<<endl;
      sum+=s.at(j-1);
    }
    //cout<<"sum: "<<sum<<endl;
    if(sum%2==a.at(i-1))s.at(i-1)=0;
    else {s.at(i-1)=1;
      count++;
    }
  }
  cout<<count<<endl;
  for(int i=0;i<N;i++){
    if(s.at(i)==1)cout<<(i+1)<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 2432
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<cstdio>
#include<cmath>
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
using namespace std;
int main(){
	int a,b;
	bool h=true;
	while(cin>>a>>b,a|b){
		if(!h)cout<<endl;
		h=false;
		int co=0;
		loop(i,a,b+1){
			if(i%4!=0||(i%100==0&&i%400!=0));
			else{cout<<i<<endl;co++;}
		}
		if(!co)cout<<"NA"<<endl;
	}	
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#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++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{

  int n;
  cin >> n;
  ll ans = 0;
  rep(i, n + 1){
    if(i == 0) continue;
    if(i % 3 == 0 || i % 5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>
#define M 1000000007
typedef long long LL;

LL qpow(LL x, int y)
{
	if(!y) return 1;
	LL t = qpow(x, y >> 1);
	t = t * t % M;
	if(y & 1) t = t * x % M;
	return t;
}

int main()
{		
	int x, y, a, b, c, t, i, j;
	LL f1 = 1, f2 = 1;
		
	scanf("%d%d", &x, &y);
	c = x + y;
	if(c % 3){
		puts("0");
		return 0;
	}
	c /= 3;
	b = x - c, a = y - c;
	if(b < 0 || a < 0){
		puts("0");
		return 0;
	}
	if(a < b) t = a;
	else t = b;
	for(i = 1, j = c; i <= t; i++, j--){
		f1 = f1 * (LL)j % M;
		f2 = f2 * (LL)i % M;
	}
	printf("%lld\n", f1 * qpow(f2, M - 2) % M);
		
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    ll ans = 0;
    if (a[1] + a[0] > x) {
        ans += a[1] + a[0] - x;
        if (a[1] + a[0] - x <= a[1]) {
            a[1] -= a[1] + a[0] - x;
        } else {
            a[1] = 0;
            a[0] = x;
        }
    }
    for (int i = 1; i < N; i++) {
        if (a[i] + a[i - 1] > x) {
            ans += a[i] + a[i - 1] - x;
            a[i] -= a[i] + a[i - 1] - x;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
n = int(input())
a = list(map(int, input().split()))

ans = 0
xor = 0
tempSum = 0
l, r = 0, 0
while r < n:
    if xor ^ a[r] == tempSum + a[r]:
        xor ^= a[r]
        tempSum += a[r]
        r += 1
        ans += (r - l)
    else:
        xor ^= a[l]
        tempSum -= a[l]
        l += 1

print(ans)


Measured memory_bytes: 24712
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	long long ans=0;
	if(a[0]!='C')  ans++;
	if(a[1]!='O')  ans++;
	if(a[2]!='D')  ans++;
	if(a[3]!='E')  ans++;
	if(a[4]!='F')  ans++;
	if(a[5]!='E')  ans++;
	if(a[6]!='S')  ans++;
	if(a[7]!='T')  ans++;
	if(a[8]!='I')  ans++;
	if(a[9]!='V')  ans++;
	if(a[10]!='A')  ans++;
	if(a[11]!='L')  ans++;
	if(a[12]!='2')  ans++;
	if(a[13]!='0')  ans++;
	if(a[14]!='1')  ans++;
	if(a[15]!='6')  ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int sum = 0;
    REP(i,3){
        int a;
        cin >> a;
        sum += a;
    }
    if(sum >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
 
 /**
 *縦横の四角を#で表示
 */ 
public class Main{
    public static void main(String[] args){
    	
        Scanner sc = new Scanner(System.in);
        while(true){
           int H = sc.nextInt();
           int W = sc.nextInt();
            if( H==0 && W==0 )break;
        	
            for(int i=0; i<H ;i++){
                for(int j=0; j<W ;j++){
                    System.out.print("#");
                }
                System.out.println();
            }
                System.out.println();
        }
    }
}


Measured memory_bytes: 32916
# 0: 下、1: 右、2: 上、3: 左、4: 右下、5: 右上、6: 左上、7: 左下
dx = [1, 0, -1, 0, 1, -1, -1, 1]
dy = [0, 1, 0, -1, 1, 1, -1, -1]

# 入力
H, W = map(int, input().split())
S = [input() for _ in range(H)]

# Python3 では str 型の要素の書き換えはできない
# 答えを格納する二次元配列を別途用意する ('.' のところは 0 とする)
result = [[0 if v == '.' else '#' for v in row] for row in S]

# 各マス (i, j) について順に処理
for i in range(H):
    for j in range(W):
        if S[i][j] != '.':
            continue
        for d in range(8):
            ni = i + dx[d]
            nj = j + dy[d]
            if ni < 0 or ni >= H or nj < 0 or nj >= W:
                continue
            if S[ni][nj] == '#':
                result[i][j] += 1

for row in result:
    # 出力形式に合わせて出力
    print(*row, sep = '')

Measured memory_bytes: 9392
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

int value(int x){
  int res = 0;
  while(x){
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main(){
  int n = in();
  int l = in();
  int r = in();
  int ans = 0;
  rep(i,1,n+1){
    int val = value(i);
    if(l <= val and val <= r){
      ans += i;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

#define REP(i, n) for (int i=0;i<n;++i)
#define MP make_pair
#define PB push_back

typedef double DB;
typedef long long LL;

const DB EPS = 1e-8;
const DB PI = acos(-1);
const DB gg = 9.8;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;


inline void checkMin(int &a, int b){
    if (b < a) a = b;
}

inline int sgn(double x){
    return x < -EPS ? -1 : x > EPS;
}

const int N = int(1e2) + 9;
int n, l[N], b[N], r[N], t[N];
int X, Y; DB V; int low;

inline DB y(DB a, DB x) {
    DB t = x/(V*cos(a));
    return V*sin(a)*t - 0.5*gg*t*t;
}

inline DB getM(DB a){
    DB t = V*sin(a)/gg;
    return V*cos(a)*t;
}

bool ck(DB a) {

    DB h = y(a, X); if (sgn(h-Y) < 0 || sgn(h-low) > 0 ) return false;
    DB mx = getM(a), my = y(a, mx);

    REP(i, n){

        DB h1 = y(a, l[i]), h2 = y(a, r[i]);

        if (l[i] <= mx && mx <= r[i]){
            if (!(h1 <= b[i] && h2 <= b[i] && my <= b[i] || h1 >= t[i] && h2 >= t[i] && my >= t[i])) return false;
        }
        else{
            if (!(h1 <= b[i] && h2 <= b[i] || h1 >= t[i] && h2 >= t[i])) return false;
        }
    }
    return true;
}

bool ck() {

    REP(i, n){
        if (l[i] == 0 && b[i] == 0) return false;
        if (l[i] <= X && X <= r[i]  && b[i] <= Y && Y <= t[i]) return false;
    }

    DB d = PI/2/10000;
    for (DB a=d;a<=PI/2;a+=d) if (ck(a)) return true;
    return false;
}

int main() {
    //freopen("in.txt", "r", stdin);
    while (~scanf("%d%lf%d%d", &n, &V, &X, &Y)) {
        low = INF; REP(i, n){
            scanf("%d%d%d%d", &l[i], &b[i], &r[i], &t[i]);
            if (l[i] > X){
                --i; --n;
                continue;
            }
            if (r[i] >= X){
                if (b[i] >= Y) checkMin(low, b[i]);
                r[i] = X;
            }
        }
        puts(ck() ? "Yes" : "No");
    }
}

Measured memory_bytes: 1196
#include <iostream>

using namespace std;

int main() {
    int n, a, b, c=1;
    cin >> n;
    cin >> a;
    for(int i=1;i<n;i+=1) {
        cin >> b;
        if (a <= b) {
            a = b;
            c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  while(true){
    int n,m,t,p;
    cin >> n>>m>>t>>p;
    if(n==0&&m==0&&t==0&&p==0)
      break;
    int Ori[64][64] = {{0}};
    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
        Ori[i][j]=1;
      }
    }
    for(int i=0;i<t;i++){
      int d,c;
      cin >> d>>c;
      if(d==1){
        for(int x=0;x<c;x++){
          for(int y=0;y<m;y++){
            Ori[y][2*c-1-x] += Ori[y][x];
            Ori[y][x]=0;
          }
        }
        for(int x=0;x<n;x++){
          for(int y=0;y<m;y++){
            Ori[y][x]=Ori[y][x+c];
            Ori[y][x+c]=0;
          }
        }
      }else{
        for(int y=0;y<c;y++){
          for(int x=0;x<n;x++){
            Ori[2*c-1-y][x] += Ori[y][x];
            Ori[y][x]=0;
          }
        }
        for(int y=0;y<m;y++){
          for(int x=0;x<n;x++){
            Ori[y][x]=Ori[y+c][x];
            Ori[y+c][x]=0;
          }
        }
      }
    }
    for(int i=0;i<p;i++){
      int x,y;
      cin>>x>>y;
      cout<<Ori[y][x]<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <string>

int main(){
	int n;
	std::cin >> n;
	std::cin.ignore();
	
	while(n--){
		std::string Eng;
		getline(std::cin, Eng);
		std::string::size_type pos = 0;
		while((pos = Eng.find("Hoshino", pos)) != std::string::npos){
			Eng.replace(pos, 7, "Hoshina");
			pos += 7;
		}
		std::cout << Eng << std::endl;
	}
	
    return 0;
}

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

int	main()
{
	int64_t	A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;
	if (A + B < 2 * C)
		cout << X * A + Y * B << endl;
	else if (X < Y && B < 2 * C) 
		cout << X * 2 * C + (Y - X) * B << endl;
	else if (X > Y && A < 2 * C) 
		cout << (X - Y) * A + Y * 2 * C << endl;
	else
		cout << max(X, Y) * 2 * C << endl;
}


Measured memory_bytes: 256
function main(lines) {
  const K = +lines[0];
  const S = lines[1];

  let res = K < S.length ? S.slice(0, K) + '...' : S;

  console.log(res);
}


main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );



function splitN(s) {
  return s.split(' ').map(Number);
}

Measured memory_bytes: 29628
//行・列基本変形しても答えが変わらないというギャグ。
//ランクrとすると、本質は(1, 1)をi箇所、{(0,0),(0,1),(1,0)}をr-i箇所作る問題。これは算数。
#include <iostream>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
typedef vector<int> Array;
typedef vector<Array> Mat;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return a * powmod(a, n - 1, mod) % mod;
}

int mod = 998244353;
int fact[301];
int finv[301];

int comb(int n, int k) {
	return fact[n] * finv[k] % mod * finv[n - k] % mod;
}

void henkei(Mat &a) {
	int h = a.size();
	int w = a[0].size();
	
	int i, j, k;
	int cor = 0;
	
	rep(i, w) {
		for (j = cor; j < h; j++) {
			if (a[j][i] == 1) {
				break;
			}
		}
		if (j == h) continue;
		
		int pos = j;
		rep(j, w) {
			swap(a[cor][j], a[pos][j]);
		}
		
		for (j = cor + 1; j < h; j++) {
			if (a[j][i] == 0) continue;
			rep(k, w) {
				a[j][k] ^= a[cor][k];
			}
		}
		cor++;
	}
}

void tenti(Mat &a) {
	int h = a.size();
	int w = a[0].size();
	Mat b(w, Array(h));
	
	int i, j;
	rep(i, h) rep(j, w) b[j][i] = a[i][j];
	a = b;
}

int _rank(Mat &a) {
	int i;
	rep(i, a.size()) {
		if (i >= a[0].size() || a[i][i] == 0) break;
	}
	return i;
}

signed main() {
	int i, j;
	
	fact[0] = finv[0] = 1;
	for (i = 1; i <= 300; i++) {
		fact[i] = i * fact[i - 1] % mod;
		finv[i] = powmod(fact[i], mod - 2, mod);
	}
	
	int n, m;
	cin >> n >> m;
	Mat a(n, Array(m));
	rep(i, n) rep(j, m) cin >> a[i][j];
	henkei(a);
	tenti(a);
	henkei(a);
	int r = _rank(a);
	int ans = 0;
	for (int i = 1; i <= r; i += 2) {
		ans += comb(r, i) * powmod(3, r - i, mod) % mod;
		ans %= mod;
	}
	ans *= powmod(2, n + m - 2 * r, mod);
	ans %= mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5316
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

ll digit_sum(ll x)
{
    ll sum = 0;

    while (x > 0) {
        sum += x % 10;
        x /= 10;
    }

    return sum;
}

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

    if (N % digit_sum(N) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# abc127/abc127_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))


def main():
    N, M = i2nn()
    L, R = (0, N)
    for i in range(M):
        Li, Ri = i2nn()
        if L < Li:
            L = Li
        if Ri < R:
            R = Ri
    if L > R:
        print(0)
    else:
        print(R - L + 1)
    return

main()


Measured memory_bytes: 3064
MOD = 1000000007
MAX = 10**6  # max n

fac = [0 for _ in range(MAX)]  # = n! (mod MOD)
finv = [0 for _ in range(MAX)]  # = 1/r! (mod MOD)
inv = [0 for _ in range(MAX)]  # = 1/r (mod MOD)


# init
def COMinit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD


# nCk, n < [0, MAX), k < [0, n]
def COM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

def main():
    # input
    x, y = map(int, input().split())
    if (x+y)%3 == 0:
        num = (x+y)//3
        for i in range(num+1):
            if i + 2*(num-i) == x and 2*i + (num-i) == y:
                break
        else:
            print(0)
            return
    else:
        print(0)
        return

    # calc
    COMinit()
    print(COM(num, i))


if __name__ == '__main__':
    main()


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

int main(void) {
	string S;
	cin >> S;
	int alfabet[26] = {0};
	for (int i = 0; i < S.length(); i++) {
		alfabet[S[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (alfabet[i] == 0) {
			printf("%c\n", 'a' + i);
			return 0;
		}
	}
	printf("None\n");
	return 0;

}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int mod = 1e9 + 7;
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
struct mint {
  ll x; // typedef long long ll;
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){ 
  int n;
  cin >> n;
  ll zero = 0;
  map<pair<ll, ll>, P> mp; 
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      zero++;
      continue;
    }
    ll g = gcd(x, y);
    x /= g;
    y /= g;
    if (y < 0) x = -x, y = -y;
    if (y == 0 && x < 0) x = -x, y = -y;
    bool ok = false;
    if (x <= 0) ok = true;
    if (ok) {
      ll tmp = x;
      x = y; y = -tmp;
    }
    if (ok) mp[{x, y}].first++;
    else mp[{x, y}].second++;
  }

  mint res = 1;

  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    mint cur = 1;
    cur += mint(2).pow(s) - 1;
    cur += mint(2).pow(t) - 1;
    res *= cur;
  }
  res -= 1;
  res += zero;
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 16128
#include <bits/stdc++.h>
//\\//\\//\\//\\//\\//\\//\\//
#define fio ios::sync_with_stdio(false); cin.tie(nullptr)
#define all(x) (x).begin(),(x).end()
#define dlog(x) cerr<<#x<<'='<<x<<'\n'
#define endl '\n'
#define eb emplace_back
#define f first
#define s second
//\\//\\//\\//\\//\\//\\//\\//
using namespace::std;
using ll=long long;
using pii=pair<int,int>;
const int inf=INT_MAX,mod=1e9+7;
//\\//\\//\\//\\//\\//\\//\\//


ll solve(ll x) {
      if (x==1) return 1;
      ll p=solve(x/2);
      return 2*p+1;
}

signed main(){
      fio;
      ll x; cin>>x;
      cout<<solve(x)<<endl;
      return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N= S.size();
  int x =0;
  for(int i=0;i<N;i++){
   for(int j=0;j<N;j++){
    if(i != j && S[i] == S[j]){
	x++;
    }
      
      
   }
  }
  if(x > 0 ){
   cout << "no" <<endl; 
  }
  else {
   cout <<"yes" <<endl; 
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
int n,k;
    cin>>n>>k;
    int x;
    vector<int>v;
    vector<int>a;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        v.push_back(x);
       
    }
    
    for(int i=0;i<n-k+1;i++){
        a.push_back((min(abs(v[i])+abs(v[i+k-1]-v[i]),abs(v[i+k-1])+abs(v[i+k-1]-v[i]))));


    }
    sort(a.begin(),a.end());
    cout<<a[0]<<endl;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

const ll mo0=1000000021,mo1=1000000009;
ll mul0,mul1;
const ll add0=1000010007, add1=1003333331;
vector<ll> pmo[2];
vector<ll> hash_[2];
struct RollingHash {
	vector<int> s; int l; 
	void init(vector<int> s) {
		this->s=s; l=s.size(); int i,j;
		hash_[0]=hash_[1]=vector<ll>(1,0);
		FOR(i,l) hash_[0].push_back((hash_[0].back()*mul0+add0+s[i])%mo0);
		FOR(i,l) hash_[1].push_back((hash_[1].back()*mul1+add1+s[i])%mo1);
	}

	pair<ll,ll> hash(int l,int r) { // s[l..r]
		if(l>r) return make_pair(0,0);
		while(pmo[0].size()<r+2)
			pmo[0].push_back(pmo[0].back()*mul0%mo0), pmo[1].push_back(pmo[1].back()*mul1%mo1);
		return make_pair((hash_[0][r+1]+(mo0-hash_[0][l]*pmo[0][r+1-l]%mo0))%mo0,
			             (hash_[1][r+1]+(mo1-hash_[1][l]*pmo[1][r+1-l]%mo1))%mo1);
	}
	static pair<ll,ll> concat(pair<ll,ll> L,pair<ll,ll> R,int RL) { // hash(L+R) RL=len-of-R
		while(pmo[0].size()<RL+2) pmo[0].push_back(pmo[0].back()*mul0%mo0), pmo[1].push_back(pmo[1].back()*mul1%mo1);
		return make_pair((R.first + L.first*pmo[0][RL])%mo0,(R.second + L.second*pmo[1][RL])%mo1);
	}
};

int N,K;
vector<int> P;

int NV=1<<20;
vector<pair<pair<ll,ll>,int>> val;

pair<pair<ll,ll>,int> comp(pair<pair<ll,ll>,int>& A,pair<pair<ll,ll>,int>& B) {
	int L=A.second+B.second;
	pair<ll,ll> P=RollingHash::concat(A.first,B.first,B.second);
	return {P,L};
}

void update(int entry, pair<pair<ll,ll>,int> v) {
	entry += NV;
	val[entry]=v;
	while(entry>1) entry>>=1, val[entry]=comp(val[entry*2],val[entry*2+1]);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	mul0=10009+(((ll)&mul0)>>5)%259,mul1=10007+(((ll)&mul1)>>5)%257;
	pmo[0].push_back(1),pmo[1].push_back(1);
	
	val.resize(2*NV);
	
	cin>>N>>K;
	FOR(i,N) {
		cin>>x;
		P.push_back(x);
	}
	RollingHash rh;
	rh.init(P);
	
	set<pair<ll,ll>> S;
	
	FOR(i,K-1) update(P[i],make_pair(make_pair(P[i]+add0,P[i]+add1),1));
	for(i=0;i+K<=N;i++) {
		update(P[i+K-1],make_pair(make_pair(P[i+K-1]+add0,P[i+K-1]+add1),1));
		auto HL=rh.hash(0,i-1);
		auto HM=val[1];
		auto HR=rh.hash(i+K,N-1);
		
		HR=RollingHash::concat(HM.first,HR,N-i-K);
		HL=RollingHash::concat(HL,HR,N-i);
		S.insert(HL);
		update(P[i],make_pair(make_pair(0,0),0));
	}
	
	cout<<S.size()<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 70240
#include <bits/stdc++.h>
 
using namespace std;
 
const int N=3e2+10;
 
int n,m,a[N][N];
int des[N],h[N],co[N];
 
bool check(int len){
    memset(des,0,sizeof(des));
    memset(h,0,sizeof(h));
    memset(co,0,sizeof(co));
    int rem=m;
    for(int i=1;i<=n;i++) co[a[i][++h[i]]]++;
    while (rem){
        int old=rem;
        for(int i=1;i<=m;i++) if (co[i]>len){
            des[i]=1;
            for(int j=1;j<=n;j++){
                co[a[j][h[j]]]--;
                while (h[j]<=m&&des[a[j][h[j]]]) h[j]++;
                co[a[j][h[j]]]++;
            }
            rem--;
        }
        if (old==rem) {
//            cout<<len<<'\n';
//            for(int i=1;i<=m;i++) cout<<des[i]<<" \n"[i==m];
            return 1;
        }
    }
    return 0;
}
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) scanf("%d",a[i]+j);
    int L=1,R=n;
    while (L<=R){
        int mid=(L+R)/2;
        if (check(mid)) R=mid-1;
        else L=mid+1;
    }
    cout<<L;
}

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

namespace AtCoderConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            // 標準入力から1行取得
            string input = Console.ReadLine();

            // AとBを取得
            int a = int.Parse(input.Split(' ')[0]);
            int b = int.Parse(input.Split(' ')[1]);

            // 出力を宣言
            string output = string.Empty;

            // どちらかが9以上の場合、隣り合うケーキを取ってしまうことになる
            if(a>=9 || b >= 9)
            {
                output = ":(";
            }
            else
            {
                output = "Yay!";
            }

            // 標準出力に出力
            Console.WriteLine(output);
        }
    }
}

Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var As = new List<A>();
            for (int i = 0; i < N; i++)
            {
                var a = new A();
                var shougenCount = int.Parse(Console.ReadLine());
                for (int j = 0; j < shougenCount; j++)
                {
                    var xy = Console.ReadLine().Split(' ');
                    a.Shougens.Add(new Shougen
                    {
                        X = int.Parse(xy[0]),
                        Y = int.Parse(xy[1]) == 1,
                    });
                }

                As.Add(a);
            }

            var patterns = GetTFPattern(N).ToList();
            var valids = patterns.Where(x => IsValid(As, x));

            if (!valids.Any())
            {
                Debug.WriteLine(0);
                Console.WriteLine(0);
            }
            var max = valids.Max(x => x.Count(y => y));
            Debug.WriteLine(max);
            Console.WriteLine(max);
        }
        private static bool IsValid(List<A> As, List<bool> pattern)
        {
            foreach (var a in As.Select((a, i) => new { A = a, Index = i }))
            {
                // 信用しないので無視
                if (pattern[a.Index] == false) continue;

                // 矛盾するかどうかの判定
                if (a.A.Shougens.Any(x => pattern[x.X - 1] != x.Y))
                {
                    return false;
                }
            }

            return true;
        }
        private static IEnumerable<List<bool>> GetTFPattern(int n)
        {
            for (int i = 0; i < Math.Pow(2, n); i++)
            {
                yield return Convert.ToString(i, 2).PadLeft(n, '0').Select(x => x == '1').ToList();
            }
        }

        class A
        {
            public List<Shougen> Shougens { get; set; } = new List<Shougen>();
        }
        class Shougen
        {
            public int X { get; set; }
            public bool Y { get; set; }
        }
    }
}


Measured memory_bytes: 23112
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        pw.println(Integer.parseInt(br.readLine())>=30?"Yes":"No");
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 32904
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX 10000005
#define mod 1000000007
#define sp fixed<<setprecision(12)
using namespace std;
/*
vector<int> primes;
ll sumprime[MAX];
bool is_prime[MAX];
void sieve(){
    is_prime[0]=is_prime[1]=true;
    for(int i=4;i<MAX;i+=2){
        is_prime[i]=true;
    }
    for(int i=3;i*i<MAX;i+=2){
        if(!is_prime[i]){
            for(int j=i*i;j<MAX;j+=i){
                is_prime[j]=true;
            }
        }
    }
    for(int i=0;i<MAX;i++){
        if(!is_prime[i]){
            sumprime[i]=sumprime[i-1]+i;
        }else{
            sumprime[i]=sumprime[i-1];
        }
    }
}
*/
/*
void lcs(char s1[],char s2[]){
    int n=strlen(s1);
    int m=strlen(s2);
    vector<vector<int>> dp(n+1,vector<int>(m+1,0));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int sum=0;
            if(s1[i-1]==s2[j-1]){
                sum=1+dp[i-1][j-1];
            }
            else{
                sum=max(dp[i-1][j],dp[i][j-1]);
            }
            dp[i][j]=sum;
        }
    }
    
    int index=dp[n][m];
    //cout<<index<<endl;
    char ans[index+1];
    ans[index]='\0';
    index--;
    int x=n;
    int y=m;
    while(x>0 and y>0){
        if(dp[x-1][y]==dp[x][y-1] and dp[x-1][y]!=dp[x][y]){
            ans[index]=s1[x-1];
            index--;
            x--;
            y--;
        }else if(dp[x-1][y]>dp[x][y-1]){
            x--;
        }else{
            y--;
        }

    }
    //reverse(ans.begin(),ans.end());

    cout<<ans;
    return;
}
*/
string s[1001];
int dp[1001][1001];

using namespace std;
int32_t main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    //double    pi=3.14159265358979323846;
    //sieve();
    int t=1;
    //cin>>t;
    for(int tc=1;tc<=t;tc++){
        int n,m;
        cin>>n>>m;
        for(int i=0;i<n;i++){
            cin>>s[i];
        }
        dp[0][0]=1;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(s[i][j]=='#'){
                    dp[i][j]=0;
                    continue;
                }
                if(i>0){
                    dp[i][j]+=dp[i-1][j];
                    dp[i][j]%=mod;
                }
                if(j>0){
                    dp[i][j]+=dp[i][j-1];
                    dp[i][j]%=mod;
                }
            }
        }
        cout<<dp[n-1][m-1]<<'\n';

    }
    
    
    
    
    
    return 0;
    
}

Measured memory_bytes: 12488
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    string s;

    cin >> s;

    if (s[1] == s[2] && (s[0] == s[1] || s[2] == s[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100000;
int n;
ll a[maxn + 10], b[maxn + 10], sa, sb, ans, tot;
bool vis[maxn * 2 + 10];
struct node {
	int id; ll v;
	bool operator < (const node &t) const {
		return v < t.v;
	}
}c[maxn * 2 + 10];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld%lld", &a[i], &b[i]);
		sa += a[i]; sb += b[i];
		c[i * 2 - 1] = (node){i * 2 - 1, a[i]};
		c[i * 2] = (node){i * 2, b[i]};
	}
	ans = min(sa, sb);
	sort(c + 1, c + n * 2 + 1);
	for (int i = 1; i <= n - 2; ++i) {
		tot += c[i].v; vis[c[i].id] = 1;
	}
	for (int i = 1; i <= n; ++i) {
		ll now = tot + a[i] + b[i];
		int cnt = n - 2;
		if (vis[i * 2 - 1]) {
			now -= a[i]; 
			++cnt;
			if (c[cnt].id == i * 2 || c[cnt].id == i * 2 - 1) ++cnt;
			now += c[cnt].v;
		}
		if (vis[i * 2]) {
			now -= b[i]; 
			++cnt;
			if (c[cnt].id == i * 2 || c[cnt].id == i * 2 - 1) ++cnt;
			now += c[cnt].v;
		}
		ans = min(ans, now);
	}
	printf("%lld", ans);
}


Measured memory_bytes: 5120
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	s := make([]int, n)

	var d, a int
	for i := 0; i < k; i++ {
		fmt.Scan(&d)
		for j := 0; j < d; j++ {
			fmt.Scan(&a)
			s[a-1] ++
		}
	}

	c := 0
	for _, v := range s {
		if v == 0 {
			c++
		}
	}

	fmt.Println(c)
}


Measured memory_bytes: 2324
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n=0,e=0,w=0,s=0;
  string h;
  cin>>h;
  for(int i=0;i<h.length();i++){
    if(h[i]=='N') n+=1;
    else if(h[i]=='E') e+=1;
    else if(h[i]=='W') w+=1;
    else s+=1;
  }
  
  if(n>0&&e>0&&w>0&&s>0) cout<<"Yes"<<endl;
  else if(n>0&&s>0&&e==0&&w==0) cout<<"Yes"<<endl;
  else if(n==0&&s==0&&e>0&&w>0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int dp[3010][3010];
pair<int, int> p[3010][3010];

void solve()
{
  string s, t; cin >> s >> t;
  int n = s.size(), m = t.size();
  
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      if (s[i] == t[j])
      {
        dp[i + 1][j + 1] = dp[i][j] + 1;
        p[i + 1][j + 1] = make_pair(i, j);
      }
      else
      {
        if (dp[i + 1][j] > dp[i][j + 1])
        {
          dp[i + 1][j + 1] = dp[i + 1][j];
          p[i + 1][j + 1] = make_pair(i + 1, j);
        }
        else
        {
          dp[i + 1][j + 1] = dp[i][j + 1];
          p[i + 1][j + 1] = make_pair(i, j + 1);
        }
      }
    }
  }
  
  string ans = "";
  
  int a = n;
  int b = m;
  
  while (ans.size() != dp[n][m])
  {
    if (s[a - 1] == t[b - 1])
    {
      ans += s[a - 1];
    }
    int aa = p[a][b].first;
    int bb = p[a][b].second;
    a = aa, b = bb;
  }
  
  reverse(ans.begin(), ans.end());
  
  cout << ans << endl;
}

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

Measured memory_bytes: 106368
n, m = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] = a[i]//2
    
# print(a)
def calc(n):
    ret = 0
    while n%2 == 0:
        ret +=1
        n//=2
    return ret


flag = True
t = 0
for i in range(n-1):
    t = 2**calc(a[i])
    if calc(a[i]) == calc(a[i+1]):
        # print(calc(a[i]),calc(a[i+1]))
        continue
    else:
        flag = False
        break


def gcd(a, b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)



if flag:
    lcm = 1
    for i in range(n):
        p = max(lcm, a[i])
        q = min(lcm, a[i])
        lcm = lcm*a[i]//gcd(p, q)
        # print(lcm)
    if (m//lcm)%2 == 0:
        print(int((m//lcm)//2))
    else:
        print(int((m//lcm+1)//2))

else:
    print(0)


Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(ll i=1;i<=(n);++i)
#define ifr(i,n) for(ll i=(n)-1;i>=0;--i)
#define iFr(i,n) for(ll i=(n);i>0;--i)
//グローバルな場所に配列を置くとすべて0に初期化される。

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n,m,o,j,ans,a;
  j=0;
  ans=0;
  cin>>n>>m;
  o=pow(2, n);
  ll arr[m]={0};
  ll arr2[n][m];
  ll tehon[m];
  fr(i,n){
    fr(l,m){
      arr2[i][l]=0;
    }
  }
  fr(i,m){
    int b;
    cin>>a;
    a;
    fr(l,a){
      cin>>b;
      --b;
      arr2[b][i]=1;
    }
  }
  fr(i,m){
    cin>>a;
    tehon[i]=a;
  }
  fr(i,o){
    fr(l,m){
      arr[l]=0;
    }
  j=0;
    fr(l,n){
      if(i & (1<<l)){
        fr(k,m){
          arr[k]+=arr2[l][k];
        }
      }
    }
    fr(l,m){
      if(arr[l]%2!=tehon[l]){
        j=1;
      }
    }
    if(!j){
      ++ans;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
import collections
from operator import itemgetter

N = int(input())

up = []
down = []
for i, v in enumerate(list(map(int, input().split()))):
    if i % 2 == 0:
        up.append(v)
    else:
        down.append(v)

ud = collections.Counter(up)
dd = collections.Counter(down)

ul = []
for u, c in ud.items():
    ul.append([u, c])
dl = []
for d, c in dd.items():
    dl.append([d, c])

ul.sort(key=itemgetter(1), reverse=True)
dl.sort(key=itemgetter(1), reverse=True)

if ul[0][0] != dl[0][0]:
    print(N - ul[0][1] - dl[0][1])
elif len(ul) == 1 and len(dl) > 1:
    print(N - ul[0][1] - dl[1][1])
elif len(ul) > 1 and len(dl) == 1:
    print(N - ul[1][1] - dl[0][1])
elif len(ul) == 1 and len(dl) == 1:
    print(N//2)
else:
    print(N - max(ul[0][1]+dl[1][1], ul[1][1]+dl[0][1]))

Measured memory_bytes: 24264
#include<stdio.h>

int battle(int a, int b, int c, int d) {
   while(a > 0 && c > 0) {
      a -= d;
      c -= b;
   }
   if(c > 0) {
      return 0;
   }
   return 1;
}

int main() {
   int a,b,c,d;
   scanf("%d %d %d %d", &a, &b, &c, &d);
   if(battle(a,b,c,d) == 1) {
      printf("Yes\n");
   }else {
      printf("No\n");
   }
   return 0;
}


Measured memory_bytes: 1648
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Cin(type, val) type val; cin >> val;
#define Cout(val) cout << (val) << "\n";
#define Range(container) container.begin(), container.end()
#define RevRange(container) container.rbegin(), container.rend()
using namespace std;
using ll = long long;
 
using Sushi = pair<int, int>;
#define del first
#define typ second
 
int main(void){
    Cin(int, n);
    Cin(int, k);
    vector<Sushi> sushi(n);
    For(i, n) cin >> sushi[i].typ >> sushi[i].del;
    sort(RevRange(sushi));
    
    vector<ll> disposable, numTypes(n+1);
    ll d = 0;
    For(i, k){
        if(numTypes[sushi[i].typ] ++) disposable.push_back(sushi[i].del);
        else numTypes[0] ++;
        d += sushi[i].del;
    }
    sort(RevRange(disposable));
    
    ll ans = d + numTypes[0] * numTypes[0];
    for(int i = k; i < n; i ++){
      	if(disposable.empty()) break;
        if(numTypes[sushi[i].typ]) continue;
        d = d + sushi[i].del - disposable.back();
        disposable.pop_back();
        numTypes[0] ++;
        numTypes[sushi[i].typ] ++;
        ans = max(ans, d + numTypes[0] * numTypes[0]);
    }
    
    Cout(ans);
}

Measured memory_bytes: 2428
/************************************************************
	> File Name: a.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Sun 31 May 2020 08:00:53 PM CST
************************************************************/
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#include <ext/rope>
#define lowbit(x) (x&-x)
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<LL> vll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int INF = 0x3f3f3f3f;
const LL INF_ll = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-8;
signed main(void){
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
void so(int n,int *p)
{
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(p[i]>p[j]){int t=p[i];p[i]=p[j];p[j]=t;}}}}

int main()
{
  int N,K;
  cin>>N>>K;
  int p[N];
  for(int i=0;i<N;i++) cin>>p[i];
  so(N,p);
  int c=0;
  int sum=0;
  while(K>0){
    sum+=p[c];
    K--;c++;
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
#define REP(i, n) for (i64 (i) = 0; (i) < (n); ++(i))
#define FOR(i, a, b) for (i64 (i) = (a); (i) < (b); ++(i))

struct UnionFind {
    int V;
	// par[x] := xのroot
	vector<int> par;
	// sz[x] := xを含む集合のサイズ
	vector<int> sz;
	UnionFind(int V) :
		V(V),
		par(vector<int>(V)),
		sz(vector<int>(V, 1))
		{
			for(int i = 0; i < V; ++i) par[i] = i;
		}
	bool unite(int x, int y) {
		x = root(x), y = root(y);
		if(same(x, y)) return false;
		if(y < x) swap(x, y);
		par[y] = x;
		sz[x] += sz[y];
		return true;
	}
	int root(int x) {
		if(par[x] == x) return x;
		return (par[x] = root(par[x]));
	}
	bool same(int x, int y) {
		return (root(x) == root(y));
	}
	int size(int x) {
		return sz[root(x)];
	}
};

int N, M;

void solve() {
    ui64 res = 0;
    UnionFind uf(N);
    map<int, vector<int>, greater<>> H;
    REP(i, N) {
        int h; cin >> h;
        H[h].emplace_back(i);
    }
    vector<vector<pair<int, int>>> graph(N, vector<pair<int, int>>());
    // vector<tuple<int, int, int>> edges;
    REP(i, M) {
        int A, B, C;
        cin >> A >> B >> C;
        --A, --B;
        graph[A].emplace_back(B, C);
        graph[B].emplace_back(A, C);
        // edges.emplace_back(A, B, C);
    }
    vector<bool> connected(N, false);
    int connected_vertex = 0;
    for (auto& e: H) {
        auto& vec = e.second;
        connected_vertex += e.second.size();
        // cerr << "time: " << e.first << endl;
        // for (auto& i: vec) cerr << i + 1 << ' ';
        // cerr << endl;

        vector<bool> want(N, false);
        vector<tuple<int, int, int>> need;
        for (auto& g: vec) want[g] = true;
        REP(i, N) if (want[i] or connected[i]) {
            for (auto& edge: graph[i]) {
                if (want[edge.first] or connected[edge.first]) {
                    need.emplace_back(edge.second, i, edge.first);
                }
            }
        }
        sort(need.begin(), need.end());
        for (auto& g: need) {
            int cst, frm, dst;
            tie(cst, frm, dst) = g;
            if (uf.unite(frm, dst)) {
                res += cst;
            }
        }
        // cout << res << endl << endl;
        if (uf.size(H.begin()->second[0]) != connected_vertex) {
            // connected_vertex = 0;
            // cout << "sink : " << e.second.size() << endl;
            res = 0;
            uf = UnionFind(N);

            // vector<int> con;
            // REP(i, N) if (connected[i] or want[i]) con.emplace_back(i);
            // REP(i, con.size() - 1) uf.unite(con[i], con[i + 1]);
        }
        for (auto& g: vec) connected[g] = true;
    }
    // if (uf.size(0) != N) cout << 0 << endl;
    // else cout << res << endl;
    cout << res << endl;
}

signed main() {

    while (cin >> N >> M, N) {
        solve();
    }

}


Measured memory_bytes: 4672
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	cin >> n;
	string s[n];
	ll sum = 0;
	map< string , ll> mp;
	for(int i = 0 ; i < n ; i++){
		cin >> s[i];
		sort(s[i].begin() , s[i].end());
		if(mp[s[i]]){
			sum += mp[s[i]];
		}
		mp[s[i]]++;
	}
	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 16640
#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)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A) {
  if (A.size() == n+1) {
    int now = 0;
    rep(i,q) {
      if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    chmax(ans, now);
    return;
  }
  
  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return(0);
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

int main(int argc, char** argv) {
  int a, b, c;
  cin >> a;
  cin >> b;
  cin >> c;

  int cap = a - b;
  if (c > cap) {
    cout << c - cap << endl;
  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import numpy as np
n,k = map(int,input().split())
# python3だとTLE
h = np.array(input().split(), dtype=np.int64)
#h = list(map(int,input().split()))
dp = np.zeros(n,dtype=np.int64)
for i in range(1,n):
    l = max(0,i-k)
    dp[i] = np.min(np.abs(h[i]-h[l:i]) + dp[l:i] )
"""
INF = 10**12 #最大を考えて初期化は大きく
dp = [INF]*n
dp[0] = 0 #初期化
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    for j in range(1,k+1):
        if i - j >= 0: 
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))"""
print(dp[n-1])

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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {
  
  long long r,d,x;
  cin >> r >> d >> x;
  
  for ( int i = 1; i <= 10; i++){
    x = r * x - d;
    cout << x << endl;
  }
  
}

Measured memory_bytes: 256