akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
 
#define INIT() std::ios::sync_with_stdio(false);std::cin.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i)
 
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
 
#define LOWBIT(x) ((x)&(-x))
 
#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())
 
#define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a))

#define MP make_pair
#define PB push_back
#define ft first
#define sd second
 
template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
    in >> p.first >> p.second;
    return in;
}
 
template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
    for (auto &x: v)
        in >> x;
    return in;
}
 
template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]" << "\n";
    return out;
}
 
typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef pair< int, int > PII;
typedef set< int > SI;
typedef vector< int > VI;
typedef map< int, int > MII;
const double EPS = 1e-10;
const int inf = 1e9 + 9;
const LL mod = 1e9 + 7;
const int maxN = 1e5 + 7;
const LL ONE = 1;
const LL evenBits = 0xaaaaaaaaaaaaaaaa;
const LL oddBits = 0x5555555555555555;

LL fac[2*maxN], inv[2*maxN + 1];

//ax + by = gcd(a, b) = 1
// 扩展欧几里德算法
inline void ex_gcd(LL a, LL b, LL &x, LL &y, LL &d){
    if (!b) {d = a, x = 1, y = 0;}
    else{
        ex_gcd(b, a % b, y, x, d);
        y -= x * (a / b);
    }
}

// 求a关于p的逆元，如果不存在，返回-1 
// a与p互质，逆元才存在 
LL inv_mod(LL a, LL p){
    LL d, x, y;
    ex_gcd(a, p, x, y, d);
    return d == 1 ? (x % p + p) % p : -1;
}

// Calculate x^y % p
inline LL pow_mod(LL x, LL y, LL p){
	LL ans = 1;
	while(y){
		if(y & 1) ans = (ans * x) % p;
        x = (x * x) % p;
        y >>= 1;
	}
	return ans;
} 

LL comb_mod(LL m,LL n){
	LL ans;

	if(m > n) swap(m, n);
	
	//ans = (fac[n] * inv[fac[m]]) % mod;
	//ans = (ans * inv[fac[n - m]]) % mod;
	ans = (fac[n] * inv_mod(fac[m], mod)) % mod;
	ans = (ans * inv_mod(fac[n - m], mod)) % mod;
	
	return ans;
}

void init_fact() {
	fac[0] = 1;
	For(i, 1, 2*maxN - 1) {
		fac[i] = (i * fac[i - 1]) % mod;
	}
}

void init_inv() {
	
}

int H, W, A, B;

LL ans;

