akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#pragma GCC optimize(3)   
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector < ll > vl;
typedef vector < vl > vvl;
typedef pair < ll, ll > pll;
typedef vector < pair < ll, ll > > vpll;
#define kill freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define pb push_back
#define fo(i,n) for(ll i=0;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(c) c.begin(), c.end()
#define go(c,it) for(auto it=(c).begin(); it!=(c).end(); it++)
#define fi first
#define se second
#define MOD 998244353
#define Boost() ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD1 1000000007
ll power(ll a, ll b){ll res=1;while(b>0){if(b&1){res=(res*a)%MOD;}a=(a*a)%MOD;b>>=1LL;}return res;}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
#define oo LLONG_MAX
const ll dx[]={-1,0,1, 0,-1,1, 1,-1};
const ll dy[]={ 0,1,0,-1, 1,1,-1,-1};

void solve(){
  ll n,k;
  cin>>n>>k;
  vl l(k),r(k);
  fo(i,k){
     cin>>l[i]>>r[i];
  }
  ll ans = 0;
  ll dp[n+1] = {0};
  dp[1] = 1;
  dp[2] = -1;
  for(ll i = 1;i<=n;i++){
      dp[i] = (dp[i]+dp[i-1])%MOD;
      fo(j,k){
          ll left = l[j];
          ll right = r[j]+1;
          if(i+left<=n)
            dp[i+left] = (dp[i+left]+dp[i])%MOD;
          if(i+right<=n)
            dp[i+right] = (dp[i+right]-dp[i]+MOD)%MOD;
      }
  }
  cout<<dp[n];
}

int main(){
    Boost();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 5200
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    if a[i]%2 == 1:
        continue
    else:
        if a[i]%3 == 0:
            continue
        elif a[i]%5 == 0:
            continue
        else:
            print ("DENIED")
            exit (0)
print ("APPROVED")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int D, G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  int ans = 1e9;
  REP(i, D) { cin >> p[i] >> c[i]; }
  for(int bit = 0; bit < (1 << D); bit++) {
    int score = 0;
    int num = 0;
    for(int i = 0; i < D; i++) {
      if(bit & (1 << i)) {
        score += p[i] * 100 * (i + 1) + c[i];
        num += p[i];
      }
    }
    if(score >= G) {
      ans = min(ans, num);
    } else {
      for(int i = D - 1; i >= 0; i--) {
        if(!(bit & (1 << i))) {
          REP(j, p[i]) {
            if(score >= G) { break; }
            score += 100 * (i + 1);
            num++;
          }
        }
      }
      ans = min(ans, num);
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int N, Y;
    scanf("%d %d", &N, &Y);

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            int k = N - i - j;
            if (i + j + k == N && (i * 10000) + (j * 5000) + (k * 1000) == Y) {
                printf("%d %d %d\n", i, j, k);
                return 0;
            }
        }
    }

    printf("%d %d %d\n", -1, -1, -1);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n;
  int sum=0;
  scanf("%d",&n);
  int i;
  int a[n+1];
  int b[n+1];
  int c[n];
  int k;
  for(i=1;i<=n;i++){
  scanf("%d",&a[i]);
}
for(i=1;i<=n;i++){
  scanf("%d",&k);
  b[i]=k;

  sum+=k;

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

  }
  printf("%d\n",sum);
}



Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;                                

struct cell{
  long int a;
  long int b;
};

bool operator< (const cell& left, const cell& right)
{
  if (left.b == right.b) return left.a > right.a;
  return left.b < right.b ;
}
int main(void){                                     
  int N;
  bool t = true;
  long int sum_a = 0,max_b = 0;
  cin >> N;
  vector<struct cell> v;
  for(int i = 0; i < N;i++){
    long int x,y;
    cin >> x >> y;
    struct cell a = {x,y};
    v.push_back(a);
    if(max_b < y) max_b = y; 
  }
  std::sort(v.begin(),v.end());//昇順ソート
  for(auto u : v){
    sum_a += u.a;
    if(sum_a > u.b){
      t = false;
      break;
    }
  }
  if(t == true) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;                                         
}     


Measured memory_bytes: 6512
#include<bits/stdc++.h>
const int M=2e6+100;//M=300000;//
typedef long long int ll;
using namespace std;
 
