akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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

    int ans[H][W];

    for(int i=0; i<H; i++){
        if(i%2 == 0){
            for(int j=0; j<W; j++){
                ans[i][j] = pos+1;
                a[pos]--;
                if(a[pos] == 0) pos++;
            }
        } else {
            for(int j=W-1; j>=0; j--){
                ans[i][j] = pos+1;
                a[pos]--;
                if(a[pos] == 0) pos++;
            }
        }
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(j) cout << " ";
            cout << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int ans=0;
    int n,x;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x;
        if(i%2==1&&x%2==1) ans++;
    }
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3600
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int main() {
	char s[200005];
	scanf("%s", s);
	int n = strlen(s);
	int k = 0, c = 1;
	map<int, int> mp;
	mp[0] = 1;
	for (int i = n - 1; i >= 0; i--) {
		k += c * (s[i] - '0');
		k %= 2019;
		c = c * 10 % 2019;
		mp[k]++;
	}
	int ans = 0;
	for (auto p : mp) ans += p.second * (p.second - 1) / 2;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4076
s = list(input())

for i in range(len(s)):
  if s[i] == '?':
    if i-1 >= 0 and s[i-1] == 'P':
      s[i] = 'D'
    elif i+1 < len(s) and s[i+1] == 'D':
      s[i] = 'P'
    elif i+1 < len(s) and  s[i+1] == '?':
      s[i] = 'P'
      s[i+1] = 'D'
    else :
      s[i] = 'D'
      
print("".join(s))

Measured memory_bytes: 10880
#include<iostream>
#include<algorithm>

using namespace std;

int A, B, M;
int pA[100000 + 100], pB[100000 + 100];

int main() {
	cin >> A >> B >> M;
	int ans = 0;
	for (int i = 0; i < A; i++)cin >> pA[i];
	for (int i = 0; i < B; i++)cin >> pB[i];
	ans += *min_element(pA, pA + A);
	ans += *min_element(pB, pB + B);
	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		ans = min(ans, pA[a] + pB[b] - c);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int sum = 0;
  for (int i = 0; i < K; i++) {
    if (i < A) {
      sum += 1;
    }
    else if (i >= A + B) {
      sum -= 1;
    }
  }
  cout << sum << endl;
}

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

int main()
{
  int N,K ;
  cin>>N>>K ;
  vector<int>H(N) ;
  for(int i=0;i<N;i++) cin>>H.at(i) ;
  
  sort(H.begin(),H.end()) ;
  reverse(H.begin(),H.end()) ;
  int64_t count=0 ;
  for(int i=K;i<N;i++) count+=H.at(i) ;
  
  cout<<count<<endl ;
  
  return 0 ;
}


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

using namespace std;

void f(char str[])
{
    int len = strlen(str);
    char tmp = str[len-1];
    for(int i = len - 1; i >= 1; --i) {
        str[i] = str[i-1]; //  文字列を1文字後ろにずらす
    }
    str[0] = tmp;      // 先頭に1文字挿入
    }

int main(void){
    
    char s[100];
    char t[100];
    
    std::cin >> s;
    std::cin >> t;
    
    for(int i = 0; s[i] != '\0'; i++){
        f(s);
        if(strncmp(s,t,strlen(s))==0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    std::cout << "No" << std::endl;
    
    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

int n;
vec<vec<vec<double>>> dp;
/*FUNCs=================================================*/
double rec(int i, int j, int k) {
    if(dp[i][j][k] != -1) return dp[i][j][k];
    if(i==0 && j==0 && k==0) return 0;  // どれも残ってないなら操作しないでいい

    // 漸化式の+1は今行う操作によって増える分の操作回数の増加を表す(式変形で+nになった)
    double ret = 0;
    if(i>0) ret += rec(i-1, j, k) * i;
    if(j>0) ret += rec(i+1,j-1,k) * j;
    if(k>0) ret += rec(i,j+1,k-1) * k;
    ret += n;
    ret *= 1.0/(i+j+k);  // これ 1.0 ってしないと int になっちゃいます。

    dp[i][j][k] = ret;
    return ret;
}

/*MAIN==================================================*/
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    cout << fixed << setprecision(15);

    cin >> n;
    dp.resize(301, vec<vec<double>>(301, vec<double>(301, -1)));
    int one=0,two=0,three=0;
    rep(i,n) {
        int p; cin >> p;
        if(p==1) ++one;
        else if(p==2) ++two;
        else ++three;
    }

    cout << rec(one, two, three) << '\n';
}

Measured memory_bytes: 216960
h, w, d = map(int, input().split())
C = ["R", "Y", "G", "B"]
G = [[None]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    y, x = i+j, i-j
    G[i][j] = C[((y//d)%2)*2+(x//d)%2]
for g in G:
  print("".join(g))

Measured memory_bytes: 5236
#include <iostream>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <iomanip>
#include <math.h>
#include <algorithm>
#define M_PI 3.14159265358979323846264338327950288
#define oo 1000000007
#define maxN 1000007
using namespace std;

int com[maxN];

int count(int n) {
    vector <int> vc;
    while (n != 1) {
        vc.emplace_back(com[n]);
        n /= com[n];
    }
    sort(vc.begin(), vc.end());
    int ans = 1;
    int cnt = 1;
    for (int i = 1; i < (int)vc.size(); ++i) {
        if (vc[i] == vc[i-1]) ++cnt;
        else {
            ans *= cnt + 1;
            cnt = 1;
        }
    }
    ans *= cnt + 1;
    return ans;
}

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

    for (int i = 2; i <= sqrt(n)+7; ++i) {
        if (com[i]) continue;
        for (int j = i*i; j <= n; j += i) {
            com[j] = i;
        }
    }
    for (int i = 1; i <= n; ++i) if (!com[i]) com[i] = i;
    long long ans = 0LL;
    for (int i = 1; i < n; ++i) {
        long long tmp = (long long)count(n-i);
        ans += tmp;
    }

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

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

using namespace std;

#define MAX (1<<17)
#define INF (1LL<<55)
typedef long long ll;
typedef pair<ll, ll> P;

struct SegmetTree {
    int n;
    P dat[2*MAX-1];    
    
    SegmetTree(int n_)
    {
        n = 1;
        while (n < n_) {
            n *= 2;
        }
        for (int i = 0; i < 2 * n - 1; i++) {
            dat[i] = P(0, 1);
        }
    }

    ll get_nearest_marked_node(int k)
    {
        k += n - 1;
        P p = dat[k];
        while (k > 0) {
            k = (k - 1) / 2;
            p = max(p, dat[k]);
        }
        return p.second;
    }
        
    void mark(int a, int b, int k, int l, int r, P x)
    {
        if (r <= a || b <= l) return;

        if (a <= l && r <= b) {
            dat[k] = max(dat[k], x);
        } else {
            mark(a, b, k * 2 + 1, l, (l + r) / 2, x);
            mark(a, b, k * 2 + 2, (l + r) / 2, r, x);
        }
    }    
};

ll L[MAX], R[MAX], D[MAX], p;
vector<int> G[MAX];

void init(int N)
{
    p = 0;
    for (int i = 0; i < N; i++) {
        G[i].clear();        
    }
}

void dfs(int v, int depth)
{
    L[v] = p++;
    D[v] = depth;
    for (int i = 0; i < (int)G[v].size(); i++) {
        dfs(G[v][i], depth + 1);
    }
    R[v] = p;
}

int main()
{
    int N, Q, x;
    while (cin >> N >> Q, N) {
        init(N);
        for (int i = 1; i < N; i++) {
            cin >> x; x--;
            G[x].push_back(i);
        }

        dfs(0, 0);

        SegmetTree st(N);
        
        char m;
        ll v, res = 0;
        while (Q--) {
            cin >> m >> v; v--;
            if (m == 'M') {
                st.mark(L[v], R[v], 0, 0, st.n, P(D[v], v+1));
            } else {
                res += st.get_nearest_marked_node(L[v]);
            }
        }
        cout << res << endl;
    }
    return 0;
}

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

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

Measured memory_bytes: 256
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}
namespace IO{
    char nc(){ static char bf[100000],*p1=bf,*p2=bf; return p1==p2&&(p2=(p1=bf)+ fread(bf,1,100000,stdin),p1==p2)?EOF:*p1++; }
    int rd(){ int res=0; char c=getchar(); while(!isdigit(c))c=getchar(); while(isdigit(c))res=res*10+c-'0',c=getchar(); return res; }
}/*}}}*/
/******************heading******************/
#define int lld
const int N=2*3e5+50,P=1e9+7;

int n,m,l,r;
int fac[N],fnv[N];

int pw(int a,int m,int p){
    int res=1;
    while(m)m&1?res=res*a%p:0,a=a*a%p,m>>=1;
    return res;
}
int binom(int n,int m){
    if(n<m)return 0;
    return fac[n]*fnv[m]%P*fnv[n-m]%P;
}
void init(int k){
    fac[0]=1;
    FOR(i,1,k)fac[i]=fac[i-1]*i%P;
    fnv[k]=pw(fac[k],P-2,P);
    ROF(i,k,1)fnv[i-1]=fnv[i]*i%P;
}
int calc2(int x){
    //printf("  calc2(%lld)\n",x);
    return binom(n+x,x);
}
int calc2(int a,int b,int s){
    //printf("  calc2(n=%lld,a=%lld,b=%lld,s=%lld)\n",n,a,b,s);
    //至多和为s,m个数大于等于a，n-m个数小于等于b的方案数
    if(s<m*a)return 0;
    int lim=min((s-m*a)/(b+1),n-m);
    int res=0;
    FOR(i,0,lim){//枚举n-m个数中有i个大于b
        int t=calc2(s-m*a-i*(b+1))%P*binom(n-m,i)%P;
        //printf("  i=%lld,t=%lld\n",i,t);
        res+=(1-2*(i&1))*t;
        res%=P;
    }
    res=res*binom(n,m)%P;
    //printf("  res=%lld\n",res);
    return res;
}
int calc(int a,int b,int s){
    //printf("\033[32mcalc(a=%lld,b=%lld,s=%lld)\033[0m\n",a,b,s);
    //至多和为s,第m为a，n-m个数小于等于b的方案数
    int res=calc2(a,b,s)-calc2(a+1,b,s);
    res=(res%P+P)%P;
    //printf("\033[32mres=%lld\033[0m\n",res);
    return res;
}
int calc(int s){
    //printf("calc(n=%lld,m=%lld,s=%lld)\n",n,m,s);
    int tot=binom(n+s,s);
    //printf("tot=%lld\n",tot);
    FOR(i,1,s)tot-=calc(i,i-1,s),tot%=P;
    tot+=P,tot%=P;
    return tot;
}
signed main(){
    scanf("%lld%lld%lld%lld",&n,&m,&l,&r);
    init(n+r);
    printf("%lld",((calc(r)-calc(l-1))%P+P)%P);
    return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
int main(){
  int h,w;
  char a[110][110];
  scanf("%d%d",&h,&w);
  for(int i=0;i<h;i++)scanf("%s",&a[i]);
  for(int i=0;i<w+2;i++)printf("#");
  printf("\n");
  for(int i=0;i<h;i++)printf("#%s#\n",a[i]);
  for(int i=0;i<w+2;i++)printf("#");
  return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 1e5 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

ll wt[maxN];
ll val[maxN];
ll dp[110][maxN];

ll solve(ll n, ll w) {
	if (n <= 0 || w <= 0) {
		return 0;
	}
	if (dp[n][w] != -1) return dp[n][w];
	if (wt[n - 1] <= w)
		return dp[n][w] = max(dp[n - 1][w] == -1 ? dp[n - 1][w] = solve(n - 1, w) : dp[n - 1][w],
		                      val[n - 1] + (dp[n - 1][w - wt[n - 1]] == -1 ? dp[n - 1][w - wt[n - 1]] = solve(n - 1, w - wt[n - 1]) : dp[n - 1][w - wt[n - 1]]));
	else
		return dp[n][w] = dp[n - 1][w] == -1 ? dp[n - 1][w] = solve(n - 1, w) : dp[n - 1][w];
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	FIO
	ll n, w;
	cin >> n >> w;
	FOR(i, n) cin >> wt[i] >> val[i];
	FOR(i, n + 1) {
		FOR(j, w + 1) {
			dp[i][j] = -1;
		}
	}
	cout << solve(n, w);
	return 0;
}


Measured memory_bytes: 82524
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int a,b;
  cin >> a >> b;
  cout<< max(0,a-2*b) <<endl;
}


Measured memory_bytes: 256
n,a,b=map(int,input().split())
if (b-a)%2==0:
    print(int((b-a)//2))
else:
    if (a-1)<=(n-b):
        b-=a
        print(int((b-1)//2)+a)
    else:
        a+=n-b+1
        print(int((n-a)//2)+n-b+1)
    

Measured memory_bytes: 2940
def main():
    a, b, m = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    B = [int(e) for e in input().split()]

    ans = min(A) + min(B)
    for mi in range(m):
        x, y, c = [int(e) for e in input().split()]
        ans = min(A[x - 1] + B[y - 1] - c, ans)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 65596
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
int main() {
  while (cin >> N) {
	map<int,int> ma;
	for (int i = 0; i < N; ++i) {
	  int a;
	  cin >> a;
	  ma[a]++;
	}
	int even = 0;
	EACH(it,ma) if (it->second % 2 == 0) ++even;
	int res = ma.size();
	if (even & 1) --res;
	cout << res << endl;
  }
}





Measured memory_bytes: 4992
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
n,m = m()
mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


for i in range(1,m+1):
    if i == 1:
        cb = 1
    else:
        cb = cmb(m-1,i-1,mod)
    al = cb * cmb(n-m+1,i,mod)% mod
    print(al%mod)


Measured memory_bytes: 43612
#include<bits/stdc++.h>
#define debug(x) cout<<#x<<"::"<<x<<endl;
using namespace std;
typedef long long ll;

void solve()
{
    ll h;
    int n;
    cin>>h>>n;
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        sum+=x;
    }   
    if(sum>=h)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  //if (a > b) {cout << 0 << endl; return 0;}

  ll mi = a * (n-1) + b;
  ll ma = a + b * (n-1);
  if (ma-mi+1 >= 0) cout << ma-mi+1 << endl;
  else cout << 0 << endl;
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  int start;
  int goal;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='A'){
      start = i;
      break;
    }
  }
  for(int i=start;i<S.size();i++){
    if(S.at(i)=='Z'){
      goal = i;
    }
  }
  
  cout << goal-start+1 << endl;
}

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

#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;

using vecint = vector<int>;
using ll = int64_t;

int main()
{
  string s;
  cin>>s;
  int res = 10000;
  FOR(i,'a','z'+1) {
    int cnt = 0;
    int cost = 0;
    REP(j,s.size()) {
      if (s[j] != i) ++cnt;
      else {
        cost = max(cost, cnt);
        cnt = 0;
      }
    }
    cost = max(cost, cnt);
    res = min(cost, res);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<ctype.h>
#include<stack>
#include<math.h>
#include <string>
#include<algorithm>
#include<iomanip>
#define _for(i,a,b) for(int i = (a);i < (b);i++)
#define mset(x) memset(x,0,sizeof(x));
using namespace std;

int main() {
	long long int s,H,M,S;
	cin>>s;
	S = s % 60;
	M = s / 60 % 60;
	H = s / 3600; 
	cout<<H<<":"<<M<<":"<<S<<endl;
	return 0;
}


Measured memory_bytes: 3100
def partition(p, r):
    i = p
    for j in range(p, r):
        if A[r][1] >= A[j][1]:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[r], A[i] = A[i], A[r]
    return i

def quick_sort(p, r):
    if p < r:
        q = partition(p, r)
        quick_sort(p, q-1)
        quick_sort(q+1, r)

def is_stable():
    for i in range(N-1):
        if A[i][1] == A[i+1][1]:
            small_idx, large_idx = 0, 0
            cnt = 0
            for j in range(N):
                if A[i] == orig_list[j]:
                    small_idx = j
                    cnt += 1
                elif A[i+1] == orig_list[j]:
                    large_idx = j
                    cnt += 1
                if cnt == 2:
                    break
            if small_idx > large_idx:
                return False
    return True


N = int(input())
A = []
for _ in range(N):
    suit, num = input().split()
    num = int(num)
    A.append([suit, num])
orig_list = A[:]

quick_sort(0, N-1)

is_stable = is_stable()
if is_stable:
    print("Stable")
else:
    print("Not stable")

for card in A:
    print("%s %d" % (card[0], card[1]))


Measured memory_bytes: 18572
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    if N % 2 == 0:
        print N
    else:
        print N*2

if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
// 2020-09-13 21:00:00
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
void answer() {
  int n;
  cin >> n;
  if (n == 0) {
    cout << 1 << '\n';
  } else {
    cout << 0 << '\n';
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int N;
    scanf("%d",&N);
    char S[N];
    scanf("%s",S);
    int b[N],w[N];
    
    if (S[0]=='#'){b[0]=1;w[0]=0;}else{b[0]=0;w[0]=1;}

    for (size_t i = 1; i < N; i++){
        if (S[i]=='#'){
            b[i]=b[i-1]+1;
            w[i]=w[i-1];
        }else{
            b[i]=b[i-1];
            w[i]=w[i-1]+1;
            }
    }

    int ans=b[N-1];
    if (ans>w[N-1]){ans=w[N-1];}

    for (size_t i = 0; i < N-1; i++){
        if (ans>b[i]+w[N-1]-w[i]){
            ans=b[i]+w[N-1]-w[i];
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <complex>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef complex<double> C;

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

#define EPS (1e-8)
#define EQ(a,b) (abs(a-b) < EPS)
#define EQV(a,b) (EQ(a.real(),b.real()) && EQ(a.imag(),b.imag()))

double cross(C a, C b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

bool is_crossed(C a1, C a2, C b1, C b2) {
  return cross(a2-a1, b2-a1) * cross(a2-a1, b1-a1) < EPS &&
         cross(b2-b1, a2-b1) * cross(b2-b1, a1-b1) < EPS;
}

C intersection(C a1, C a2, C b1, C b2) {
  C b = b2 - b1;
  double d1 = abs(cross(b, a1-b1));
  double d2 = abs(cross(b, a2-b1));
  double t = d1 / (d1 + d2);
  return a1 + (a2-a1) * t;
}

C s[100], e[100];

void solve() {
  int xa, ya, xb, yb, n;
  cin>>xa>>ya>>xb>>yb>>n;
  C a(xa, ya), b(xb, yb);
  C ab = b - a;
  
  vector<pair<double,pair<int,int> > > iss;
  rep(i,n) {
    int xs, ys, xt, yt, o, l;
    cin>>xs>>ys>>xt>>yt>>o>>l;
    C s(xs, ys), t(xt, yt);
    C st = t - s;
    
    if(!is_crossed(a, b, s, t)) continue;
    if(abs(cross(ab, st)) < EPS) continue;
    C is = intersection(a, b, s, t);
    iss.push_back(make_pair(is.real(), make_pair(o,l)));
  }
  
  sort(iss.begin(), iss.end());
  int res = 1000;
  rep(z,2) {
    int mode = z, tres = 0;
    rep(i,iss.size()) {
      int to = iss[i].second.first, tl = iss[i].second.second;
      bool flag = false;
      if ((to == 1 && tl != mode) || (to == 0 && tl == mode)) {
        tres++; mode++;
        if (mode >= 2) mode = 0;
      }
    }
    res = min(tres, res);
  }
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  int n;
  cin>>n;
  rep(i,n)
    solve();
  return 0;
}

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

int n;
int cnt[100005];

int main(void){
	scanf("%d",&n);
	int res=0;
	for(int i=0;i<n;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		res+=r-l+1;
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999
#define EPS 1e-9
#define PI 3.14159265358979323846
double calc(int theta){
    return sin(theta/360.0*PI)*cos(theta/360.0*PI);
}


double solve(vector<int> data){
    double ret=0;
    rep(i,data.size()){
        ret+=calc(data[i]);
    }
    return ret;
}


int main(){
    int n,m;
    while(cin>>n){
        if(n==0)break;
        double s1,s2;
        vector<int> data;
        int less=360;
        rep(i,n-1){
            int a;
            cin>>a;
            less-=a;
            data.pb(a);
        }
        data.pb(less);
        s1 = solve(data);
        
        less=360;
        data.clear();
        cin>>m;
        rep(i,m-1){
            int a;
            cin>>a;
            less-=a;
            data.pb(a);
        }
        data.pb(less);
        s2 = solve(data);
        if(fabs(s1-s2)<EPS)cout<<0<<endl;
        else if(s1>s2)cout<<1<<endl;
        else if(s1<s2)cout<<2<<endl;
    }
}

Measured memory_bytes: 1220
import Data.Maybe
import Data.Array
import Data.List
import qualified Data.ByteString.Char8 as C

parseInt :: C.ByteString -> Int
parseInt = fst . fromJust . C.readInt

m = 10^9 + 7
x @* y = x * y `mod` m
x @+ y = let z = x + y in if z >= m then z - m else z

fpm :: Int -> Int ->Int
fpm a e
  | e == 0 = 1
  | odd e = a' @* a' @* a
  | otherwise = a' @* a'
  where
  a' = fpm a (e `div` 2)

main :: IO ()
main = do
  [n, k] <- map parseInt . C.words <$> C.getLine
  let calc = foldl' (@+) 0
      f = array (1, k) [(i, fpm y n - calc [f ! (j * i) | j <- [2..y]]) | i <- reverse [1..k], let y = k `div` i]
  putStrLn $ show $ calc [f ! i @* i | i <- [1..k]]


Measured memory_bytes: 17928
import java.util.Scanner;
class Main{
    public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String b = sc.nextLine();
    String s = sc.nextLine();
    int a = Integer.parseInt(b);
    if (a >= 3200){
        System.out.println(s);
    }
    else{
        System.out.println("red");
    }
    }
}

Measured memory_bytes: 21844
q, h, s, d = map(int, input().split())
if 2*q < h:
    h = 2*q
if 2*h < s:
    s = 2*h
if 2*s < d:
    d = 2*s

n = int(input())
if n%2==0:
    kosu = n//2
    print(d*kosu)
else:
    kosu = n//2
    print(d*kosu + s)

Measured memory_bytes: 3060
#include<cstring>
#include<cstdio>
using namespace std;
int l,i;
char s[110];
bool a=0;
int main(){
	scanf("%s",s);
	l=strlen(s);
	for(i=0;i<l;i++){
		if(!a&&s[i]=='C') a=1;
		if(a&&s[i]=='F'){printf("Yes");return 0;}
	}
	printf("No");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007;
#define inf (1LL<<60)
using namespace std;


ll solve(ll h[],ll b[],int n)
{
    ll dp[n];
    map<ll,ll> m;
    dp[0]=b[0];
    m[h[0]]=dp[0];
    ll ans=dp[0];
    for(int i=1;i<n;i++)
    {
        dp[i]=b[i];
        auto it=m.lower_bound(h[i]);
        if(it!=m.begin())
        {
            it--;
            dp[i]+=it->second;
        }
        m[h[i]]=dp[i];
        it=m.upper_bound(h[i]);
        while(it!=m.end()&&it->second<=dp[i])
        {
            auto temp =it;
            temp++;
            m.erase(it);
            it=temp;
        }
        ans=max(ans,dp[i]);
    }
    return ans;
}
int main()
{
    int n;
    cin>>n;
    ll h[n],b[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    cout<<solve(h,b,n);
    return 0;
}


Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
int n, c[N], cnt[N], siz[N];
inline ll cal(int x) {
	return 1ll * x*(x+1)/2;
}
ll ans[N];
vector<int>G[N];
	void dfs(int v, int fa) {
		int tmp = cnt[c[v]];
		siz[v] = 1;
		for(int u:G[v]) {
			if(u==fa) continue;
			cnt[c[v]] = 0;
			dfs(u, v);
			siz[v] += siz[u];
			ans[c[v]]+=cal(siz[u]-cnt[c[v]]);
		}
		cnt[c[v]] = tmp + siz[v];
	}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%d", &c[i]);
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", cal(n) - ans[i] - cal(n - cnt[i]));
	}
	return 0;
}


Measured memory_bytes: 37428
class Unionfind:
    def __init__(self,n):
        self.par=[x for x in range(n)]
        self.rank=[1]*n
        self.num=[1]*n

    def root(self,a):
        if self.par[a]==a : return a
        parent=self.root(self.par[a])
        self.par[a]=parent
        return parent

    def unite(self,a,b):
        ra,rb=self.root(a),self.root(b)
        out=self.num[ra]*self.num[rb]
        if self.rank[ra]<self.rank[rb]:
            ra,rb=rb,ra
        self.par[rb]=ra
        self.num[ra]+=self.num[rb]
        if self.rank[ra]==self.rank[rb]:
            self.rank[ra]+=1
        return out
        
    def same(self,a,b):
        return self.root(a)==self.root(b)

    def com_num(self,a,b):
        if self.same(a,b): return 0
        else : return self.unite(a,b)
        

def main():
    n,m=map(int,input().split())
    incon=[0]*(m+1)
    bridge=[0]*m
    uf=Unionfind(n)
    for i in range(m):
        a,b=map(int,input().split())
        bridge[i]=(a-1,b-1)
    incon[m]=n*(n-1)//2

    for i in range(m-1,-1,-1):
        a,b=bridge[i]
        incon[i]=incon[i+1]-uf.com_num(a,b)

    for i in range(1,m+1):
        print(incon[i])

main()

Measured memory_bytes: 28696
import math
N = int(input())
A = sorted([int(_) for _ in input().split()], reverse=True)
dp = {}
for a in A:
    dp[a] = dp.get(a, 0) + 1
ans = 0
for a in A:
    if dp[a]:
        dp[a] -= 1
        if dp.get(2**int(math.log2(a) + 1) - a, 0) > 0:
            dp[2**int(math.log2(a) + 1) - a] -= 1
            ans += 1
print(ans)

Measured memory_bytes: 33168
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int ans = count();
        System.out.println(ans);
    }

    static int count() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int idx = sc.nextInt();
        int[][] ret = new int[n][idx];
        int ans = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < idx; j++) {
                ret[i][j] = sc.nextInt();
            }
            ans += cntInt(i, idx, ret);
        }
        sc.close();

        return ans;
    }
    static int cntInt(int i, int idx, int[][] ret) {
    	int cnt = 0;

        if (i > 0) {
            for (int k = 0; k < i; k++) {
                double sum = 0;
            	for (int j = 0; j < idx; j++) {
            		sum += Math.pow(Math.abs(ret[i][j] - ret[k][j]), 2);
            	}
                double calc = Math.sqrt(sum);
                if (calc == Math.floor(calc)) {
                    cnt++;
                }
            }
        }
        return cnt;
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<int> sort(vector<int> vec) {
    sort(vec.begin(), vec.end());
    return vec;
}
vector<int> resort(vector<int> vec) {
    sort(vec);
    reverse(vec.begin(), vec.end());
    return vec;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
      return(b);
    }else{
      return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  string s;
    cin >> s;
    bool flag = true;
    if (s[0] != 'A') {
        flag = false;
    }
    string t = s.substr(2, s.size() - 3);
    sort(t.begin(),t.end());
    if (t[0] != 'C') {
        flag = false;
    }
    int cnt = 0;
    for (int i = 0; i < s.size(); i++) {
        if (islower(s[i])) {
            cnt++;
        }
    }
    if (cnt != s.size() - 2) {
        flag = false;
    }
    if (flag) {
        cout << "AC" << endl;
    }
    else {
        cout << "WA" << endl;
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define loopi(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) loopi(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    // #define endl "\n"
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max()/10;

int popcount(unsigned long long x){
    return __builtin_popcount(x);
    static int dp[66000];
    if(dp[65536] != 16) for(int i = 0; i < 65536; i++) dp[i] = (i&1) + dp[i>>1];
    int res = 0;
    while(x) res += dp[x&65535], x >>= 16;
    return res;
}

int solve(ll s, ll d){
    //if(s <= 0 && d >= 0) return __builtin_popcount(-s) + __builtin_popcount(d);
    if(s <= 0 && d >= 0) return popcount(-s) + popcount(d);
    else if(s >= 0 && d >= 0){
        int j = 0;
        int ans = 0;
        while(s < d){
            if((s>>j&1) && (d>>j&1)){
                s += 1LL<<j;
                d -= 1LL<<j;
                ans += 2;
            } else if((s>>j&1) ^ (d>>j&1)){
                s += 1LL<<j;
                ans ++;
            }
            j++;
        }
        return ans;
    } else return solve(-d,-s);
}

signed main(){
    fastios();
    int N;
    cin >> N;
    rep(i,N){
        ll s,d;
        cin >> s >> d;
        cout << solve(s,d) << endl;
    }
}

Measured memory_bytes: 1204
from collections import defaultdict
n = int(raw_input())
s = raw_input().strip()
ans = 1
d = defaultdict(int)
for c in s:
    d[c] += 1
for v in d.viewvalues():
    ans = ans * (v + 1) % 1000000007
print (ans - 1) % 1000000007


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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

int N, A, B, C, acpt, th;
string s;

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

	cin >> N >> A >> B;

	cin >> s;

	for(auto x: s){
		if(x == 'a' && acpt < A+B){
			acpt++;
			cout << "Yes\n";
		}else if(x == 'b' && acpt < A+B && th < B){
			th++;
			acpt++;
			cout << "Yes\n";
		}
		else
			cout << "No\n";
		}

	return 0;		
}

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

typedef long long ll;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;

vector<vpil> adj;
vector<ll> d;

void dfs(int x) {
	for(auto e:adj[x]) if(d[e.first]==-1) {
		d[e.first]=d[x]+e.second;
		dfs(e.first);
	}
}

int main() {
	int i, k, q, n, u, v;
	ll w;
	scanf("%d", &n);
	adj.assign(n+1, vpil(0));
	for(i=0; i<n-1; i++) {
		scanf("%d%d%lld", &u, &v, &w);
		adj[u].push_back(pil(v, w));
		adj[v].push_back(pil(u, w));
	}
	d.assign(n+1, -1);
	scanf("%d%d", &q, &k);
	d[k]=0;
	dfs(k);
	for(; q; q--) {
		scanf("%d%d", &u, &v);
		printf("%lld\n", d[u]+d[v]);
	}
	return 0;
}

Measured memory_bytes: 12672
#include<iostream>
#include<vector>
#include<queue>

using namespace std;


int main(){
	while(1){
		int x,y,s; cin >> x >> y >> s;
		if (x + y + s == 0) break;
		int max = -1;
		for (int i = 1; i <= 1000; i++){
			for (int j = 1; j <= 1000; j++){
				if (i + j > s) break;
				int item1 = (double)(i * (100+x)/100);
				int item2 = (double)(j * (100+x)/100);;
				if (item1 + item2 == s){
					int item3 = (double)(i * (100+y)/100);
					int item4 = (double)(j * (100+y)/100);
					if (max < item3 + item4){
						max = item3 + item4;
					}
				}
			}
		}
		cout << max << endl;
	
	}
return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

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

using namespace std;

typedef vector<int> vi;

int m, n;
vi ok;
int dist[300][300];

int main(){
	//freopen("test.txt", "r", stdin);
	while(cin >> m, m){
		cin >> n;
		vi d(n+2, 0);
		FOR(i, 1, n+1) cin >> d[i];
		rep(i, n+2){
			d[i] += i;
			if(d[i] < 0) d[i] = 0;
			if(d[i] > n) d[i] = n+1;
		}

		const int INF = 10000;
		rep(i, n+2)rep(j, n+2) dist[i][j] = INF;
		dist[0][0] = 0;

		rep(i, n+2){
			for(int j = 1; j <= m; j++){
				int dest = i+j;
				if(dest > n) dest = n+1;
				dist[i][d[dest]] = min(dist[i][d[dest]], 1);
			}
		}
		rep(i, n+2)rep(j, n+2)rep(k, n+2) dist[j][k] = min(dist[j][k], dist[j][i]+dist[i][k]);

		bool ok = true;
		rep(i, n+2){
			ok &= (dist[0][i] == INF || dist[i][n+1] != INF);
		}
		cout << (ok?"OK":"NG") << endl;
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 2e5 + 10;

int n;
int a[N];
ll ans = LLONG_MAX;

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

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

	sort(a + 1, a + n + 1);

	ll currAns = 0LL;
	for (int i = 2; i <= n; i++) currAns += a[i] - a[1];
	ans = min(ans, currAns);

	for (int i = 2; i <= n; i++) {
		ll diff = a[i] - a[i - 1];
		currAns += (i - 1) * diff;
		currAns -= (n - i + 1) * diff;
		ans = min(ans, currAns);
	}

	printf("%lld\n", ans);

	return 0;
}

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

int main(){
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int sum=0, ans=0;
    for(int i=0;i<n-1;i++){
        if(h[i]>=h[i+1]){
            sum++;
        }else{
            sum = 0;
        }
        if(ans<sum) ans = sum;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

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

    // compute
    int ans = 700; 
    for (int i = 0; i < 3; i++){
        if(S[i] == 'o') ans += 100; 
    }

    // output
    cout << ans << endl;
}


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

#define FOR(i, l, r) for(int i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n, q; cin >> n >> q;
    UnionFind tree(n);

    queue<int> ans;
    rep(i,q){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 1){
            ans.push( tree.same(x,y) );
        }else{
            tree.unite(x,y);
        }
    }

    while(!ans.empty()) {
        cout << ans.front() << "\n";
        ans.pop();
    }   
    return 0;
}



Measured memory_bytes: 3260
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int num[n];
    for(int i=0;i<n;i++)
        cin >> num[i];
    long long big=num[0],little=num[0],sum=0;
    for(int i=0;i<n;i++){
        if(little>num[i])
            little=num[i];
        if(big<num[i])
            big=num[i];
        sum+=num[i];
    }

    cout << little << " " << big << " " << sum << endl;
    return 0;
}



Measured memory_bytes: 3136
#include <iostream>
int main()
{
    uint64_t a, b;
    std::cin >> a >> b;
    uint64_t result = 0;
    if ((b - a) >= 2) {
        bool isAEven = ((a % 2) == 0);
        bool isBEven = ((b % 2) == 0);
        uint64_t aa = isAEven ? a : a + 1;
        uint64_t bb = isBEven ? b - 1 : b;
        int numPairs = (bb + 1 - aa) / 2;
        if ((numPairs % 2) == 0) result = 0;
        else result = 1;
        if (isAEven && !isBEven) {
        } else if (isAEven && isBEven) {
            result ^= b;
        } else if (!isAEven && isBEven) {
            result ^= a ^ b;
        } else {
            result ^= a;
        }
    } else if ((b - a) == 1){
        result = a ^ b;
    } else {
        result = a;
    }
    std::cout << result << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int H;
int heap[250];

int main(void) {

    cin >> H;

    for (int i = 0; i < H; ++i) {
        scanf("%d", heap + i);
    }

    for (int i = 0; i < H; ++i) {
        printf("node %d: key = %d, ", i + 1, heap[i]);
        if (i != 0) {
            printf("parent key = %d, ", heap[(i - 1) / 2]);
        }
        if (i * 2 + 1 < H) {
            printf("left key = %d, ", heap[i * 2 + 1]);
        }
        if (i * 2 + 2 < H) {
            printf("right key = %d, ", heap[i * 2 + 2]);
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<string>
#include<vector>

using namespace std;

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

int main(){
    int N;
    string S;
    cin >> S;
    N = S.size();

   string tmp = S;
    int ans = 0;
    int i = 0;
   while(tmp[i] != '\0'){
        if((tmp[i] == '0' && tmp[i+1] == '1') || (tmp[i] == '1' && tmp[i+1] == '0') ){
            tmp.erase(tmp.begin() + i);
            tmp.erase(tmp.begin() + i);
            if(i != 0)i--;
        }
        else i++;
    }

    cout << S.size() - tmp.size();

}

Measured memory_bytes: 640