int main(){
	INIT();
	init_fact();
	//init_inv();
	cin >> H >> W >> A >> B; 
	For(i, 1, H - A) {
		ans = ans + (comb_mod(i - 1, i + B - 2) * comb_mod(W - B - 1, W - B + H - i - 1)) % mod;
		ans %= mod;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())
S = []
C = []
for i in range(M):
    s, c = input().split()
    S.append(int(s))
    C.append(int(c))


A = ["x"]*N
for a, b in zip(S, C):
    if A[a-1] == "x":
        A[a-1] = b
    else:
        if b == A[a-1]:
            A[a-1] = b
        else:
            print(-1)
            exit()

if N != 1 and A[0] == "x":
    A[0] = 1

if A[0] == "x":
    if N != 1:
        print(-1)
        exit()
if A[0] == 0 and N != 1:
    print(-1)
    exit()

for a in range(N):
    if A[a-1] == "x":
        A[a-1] = 0
for a in A:
    print(a, end="")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define ARRAY_MAX 105

int main(){

    int n,x;
    bool ans = false;
    cin >> n >> x;
    vector<int> a(2*n-1);
    if(x == 1 || x == 2*n-1){
        ans = false;
    }else{
        ans = true;
        int maxi = x;//右半分用
        int middle = (2*n-1)/2;
        a[middle] = maxi;
        for(int i = 1;i <= (2*n-2)/2;i++){
            a[middle+i] = maxi-i > 0 ? maxi-i : maxi-i+(2*n-1);
            a[middle-i] = maxi+i <= (2*n-1) ? maxi+i : maxi+i-(2*n-1); 
        }
    }

    if(ans){
        cout << "Yes" << endl;
        REP(i,a.size()){
            cout << a[i] << endl;
        }
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	int x=0,y=0;
	lol(i,n){
		if(s[i]=='a'){
			if(x<a+b){
				cout<<"Yes"<<endl;
				x++;
			}
			else cout<<"No"<<endl;
		}
		if(s[i]=='b'){
			if(x<a+b&&y<b){
				cout<<"Yes"<<endl;
				x++,y++;
			}
			else cout<<"No"<<endl;
		}
		if(s[i]=='c')cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 100000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back


void f(int n,int m){
  vector<bool> v(10000000,false);

  int i=n;
  while(m>0){
    if(!v[i]){
      for(int j=i;j<10000000;j+=i){
        v[j]=true;
      }
      m--;
    }
    i++;
  }
  while(v[i]) i++;

  cout<<i<<endl;
}

int main(){
  int n,m;
  while(true){
    cin>>n>>m;
    if(!n) break;
    f(n,m);
  }
}



Measured memory_bytes: 4300
k = 31
K = 1<<k
nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(1001)]]

N = int(input())
A = [int(a) for a in input().split()]
C = [0] * 1001
for a in A:
    C[a] += 1
B = li(st(nu(C) ** 2))
for a in A:
    if a <= 500: B[2*a] -= 1
for i in range(1001):
    B[i] //= 2
for i in range(1, 1001):
    C[i] += C[i-1]
ans = N*(N-1)*(N-2)//6
for i in range(1, 1001):
    ans -= (N-C[i-1]) * B[i]
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    double a, b, x;
    cin >> a >> b >> x;
    double border = a * a * b / 2;
    double ans;
    if (x > border) {
        double y = 2 * (b - x / pow(a, 2));
        ans = atan(y / a);
    }
    else if (x == border) {
        ans = atan(b / a);
    }
    else {
        double y = 2 * x / a / b;
        ans = atan(b / y);
    }
    ans = ans * 180 / acos(-1.0);
    cout << setprecision(10) << ans << "\n";
}

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

using namespace std;
const int N = 1e5 + 5;

int nn, n;
int a[N << 1];

int small(int x, int y, int k) {
	return (a[x] <= k && a[y] <= k);
}

int big(int x, int y, int k) {
	return (a[x] > k && a[y] > k);
}

bool check(int k) {
	if (small(n, n - 1, k) || small(n, n + 1, k)) return 1;
	if (big(n, n - 1, k) || big(n, n + 1, k)) return 0;
	for (int i = 1; i < n - 1; i ++) {
		if (small(n - i, n - i - 1, k) || small(n + i, n + i + 1, k)) return 1;
		if (big(n - i, n - i - 1, k) || big(n + i, n + i + 1, k)) return 0;
	}
	return small(1, 1, k);
}

int main() {
	scanf("%d", &n);
	nn = 2 * n - 1;
	for (int i = 1; i <= nn; i ++) scanf("%d", &a[i]);
	int l = 1, r = nn, pos;
	while (l < r) {
		int mid = (l + r) >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	printf("%d\n", r);
	return 0;	
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

class Main{



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int a = sc.nextInt();
		int[] x = new int[n+1];
		for(int i = 1;i <= n;i++){
			x[i] = sc.nextInt();
		}
		Arrays.sort(x);

		long[][][] dp = new long[51][51][50*50+1];

		
		for(int i = 0;i <= n;i++){
			for(int j = 0;j<= n;j++){
				for(int k = 0;k <= 2500;k++){
					if(i == 0 && j == 0 && k == 0){
						dp[i][j][k] = 1;
						
						
					}else if(i >= 1 && k < x[i]){
						
						dp[i][j][k] = dp[i-1][j][k];
					}else if(i >= 1 && j >= 1 && k >= x[i]){
						
						dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i]];
					}else{
						
						dp[i][j][k] = 0;
					}
				}
			}
		}
		
		long ans = 0;
		for(int i = 1;i <= n;i++){
			ans += (long)dp[n][i][i*a];
		}

		System.out.println(ans);

	}
}

Measured memory_bytes: 86560
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
#include <numeric>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
//#define int ll

const int md = 1000000007;
const int INF = 1<<30;