ll n,m,i,j,x,y,z,t,k(0),cnt(0),ans(0),sum(0),mn(M),mx(-9e9);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>n;
	ll a[n+1];
	cin>>a[0];
	for(i=1;i<n;i++)
	{
		cin>>a[i];
		if(a[i]<a[i-1])
		{
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin >> n;
  vector<int> b,ans;
  for(int i=0;i<n;i++){
    int a; cin >> a;
    b.push_back(a);
  }
  for(int i=0;i<n;i++){
    for(int j=b.size()-1;j>=0;j--){
      if(b[j]==j+1){
        ans.push_back(b[j]);
        b.erase(b.begin()+j);
        break;
      }
      if(j==0){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  reverse(ans.begin(),ans.end());
  for(int i=0;i<n;i++){
    cout << ans[i] << endl;
  }
  return 0;
}


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

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

#define MAX 100000

int par[MAX], rank_[MAX];
int n;

void init(int par[], int V){
  for(int i = 0; i < V; ++i)
    par[i] = i;
}

int find(int x, int par[]){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x], par);
  }
}

void unite(int x, int y, int par[], int rank_[]){
  x = find(x, par);
  y = find(y, par);

  if(x == y)
    return;

  if(rank_[x] > rank_[y]){
    par[y] = x;
  }else{
    par[x] = y;
    if(rank_[x] == rank_[y])
      rank_[y]++;
  }
}

int same(int x, int y, int par[]){
  return find(x, par) == find(y, par);
}

int main(){

  int m;
  cin >> n >> m;

  init(par, n);

  REP(i,m){
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--;
    unite(x, y, par, rank_);
  }

  map<int, int> mp;
  REP(i,n){
    mp[find(i, par)] = 1;
  }
  
  cout << mp.size() << endl;


  return 0;
}



Measured memory_bytes: 5632
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
a=[0 for i in range(H*W)]
b=[0 for i in range(N)]
b[0]=A[0]
for i in range(1,N):
  b[i]=b[i-1]+A[i]

for i in range(N):
  if i==0:
    for j in range(b[i]):
      a[j]=1
  else:
    for j in range(b[i-1],b[i]):
      a[j]=i+1
   
ans=[[0 for i in range(W)] for j in range(H)]
for i in range(H):
  for j in range(W):
    ans[i][j]=a[W*i+j]
for i in range(H):
  if i%2==1:
    ans[i].reverse()
  print(*ans[i])

Measured memory_bytes: 74572
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
int k, a[505][505];
void solve1() {
	printf("%d\n", k); for(int i = 1; i <= k; ++ i, puts("")) for(int j = 1; j <= k; ++ j, printf(" ")) printf("%d", j);
}
void solve2() {
	puts("500");
	for(int i = 1; i <= 500; ++ i) for(int j = 1; j <= 500; ++ j) a[i][j] = (i + j - 2) % 500 + 1;
	for(int i = 501; i <= k; ++ i) for(int j = 1; j <= 500; ++ j) if(j & 1) a[(i - j + 500 - 2) % 500 + 1][j] = i;
	for(int i = 1; i <= 500; ++ i, puts("")) for(int j = 1; j <= 500; ++ j, printf(" ")) printf("%d", a[i][j]);
}
int main() {
	if((k = read()) <= 500) return solve1(), 0;
	else return solve2(), 0;
	return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define endl '\n';
const int maxn=2e5+5;
int dp[maxn][62];
int32_t main(){
	ios::sync_with_stdio(0); 
	cin.tie(0); 
	cout.tie(0);
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		a[i]--;
		dp[i][0] = a[i];
	}
	for (int j = 1; j < 62; ++j)
	{
		for (int i = 0; i < n; ++i)
		{
			dp[i][j] = dp[dp[i][j-1]][j-1];
		}
	}
	int id=0;
	for (int i = 0; i < 62; ++i)
	{
		if(k&(1ll<<i)){
			// cout<<i<<" "<<dp[id][i]<<endl;
			id = dp[id][i];
		}
	}
	cout<<id+1<<endl;
	return 0;
}

Measured memory_bytes: 102088
#include<stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int array[3];
	for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
	for(int i = 2; i > 0; i--){
		for(int j = 0; j < i; j++){
			if(array[j] > array[j+1])swap(array[j],array[j+1]);
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
}



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

int main() {
	int n,a,b,c,x,y[100]={0};
	while(1){
		cin>>n>>a>>b>>c>>x;
		if(n==0&&a==0&&b==0&&c==0&&x==0)break;

		for(int i=0;i<n;i++) cin>>y[i];
		
		int cnt=0;
		int i=0;
		while(1){
			//cout<<x<<endl;
			if(x==y[i])i++;
			cnt++;
			if(cnt>10000||i==n)break;
			x=(a*x+b)%c;
		}
		if(i==n)cout<<cnt-1<<endl;
		else cout<<"-1"<<endl;
	}
	return 0;
}

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

def main():
    H, N = map(int, input().split())
    inf = float('inf')
    AB = [tuple(map(int, input().split())) for _ in range(N)]
    dp = [inf] * (H+10**4+1)
    dp[0] = 0
    for h in range(H+1):
        for a, b in AB:
            dp[h+a] = min(dp[h+a], dp[h]+b)
    print(min(dp[H:]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 42220
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int x = 0;
    int ans = 0;
    rep(i,s.size()){
        s[i] == 'I' ? x++ : x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N 10000

#define MIN(A,B) (A)<(B)?(A):(B)
#define MAX(A,B) (A)>(B)?(A):(B)

int main(){
  int n, a, b, d, i, j;
  int V[N]={0}, t;
  double tmp, prev;
  char S[N];
  scanf("%d", &n);
  tmp=0.0;
  for (i=0; i<n; i++){
    scanf("%d", &V[i]);
  }

  for (i=0; i<n; i++){
    for (j=i+1; j<n; j++){
      if (V[i]<V[j]) {
        t=V[i]; V[i]=V[j]; V[j]=t;
      }
    }
  }
  prev=(double)V[n-1];
  for (i=n-2; i>=0; i--){
    prev=(double)(prev+V[i])/2;
  }
  printf("%.10lf\n", (double)prev);
  return 0;
}


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

int main(){
  int k,x;
  scanf("%d %d", &k, &x);

  int range = (k-1)*2+1;
  int min = x - (k-1);
  for(int i = 0; i<range; i++){
    printf("%d ", min+i);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i, r, n) for (int i = (r); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<int> divisor(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> a(N + 1);
    REP(i, N) { cin >> a.at(i + 1); }

    vector<int> ans;
    RREP(i, N) {
        if (a[i + 1]) {
            ans.push_back(i + 1);
            auto ds = divisor(i + 1);
            for (auto d : ds) {
                a[d] = (a[d] + 1) % 2;
            }
        }
    }

    cout << ans.size() << endl;
    if (ans.size()) {
        REP(i, ans.size()) {
            cout << ans[i];
            if (i != ans.size() - 1) {
                cout << " ";
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 2424
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    sort(D.begin(), D.end());
    int ans = 0;
    int index = N/2-1;
    ans = D[index+1] - D[index];
    if(D[index] == D[index+1]){
        ans = 0;
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

const int INF = 100000000;

int main() {
    int N;
    int ans = 0;
    string S;
    cin >> N >> S;
    for (int i = 0; i < S.size()-2; i++) {
        if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') {
            ans++;
        }
    }

    cout << ans << endl;
}


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

using namespace std;

int main(){
  string s;
  cin >>s;
  int flag = 0;
  int c = 0;
  if(s[0] != 'A')
    flag = 1;
  
  for (int i=2; i<s.size()-1; ++i){
    if(s[i] == 'C'){
      c++;
      s[i] = tolower(s[i]);
    }
  }
  if(c != 1) flag = 1;
  
  for (int i=1; i<s.size(); ++i)
    if(isupper(s[i])) flag = 1;
  
  if(flag == 0) cout << "AC" << endl;
  else cout << "WA" << endl;
}


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

typedef long long ll;

int main() {
    int N, M, L, R;
    cin >> N >> M;
    vector<int> d(N + 1, 0), s(N + 1, 0);
    rep(i, M) {
        cin >> L >> R;
        d[L - 1]++;
        d[R]--;
    }
    rep(i, N) {
        s[i + 1] = s[i] + d[i];
    }
    int ans = 0;
    rep(i, N + 1) {
        if (s[i] == M) ans++;
        //cout << s[i] << " ";
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    string s;
    cin>>s;
    int tmp=stoi(s.substr(0,2));
    int tmp2=stoi(s.substr(2,2));
    if(tmp>=1&&tmp<=12&&1<=tmp2&&tmp2<=12)
        cout<<"AMBIGUOUS"<<endl;
        else if(tmp>=1&&tmp<=12)
            cout<<"MMYY"<<endl;
        else if(tmp2>=1&&tmp2<=12)
            cout<<"YYMM"<<endl;
        else
            cout<<"NA"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
using namespace std;
#define inf 0x3fffffff

int n,m;
LL f[110][110][2][2];
char s[110];

int main()
{
    scanf("%s%d",s+1,&m);
    n=strlen(s+1);
    memset(f,0,sizeof(f));
    f[1][0][1][0]++;
    for (int i=1;i<s[1]-'0';i++)
        f[1][1][0][0]++;
    f[1][1][0][1]++;
    for (int i=2;i<=n;i++)
    {
        for (int j=0;j<=m;j++)
        {
            f[i][j][0][0]+=f[i-1][j][0][0];
            for (int k=1;k<=9;k++)
            {
                f[i][j+1][0][0]+=f[i-1][j][0][0];
            }
            f[i][j][1][0]+=f[i-1][j][1][0];
            for (int k=1;k<=9;k++)
                f[i][j+1][0][0]+=f[i-1][j][1][0];
            if (s[i]=='0')
            {
                f[i][j][0][1]+=f[i-1][j][0][1];
            }
            else
            {
                f[i][j][0][0]+=f[i-1][j][0][1];
                for (int k=1;k<s[i]-'0';k++)
                    f[i][j+1][0][0]+=f[i-1][j][0][1];
                f[i][j+1][0][1]+=f[i-1][j][0][1];
            }
        }
    }
    LL ans=f[n][m][0][0]+f[n][m][0][1];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100005

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  int i,ans=0;
  char S[3];
  scanf("%s",S);
  if(S[0]=='S'&&S[1]=='U'&&S[2]=='N')ans=7;
  if(S[0]=='M'&&S[1]=='O'&&S[2]=='N')ans=6;
  if(S[0]=='T'&&S[1]=='U'&&S[2]=='E')ans=5;
  if(S[0]=='W'&&S[1]=='E'&&S[2]=='D')ans=4;
  if(S[0]=='T'&&S[1]=='H'&&S[2]=='U')ans=3;
  if(S[0]=='F'&&S[1]=='R'&&S[2]=='I')ans=2;
  if(S[0]=='S'&&S[1]=='A'&&S[2]=='T')ans=1;

  printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
// 解説前
#include <iostream>
#include <vector>

int solve_D() {
  size_t N, Q;
  std::cin >> N >> Q;

  std::vector<std::vector<size_t>> graph(N);
  for (size_t i = 0; i < N - 1; ++i) {
    size_t a, b;
    std::cin >> a >> b;
    graph[a - 1].push_back(b - 1);
    graph[b - 1].push_back(a - 1);
  }



  std::vector<uint64_t> scores(N);
  for (size_t i = 0; i < Q; ++i) {
    size_t p;
    uint64_t x;
    std::cin >> p >> x;
    scores[p - 1] += x;
  }

  // 子が連続するようにソートする
  std::vector<size_t> stack;
  stack.reserve(N);
  std::vector<bool> visited(N);
  std::vector<uint64_t> total_scores(N);

  stack.push_back(0);
  visited[0] = true;
  total_scores[0] = scores[0];
  while (true) {
    const auto v = stack.back();

    auto& children = graph[v];
    bool all_visited = true;
    while (!children.empty()) {
      const auto child = children.back();
      children.pop_back();
      if (!visited[child]) {
        stack.push_back(child);
        visited[child] = true;
        total_scores[child] = total_scores[v] + scores[child];
        all_visited = false;
        break;
      }
    }

    if (all_visited) {
      stack.pop_back();
      if (stack.empty()) break;
    }
  }

  // 結果発表
  for (const auto score : total_scores) {
    std::cout << score << ' ';
  }

  return 0;
}

int main() {
  return solve_D();
}


Measured memory_bytes: 18432
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    int r,d,x;
    cin >> r >> d >> x;
    rep(i,10){
        int ans = r * x -d;
        cout << ans << endl;;
        x = ans;
    }
}

Measured memory_bytes: 3636
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    a = LI()
    s = sum(a)
    dv = set([1,s])
    for i in range(2,int(s**0.5)+5):
        if s%i == 0:
            dv.add(i)
            dv.add(s//i)

    def f(i):
        pm = []
        for c in a:
            t = c % i
            if t == 0:
                continue
            pm.append((i-t, t))
        pm.sort()
        p = pi = m = 0
        mi = len(pm) - 1
        while pi <= mi:
            if p < m:
                p += pm[pi][0]
                pi += 1
            else:
                m += pm[mi][1]
                mi -= 1
        return max(p,m) <= k

    r = 1
    for c in dv:
        if f(c):
            if r < c:
                r = c

    return r


print(main())





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

int main(){
	int n, m;
	int i, j;
	int A[100][100], B[100], C[100]={0};
	
	cin >> n >> m;
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}
	
	for(j = 0; j < m; j++){
		cin >> B[j];
	}
	
	for (i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			C[i] += A[i][j] * B[j];
		}
	}
	for(i = 0; i < n; i++){
		cout << C[i] << endl;
	}
	
    return 0;
}

Measured memory_bytes: 3132
N = int(input())
if N == 1:
    print(1)
    exit()
P = 10**9+7
d = {}
for i in range(2,N+1):
    k = i
    for j in range(2,i):
        while i%j == 0:
            i = i//j
            if j in d.keys():
                d[j] += 1
            else:
                d[j] = 1
    if k == i:
        d[i] = 1
ans = 1
for v in d.values():
    ans = ans*(v+1)%P
print(ans)


Measured memory_bytes: 3064
N = int(input())
h = [int(i) for i in input().split()]

INF = 10**4

dp = [INF for i in range(N)]

dp[0] = 0
dp[1] = abs(h[0]-h[1])

for i in range(2, N):

    dp[i] = min(
        dp[i-2]+abs(h[i-2]-h[i]),
        dp[i-1]+abs(h[i-1]-h[i])
        )


print(dp[N-1])

Measured memory_bytes: 13924
fun main(args: Array<String>) {
    val n = readInt()
    val a = readLongList().sorted().reversed()

    val ans = mutableListOf<Long>()
    var x = a[0]
    var i = 1
    while (i < n) {
        if (a[i] == x) {
            ans.add(x)
            if (ans.size == 2) {
                println(ans[0] * ans[1])
                return
            }
            i++
            if (i < n) x = a[i]
        } else {
            x = a[i]
        }
        i++
    }
    println(0)
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

ll solve() {
    ll N, L, Q, a, b, xp, x;
    cin >> N;
    vector<ll> DX(N-1);
    for ( int i = 0; i < N; i++ ) {
        cin >> x;
        if ( i > 0 ) DX[i-1] = x - xp;
        xp = x;
    }
    cin >> L >> Q;
    vector<int> A(Q), B(Q);
    for ( int i = 0; i < Q; i++ ) {
        cin >> a >> b;
        a--, b--;
        A[i] = a, B[i] = b;
    }

    int logN = 0, t = 1;
    while ( t < N ) {
        logN++;
        t *= 2;
    }
    logN++;
    vector<vector<int>> next(logN, vector<int>(N-1));
    int nx = 0;
    ll len = 0;
    for ( int i = 0; i < N-1; i++ ) {
        while ( nx < N-1 && len + DX[nx] <= L ) {
            len += DX[nx];
            nx++;
        }
        next[0][i] = nx;
        len -= DX[i];
    }
    for ( int j = 0; j + 1 < logN; j++ ) {
        for ( int i = 0; i < N-1; i++ ) {
            if ( next[j][i] >= N-1 ) next[j+1][i] = N-1;
            else next[j+1][i] = next[j][next[j][i]];
        }
    }

    auto can_move = [&](int from, int to, int days) -> bool {
        int p = from;
        int j = 0;
        while ( days > 0 ) {
            if ( p >= N-1 ) break;
            if ( days & 1 ) {
                p = next[j][p];
            }
            days >>= 1;
            j++;
        }
        return p >= to;
    };

    auto get_days = [&](int a, int b) -> int {
        if ( a == b ) return 0;
        if ( a > b ) swap(a,b);
        int l = 0, r = N-1, m;
        while ( r - l > 1 ) {
            m = (l + r) / 2;
            if ( can_move(a,b,m) ) r = m;
            else l = m;
        }
        return r;
    };

    for ( int i = 0; i < Q; i++ ) {
        int d = get_days(A[i],B[i]);
        cout << d << "\n";
    }
    
    return 0;
}

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

Measured memory_bytes: 9464
using namespace std;
#include<iostream>
#include<vector>
int N,M;
int ans=1;
const int maxV=100000;
const int maxN=101;
const long maxW=1E9+1;


long DP[maxV+1];
long w[maxN];
long v[maxN];


int main(){
    int N,W;
    int a,b;
    cin >> N >> W;  
    for(int i = 1; i<= N;i++){
        cin >> a >> b; 
        w[i]=a;
        v[i]=b;
    }
    for(int vj = 0; vj <=maxV; vj++){
        DP[vj] = maxW; 
    }
    DP[0]=0;
    DP[v[1]]=w[1]; 


    for(int i = 2; i<= N; i++){
        for(int vj = maxV; vj >= v[i]; vj--){
            DP[vj] = min(DP[vj], DP[vj - v[i]] + w[i]);  
        }
    }
    for(int vj = maxV; vj >= 0; vj--){
        if(DP[vj]<=W){
            cout << vj << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 1024
INF = 2 * 10 ** 5
MOD = 10 ** 9 + 7
n = gets.to_i
colors = []
n.times { colors << gets.to_i }
previous_places = Array.new(INF + 1)
previous_places[colors.shift] = 0
dp = [1]
colors.each.with_index(1) do |color, index|
  previous_place = previous_places[color]
  if previous_place == index - 1 || !previous_place
    dp[index] = dp[index - 1] % MOD
  else
    dp[index] = (dp[index - 1] + dp[previous_place]) % MOD
  end
  previous_places[color] = index
end
puts dp.last % MOD

Measured memory_bytes: 7604
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  if n%2==0:
    for i in range(n//2):
      if l[i]!=i//2*2+1:
        return 0
  else:
    if l[0]!=0:
      return 0
    for i in range(1,n):
      if -(-i//2)*2!=l[i]:
        return 0
  return pow(2,n//2)%mod

print(main())


Measured memory_bytes: 16300
#include <stdio.h>

int main(void) {

  int n,a,b;
  scanf("%d %d %d", &n, &a, &b);
  int p[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }
  int under_a = 0;
  int under_b = 0;
  int contest;
  for (int i = 0; i < n; i++) {
    if (p[i] <= a) {
      under_a++;
    } else if (p[i] <= b) {
      under_b++;
    }
  }
  contest = under_a;
  if (contest > under_b) {
    contest = under_b;
  }
  if (contest > n-under_a-under_b) {
    contest = n-under_a-under_b;
  }
  printf("%d\n", contest);

  return 0;
}

Measured memory_bytes: 128
'use strict';
const fs = require('fs');
const mod = BigInt(1e9+7);


class ABC041 {
  static A(input) {
    var s, i
    input = input.trim().split('\n');
    [s, i] = input;
    i = parseInt(i, 10);
    console.log(s[i-1]);
  }
  static B(input) {
    var a, b, c;
    input = input.trim().split(' ').map(BigInt);
    [a, b, c] = input;
    var ans = a * b % mod * c % mod;
    ans = Number(ans);
    console.log(ans);
  }
  static C(input) {
    var [n, height] = input.trim().split('\n');
    height = height.split(' ').map(n => parseInt(n, 10));
    n = parseInt(n, 10);
    var height = Object.keys(height).map(key => [parseInt(key, 10)+1, height[key]]);
    height.sort(function(first, second) {
      return (second[1] - first[1]);
    });
    for (var [i, _] of height) {console.log(i);}
  }
  static D(input) {
    var lines = input.trim().split('\n');
    var [n, m] = lines[0].split(' ').map(x => +x);
    var edges = new Array(n).fill(0);
    for (var i = 0; i < m; i++) {
      var [x, y] = lines[1+i].split(' ').map(x => +x);
      edges[x-1] |= 1<<(y-1);
    }
    var comb = new Array(1<<n).fill(null); comb[0] = 1;
    function count(edges, bit) {
      if (comb[bit] != null) {return comb[bit];}
      comb[bit] = 0;
      for (var i = 0; i < n; i++) {
        if (bit>>i&1 && !edges[i]) {
          var nxt_bit = bit & ~(1<<i);
          var nxt_edges = edges.slice();
          for (var j = 0; j < n; j++) {
            nxt_edges[j] &= ~(1<<i);
          }
          comb[bit] += count(nxt_edges, nxt_bit);
        }
      }
      return comb[bit];
    }
    console.log(count(edges, (1<<n)-1));
  }
}

class ABC173 {
  static A(input) {
    var n = +input.trim();
    console.log(Math.floor((n+999)/1000)*1000 - n);
  }
  static B(input) {
    var lines = input.trim().split('\n');
    var n = +lines[0];
    var cnt = {
      'AC': 0,
      'WA': 0,
      'TLE': 0,
      'RE': 0
    }
    for (var i = 0; i < n; i++) {
      cnt[lines[1+i]]++;
    }
    for (var [verd, c] of Object.entries(cnt)) {
      console.log(`${verd} x ${c}`);
    }
  }
  static C(input) {
    var lines = input.trim().split('\n');
    var [h, w, k] = lines[0].split(' ').map(x => +x);
    var c = lines.slice(1);
    var tot = 0;
    for (var i = 0; i < (1<<h); i++) {
      for (var j = 0; j < (1<<w); j++) {
        var cnt = 0;
        for (var y = 0; y < h; y++) {
          for (var x = 0; x < w; x++) {
            cnt += c[y][x]=='#' && ~i>>y&1 && ~j>>x&1;
          }
        }
        tot += cnt == k;
      }
    }
    console.log(tot);
  }
  static D(input) {
  }
  static E(input) {
  }
  static F(input) {
  }
}


var input = fs.readFileSync('/dev/stdin', 'utf8');
ABC173.C(input);

Measured memory_bytes: 32304
#include<stdio.h>

int main(void){
	int i,n,a[200000]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	int maxI1,maxI2;
	int max1=0,max2=0;
	for(i=0;i<n;i++){
		if(a[i]>max1){
			max1=a[i];
			maxI1=i;
		}		
	}
	for(i=0;i<n;i++){
		if(a[i]>max2){
		if(i!=maxI1){
			max2=a[i];
			maxI2=i;
		}
		}		
	}
	for(i=0;i<n;i++){
		if(i!=maxI1) printf("%d",a[maxI1]);
		else printf("%d",a[maxI2]);
		puts("");
	}
	return 0;
}

Measured memory_bytes: 2304
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int t = Integer.parseInt(bf.readLine());
 		
// 		for(int i = 0;i<t;i++){
////	 		String input1 = bf.readLine().trim();
////	 		String input2 = bf.readLine().trim();
//	 		StringTokenizer st = new StringTokenizer(bf.readLine());
//	 		int n = Integer.parseInt(st.nextToken());
//	 		int m = Integer.parseInt(st.nextToken());
//	 		ArrayList<Integer> array = new ArrayList<Integer>();
//	 		StringTokenizer st2 = new StringTokenizer(bf.readLine());
//	 		for(int j=0;j<n;j++){
//	 			array.add(Integer.parseInt(st2.nextToken()));
//	 		}
// 		}
 		
 		
 		out.println(t+t*t+t*t*t);
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25428
N, M = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)

card = [0] * M
for i in range(M):
    b, c = map(int, input().split())
    card[i] = (c, b)

card.sort(reverse=True)

arr = []
l = 0
#変更できるカード配列を作る
for i in range(M):
    if l+card[i][1] > 10**5:
        add = 10**5-l
        for j in range(add):
            arr.append(card[i][0])
        break
    else:
        for j in range(card[i][1]):
            arr.append(card[i][0])
        l += card[i][1]

a = a+arr
a.sort(reverse=True)
print(sum(a[:N]))

Measured memory_bytes: 23260
#coding:utf-8
n = int(input())
S = [list(input()) for i in range(n)]
query = S.pop()
ans = ""
for q in query:
    ok = True
    for s in S:
        if (q not in s):
            ok = False
    if ok:
        ans += q
        for s in S:
            s.remove(q)
print ("".join(sorted(ans)))




Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS_AtCoder {
	class Program {
		static void Main(string[] args) {
			new Calc().Solve();
		}
	}
	public class Calc {
		Scan cin = new Scan();
		public void Solve() {
			var NK = cin.ReadInt(' ');
			var l = cin.ReadInt(' ');
			l.OrderByDescending(x => x).Take(NK[1]).Sum().WL();
			return;
		}


	}

	public class Scan {
		public Scan() { }
		public int ReadInt() => int.Parse(Console.ReadLine());
		public int[] ReadInt(char separator) => Console.ReadLine().Split(separator).Select(int.Parse).ToArray();
		public double ReadDouble() => double.Parse(Console.ReadLine());
		public double[] ReadDouble(char separator) => Console.ReadLine().Split(separator).Select(double.Parse).ToArray();
		public long ReadLong() => long.Parse(Console.ReadLine());
		public long[] ReadLong(char separator) => Console.ReadLine().Split(separator).Select(long.Parse).ToArray();
		public string ReadLine() => Console.ReadLine();
		public string[] ReadLine(char separator) => Console.ReadLine().Split(separator).ToArray();
	}
	public static class Utils {
		public static string Docking<T>(this IEnumerable<T> collection,Func<T,string> filter = null) {
			StringBuilder sb = new StringBuilder();
			long Length = collection.Count();
			foreach (var item in collection.Select((v, i) => new { V = v, I = i })) {
				sb.Append(filter != null ? filter(item.V) : item.V.ToString());
			}
			return sb.ToString();
		}
		public static void WL(this object obj) => Console.WriteLine(obj);
		public static int IntParse(this string s) => int.Parse(s);
		public static int IntParse(this char c) => c - '0';
		public static List<int> SieveOfEratosthenes(int max) {
			int prime;
			double sqMax = Math.Sqrt(max);
			var prList = new List<int>();
			var srList = new List<int>();
			for (int i = 2; i < max+1; i++) {
				srList.Add(i);
			}
			do {
				prime = srList[0];
				prList.Add(prime);
				srList.RemoveAll(x => x % prime == 0);
			} while (prime<sqMax);
			prList.AddRange(srList);
			return prList;
		}
		public static long NCR(int n,int r) {
			long p = 1;
			for (int i = 1; i <=r; i++) {
				p = p * (n - i + 1) / i;
			}
			return p;
		}
	}
}


Measured memory_bytes: 13396
#include <iostream>
using namespace std;
 
int C[102][102];
 
void meiro(int W,int H,int c){
  if(C[W][H]!=c){
    return;
  }
 
  C[W][H] = -1;
 
  meiro(W+1,H  ,c);
  meiro(W-1  ,H,c);
  meiro(W,H+1 ,c);
  meiro(W  ,H-1,c);
}
 
int main(){
  while(1){
    int w,h;
    cin >> w >> h;
    if(w==0 && h==0){
      break;
    }
 
    for(int i=0;i<102;i++){
      for(int j=0;j<102;j++){
        C[i][j] = 10;
      }
    }
 
    int xs,ys,xg,yg;
    cin >> xs >> ys >> xg >> yg;
 
    int n;
    cin >> n;
 
    int c,d,x,y;
    for(int i=0;i<n;i++){
      cin >> c >> d >> x >> y;
 
      if(d==0){
        for(int j=x;j<x+4;j++){
          for(int k=y;k<y+2;k++){
            C[j][k]=c;
          }
        }
      }else{
        for(int j=x;j<x+2;j++){
          for(int k=y;k<y+4;k++){
            C[j][k]=c;
          }
        }
      }
    }
 
    meiro(xs,ys,C[xs][ys]);
 
    if(C[xg][yg] == -1){
      cout << "OK" << endl;
    }else{
      cout << "NG" << endl;
    }
  }
 
  return 0;
}


Measured memory_bytes: 3740
using System.Collections.Generic;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a = new long[n + 1];
        for (int i = 0; i < n; i++)
            a[i + 1] = a[i] + long.Parse(Console.ReadLine().Trim());
        var d = new Dictionary<long, int>();
        var ans = -1L;
        for (int i = 0; i <= n; i++)
        {
            if (d.ContainsKey(a[i]) ) ans = Math.Max(ans, i - d[a[i]]);
            else d[a[i]] = i;
        }
        if (ans == -1  ) Console.WriteLine(0);
        else  Console.WriteLine(ans);
    }
}

Measured memory_bytes: 24432
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

mod = 10**9+7 #出力の制限
N = int(input())
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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

li=list(map(int,input().split()))
cl=[0]*N
for i in range(N+1):
    cl[li[i]-1]+=1
hu=0
for i in range(N):
    if cl[i]==2:
        hu=i+1
h1=-1
h2=-1
for i in range(N+1):
    if h1==-1 and li[i]==hu:
        h1=i
    if h1>=0 and li[i]==hu:
        h2=N-i

print(N)
for i in range(N):
    print((cmb(N+1,i+2,mod)-cmb(h1+h2,i+1,mod))%mod)


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


namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int[] array = sc.intarr;

            int a = array[0];
            int b = array[1];
            int x = array[2];

            if(a + b < x || a > x)
            {
                wr.wri("NO");
            }
            else
            {
                wr.wri("YES");
            }

        }
    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13268
N, K = map(int, input().split())
MOD = 10**9 + 7

low = high = 0
ans = 0
for i in range(K, N+2):
  low = i*(i-1)//2  # i個取った時の和の最小値
  high = i*(2*N - i + 1)//2  # i個取った時の和の最大値
  ans += (high - low + 1)  # i個取った時の和の場合の数
  ans %= MOD
  
print(ans)

Measured memory_bytes: 9132
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n, m;
  cin >> n >> m;
  int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n , k , q;
   cin >> n >> k >> q;

   vector<int> a(n , 0);
   while (q--){
      int x;
      cin >> x;
      x--;
      a[0]-- , a[x]++;
      if(x + 1 < n)a[x + 1]--;
   }

   for(int i = 1 ; i < n ; ++i){
      a[i] += a[i - 1];
   }

   for(int i = 0 ; i < n ; ++i){
      a[i] += k;
      if(a[i] > 0){
         cout << "Yes\n";
      }
      else{
         cout << "No\n";
      }
   }
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#define int long long

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

signed main(){
	int N, M, i, j, a, b, g;
	scanf("%lld%lld", &N, &M);
	char *S = (char *)malloc(sizeof(char) * (N + 1));
	char *T = (char *)malloc(sizeof(char) * (M + 1));
	scanf("%s", S);
	scanf("%s", T);
	g = gcd(N, M);
	a = N / g;
	b = M / g;
	for(i = 0, j = 0; i * a < N && j * b < M; i++, j++){
		if(S[i * a] != T[j * b]){
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n", (N * M) / g);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define veci(x,n) vector<int> x((int) (n))
#define vecs(x,n) vector<string> x((int) (n))
#define vecbf(x,n) vector<bool> x((int) (n), false)

int main(){
  int n,k;
  cin >> n >> k;
  if(k > (n-1)*(n-2)/2){
    cout << "-1" << endl;
    return 0;
  }
  int m = n - 1 + (n-1)*(n-2)/2 - k;
  cout << m << endl;
  for(int i=2;i<=n;i++){
    cout << "1 " << i << endl;
  }
  int v = 2;
  int w = 3;
  for(int i=0;i<(n-1)*(n-2)/2 - k ;i++){
    cout << v << " " << w << endl;
    if(w == n){
      v++;
      w = v + 1;
    }else{
      w++;
    }
  }
}

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N, L;
signed main() {
    cin >> N >> L;
    int sum = 0, eat = 114514;
    for (int i = 1; i <= N; i++) {
        int taste = L + i - 1;
        sum += taste;
        if (abs(taste) < abs(eat)) { eat = taste; }
    }
    cout << sum - eat << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=2005;
int n;
bitset<MAXN*MAXN> bi;
int main()
{
	n=read();bi[0]=1;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		int x=read();sum+=x;
		bi|=(bi<<x);
	}
	for(int i=(sum+1)/2;;i++)if(bi[i])return pr2(i),0;
	return 0;
}


Measured memory_bytes: 1664
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

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

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int pow2diff(int n1,int n2){
	return (n1 - n2) * (n1 - n2);
}

int main(int argc, char const *argv[]){
	int n;
	int sum,min = 0x3FFFFF;
	cin >> n;
	std::vector<int> a(n);
	for (int i = 0; i < n; ++i)	cin >> a.at(i);
	sort(a.begin(), a.end());
	
	for (int i = a.at(0); i <= a.at(n - 1); ++i)
	{
		sum = 0;
		for (int j = 0; j < n; ++j)	sum += pow2diff(i, a.at(j));
		if(sum < min)	min = sum;
	}
	OUT(min) BR;
	RET;
}


Measured memory_bytes: 256
n = int(input())
t, a = [int(_) for _ in input().split()]
h = [int(_) for _ in input().split()]
ans = float('inf')
for i in range(n):
    tem = t - 0.006 * h[i]
    res = abs(tem - a)
    if res <= ans:
        ans = res
        result = i+1
print(result)

Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.stream.IntStream;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < A.length; ++i) {
            A[i] = sc.nextInt();
        }
 
        System.out.println(solve(A));
 
        sc.close();
    }
 
    static long solve(int[] A) {
        int[] regulated = IntStream.range(0, A.length).map(i -> A[i] - i - 1).sorted().toArray();
 
        return IntStream.range(0, A.length / 2).map(i -> regulated[A.length - 1 - i] - regulated[i]).asLongStream()
                .sum();
    }
}

Measured memory_bytes: 94036
import bisect
import sys
input = sys.stdin.buffer.readline

INF = float('INF')

a, b, q = map(int, input().split())
S = [-INF] + [int(input()) for _ in range(a)] + [INF]
T = [-INF] + [int(input()) for _ in range(b)] + [INF]
X = [int(input()) for _ in range(q)]

for x in X:
    S_idx = bisect.bisect_left(S, x)
    T_idx = bisect.bisect_left(T, x)

    s_left, s_right = S[S_idx-1], S[S_idx]
    t_left, t_right = T[T_idx-1], T[T_idx]
    pathA = x - min(s_left, t_left)
    pathB = max(s_right, t_right) - x
    pathC = min(x-s_left, t_right-x) + t_right - s_left
    pathD = min(x-t_left, s_right-x) + s_right - t_left
    print(min(pathA, pathB, pathC, pathD))

Measured memory_bytes: 16120