akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=1000000000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<P,P>Pa;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
ll C[100005]={};
int n,m;
vector<int> v[100005];
int a[1001],b[1001];
bool ca[1004],cb[1005];
ll kaijou(ll x,ll d){
	ll s=1;
	for(int i=0;i<d;++i){
		s=(s*(x-i))%r197;
	}
	return s;
}
int main() {
	cin>>n>>m;
	rep(i,0,n)cin>>a[i];
	rep(i,0,m)cin>>b[i];
	priority_queue<Pa,vector<Pa>,greater<Pa> > que;
	rep(i,0,n){
		rep(j,0,m){
			if(a[i]==b[j]){
				ca[i]=1;
				cb[j]=1;
			}
		}
	}
	bool v=0;
	rep(i,0,n){
		rep(j,0,n){
			if(i!=j&&a[i]==a[j]){
				v=true;
			}
		}
	}
	rep(i,0,m){
		rep(j,0,m){
			if(i!=j&&b[i]==b[j]){
				v=true;
			}
		}
	}
	rep(i,0,n){
		if(ca[i])que.push(Pa(P(a[i],i),P(0,1)));
		else que.push(Pa(P(a[i],i),P(0,0)));
	}
	rep(i,0,m){
		if(cb[i])que.push(Pa(P(b[i],i),P(1,1)));
		else que.push(Pa(P(b[i],i),P(1,0)));
	}
	ll ans=1,k=0,mi=0,c=0,d=0;
	while(!que.empty()){
		Pa pa=que.top();que.pop();
		ll ma=pa.first.first,num=pa.first.second,h=pa.second.first,x=pa.second.second;
		k+=ma-mi-1;
		if(mi==ma)++k;
//		cout<<ma<<" "<<num<<" "<<ans<<" "<<k<<" "<<h<<" "<<d<<endl;
		int z=0;
		if(mi==ma)z++;
		if(h==0){
			if(k<m-c-1+z){
				ans=0;
				break;
			}
			//縦
			if(!x){
				ans=(ans*(m-c))%r197;
				ans=(ans*kaijou(k,m-c-1+z))%r197;
			}else{
				ans=(ans*kaijou(k,m-c-1+z))%r197;
			}
			++d;
			k-=m-c-1;
			if(ma==mi)k--;
		}else{
			if(k<n-d-1+z){
				ans=0;
				break;
			}
			//横
			if(!x){
				ans=(ans*(n-d))%r197;
				ans=(ans*kaijou(k,n-d-1+z))%r197;
			}else{
				ans=(ans*kaijou(k,n-d-1+z))%r197;
			}
			++c;
			k-=n-d-1;
			if(ma==mi)k--;
		}
		mi=ma;

	}
	if(v)ans=0;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2688
#include<iostream>

using namespace std;

long long int N, K;


int main(void) {

	cin >> N>>K;

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

	long long int ans = 0;

	for (long long int b = K + 1; b<=N; b++) {
		long long int m = N%b;
		long long int M = (N - m) / b;

		//cout << "m= " << m << "  M= " << M << endl;

		if (m < K) { ans += (M)*(b - 1 - K + 1); }
		else { ans += (M+1)*(m - K + 1) + (M)*(b - 1 - m); }
		//break;
	}

	cout << ans << endl;

	//system("pause");
	return 0;

};

Measured memory_bytes: 256
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc103/tasks/arc103_d

面白そう！
とっかかりはどのへんだろうか

偶奇あたりから考えてみる？
まず、A→BとA←B　の距離は等しいので、Dの合計は絶対偶数になる
Dの和が奇数なら構築不可能

辺u,vを取り除いて,2つの部分木に分解する、各木の含む頂点数を x[u],x[v]とすると
D[u]+x[u] == D[v]+x[v]　となる (x[u] + x[v] == N)

最大のDについて考えてみよう
最大のDから繋がってる点を根とした部分木は少なくとも半分の数の要素を含む
なので、Dmaxは2つ以上辺を持っていてはいけない→Dmaxは葉

Dmaxを置くと、それとつながる要素のdは1意に定まる
残り(unused)の頂点の内、最大のを考える。
こいつももう葉になるしかない
1意に定まりんぐ

ん～？
こんな感じで大を小につけていけば構築完了するんじゃね？
小-大-小　となることはない(小の成分は半分以上の点を含むため)　なのでおｋそう！

D[u] > D[v]のとき
D[v] = D[u] + x[u] - x[v]
x[v] = N-x[u]なので
D[v] = D[u] + 2*x[u] - N

だめな理由がわからないが…
可能性1: 大が2つ以上の小に繋がってる場合がある(可能を-1にしてる)
可能性2: 実は構築したやつが条件を満たしてない(-1を可能にしてる)
→どっちもそんなこと無さそうなのに…

====テストケースを見たら2っぽさそう====
可能性2の方をつぶそう
→連結じゃない？自分より小さいdにすべて繋いでるんだからそんなことないだろ

じゃあ場合によってはxが違う？
→どんな場合よ？
→うーん？　最後に一応チェック機構入れるか
→つまりジャッジを書く

簡易的に、xに問題が生じてそうなとき(根がNになってないとき)は-1にするようにしてみた
→xの数がちゃんと計算されていないわけではない？？

===kmjp氏のぶろぐ===
検算が必要？？なんで？
dの条件は必要条件であって十分条件ではないからか！
→むずいよ…
dの間に成り立つべき関係を書いただけで、d全部がずれてる可能性があると…

→つまり1頂点の付いて成立すればいいので、根のdを調べてあげればいいか
"""

import sys
N = int(input())

Dz = 0
Di = []
d_to_ind = {}

for i in range(N):
    d = int(input())
    if i == 0:
        Dz = d
    Di.append([d,i])
    d_to_ind[d] = i

Di.sort()
Di.reverse()

x = [1] * N
ans = []
lis = [ [] for i in range(N) ]

for lp in range(N-1):

    nowd,nowi = Di[lp]

    nexd = nowd + 2*x[nowi] - N

    if nexd >= nowd:
        print (-1)
        sys.exit()

    if nexd not in d_to_ind:
        print (-1)
        sys.exit()

    nexi = d_to_ind[nexd]
    x[nexi] += x[nowi]
    ans.append([nowi+1,nexi+1])
    lis[nowi].append(nexi)
    lis[nexi].append(nowi)

#ジャッジを書く(1頂点について成立すればおｋ)
from collections import deque
q = deque([0])
dis = [float("inf")] * N
dis[0] = 0
while len(q) > 0:
    now = q.popleft()
    for nex in lis[now]:
        if dis[nex] > dis[now]:
            dis[nex] = dis[now] + 1
            q.append(nex)

if sum(dis) != Dz:
    print (-1)
    sys.exit()

for i in range(N-1):

    print (ans[i][0] , ans[i][1])
    


Measured memory_bytes: 106712
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

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

  ll q, h, s, d, n;
  while (scanf("%lld%lld%lld%lld%lld", &q, &h, &s, &d, &n) == 5) {
    h = min(h, 2 * q);
    s = min(s, 2 * h);
    ll ans = 0;
    if (n % 2 == 1) {
      ans += s;
      n--;
    }
    d = min(d, 2 * s);
    ans += (n / 2) * d;
    printf("%lld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 256
n,m,k=list(map(int,input().split()))
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=list(a)
sb=list(b)
s = 0
for i in range(n):
	s+=a[i]
	sa[i]=s

s = 0
for i in range(m):
	s+=b[i]
	sb[i]=s

# print(sa)
# print(sb)
ans = 0
pt1 = -1
pt2 = m-1
while pt1<n:
	s = 0
	if(pt1!=-1):
		s=sa[pt1]
	while pt2>-1 and (sb[pt2]+s)>k:
		pt2-=1
	if(pt2==-1):
		if(s<=k):
			ans = max(ans,pt1+1+pt2+1)
		# break
	else:
		ans = max(ans,pt1+1+pt2+1)
	pt1+=1
print(ans)


Measured memory_bytes: 111148
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    output = 1110 - input;
    console.log(output);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import scala.io.Source.stdin

object Main extends App {
  def det(a00:Double,a01:Double,a10:Double,a11:Double) = a00*a11-a01*a10

  for( i <- stdin.getLines ) {
    val Array(a,b,e,c,d,f) = i.split(" ").map(_.toDouble)
    val detA = det(a,b,c,d)
    printf("%.3f %.3f\n",det(e,b,f,d)/detA+0.0,det(a,e,c,f)/detA+0.0)
  }
}

Measured memory_bytes: 44404
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    char c; cin >> c;
    cout << char(c + 1) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
typedef struct list{
  int parent;
  int sibling;
  int degree;
  int depth;
  int height;
  int left;
  int right;
}node_list;

void renew_depth(node_list *,int);

int main(){
  int i,j,n,L,R,id,degree,*leaf,leaf_count=0;
  node_list *A;

  scanf("%d",&n);

  A = malloc(sizeof(node_list)*n);
  leaf = malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    A[i].parent = -1;
    A[i].depth = 0;
    A[i].sibling = -1;
    A[i].height = 0;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&L,&R);
    A[id].left = L;
    A[id].right = R;
    if(L != -1){
      degree++;
      A[L].sibling = R;
      A[L].parent = id;
      A[L].depth ++;
    }
    if(R != -1){
       degree++;
      A[R].sibling = L;
      A[R].parent = id;
      A[R].depth ++;
    }
    if(degree == 0)leaf[leaf_count++]=id;
    else{
    A[id].degree = degree;
    degree = 0;
    }
  }
  for(i=0;i<n;i++){
    if(A[i].parent ==  -1){
      renew_depth(A,i);
      break;
    }
  }
  for(i=0;i<leaf_count;i++){
    j = leaf[i];
    while(A[j].parent != -1){
      A[A[j].parent].height = A[j].height+1 >  A[A[j].parent].height ? A[j].height+1 : A[A[j].parent].height ;
      j = A[j].parent;
    }
  }

  for(i=0;i<n;i++){ 
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,A[i].parent,A[i].sibling,A[i].degree,A[i].depth,A[i].height);
    if(A[i].parent == -1)printf("root\n");
    else if(A[i].degree == 0)printf("leaf\n");
    else printf("internal node\n");
  }
  free(leaf);
  free(A);
  return 0;
}

void renew_depth(node_list *A,int i){
  if(A[i].left != -1){
    A[A[i].left].depth += A[i].depth ;
    renew_depth(A,A[i].left);
  }
  if(A[i].right != -1){
    A[A[i].right].depth +=  A[i].depth ;
    renew_depth(A,A[i].right);
  }
}


Measured memory_bytes: 2148
#include<cstdio>
#include<cstring>
#define MAXN 110
char a[MAXN],b[MAXN],c[MAXN];
int main()
{
	scanf("%s\n%s\n%s",a+1,b+1,c+1);
	int la=strlen(a+1),lb=strlen(b+1),lc=strlen(c+1);
	int na=2,nb=1,nc=1;
	char turn=a[1];
	while(1)
	{
		if(turn=='a')
		{
			if(na>la){printf("A\n"); return 0;}
			turn=a[na];
			na++;
		}
		if(turn=='b')
		{
			if(nb>lb){printf("B\n"); return 0;}
			turn=b[nb];
			nb++;
		}
		if(turn=='c')
		{
			if(nc>lc){printf("C\n"); return 0;}
			turn=c[nc];
			nc++;
		}
	}
}

Measured memory_bytes: 128
N,Q = map(int, input().split())

es = [[] for _ in range(N)]
for i in range(N-1):
    a,b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)


ans = [0] * N
px = [0] * N
for i in range(Q):
    p, x = map(int, input().split())

    px[p-1] += x

visited = [False] * N
from collections import deque
stack = deque([0])
while stack:
    i = stack.popleft()
    ans[i] += px[i]
    visited[i] = True
    for j in es[i]:
        #print(i,j,es)
        if visited[j] == False:
            ans[j] += ans[i]
            stack.append(j)
    

print(*ans)

Measured memory_bytes: 63528
#include<bits/stdc++.h>
#include <chrono> 
#define rep(i,a,b) for (int i=a;i<b;i++)
#define rep2(i,a,b) for (int i=a;i>=b;i--)
#define mod 1000000007
#define INF  1e9+5
#define fr first
#define se second
#define int long long
#define ll long long
#define PI 3.1415926535 
#define pll pair <ll,ll>
#define vl vector <ll>
#define mll map<ll,ll>
#define mci map<char,int>
#define msi map<string,int>
#define vb  vector <bool>
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 100005;
vector<ll>v[26];
signed main()
{
    Senky_Bansal
    IIIT_ALLAHABAD
      ll n,a,b;
      cin>>n>>a>>b;
      cout<<min(a,b)<<" "<<max((ll)0,a+b-n)<<endl;
}

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

const ll MOD = 1000000007;
const ll MAX = 3e6;

vector<ll> fac(MAX);
vector<ll> finv(MAX);

ll power_MOD(ll a, ll b){
  ll ans = 1;
  while(b > 0){
    if(b&1) ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b = (b >> 1);
  }
  return ans;
}

void comb_ini(){
  fac[0] = 1; fac[1] = 1;
  finv[0] = 1; finv[1] = 1;
  for(ll i = 2; i <= MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    finv[i] = finv[i - 1] * power_MOD(i, MOD - 2) % MOD;
  }
}

ll comb_MOD(ll n, ll r){
  if(n < r) return 0;
  if(n < 0 || r < 0) return 0;
  if(r == 0) return 1;
  return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}


int main(){
  comb_ini();
  ll x, y; cin >> x >> y;
  if( ((2*x - y)%3) || ((-x + 2*y)%3) ){
    cout << 0 << endl;
    return 0;
  }
  ll nx, ny;
  nx = (2*x - y)/3;
  ny = (-x + 2*y)/3;
  
  cout << comb_MOD(nx+ny, nx) << endl;
}

Measured memory_bytes: 47104
N = int(input())
A = list(map(int, input().split()))
AA = {}
t = 0
for a in A:
	t += a
	if a in AA:
		AA[a] += 1
	else:
		AA[a] = 1

Q = int(input())
ans = []
for i in range(Q):
	b, c = list(map(int, input().split()))
	if b in AA:
		if c not in AA:
			AA[c] = 0
		AA[c] += AA[b]
		t += (c - b) * AA[b]
		ans += [t]
		del AA[b]
	else:
		ans += [t]
[print(a) for a in ans]

Measured memory_bytes: 21384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	int a;
	string s;
	cin>>a;
	cin>>s;
	if(a>=3200)
		cout<<s<<"\n";
	else
		cout<<"red\n";
}
int main()
{
//	ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner n = new Scanner(System.in);

		int X = n.nextInt();

		int fiveHundred = X / 500;
		int happy = fiveHundred * 1000;
		X  = X - (fiveHundred * 500);

		int five = X / 5;
		happy = happy + (five * 5);

		System.out.println(happy);
	}

}


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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(int64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

signed main() {
  uint32_t n, k;
  n = 0;
  cin >> n;
  
  uint64_t total = 0;
  uint32_t *x = (uint32_t *)malloc(sizeof(uint32_t)*n);
  
  for(int i=0; i<n; i++) {
    cin >> x[i];
    total += x[i];
  }
  int avg =  (int) (0.5f + (float) total / (float) n);
  
  uint64_t value = 0;
  for(int i=0; i<n; i++) {
    value += (x[i]-avg)*(x[i]-avg);
  }
  delete x;
  cout << value;

  return 0;
}

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

using System.Text;


namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {

            while (true)
            {
                string[] s = Console.ReadLine().Split(' ');


                int x = int.Parse(s[0]);
                int y = int.Parse(s[1]);

                if (x == 0 && y == 0)
                    break;

                if (x > y)
                {
                    Console.WriteLine(y + " " + x);
                }
                else
                {
                    Console.WriteLine(x + " " + y);
                }
            }
        }
    }
}    

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

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORTASC(c) sort((c).begin(), (c).end())
#define SORTDESC(c, t) sort((c).begin(), (c).end(), std::greater<t>());
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

const double PI = acos(-1.0);

using ll = long long;
using namespace std;

int main()
{
    ll n;
    string s;
  	string ans = "";

    cin >> n >> s;

    REP(i, s.length()){
        ans += 'A' + (s[i] + n - 'A') % 26;
    }

    cout << setprecision(20) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */



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

    
    int n, a, b; cin >> n>> a >> b;
    ll ans = modpow(2, n);

    ans--; chmod(ans);
    ll x = 1, y = 1;
    for(ll i=n-a+1; i<=n; ++i) { x *= i; chmod(x); }
    for(ll i=1; i<=a; ++i) { y*= i; chmod(y); }
    y = modpow(y, mod-2);
    ll nca = x*y%mod;
    ans -= nca; chmod(ans);

    x = 1, y = 1;
    for(ll i=n-b+1; i<=n; ++i) { x*= i; chmod(x); }
    for(ll i=1; i<=b; ++i) { y *= i; chmod(y); }
    y = modpow(y, mod-2);
    ll ncb = x*y%mod;
    ans -= ncb; chmod(ans);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
#define pii pair<int, int>
#define MP make_pair
using namespace std;
typedef long long LL;
const int N = 305;
const int MOD = 1e9 + 7;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, m;
int dp[N][N][N], ans;
vector<pii> lim[N];

inline void Inc(int &x, int y) {
	x += y; if (x >= MOD) x -= MOD;
}

void init() {
	read(n); read(m);
	for (int i=1;i<=m;++i) {
		int l, r, x;
		read(l); read(r); read(x);
		lim[r].push_back(MP(l, x));
	}
}

bool valid(int i, int j, int k) {
	if (!dp[i][j][k]) return 0;
	if (i && j && i == j) return 0;
	if (i && k && i == k) return 0;
	if (j && k && j == k) return 0;
	int r = max(i, max(j, k));
	for (int a=0;a<lim[r].size();++a) {
		int l = lim[r][a].first, x = lim[r][a].second;
		if (((i>=l) + (j>=l) + (k>=l)) != x) return 0;
	}
	return 1;
}

void solve() {
	dp[0][0][0] = 1;
	for (int i=0;i<=n;++i) {
		for (int j=0;j<=n;++j) {
			for (int k=0;k<=n;++k) {
				if (!valid(i, j, k)) continue;
				int t = max(i, max(j, k)), x = dp[i][j][k];
				if (t == n) {
					Inc(ans, x);
					continue;
				}
				Inc(dp[t+1][j][k], x);
				Inc(dp[i][t+1][k], x);
				Inc(dp[i][j][t+1], x);
			}
		}
	}
	printf("%d\n", ans);
}

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


Measured memory_bytes: 110848
#include <iostream>
#include<string>
using namespace std;
int main()
{
  int n,k;
  cin >> n >> k;
  int d[10];
  for (int i = 0; i < k; i++) {
	cin >> d[i];
  }

  string price;
  while(1){
	price = to_string(n);
	int i;
	for(i= 0;i<k;i++){
	  if((int)price.find(to_string(d[i])) != -1) break;
	}
	if(i == k) break;
	n++;
  }
  cout << n << endl;
  return 0;
}


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

int memberNumberToIndex(int memberNumber)
{ return memberNumber - 1; }

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

	vector<int> bossNumbers(memberCount - 1);
	for (auto index = 0; index < memberCount - 1; ++index) {
		cin >> bossNumbers.at(index);
	}

	vector<int> subordinateCounts(memberCount);
	for (auto index = 0; index < memberCount - 1; ++index) {
		++(subordinateCounts.at(memberNumberToIndex(bossNumbers.at(index))));
	}

	for (auto count : subordinateCounts) {
		cout << count << "\n";
	}

	return 0;
}


Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
const ll mod = 1e9+7;

int main(){
    int n,k;
    cin >> n >> k;
    int ans=0;
    rep(i,n){
         int x;
         cin >> x;
         ans+=min(x*2,(k-x)*2);
    }
    cout << ans << endl;
    
    
     
     
    
     
     return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 55
#define int long long
using namespace std;
const int s = ('a'-1);
const int mod = (1e9)+7;
int n;
string str[N];

int calc(int y,int x,int ch){
  if(x>=(int)str[y].size() || ch>=27) return 0;
  int k = 0;
  if(str[y][x] != '?') k = 1;
  if(str[y][x] == '?') k = 27 - ch;
  if(k == 0) return 0;
  static int mem[N][22]={},used[N][22]={};
  if(used[y][x]) return (k*mem[y][x])%mod;
  used[y][x] = 1;
  int &res = mem[y][x] = 1;
  for(++x;x<(int)str[y].size();x++) if(str[y][x]=='?') res = (res*26)%mod;
  return (res*k)%mod;
}


bool check(int u,int d,int x,char ch){
  static bool memc[N][N][22][30],usedc[N][N][22][30];
  if(usedc[u][d][x][ch-s]) return memc[u][d][x][ch-s];
  usedc[u][d][x][ch-s] = 1;
  for(int y=u;y<=d;y++) if(str[y][x] != '?' && str[y][x] != ch) return memc[u][d][x][ch-s]=0;
  return  memc[u][d][x][ch-s]=1;
}

int mem[N][N][22][30],used[N][N][22][30];
int dfs(int u,int d,int x,int c){
  if(u > d) return 1;
  if(u == d) return calc(u,x,c);
  if(x >= 21) return 0;
  if(c > 26) return 0;
  if(str[u][x] == s) return mem[u][d][x][c] = (c == 1 && str[u+1][x] != s ? dfs(u+1,d,x,c):0);
  if(used[u][d][x][c]++) return mem[u][d][x][c];

  vector<int> mnc(N,30);
  for(int y=d;y>=u;y--)mnc[y] = min(mnc[y+1],str[y][x]=='?'? 30:str[y][x] - s);  
  
  int res = dfs(u,d,x,c+1); 
  //[u,y]?????????????????????????????????????????????
  for(int y=u;y<=d;y++){
    if(mnc[y+1] <= c || !check(u,y,x,c+s)) continue;
    res = (res+(dfs(u,y,x+1,1)*dfs(y+1,d,x,c+1))%mod)%mod;
  }
    return mem[u][d][x][c] = res;
}


signed main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str[i];
    while(str[i].size()<21) str[i]+=s;
  }
  cout<<dfs(0,n-1,0,1)<<endl;
  return 0;
}

Measured memory_bytes: 18296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
    bool z=false;
    ll n;
    cin>>n;
    ll ans=0;
    while(n!=0){
        ll a=n%10;
        n/=10;
        if(n==0){
            if(z){
                ans+=a-1;
            }
            else{
                ans+=a;
            }
        }
        else if(a==9){
            ans+=a;
        }
        else{
            ans+=9;
            z=true;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int n,i;
    cin>>n>>i;
    cout<<n-i+1<<endl;
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    ll n,a=0,b=0;
    cin >> n;
    vl v(n);
    rep(i,n)cin >> v[i];
    sort(all(v));
    reverse(all(v));
    rep(i,n-3){
        if(v[i]==v[i+1]){
            if(v[i+1]==v[i+2]&&v[i+2]==v[i+3]){
                a=v[i];
                b=v[i];
                break;
            }
            a=v[i];
            for(int j=i+2;i<n-1;j++){
                if(v[j]==v[j+1]){
                    b=v[j];
                    break;
                }
            }
            break;
        }
    }         
    cout << a*b << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int k; string s; cin >> k >> s;
  cout << s.substr(0, k);
  if (s.size() > k) cout << "...";
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3632
text = input()

a = int(text.split(' ')[0])
b = int(text.split(' ')[1])
c = int(text.split(' ')[2])

x, y, z = sorted([a, b, c])

cnt = z - y
y = z
x += cnt

cnt += int((y - x) / 2)
x += int((y - x) / 2) * 2

if y - x == 1:
    print(cnt+2)
else:
    print(cnt)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

vector<int> G[100010];
vector<int> dist1(100010,-1);//1からの距離を持つ配列
vector<int> distN(100010,-1);//nからの距離を持つ配列

void dfs1(int now){
  for(int i:G[now]){
    if(dist1[i]>=0)continue;
    dist1[i] = dist1[now] + 1;
    dfs1(i);
  }
  return;
}

void dfsN(int now){
  for(int i:G[now]){
    if(distN[i]>=0)continue;
    distN[i] = distN[now] + 1;
    dfsN(i);
  }
  return;
}

int main(){
  
  int n;
  cin>>n;
  int a,b;
  REP(i,n-1){
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  dist1[0]=0;
  dfs1(0);
  distN[n-1]=0;
  dfsN(n-1);
  
  int cnt=0;
  REP(i,n){
    if(dist1[i]<=distN[i]){
      cnt++;
    }
  }
  
  if(cnt>n-cnt){
    cout<<"Fennec"<<endl;
  }else{
    cout<<"Snuke"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 9600
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<bitset>
using namespace std;
bitset<10004> b[14];
int m, n;
const int INF = 0x3f3f3f3f;
int ans = -INF;
void dfs(int k) {
	if (k == m) {
		int sum = 0;
		for (int j = 0; j < n; j++) {
			int sum1 = 0;
			for (int i = 0; i < m; i++) {
				if (b[i][j])
					sum1++;
			}
			sum += max(sum1, m - sum1);
		}
		ans = max(ans, sum);
		return;
	}

	dfs(k + 1);
	b[k].flip();
	dfs(k + 1);
}
int main() {
	while (cin >> m >> n&&(m||n)) {
		ans = -INF;
		int v;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				cin >> v;
				b[i][j]=v;
			}
		}
		dfs(0);
		cout << ans << endl;
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 3032
#include<stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

int x[N][N];
void initialize(void);
void printBoard(void);
void recursive(int);

int main(){
  int i,j;
  
  initialize();

  for( i = 0 ; i < N ; i++ ){
    for(j = 0 ; j < N ; j++ ){
      x[i][j] = 0;

    }
  }

  int k;
  int r,c;
  
  scanf("%d",&k);

  for( i = 0 ; i < k ; i++ ){
    scanf("%d%d",&r,&c);
    x[r][c] = 1;
  }

  recursive(0);

  return 0;
}

void initialize(){
  int i,j;
  for( i = 0 ; i < N ; i++ ) {
    row[i] = FREE;
    col[i] = FREE;
  }

  for( i = 0 ; i < 2*N-1 ; i++ ){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }

}


void printBoard(){
  int i,j;
  
  for( i = 0 ; i < N ; i++ ){
    for( j = 0 ; j < N ; j++ ){
      if(x[i][j]){
	if(row[i] != j) return;
      }
    }
  }

  for( i = 0 ; i < N ; i++ ){
    for( j = 0 ; j < N ; j++ ){
      if(row[i] == j ) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  if( i == N ){
    printBoard();
    return;
  }

  int j;

  for( j = 0 ; j < N ; j++ ){
    if( NOT_FREE == col[j] || NOT_FREE == dpos[i+j] || NOT_FREE == dneg[i-j+N-1]) continue;

    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;

    recursive(i+1);

    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;
const int INF = 2147483647;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
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;
    }
};

//main code

int main(int argc, char const* argv[])
{
    unsigned long long x,y;
    cin >> x >> y;
    unsigned long long count = 0;
    while (x <= y) {
        count++;
        x *= 2;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
    int n,a,b;
    cin>>n;
    vi p(n);
    vi q(n);
    FOR(i,0,n){
        cin>>p[i];
    }
    FOR(i,0,n){
        cin>>q[i];
    }
    std::vector<int> v;
    FOR(i,0,n){
        v.PB(i+1);
    }
    int cnt=0;
    do {
        cnt++;
        int pp=1;
        int qq=1;
        FOR(i,0,n){
            if(p[i]!=v[i])pp=0;
            if(q[i]!=v[i])qq=0;
        }
        if(pp)a=cnt;
        if(qq)b=cnt;
    } while (std::next_permutation(v.begin(), v.end()));
  cout<<abs(a-b)<<endl;
}


Measured memory_bytes: 256
n, d = map(int, input().split())
x = [[int(j) for j in input().split()] for i in range(n)]
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        acum = 0.0
        for k in range(d):
            acum += (x[j][k] - x[i][k]) ** 2
        if (acum ** 0.5).is_integer():
            ans += 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
    int N, M, k;
    int A[101];
    int student;
    int i;
    int t;
    
    scanf("%d%d", &N, &M);
    
    for (i = 1; i <= N; i++){
        scanf("%d", &A[i]);
    }
    
    for (k = 1; k <= M; k++){
        student = 1;
        while (student != N){
            if (A[student] % k > A[student + 1] % k){
                t = A[student];
                A[student] = A[student + 1];
                A[student + 1] = t;
            }
            student++;
        }
    }
    
    for (i = 1; i <= N; i++){
        printf("%d\n", A[i]);
    }
    
    return (0);
}



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

using namespace std;

int main(){
  //文字列を受け取る配列s
  string S;
  cin >> S;
  //文字列を受け取る配列t
  string T;
  cin >> T;
  //フラグstring:consider
  string consider = "Yes";
  //全ての文字を頭から確認違えばフラグ立ててbreak
  for (int i = 0; i < (int)S.size(); i++){
    if(S.at(i)!=T.at(i)){
      consider = "No";
      break;
    }
  }
  //consider出力

  cout << consider << endl;
}


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

long long ans;
long long m[5];

int main(){
    int N; cin >> N;
    for(int i=0; i<N; i++){
        string S; cin >> S;
        if(S.at(0)=='M') m[0]++;
        if(S.at(0)=='A') m[1]++;
        if(S.at(0)=='R') m[2]++;
        if(S.at(0)=='C') m[3]++;
        if(S.at(0)=='H') m[4]++;
    }
    for(int i=0; i<5; i++){
        for(int j=i+1; j<5; j++){
            for(int k=j+1; k<5; k++){
                ans +=m[i]*m[j]*m[k];
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}

int main()
{
    const ll MOD = 1e9 + 7;
    ll N, K;
    input(N, K);
    
    ll res = 0;
    rep(i, K, N+2)
    {
        res = ((res % MOD) + ((i * (N - i + 1) + 1) % MOD)) % MOD;
    }
    
    cout << res << endl;
    
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;
    int n = s.length();

    vector<vector<int>> hv(2, vector<int>(0));
    int cnt_head_h = 0;
    int idx = 0;
    bool is_head_h = true;
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (s.at(i) == 'F')
        {
            if (is_head_h)
            {
                cnt_head_h++;
            }
            else
            {
                cnt++;
            }
        }
        else
        {
            if (cnt > 0)
            {
                hv.at(idx).push_back(cnt);
            }
            cnt = 0;
            idx = 1 - idx;
            is_head_h = false;
        }
    }
    if (cnt > 0)
    {
        hv.at(idx).push_back(cnt);
    }

    vector<bool> reac_h(2 * n + 1, false);
    reac_h.at(cnt_head_h + n) = true;
    for (auto &&i : hv.at(0))
    {
        auto prev = reac_h;
        for (int j = 0; j < 2 * n + 1; j++)
        {
            if (j - i > 0 && prev.at(j - i))
            {
                reac_h.at(j) = true;
            }
            else if (j + i < 2 * n + 1 && prev.at(j + i))
            {
                reac_h.at(j) = true;
            }
            else
            {
                reac_h.at(j) = false;
            }
        }
    }

    vector<bool> reac_v(2 * n + 1, false);
    reac_v.at(0 + n) = true;
    for (auto &&i : hv.at(1))
    {
        auto prev = reac_v;
        for (int j = 0; j < 2 * n + 1; j++)
        {
            if (j - i > 0 && prev.at(j - i))
            {
                reac_v.at(j) = true;
            }
            else if (j + i < 2 * n + 1 && prev.at(j + i))
            {
                reac_v.at(j) = true;
            }
            else
            {
                reac_v.at(j) = false;
            }
        }
    }

    if (reac_h.at(x + n) && reac_v.at(y + n))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> X(M), Y(M);
    for(int i=0; i<M; i++){
        cin >> X[i] >> Y[i];
        X[i]--; Y[i]--;
    }
    
    vector<bitset<400>> S(N);
    for(int i=0; i<N; i++){
        S[i][i] = 1;
        for(int j=M-1; j>=0; j--){
            int x = X[j], y = Y[j];
            if(S[i][x] && S[i][y]){
                S[i].set();
                break;
            }else if(S[i][x] || S[i][y]){
                S[i][x] = S[i][y] = 1;
            }
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++) for(int j=0; j<i; j++) if((S[i] & S[j]).none()) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
from collections import deque
H,W = map(int,input().split())
l = [str(input()) for _ in range(H)]
white_count = 0
for s in l:
  white_count += s.count('.')
sy = 0
sx = 0
gy = H-1
gx = W-1
visited = [[-1]*W for _ in range(H)]
visited[sy][sx] = 0
Q = deque([[sy,sx]])
while Q:
  y,x = Q.popleft()
  if [y,x] == [gy,gx]:
    print(white_count - visited[y][x] - 1)
    exit()
  for i,j in [(1,0),(0,1),(-1,0),(0,-1)]:
    if 0 <= x+j < W and 0 <= y+i < H and visited[y+i][x+j] == -1 and l[y+i][x+j] == '.':
      visited[y+i][x+j] = visited[y][x]+1
      Q.append([y+i,x+j])
    else:
      continue
print(-1)

Measured memory_bytes: 9448
import java.util.Scanner;
class Main {
   public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		String[] cards = new String[input];
		int[] number = new int[input];
		boolean b;
		
		String[] cards_bubble = new String[input];
		String[] cards_select = new String[input];
		int[] number_bubble = new int[input];
		int[] number_select = new int[input];
		
		for(int c = 0; c < input; c++){
			cards[c] = scan.next();
			number[c] = cards[c].charAt(1) - '0';

			cards_bubble[c] = cards[c];
			cards_select[c] = cards[c];

			number_bubble[c] = number[c];
			number_select[c] = number[c];
		}

		
		BubbleSort(number_bubble, input, cards_bubble);
		System.out.println("Stable");

		SelectionSort(number_select, input, cards_select);
		b = isStable(number_select, input, cards_select, cards);
		if(b){
			System.out.println("Stable");
		}else{
			System.out.println("Not stable");
		}

	}

	static void BubbleSort(int data[], int n, String str[]){
		int temp;
		String card_temp;

		for(int i = 0; i < n - 1; i++){
			for(int j = n - 1; j > i; j--){
				if(data[j - 1] > data[j]){
					temp = data[j];
					data[j] = data[j - 1];
					data[j - 1] = temp;
					
					card_temp = str[j];
					str[j] = str[j - 1];
					str[j - 1] = card_temp;
				}
			}
		}
		Print(str, n);
	}

	static void SelectionSort(int data[], int n, String str[]){
		int temp;
		String card_temp;
		int min;
		boolean b;

		for(int i = 0; i < n - 1; i++){
			min = i;
			b = false;

			for(int j = i + 1; j < n; j++){
				if(data[j] < data[min]){
					min = j;
					b = true;
				}
			}
			if(b){
				temp = data[i];
				data[i] = data[min];
				data[min] = temp;

				card_temp = str[i];
				str[i] = str[min];
				str[min] = card_temp;
			}
		}
		Print(str, n);
	}
	
	static boolean isStable(int data[], int n, String in_str[], String out_str[]){
		for(int i = 0; i < n - 1; i++){
			for(int j = i + 1; j < n - 1; j++){
				for(int a = 0; a < n - 1; a++){
					for(int b = a + 1; b < n - 1; b++){
						if(data[i] == data[j] && in_str[i].equals(out_str[b]) && in_str[j].equals(out_str[a])){
							return false;
						}
					}
				}
			}
		}
		return true;
	}
	
	
	static void Print(String str[], int n){
		for(int i = 0; i < n; i++){
			if(i != n -1){
				System.out.print(str[i] + " ");
			}else{
				System.out.println(str[i]);
			}
		}
	}
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;

  if(N == 3){
    cout << 2 << " " << 5 << " " << 63 << endl;
  }else{

    int cnt_2;
    if(N <= 15000){
        cnt_2 = N-2;

        while(cnt_2 % 3 != 0 && cnt_2 % 3 != 2){
        cnt_2 -= 2;
      }
    }else{
      cnt_2 = 15000;
      while((cnt_2 % 2 != 0 && cnt_2 % 3 != 2) || ((N-cnt_2) % 2 == 1)){
        cnt_2--;
      }
    }

    int cnt_3 = N - cnt_2;

    vector<int> ans;

    for(int i = 0; i < cnt_2; i++){
      ans.push_back((i+1)*2);
    }

    for(int i = 0; i < cnt_3; i++){
      ans.push_back(3 + 6 * i);
    }

    for(int i = 0; i < N; i++){
      cout << ans[i] << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 640
N=int(input())
Qlist=[]
ans=0
for i in range (N):
    s=int(input())
    ans+=s
    Qlist.append(s)
if ans%10==0:
    Qlist.sort()
    for j in range(N):
        temp=ans-Qlist[j]
        if temp%10==0:
            continue
        else:
            ans=temp
            break
    else:
        ans=0
else:
    pass
print(ans)

Measured memory_bytes: 9144
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		int ans = 700;
		if(S.charAt(0)=='o')ans+=100;
		if(S.charAt(1)=='o')ans+=100;
		if(S.charAt(2)=='o')ans+=100;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <stdio.h>

#define N 101

int main(){
  int n, i, j, G[N][N], num, k, v;

  scanf("%d", &n);

  for(i = 1; i <= n; i++)
    for(j = 1; j <= n; j++)
      G[i][j] = 0;

  for(i = 1; i <= n; i++){
    scanf("%d%d", &num, &k);

    if(k == 0)
      continue;

    for(j = 1; j <= k; j++){
      scanf("%d", &v);
      G[num][v] = 1;
    }
  }

  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      printf("%d", G[i][j]);
      if(j != n)
	printf(" ");
    }

    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2052
n,l=map(int,input().split())

x=[l+i-1 for i in range(1,n+1)]
min_val=None
idx=0
for i in range(1,n+1):
  tmp=abs(l+i-1)
  if min_val is None or tmp < min_val:
    min_val=tmp
    idx=i-1

x.pop(idx)
print(sum(x))

Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;

typedef long long ll;
#define FOR(i, a, n) for (ll i=(ll)a;i<(ll)n;i++)
#define REP(i, n) FOR(i, 0, n)

ll f_func(ll x){
    if (x<0){
        return 0;
    }
    ll ans;
    if (x%2){
        ans = (x+1)/2%2;
    }
    else{
        ans = x/2%2 + x;
    }
    return ans;
}

ll xor_sum(ll a, ll b){
    ll ans = 0;
    ll num = 1;
    while(a>0||b>0){
        if (a%2+b%2==1){
            ans += num;
        }
        a /= 2;
        b /= 2;
        num *= 2;
    }
    return ans;
}

int main(){
    ll a, b; cin >> a >> b;

    //cout << f_func(a-1) << endl;;
    //cout << f_func(b) << endl;

    ll ans = xor_sum(f_func(a-1), f_func(b));

    cout << ans << endl;
}

Measured memory_bytes: 256