int main(){
    int p,q,r; cin >> p >> q >> r;

    cout << min(p+q,min(p+r,q+r)) << endl;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

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

  vector<int> idx(26, -1);
  rep(i, s.size()) {
    int ii = s[i] - 'a';
    if (idx[ii] != -1) {
      cout << "-1" << endl;
      return 0;
    }
    idx[ii] = i;
  }

  if (s.size() != 26) {
    rep(i, 26) if (idx[i] == -1) {
      s += (char)('a' + i);
      cout << s << endl;
      return 0;
    }
  } else {
    for (int i = 25; i >= 0; i--) {
      if (s[i] == 'z') continue;
      REP(k, 1, 26) {
        int ii = (int)(s[i] - 'a' + k);
        if (ii >= 26) break;
        if (i < idx[ii]) {
          rep(j, i) cout << s[j];
          cout << (char)('a' + ii) << endl;
          return 0;
        }
      }
    }
  }

  cout << "-1" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main(){
  int N, K;
  cin >> N >> K;
  vector<vector<int>> m(K+1, vector<int>(K+1, 0));
  REP(i, N) {
    int X, Y;
    char C;
    cin >> X >> Y >> C;
    X %= K * 2;
    Y %= K * 2; 
    bool c = (C == 'B') ^ (X >= K) ^ (Y >= K);
    m[X%K+1][Y%K+1] += c ? 1 : -1;
  }
  REP(i, K) {
    REP(j, K) {
      m[i+1][j+1] += m[i+1][j] + m[i][j+1] - m[i][j];
    }
  }
  int ret = 0;
  REP(i, K) {
    REP(j, K) {
      int score = m[K][K] - m[i+1][K] * 2 - m[K][j+1] * 2 + m[i+1][j+1] * 4;
      ret = max(ret, (N + abs(score)) / 2);
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>

int main() {
	int n, n_, sum;

	scanf("%d", &n);
	sum = 0;
	n_ = n;
	while (n > 0)
		sum += n % 10, n /= 10;
	printf(n_ % sum == 0 ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()

using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;

ll ryuka(int n){
	if(n == 1)return 2;
	else if(n == 2)return 1;

	else{
		ll num = 0;
		ll num1 = 2;
		ll num2 = 1;
		for(int i = 3;i <= n;i++){
			num = num1 + num2;
			num1 = num2;
			num2 = num;
		}
		return num;

	}
}

int main(void){
	int N;cin>>N;
	if(N == 0)cout<<2;
	else if(N == 1)cout<<1;
	else {
		cout<<(ryuka(N + 1));
	}
}


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

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if(s[k-1] == 'A'){
        s[k-1] = 'a';
    }else if(s[k-1] == 'B'){
        s[k-1] = 'b';
    }else{
        s[k-1] = 'c';
    }
    cout << s;

    return 0;
}

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

typedef pair<int, int> P;
typedef pair<P, int> T;
int main(){
  int n, x;
  char c;
  while(cin >> n, n){
    map<T, char> mem;
    for(int i = 0;i < n;i++){
      T tmp = T(P(0, 0), i);
      cin >> c;
      for(int j = 1;j < n;j++){
	cin >> x;
	if(x == 0)tmp.first.first--;
	if(x == 1)tmp.first.second++;
      }
      mem[tmp] = c;
    }
    map<T, char>::iterator it = mem.begin();
    while(it != mem.end()){
      cout << it->second << endl;
      it++;
    }
  }
  return 0;
}

Measured memory_bytes: 1188
parseInts :: String -> [Int]
parseInts = map (\x -> read x :: Int).words

main :: IO ()
main = do
    _    <- getLine
    line <- getLine
    let
        nums = parseInts line
        minN = minimum nums
        maxN = maximum nums
        sumN = sum nums
    putStrLn . unwords . map show $ [minN, maxN, sumN]

Measured memory_bytes: 11160
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;
  ll q;
  cin >> q;
  vector<char> arr[2];

  ll isReversed = 0;
  while (q--) {

    ll type;
    cin >> type;
    if (type == 1) {
      isReversed ^= 1;
    } else {
      ll F;
      char c;
      cin >> F >> c;
      F--;

      arr[F ^ isReversed].push_back(c);
    }
  }

  if (isReversed) {
    reverse(s.begin(), s.end());
    swap(arr[0], arr[1]);
  }

  reverse(arr[0].begin(), arr[0].end());
  for (char c : arr[0])
    cout << c;
  cout << s;
  for (char c : arr[1])
    cout << c;
  cout << en;

  return 0;
}


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

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

    sort(v,v+n);

    float ans;

    if(n<=2){
        ans = (v[0] + v[1]) / 2.0;
    }
    else{
        ans += v[0] / pow(2.0,n-1);
        ans += v[1] / pow(2.0,n-1);
        for(int i = 2; i < n; i++){
            ans += v[i] / pow(2,n-i);
        }        
    }

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int s1[105], s2[105], n, mx;
int main()
{
    cin >> n;
    for(int i =1,x;  i <= n; ++i)
        cin >> x, s1[i] = s1[i - 1] + x;
    for(int i =1, x;  i <= n; ++i)
        cin >> x, s2[i] = s2[i - 1] + x;
    for(int i = 1; i <= n; ++i)
    {
        if(s1[i] + s2[n] - s2[i - 1] > mx)mx = s1[i] + s2[n] - s2[i - 1];
    }
    cout << mx;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int n;
	cin >> n;
	if(n%2==1){
		print(0);
		return 0;
	}
	int ret=0;
	for(int i=5;i<=n;i*=5){
		ret += n/2/i;
	}
	print(ret);
}

Measured memory_bytes: 3600
#include<cstdio>
using namespace std;
int main()
{
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	x-=a;
	if(x%b==0)
	{
		printf("0");
		return 0;
	}
	else
	{
		int t=x/b;
		x-=t*b;
		printf("%d",x);
	}
	return 0;
}

Measured memory_bytes: 128
public class Main {
    public static void main(String[] args) {

	int cnt = 0;
	double out;
       
	int  n = new java.util.Scanner(System.in).nextInt();


	for(int i = n; i >= 1; i--) {
	    if(i % 2 != 0) {
		cnt++;
	
	    }
	}

	out = (double)cnt / (double)n;
	System.out.printf("%.8f", out);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int  pow(int x,int n) {int res=1; while(n){if(n&1) res=(res*x);x=(x*x);n>>=1;}return res;}
 struct solvee{
 	int A, B, C;

 };


	int n;
 int solve(struct solvee arr[]){

 		int dp[n+1][4] ={};

 		dp[1][1] = arr[1].A;
 		dp[1][2] = arr[1].B;
 		dp[1][3] = arr[1].C;

 		for(int i=2 ;i<=n;i++){
 			dp[i][1] = arr[i].A + max(dp[i-1][2] , dp[i-1][3]);
 			dp[i][2] = arr[i].B + max(dp[i-1][1] , dp[i-1][3]);
 			dp[i][3] = arr[i].C + max(dp[i-1][1] , dp[i-1][2]); 
 		}

 		return max(dp[n][1], max(dp[n][2], dp[n][3]));
 }
int32_t main()
{
	
	//Paawan Singal
	FIO;
	 cin >> n;
	mk(arr, n+1, solvee );

	for(int i=1 ;i<=n;i++){

			cin >>arr[i].A >> arr[i].B >> arr[i].C; 
	}

	cout << solve(arr)<< '\n';
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	int h, a;
	
	cin >> h >> a;
	if(h%a==0)
		cout << h/a;
	else
		cout << h/a +1;
	
	return(0);
}

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

int main() {
    int d, g;
    cin >> d >> g;

    vector<pair<int, int>> pc(d);
    REP(i, 0, d) cin >> pc[i].first >> pc[i].second;

    int total, cnt, max_p, min_cnt = INT32_MAX;
    for (int bit = 0; bit < (1 << d); bit++) {
        total = 0;
        cnt = 0;
        max_p = 0;
        REP(i, 0, d) {
            if (bit & (1 << i)) {
                total += 100 * pc[i].first * (i + 1) + pc[i].second;
                cnt += pc[i].first;
            } else {
                max_p = i;
            }
        }
        if (total < g) {
            int additional_cnt = (g - total) / (100 * (max_p + 1));
            if (additional_cnt >= pc[max_p].first) continue;
            cnt += ((additional_cnt != 0) ? additional_cnt : 1);
        }
        min_cnt = min(min_cnt, cnt);
    }
    cout << min_cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include <vector>
#define re(i,n) for(int i = 0; i < n; i++)

int main() {
	string s;
	cin >> s;
	int cnt = 0;
	int max = 0;

	re(i, 3) {
		if (s[i] == 'R') cnt++;
		else {
			if (cnt > max) max = cnt;
			cnt = 0;
		}
	}
	if (cnt > max) max = cnt;
	cout << max << endl;
	return 0;
}

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

int main(){
    string S;
    cin >> S;
    int n = S.length();
    long ans = 0;
    for(int bit = 0; bit < (1<<(n-1)); bit++){
        long x = S[0] - '0';
        for(int i = 0; i < n - 1; i++){
            if(bit & (1<<i)){
                ans += x;
                x = 0;
            }
            x = 10 * x + S[i + 1] - '0';
        }
        ans += x;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }

  vector<ll> a2(n);
  rep(i,n) {
    a2[i] = a[i] - (i+1);
  }
  sort(a2.begin(), a2.end());

  ll b = a2[n/2];

  ll result = 0;
  rep(i,n) {
    result += abs(a[i] - b - (i+1));
  }

  cout << result << endl;
}


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

typedef long long ll;

ll N;
map<string, ll> C;
map<ll, set<string>> I;
int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    string s;
    cin >> s;
    ++C[s];
  }
  for (auto sc : C) {
    I[sc.second].insert(sc.first);
  }
  for (auto s : I.rbegin()->second) {
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 35968
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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; }


int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    string t;
    rep(i,q) {
        int T;
        cin >> T;
        if(T==1) {
            swap(t,s);
        } else {
            int F;
            cin >> F;
            char c;
            cin >> c;
            if(F==1) {
                t += c;
            } else {
                s += c;
            }
        }
    }
    reverse(t.begin(),t.end());
    cout << t+s << endl;
}

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

using namespace std;

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

const int N = 2e5 + 5;

map <ll,int> mpx;
int ans,n,a[N],used[N];
vector <ll> v;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n;
  for (int i = 1 ; i <= n ; i++)
    cin >> a[i];
  sort(a + 1, a + n + 1,greater <int>());
  ll p = 1;
  while(p <= 2e9) {
    v.push_back(p);
    p *= 2;
  }

  for (int i = 1 ; i <= n ; i++) {
    bool flag = true;
    for (auto x : v) {
      if (a[i] >= x)
        continue;
      if (mpx[x - a[i]]) {
        mpx[x - a[i]]--;
        ans++;
        flag = false;
        break;
      }
    }
    if (flag) {
      mpx[a[i]]++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 39424
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		String s = sc.nextLine();
		
		switch (s) {
		case "A":
			System.out.println("T");
			break;
		case "T":
			System.out.println("A");
			break;
		case "C":
			System.out.println("G");
			break;
		default:
			System.out.println("C");
		}
		
	}
}


Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  ll x, y;
  cin >> x >> y;
  
  int count = 0;
  while (x <= y) {
    x <<= 1;
    count++;
  }
  
  cout << count << endl;
  return 0;
}

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

int main(){
	string a;
  	int count,tmp;
  	cin >> a;
  	tmp = 0;
  	for(int i = 0;i<a.size();i++){
    	if((a[i]=='A')||(a[i]=='C')||(a[i]=='G')||(a[i]=='T')){
        	count++;
          	if(tmp<count)tmp = count;
        }else{
        	count = 0;
        }
    }
	cout << tmp <<endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())

d = []
A = []
for k in range(K):
    d_temp = int(input())
    d.append(d_temp)
    a_temp = input().split()
    for a in range(d_temp):
        A.append(int(a_temp[a]))

count = 0
for n in range(N):
    judg = (n+1) in A
    if judg == False:
        count += 1
print(count)

Measured memory_bytes: 9204
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


#define huge 1000000007
typedef long long ll;

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll K = 0;
	ll M = 0;
	ll X = 0;
	//double a[100000] = {};
	//double b[100000] = {};
	//ll v[100] = {};
	ll *l, *r, *d;
	string S,T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;

	
	//char p;
	//cin >>N >> M;
	cin >> S;
	//vector<pair<float, float>> is(M);
	//sort(is.begin(), is.end());
	//l = (ll *)malloc(N * sizeof(ll));
	//r = (ll *)malloc(N * sizeof(ll));

	/*rep(i, 0, N) {
		cin >> l[i];
	}*/
	
	//sort(l,l+N);

	if (S[0] != 'A') {
		count = 1;
	}
	
	rep(i,2,S.length()-1) {
		
		if (S[i] == 'C') {
			sum++;
			max = i;
		}
	}
	
	

	if (sum != 1) {
		cout << "WA" << endl;
		return 0;
	}


	rep(i, 1, S.length()) {

		min =  (int)S[i];
		//cout << min << endl;

		if (i != max) {
			if (min >= 65 && min <=90)
				count = 1;
		}
	}

	if (count == 1) {
		cout << "WA" << endl;
	}
	else {
		cout << "AC" << endl;
	}

	//cout << sum << endl;
	
		

	return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
inline int read(){
    int x = 0; char c = getchar();
    while (!isdigit(c)) c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0',c = getchar();
    return x;
}
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }
int n,a[200050],k; LL sum;
int main(){
	int i;
	read(n),read(k);
	if (n<=k){
		cout << 0 << endl; return 0;
	}
	for (i = 1; i <= n; ++i) read(a[i]);
	sort (a+1,a+n+1);
	n -= k; sum = 0;
	for (i = 1; i <= n; ++i) sum += a[i];
	cout << sum << endl;
    return 0;
}


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

using namespace std;

typedef pair<int, int> pii;
typedef vector< pii > L;

void RotateL(L& ls) {
  int len = (int)ls.size();
  for (int i=0; i<len; i++) {
    pii p = ls.at(i);
    ls.at(i) = make_pair(p.second, -p.first);
  }
}

bool isSame(L l1, L l2) {
  int len = (int)l1.size();
  if (len != (int)l2.size() ) return false;

  for (int rep = 0; rep <= 4; rep++) {
    pii v1(l1[0].first - l2[0].first, l1[0].second - l2[0].second);
    pii v2(l1[0].first - l2[len-1].first, l1[0].second - l2[len-1].second);
    
    bool same1 = true, same2 = true;
    for (int i=0; i<len; i++) {
      if (v1.first != (l1[i].first - l2[i].first)
	  || v1.second != (l1[i].second - l2[i].second)) same1 = false;
      if (v2.first != (l1[i].first - l2[len-1-i].first)
		   || v2.second != (l1[i].second - l2[len-1-i].second)) same2 = false;
    }

    if (same1 || same2) return true;

    RotateL(l2);
  }
  return false;
}

int main() {
  while (1) {
    int n; cin >> n; if (n==0) break;

    L l0;
    int len; cin >> len;
    for (int i=0; i<len; i++) {
      int ix, iy; cin >> ix >> iy;
      l0.push_back( make_pair(ix, iy) );
    }

    for (int i=0; i<n; i++) {
      L li;
      cin >> len;
      for (int j=0; j<len; j++) {
	int ix, iy; cin >> ix >> iy;
	li.push_back( make_pair(ix, iy) );
      }
      if (isSame(l0, li)) cout << i+1 << endl;
    }
    cout << "+++++" << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;

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

for(int i=0;;i++){
int H = sc.nextInt();
int W = sc.nextInt();
if(H==0&&W==0){
    break;
}

for(int m=0;m<H;m++){

    if(m==0||m==H-1){
for(int k=0;k<W;k++){
    System.out.printf("#");
}
    }else{
        for(int k=0;k<W;k++){
        if(k==0||k==W-1){
            System.out.printf("#");
        }else{
            System.out.printf(".");
        }
    }
    }
    System.out.printf("\n");
}
    System.out.printf("\n");

}
    sc.close();
}

}


Measured memory_bytes: 59212
x, k, d = map(int, input().split())
x = abs(x)
if x >= k*d:
    print(x - (k*d))
elif x%d == 0:
    i = x//d
    if (k-i) % 2 == 0:
        print(0)
    else:
        print(d)
else:
    i = x//d
    p = k-i
    if p%2 == 0:
        print(x - d*i)
    else:
        print(abs(x - d*i - d))

Measured memory_bytes: 9196
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int counter = 0;
  string buffer;
  cin >> buffer;
  if(buffer[0]=='1') counter++;
  if(buffer[1]=='1') counter++;
  if(buffer[2]=='1') counter++;
  cout << counter << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define MAX_V 10000000
#define INF 100000000

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        int mid; cin >> mid;
        a[i] = mid;
    }
    sort(a.begin(), a.end());
    int ans = 0;
    int count1 = 0;
    int b = a[0];
    for(int i = 1; i < n; i++){
        if(b == a[i]){

        }else{
            ans++;
            b = a[i];
        }
    }
    ans++;
    if(ans%2 == 0){
        ans--;
    }
    cout << ans << endl;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N,K;
    cin >> N >> K;

    if(K==1){
        cout << 0 << endl;
        return;
    }

    N-=K;
    cout << N << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define inf 1000000007
#define FOR(i, a, b) for(int i=a; i<b; i++)
int dp[1000001] = {0};

void solve(){
	int n, cnt=0;
	cin>>n;
	set<char> s;
	string str;
	cin>>str;
	bool flag = false;
	FOR(i, 1, n){
		if(str[i]!=str[i-1]) flag =true;
	}
	if(flag==false){
		cout<<'1';
		return;
	}
	for(int i=1;i<str.size();i++){
		if(str[i]!=str[i-1]) cnt++;
	}
	cout<<cnt+1;
}
signed main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
 
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int[] AB = cin.ArrayInt(2,0);
        if(AB[0]%3==0||AB[1]%3==0||(AB[1]+AB[0])%3==0)Console.WriteLine("Possible");
      else Console.WriteLine("Impossible");
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int S,W;
    cin >> S >> W;
    if(S<=W) cout << "unsafe" << endl;
    else cout << "safe" << endl;





}


Measured memory_bytes: 3612
N, Q = list(map(int, input().split()))
S = input()
l = [0] * Q
r = [0] * Q
for x in range(Q):
    l[x], r[x] = list(map(int, input().split()))

countAC = [0] * len(S)
for x in range(len(S) - 1):
    countAC[x + 1] = countAC[x]
    if S[x] == "A" and S[x + 1] == "C":
        countAC[x + 1] += 1
for x in range(Q):
    print(countAC[r[x] - 1] - countAC[l[x] - 1])


Measured memory_bytes: 14212
#include<stdio.h>
int main(void){
	int a,b,ans;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='+'){
			ans=a+b;
		}else if(op=='-'){
			ans=a-b;
		}else if(op=='*'){
			ans=a*b;
		}else if(op=='/'){
			ans=a/b;
		}else{
			break;
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    ll a[3];
    for(int i = 0; i < 3; i++) cin >> a[i];
    sort(a,a+3);
    cout << (!(a[0]%2 && a[1]%2 && a[2]%2) ? 0LL : a[0]*a[1]) << endl; 

    return 0;
}

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

int main(){
    int cards[4][14];

    // 初期化
    for(int i = 0; i < 4; i++){
        for(int j = 1; j < 14; j++){
            cards[i][j] = 0;
        }
    }

    // 検証
    int n;
    char egara;
    int rank;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> egara >> rank;
        // cout << egara << " " << rank << endl;

        int x = 0;
        switch(egara){
            case 'S':
                x = 0;
                break;
            case 'H':
                x = 1;
                break;
            case 'C':
                x = 2;
                break;
            case 'D':
                x = 3;
                break;
        }

        cards[x][rank] = 1;
    }


    // 出力
    for(int i = 0; i < 4; i++){
        for(int j = 1; j < 14; j++){
            if(0 == cards[i][j]){
                char x;
                switch(i){
                    case 0:
                        x = 'S';
                        break;
                    case 1:
                        x = 'H';
                        break;
                    case 2:
                        x = 'C';
                        break;
                    case 3:
                        x = 'D';
                        break;
                }
                cout << x << " " << j << endl;
                // cout << cards[i][j] << endl;
            }
        }
        // cout << endl;
    }

    return 0;
}


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

template<typename T>
struct BinaryIndexedTree {
    int N;
    vector<T> data;

    BinaryIndexedTree(int sz) {
        N = sz;
        data.assign(++sz, 0);
    }

    T sum(int k) { // [0,k) (0-indexed) a[0] + … + a[k-1]
        T ret = 0;
        for(; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    T sum(int l, int r) { // [l,r) (0-indexed) a[l] + …　+ a[r-1]
        T vl = sum(l);
        T vr = sum(r);
        return vr - vl;
    }

    void add(int k, T x) { // (0-indexed) a[k] += x;
        for(++k; k <= N; k += k & -k) data[k] += x;
    }

    int lowerbound(int x) { // (0-indexed)
        int k = 1;
        int res = 0;
        while ((k<<1) <= N) k <<= 1;
        while (k > 0) {
            if (res + k <= N && data[res+k] < x) {
                x -= data[res+k];
                res += k;
            }
            k >>= 1;
        }
        return res;
    }

    int upperbound(int x) { // (0-indexed)
        ++x;
        int k = 1;
        int res = 0;
        while ((k<<1) <= N) k <<= 1;
        while (k > 0) {
            if (res + k <= N && data[res+k] < x) {
                x -= data[res+k];
                res += k;
            }
            k >>= 1;
        }
        return res;
    }
};

////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,Q; cin >> N >> Q;
    BinaryIndexedTree<ll> BIT(N);

    while (Q--) {
        ll com,x,y; cin >> com >> x >> y;
        if (com) {
            cout << BIT.sum(--x,y) << endl;
        } else {
            BIT.add(--x,y);
        }
    }
}

/*
  verified on 2019/02/03
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B&lang=ja
*/


Measured memory_bytes: 3596
const val P = 1000000007L

// Find (x, y, r) such that r = gcd(a,b) and ax + by = r.
fun extendedGCD(a: Long, b: Long): Triple<Long, Long, Long> {
  var x0 = 1L
  var y0 = 0L
  var z0 = a
  var x1 = 0L
  var y1 = 1L
  var z1 = b
  while (true) {
    if (z1 == 0L) return Triple(x0, y0, z0)
    val q = z0 / z1
    val x2 = x0 - q * x1
    val y2 = y0 - q * y1
    val z2 = z0 - q * z1
    x0 = x1
    x1 = x2
    y0 = y1
    y1 = y2
    z0 = z1
    z1 = z2
  }
}

fun inverseMod(a: Long, m: Long): Long {
  val (x, y, r) = extendedGCD(a, m)
  if (r != 1L) return 0  // No inverse.

  return (x + m) % m
}

class FiniteField(xRaw: Long) {
  val x = if (xRaw >= 0) xRaw % P else (P - ((-xRaw) % P)) % P
  constructor(xi: Int): this(xi.toLong())
  operator fun plus(o: Long) = FiniteField((x + o) % P)
  operator fun plus(o: FiniteField) = this + o.x
  operator fun minus(o: Long) = FiniteField((x + P - o) % P)
  operator fun minus(o: FiniteField) = this - o.x
  operator fun times(o: Long) = FiniteField((x * o) % P)
  operator fun times(o: FiniteField) = this * o.x
  operator fun div(o: Long) = this * inverseMod(o, P)
  operator fun div(o: FiniteField) = this / o.x
  override fun toString() = x.toString()
}

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val factorialTable = Array(n, { FiniteField(0L) })
  factorialTable[0] = FiniteField(1)
  for (k in 1..(n - 1)) {
    factorialTable[k] = factorialTable[k - 1] * k.toLong()
  }

  val fTable = Array(n, { k ->
    if (2 * k < n) FiniteField(0)
    else factorialTable[k] * factorialTable[k - 1] / factorialTable[2 * k - n]
  })

  var ans = FiniteField(0)
  for (k in 1..(n - 1)) {
    val count = fTable[k] - fTable[k - 1]
    ans += count * k.toLong()
  }
  println(ans)
}

Measured memory_bytes: 146456
#include <iostream>

using namespace std;

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

  int N, A;
  cin >> N;
  cin >> A;

  N %= 500;
  if (N <= A) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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


class UnionFind:
    def __init__(self, N):
        self.par = [-1] * N

    def find(self, x):
        r = x
        while self.par[r] >= 0:
            r = self.par[r]
        while x != r:
            tmp = self.par[x]
            self.par[x] = r
            x = tmp
        return r

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

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

    def size(self, x):
        return -self.par[self.find(x)]

N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    uf.unite(A, B)
ans = len(set([uf.find(i) for i in range(N)])) - 1
print(ans)


Measured memory_bytes: 81496
#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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N;
ll ans = 0;
void f(ll now) {
    if(N < now) return;
    set<int> st;
    ll copy = now;
    while(copy > 0) {
        st.insert(copy % 10);
        copy /= 10;
    }
    if(st.size() == 3) ans++;
    f(now * 10 + 3);
    f(now * 10 + 5);
    f(now * 10 + 7);
}

int main() {
    cin >> N;
    f(3);
    f(5);
    f(7);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define FOR(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ii> vii;

string s;
int k;
vector<string> vs;

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

    cin >> s >> k;
    for (int i = 0; i < s.size(); i++) {
        string t;
        for (int j = i; j < min((int)s.size(), i+k); j++) {
            t.push_back(s[j]);
            vs.push_back(t);
        }
    }

    sort(ALL(vs));
    vs.erase(unique(ALL(vs)), vs.end());

    cout << vs[k-1] << endl;

    return 0;
}


Measured memory_bytes: 1660
//
// Created by たかえすみずき on 2017/07/15.
//

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

//改造
typedef long long int ll;
using namespace std;

struct Masu {
    int dist1 = -1;
    int distn = -1;
    vector<int> next;
    bool near1;
};

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

    Masu masu[100005];
    masu[1].dist1 = 0;
    masu[n].distn = 0;

    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        masu[x].next.push_back(y);
        masu[y].next.push_back(x);
    }

    queue<int> q;
    q.push(n);
    while (!q.empty()) {
        int front = q.front();
        q.pop();
        for (int elem : masu[front].next) {
            if (masu[elem].distn == -1) {
                q.push(elem);
                masu[elem].distn = masu[front].distn + 1;
            }
        }
    }
    q.push(1);
    while (!q.empty()) {
        int front = q.front();
        q.pop();
        for (int elem : masu[front].next) {
            if (masu[elem].dist1 == -1) {
                q.push(elem);
                masu[elem].dist1 = masu[front].dist1 + 1;
            }
        }
    }

    int score1 = 0;
    int scoren = 0;
    for (int i = 1; i <= n; i++) {
        if (masu[i].dist1 <= masu[i].distn) {
            score1++;
        } else {
            scoren++;
        }
    }

    if (score1 > scoren) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }
}


Measured memory_bytes: 7424