akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int h;
int ray[100][100];

void Dijkst();

int main(){
  int i, j, u, k, v, w;

  scanf("%d",&h);

  for(i = 0 ; i < h ; i++){
    for(j = 0 ; j < h ; j++){
      ray[i][j] = INFTY;
    }
  }

  for(i = 0 ; i < h ; i++){
    scanf("%d%d",&u,&k);

    for(j = 0 ; j < k ; j++){
      scanf("%d%d",&v,&w);
      ray[u][v] = w;
    }
  }

  Dijkst();

  return 0;
}

void Dijkst(){
  int i;
  int minx, u, v;
  int d[100], color[100];

  for(i = 0 ; i < h ; i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;

  while(1){
    minx = INFTY;
    u = -1;
    for(i = 0 ; i < h ; i++){
      if(minx > d[i] && color[i] != BLACK){
	u = i;
	minx = d[i];
      }
    }

    if(u == -1) break;

    color[u] = BLACK;
    for(v = 0 ; v < h ; v++){
      if(color[v] != BLACK && ray[u][v] != INFTY){
	if(d[v] > d[u] + ray[u][v]){
	  d[v] = d[u] + ray[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }

  for(i = 0 ; i < h ; i++){
    printf("%d ",i);

    if(d[i] == INFTY) printf("-1\n");
    else printf("%d\n",d[i]);
  }
}
    



Measured memory_bytes: 2112
n=parse(Int,readline())
a=map(x->parse(Int,x),split(readline()))
s=0
f=1
sum=0
x=0
for i=1:n
	sum+=a[i]
	x$=a[i]
	while sum!=x
		sum-=a[f]
		x$=a[f]
		f+=1
	end
	s+=i-f+1
end
println(s)


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  while (cin >> n && n) {
    int a[n];
    REP(i, n) cin >> a[i];
    int ans = 0;
    REP(i, n) for (int j = i + 1; j < n; ++j) {
      if (a[i] > a[j]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2996
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
const int maxn = 2018, rt = 1<<10;
ll s(ll n) {
	if(n < 10) return n;
	return n%10 + s(n/10);
}
double f(ll x) {
	return (double)x/s(x);
}
ll cur = 1, d = 1;
bool good(ll i) {
	int ok = 1;
	for(ll q = 1; q <= 1000000000000000; q *= 10) {
		ok &= f(i) <= f(i+q);
	}
	return ok;
}
void next() {
	if(!good(cur+d)) d *= 10;
	cur += d;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int k;
	cin >> k;
	while(k--) {
		cout << cur << '\n';
		next();
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 300100
#define Q 998244353
using namespace std;
char s[N];
int main(){
	int n;
	int ld=0,c[10]={};
	int nxt[3]={1,2,0},pre[3]={2,0,1};
	char tonum[10]="RGB";
	long long ans=1;
	scanf("%d",&n);
	scanf("%s",s);
	for(int i=0;s[i];i++){
		for(int j=0;j<3;j++){
			if(s[i]==tonum[j]){
				s[i]=j;
				break;
			}
		}
		if(c[5-s[i]]) ans*=c[5-s[i]]--;
		else if(c[nxt[s[i]]]){
			ans*=c[nxt[s[i]]]--;
			c[5-pre[s[i]]]++;
		}
		else if(c[pre[s[i]]]){
			ans*=c[pre[s[i]]]--;
			c[5-nxt[s[i]]]++;
		}
		else{
			c[s[i]]++;
		}
		ans%=Q;
	}
	for(int i=1;i<=n;i++){
		ans=ans*i%Q;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
    ll a,b,ans;
    cin >> a >> b;
    if(a%2==0){
      if(b%2==0){
        if(((b-a)/2)%2==0){
          ans=b;
        }else{
          ans=b^1;
        }
      }else{
        if(((b-a+1)/2)%2==0){
          ans=0;
        }else{
          ans=1;
        }
      }
    }else{
      if(b%2==0){
        if(((b-a-1)/2)%2==0){
          ans=a^b;
        }else{
          ans=a^b^1;
        }
      }else{
        if(((b-a)/2)%2==0){
          ans=a;
        }else{
          ans=a^1;
        }
      }
    }
    if(a==b)ans=a;

    cout << ans << endl;
}
















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

typedef long long ll;

#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >>N;
    string S; cin >> S;
    int c[26]; memset(c,0,sizeof c);
    rep(i, N) {
        c[S[i]-'a']++;
    }    
    ll ans = 1;
    rep(i, 26) {
        if (c[i] != 0) {
            ans = ans * (c[i]+1) % MOD;
        }
    }
    ans--;
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    int n, k;
    cin >> n;
    string s;
    cin >> s;
    cin >> k;
    for(int i = 0; i < s.size(); i++){
        if(s[k-1] != s[i]){
            s[i] = '*';
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll a, b, c, d;

int main() {
  std::cin >> a >> b >> c >> d;

  std::cout << std::max( { a*c, b*c, a*d, b*d } ) << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {int p,l,r;};

Node T[MAX];
int n, D[MAX];

void print(int u){
    int i,c;
    cout << "node "  << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if( T[u].p == NIL) cout << "root, ";
    else if(T[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, " ;

    cout << "[";

    for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u, int p){
    D[u] = p;
    if(T[u].r != NIL) rec(T[u].r,p);
    if(T[u].l != NIL) rec(T[u].l, p+1);
}

int main(){
    int i,j,d,v,c,l,r;
    cin >> n;
    for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

    for(i=0;i<n;i++){
        cin >> v >> d;
        for(j = 0; j < d;j++){
            cin >> c;
            if(j==0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v; 
        }
    }
    for(i = 0; i < n; i++){
        if(T[i].p == NIL) r = i;
    }

    rec(r,0);

    for(i = 0; i < n; i++) print(i);

    return 0;
}


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

int main(){
	int n,x;
	cin >> n >> x;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int ans = 0;
	sort(a.begin(),a.end());
	for(int i = 0;i<n;++i){
		if(i == n-1){
			if(x==a[i]) ++ans;
		}
		else{
			if(x < a[i]) break;
			++ans;
			x -= a[i];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		boolean[] E=new boolean[2*123456+1];
		for(int a=2;a<=2*123456;a++) E[a]=true;
		for(int a=2;a<1000;a++) if(E[a]) for(int b=a*a;b<=2*123456;b+=a) E[b]=false;

		while(true){
			int n=sc.nextInt();
			if(n==0) break;
			int ans=0;
			for(int a=n+1;a<=2*n;a++) if(E[a]) ans++;
			System.out.println(ans);
		}

		return;
	}
}

Measured memory_bytes: 20816
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a,b,c=INT_MAX;cin>>a>>b;
  if (b-a>=2019)
  {
    cout<<0;
    return 0;
  }
  for(ll i=a;i<b+1;i++){
    for(ll o=i+1;o<b+1;o++){
      c=min(c,i%2019*o%2019);
    }
  }
  cout<<c;
}



Measured memory_bytes: 27012
#include<stdio.h>
#include<string.h>
int main(void){
    int unused __attribute__((unused));
    char name[1001];
    unused = scanf("%s", name);
    int length = strlen(name) - 1;
    char l = name[length];
    if(l != 's'){
        name[length + 1] = 's';
        name[length + 2] = '\0';
    }
    else if(l == 's'){
        name[length + 1] = 'e';
        name[length + 2] = 's';
        name[length + 3] = '\0';
    }
    printf("%s", name);
    x:
    return 0;
}

Measured memory_bytes: 1720
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string e = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
vector<string> s1 = {
	"100101", "10011010", "0101", "0001", "110",
	"01001", "10011011", "010000", "0111", "10011000",
	"0110", "00100", "10011001", "10011110", "00101",
	"111", "10011111", "1000", "00110", "00111",
	"10011100", "10011101", "000010", "10010010", "10010011",
	"10010000", "101", "010001", "000011", "10010001",
	"000000", "000001"
};
vector<string> s2 = {
	"00000", "00001", "00010", "00011", "00100", "00101", "00110", "00111", "01000", "01001",
	"01010", "01011", "01100", "01101", "01110", "01111", "10000", "10001", "10010", "10011",
	"10100", "10101", "10110", "10111", "11000", "11001", "11010", "11011", "11100", "11101",
	"11110", "11111"
};
string s;
int main() {
	while (s = "", getline(cin, s)) {
		string t;
		for (int i = 0; i < s.size(); i++) {
			for (int j = 0; j < e.size(); j++) {
				if (s[i] == e[j]) t += s2[j];
			}
		}
		string ret = "";
		for (int i = 0; i < t.size();) {
			bool flag = false;
			for (int j = 0; j < e.size(); j++) {
				if (t.substr(i, s1[j].size()) == s1[j]) {
					ret += e[j]; i += s1[j].size(); flag = true;
					break;
				}
			}
			if (!flag) break;
		}
		cout << ret << endl;
	}
	return 0;
}

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

int main(void){
  int i;
  int Count[101] = {0};
  int data = 0;
  int MaxCount = 0;
  while(scanf("%d", &data) != EOF){
    Count[data] += 1;
  }
  for(i = 1 ; i <= 100 ; i++){
    if(MaxCount < Count[i]){
      MaxCount = Count[i];
    }
  }
  for(i = 1 ; i <= 100 ; i++){
    if(Count[i] == MaxCount){
      printf("%d\n", i);
    }
  }
  return 0;
}



Measured memory_bytes: 2032
n = int(input())
a = []
ans = 0
for _ in range(2):
    s = [0]
    ai = list(map(int,input().split()))
    for i in range(n):
        s.append(s[i]+ai[i])
    a.append(s)
for i in range(n+1):
    j = a[0][i]
    k = a[1][n]-a[1][i-1]
    ans = max(ans,j+k)
print(ans)

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

int ary[100010];

int main(){
	int N,hog,res,cnt,fla,bak;
	stack<int> st;
	while(true){
		cin>>N;
		if(N==0) break;
		for(int i=1;i<=N;i++){
			cin>>ary[i];
		}
		if(ary[1]==1) fla=1;
		else fla=0;
		st.push(1);
		for(int i=2;i<=N;i++){
			hog=ary[i];
			if(i%2){
				if(fla==hog){
					st.top()++;
				}
				else{
					st.push(1);
					fla=1-fla;
				}
			}
			else{
				if(fla==hog){
					st.top()++;
				}
				else{
					bak=st.top();
					st.pop();
					if(!st.empty()) {bak+=st.top();st.pop();}
					bak++;
					st.push(bak);
					fla=1-fla;
				}
			}
		}
		cnt=0;
		while(!st.empty()){
			hog=st.top();
			st.pop();
			if(fla==0) cnt+=hog;
			fla=1-fla;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

bool isCapital(char a)
{
    if(a>='a') return false;
    else return true;
}

int main()
{
    char s[11];
    scanf("%s",s);
    int len=strlen(s);

    if(s[0]!='A')
    {
        printf("WA\n");
        return 0;
    }

    if(isCapital(s[1]))
    {
        printf("WA\n");
        return 0;
    }

    int Cn=0;
    for(int i=2;i<len-1;i++)
    {
        if(s[i]=='C') Cn++;
        else if(isCapital(s[i]))
        {
            printf("WA\n");
            return 0;
        }
    }

    if(Cn!=1)
    {
        printf("WA\n");
        return 0;
    }

    for(int i=len-1;i<len;i++)
    {
        if(isCapital(s[i]))
        {
            printf("WA\n");
            return 0;
        }
    }
    printf("AC\n");
    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
ll mod = 1000000007;
ll INF = 1000000099;

signed main(){
    ll n,m,x=-1,y=-1,ans=1;
    cin>>n>>m;
    vector<ll> fib(n+1,0);
    fib.at(0)=1;
    fib.at(1)=1;

    for(ll i=2;i <= n;i++)
    {
        fib.at(i)=fib.at(i-1)%mod+fib.at(i-2)%mod;
        fib.at(i)%=mod;
    }

    for(ll i=0;i < m;i++)
    {
        cin>>y;
        if(y==x+1){
            cout << 0 << endl;
            return 0;
        }
        ans*=fib.at(y-x-2);
        ans%=mod;
        x=y;
    }
    ans*=(fib.at(n-y-1)%mod);
    
    cout << ans%mod << endl;
}
//入力がない時初期値が効いてくるので、初期値はちゃんと考えて置くこと

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#define RoundTable 10000
#define max(a,b) ((a)>(b) ? (a):(b))

int depth[RoundTable][RoundTable];

int lcs(char *a,char *b);

int main(){
    char lancelot[RoundTable], Merlin[RoundTable];
    int kingArthur;

    scanf("%d", &kingArthur);
    while(kingArthur--)
    {
	scanf("%s%s", lancelot, Merlin);
	printf("%d\n",lcs(lancelot,Merlin));
    }

    return 0;
}

int lcs(char *a,char *b){
    int lens,lent;
    lens = strlen(a);
    lent = strlen(b);
    for(int i = 0; i < lens; ++i)
    {
	for(int j = 0; j < lent; ++j)
        {
	    if(a[i] == b[j]) depth[i+1][j+1] = depth[i][j]+1;
	    else depth[i+1][j+1] = max(depth[i+1][j], depth[i][j+1]);
	}
    }
    return depth[lens][lent];
}


Measured memory_bytes: 9628
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define MOD 1000000007
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	char str[100001];
	scanf("%s", str);
	int len = strlen(str);
	int bcou = 1, tuka = 0;
	REP(i, len) {
		if (str[i] == 'a' && tuka < (a+b)) {
			printf("Yes\n");
			tuka++;
		}
		else if (str[i] == 'b' && bcou <= b && tuka < (a + b)) {
			printf("Yes\n");
			tuka++;
			bcou++;
		}
		else
			printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
 
int main(void)
{
	int K, answer;
	scanf("%d", &K);
	if (K % 2 == 0)
	{
		answer = (K/2)*(K/2);
	}
	else
	{
		answer = ((K+1)/2)*((K-1)/2);
	}
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
A = [int(i) for i in input().split()]

p = 10 ** 9 + 7

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def get_inv(n, p=10**9 + 7):
    inv = [0, 1]
    for i in range(2, n+1):
        inv.append(-(p//i * inv[p%i]) % p)
    return inv

f = fact(30+10**5)
inv = get_inv(30+10**5)

csum = [0]

for i in range(1, n+1):
    csum.append((csum[-1] + inv[i]) % p)

ans = 0
for i, a in enumerate(A):
    ans += (csum[i+1] + csum[n-i] - csum[1] + p) % p * a
    ans %= p

print(ans * f[n] % p)

Measured memory_bytes: 19220
#include <stdio.h>
#include <math.h>

struct Point
{
  double x, y;
};

void koch(int n, Point a, Point b)
{
  if (n == 0)
    return;
  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n - 1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n - 1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n - 1, t, b);
}

int main()
{
  Point a, b;
  int n;
  scanf("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}


Measured memory_bytes: 2696
// k-stones

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define ll long long
using namespace std;
// 1 implies taro will win and 0 implies he will loose
ll solve(ll k,vector<ll>&a,vector<ll>& dp)
{
	//memoisation
	if(dp[k]!=-1)
	{
		return dp[k];
	}
	//assuming taro will not win 
	dp[k]=0;
	//traversing a array
	for(auto x:a)
	{
		if(x<=k)
		{
			ll result=solve(k-x,a,dp);
			//implies (k-x) is unplayable
			if(result==0)
			{
				dp[k]=1;
				return dp[k];
		    }
		}
	}
	//k is unplayable (for base case)
	return dp[k];
}
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n);
	vector<ll> dp(k+1,-1);
	for(ll i=0;i<n;i++)
	cin>>a[i];
	
	if(solve(k,a,dp)==1)
	cout<<"First"<<endl;
	else
	cout<<"Second"<<endl;
	
	return 0;
}


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

int main(){
	int a,b,c;
	int ans = 3;
	cin >>a >>b >>c;

	if(a==b && b==c && c==a){
		ans = 1;
	}else{
		if(a==b)
			ans--;
		if(b==c)
			ans--;
		if(a==c)
			ans--;
	}

	cout <<ans <<endl;


	return 0;
}

Measured memory_bytes: 256
n = gets.chomp
n_753 = []
count = 0
(1..n.size).each do |i|
  n_753 += [3,5,7].repeated_permutation(i).to_a.map{|k| k.join.to_i}
end
n_753 = n_753.select do |i|
  ["3","5","7"].all?{|k| i.to_s.include?(k)}
end
n_753.each do |i|
  count += 1 if n.to_i >= i
end
puts count


Measured memory_bytes: 6524
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int N, A, B, C, X;
    cin >> N >> A >> B >> C >> X;
    if (N == 0 && A == 0 && B == 0 && C == 0 && X == 0){
      break;
    }
    vector<int> Y(N);
    for (int i = 0; i < N; i++){
      cin >> Y[i];
    }
    int pos = 0;
    int t = -1;
    int rng = X;
    while (t < 10000 && pos < N){
      t++;
      if (Y[pos] == rng){
        pos++;
      }
      rng = (A * rng + B) % C;
    }
    if (pos != N){
      cout << -1 << endl;
    } else {
      cout << t << endl;
    }
  }
}


Measured memory_bytes: 2988
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
#define rep(i,n) for (int i = 0; i < (n); ++i)

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

int main(){
  int n;cin>>n;
  ll k,q;cin>>k>>q;
  vector<int> sc(n,0);
  rep(i,q){
    int a;
    cin>>a;a--;
    sc[a]++;
  }
  rep(i,n){
    if(k-q+sc[i]>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }


  return 0;

}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
  int a, min1 = 9999, min2 = 9999, i;
  for(i = 0; i < 3; ++i) {
    scanf("%d", &a);
    if(min1 > a) min1 = a;
  }
  for(i = 0; i < 2; ++i) {
    scanf("%d", &a);
    if(min2 > a) min2 = a;
  }
  printf("%d\n", min1 + min2 - 50);
  return 0;
}


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

#define  SZ(items) (int)items.size()
template <class T> inline T gcd(T a, T b) { while (b) { a = a%b; swap(a, b); } return a; }

int ar[50];

int main()
{
	//ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(10); cout.tie(nullptr); cin.tie(nullptr);
	ios_base::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr);

	int n, m;
	cin >> n >> m;
	
	for (int i = 1; i <= n; i++)
	{
		int it;
		cin >> it;

		for (int k=1;k<=it; k++)
		{
			int x;
			cin >> x;
			ar[x]++;
		}
	}

	int cnt = 0;

	for (int i = 1; i <= 40; i++)
	{
		if (ar[i] == n)
		{
			cnt++;
		}
	}

	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define trace(x)  cerr << #x << ": " << x << endl;
typedef long long ll;
typedef long double ld;
set<ll> s;
ll fexp(ll a, ll b, ll p){ll ans = 1;while(b){if(b&1) ans = ans*a%p; b/=2;a=a*a%p;}return ans;}
ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
void primeFactors(ll n)  
{  
    
    while (n % 2 == 0)  
    {  
        s.insert(2);
        n = n/2;  
    }  
  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        
        while (n % i == 0)  
        {  
            s.insert(i); 
            n = n/i;  
        }  
    }  
  
    
    if (n > 2)  
        s.insert(n);
} 
ll count(ll n,ll p)
{
	ll cnt=0;ll z=p;
	while(n>=z)
	{
		cnt+=(n/z);z*=p;
	}
	return cnt;
} 
int main()
{
	fast;
	ll n;cin>>n;cout<<n+n*n+n*n*n;

}

Measured memory_bytes: 3696
#include <stdio.h>

int main() {
    double r;
    double l;
    double s;
    double PI=3.141592653589;
    scanf("%lf",&r);
    s = r*r*PI;
    l = 2*PI*r;
    printf("%lf %lf\n",s,l);

    return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

ll mod = 1e9+7;

ll mypow(ll n){
    ll ans = 2;
    for(int i = 1; i < n; i++){
        ans = (ans % mod) * 2 % mod;
    }
    return ans;
}


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

    map<ll,ll> mp;
    for(int i = 0; i < n; i++){
        mp[a[i]]++;
    }

    if(n == 1){
        put(1);
        return 0;
    }

    for(int i = (n % 2 == 0) + 2; i < n; i++){
        if(n % 2 == 1){
            if(mp[0] != 1 and mp[i] != 2){
                put(0);
                return 0;
            }
        }else{
            if(mp[1] != 2 and mp[i] != 2){
                put(0);
                return 0;
            }
        }
    }

    put(mypow(n/2));
}

Measured memory_bytes: 7968
A,B,K = map(int,input().split(" "))

if 2*K >= B-A+1:
    for i in range(A,B+1):
        print(i)
else:
    for i in range(A,A+K):
        print(i)
    for i in range(B-K+1,B+1):
        print(i)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<utility>
#include<string>

using namespace std;

double eps=1e-6;

main(){
  int i,j,l;
  double x[4],y[4],a,b,c,s,tol,ans,temp[3];
  while(cin >> x[0] >>y[0]){
    for(i=1;i<=3;i++){
      cin >> x[i] >> y[i];
    }

    a=pow(x[0]-x[1],2)+pow(y[0]-y[1],2);
    a=sqrt(a);
    b=pow(x[1]-x[2],2)+pow(y[1]-y[2],2);
    b=sqrt(b);
    c=pow(x[2]-x[0],2)+pow(y[2]-y[0],2);
    c=sqrt(c);
    s=(a+b+c)/2;
    tol=sqrt(s*(s-a)*(s-b)*(s-c));

    for(i=0;i<3;i++){

      if(i==1){
      a=pow(x[3]-x[2],2)+pow(y[3]-y[2],2);
      a=sqrt(a);
      }
      else{
      a=pow(x[3]-x[0],2)+pow(y[3]-y[0],2);
      a=sqrt(a);
      }

      b=pow(x[i]-x[i+1],2)+pow(y[i]-y[i+1],2);
      b=sqrt(b);

      if(i==2){
      c=pow(x[2]-x[0],2)+pow(y[2]-y[0],2);
      c=sqrt(c);
      }
      else{
      c=pow(x[3]-x[1],2)+pow(y[3]-y[1],2);
      c=sqrt(c);
      }

      s=(a+b+c)/2;
      temp[i]=sqrt(s*(s-a)*(s-b)*(s-c));
    }
    ans=temp[0]+temp[1]+temp[2];
    //   printf("%f %f\n",tol,ans);

    if(fabs(tol-ans)<eps){
      puts("YES");
    }
    else{
      puts("NO");
    }

  }
}

Measured memory_bytes: 0
N = int(input())
stmt = [[] for _ in range(N + 1)]
for j in range(1, N + 1):
    a = int(input())
    stmt[j] = [tuple(int(x) for x in input().split()) for _ in range(a)]

ans = 0
for i in range(2 ** N):
    S = "{:0{haba}b}".format(i, haba = N + 1)
    n = S.count("1")  # 正直者の数
    for j in range(1, N + 1):   # すべての人について
        if int(S[j]) == 0:  continue # 人jは不親切
        # 人jは正直者
        for (who, ishonest) in stmt[j]: # 証言チェック
            if int(S[who]) != ishonest:  # 証言と異なる
                break
        else:   # 人jの証言は問題ない
            continue    # 次の人の証言チェックへ
        break
    else:
        ans = max(ans, n)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int n,A[50];

//??\?????????M???????????????????´????????????????????????°??¢??°
int solve (int i, int m){
    if( m == 0 ) return 1;
    if( i >= n ) return 0;
    int res = solve (i + 1,m) || solve(i+1,m-A[i]);
    return res;
}

int main (){
    int q,M,i;

    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> A[i];
    }
    cin >> q;
    for (int i = 0; i < q ; ++i) {
        cin >> M;
        if(solve (0,M)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int[] n = io.r<int>(' ');
        int[][] m = io.r<int>(n[0] , ' ');
        int[,] mm = new int[n[0] + 1, n[1] + 1];

        for (int i = 0; i < n[0]; i++)
        {
            for (int j = 0; j < n[1]; j++)
            {
                mm[i,j] = m[i][j];
                mm[i,n[1]] += mm[i, j];
                mm[n[0], j] += mm[i, j];
                io.w(mm[i, j] + " ", false);
            }
            mm[n[0],n[1]] += mm[i, n[1]];
            io.w(mm[i, n[1]]);
        }
        for (int j = 0; j < n[1]; j++)
        {
            io.w(mm[n[0], j] + " ", false);
        }
        io.w(mm[n[0], n[1]]);
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 10652
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b;
	cin>>a>>b;
	if(a>0&&a<10&&b>0&&b<10)
	cout<<a*b<<endl;
	else
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
As = input().split()
suma = 0
for a in As:
  suma += int(a)
th = suma / (4.0 * m)
c = 0
for a in As:
  if int(a) >= th:
    c += 1
if c >= m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define itn int
#define gI gi

using namespace std;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, m;
string ss, t;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	cin >> ss >> t;
	n = gi(), m = gi();
	string r;
	cin >> r;
	if (r == ss) --n;
	else --m;
	cout << n << ' ' << m << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[2][256];
int c[16];
int d[20000];
int M(int a){return a*a;}
int main(){
	int inf=999999999;
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<b;i++)scanf("%d",c+i);
		for(int i=0;i<a;i++)scanf("%d",d+i);
		for(int i=0;i<2;i++)for(int j=0;j<256;j++)dp[i][j]=inf;
		dp[0][128]=0;
		for(int i=0;i<a;i++){
			for(int j=0;j<256;j++)dp[(i+1)%2][j]=inf;
			for(int j=0;j<256;j++){
				if(dp[i&1][j]==inf)continue;
				for(int k=0;k<b;k++)dp[!(i&1)][max(min(j+c[k],255),0)]=min(dp[!(i&1)][max(min(j+c[k],255),0)],dp[i&1][j]+M(d[i]-(max(min(j+c[k],255),0))));
			}
		}
		int ret=999999999;
		for(int i=0;i<256;i++)ret=min(ret,dp[a&1][i]);printf("%d\n",ret);
	}
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int

using namespace __gnu_pbds;

typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;


#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
#define mod 1000000007
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);


 ll a,b,c;
 cin>>a>>b>>c;
 ll d=c-a-b;
 if(d>0&&d*d>4*a*b)
 {
     cout<<"Yes"<<endl;
 }
 else
 {
     cout<<"No"<<endl;
 }

return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <queue>
#include <math.h>
#include <cmath>
#include <unordered_map>

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





// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;

    long long ans=0;

    rep(i,S.length()){
        if(S[i]!=T[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3856
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
const ll N = 1e18;
int main() {
    fast_cin();
    ll n,c;
    cin>>n>>c;
     vector<ll>dp(n*1000+1,N);//the minimum weight at value i
     vector<ll>weight(n);
     vector<ll>value(n);
     for(ll i=0;i<n;i++) {
            cin>>weight[i]>>value[i];
     }
     ll sum=0;
     for(ll i=0;i<n;i++) {
         sum=sum+value[i];
     }
     dp[0]=0;
     for(ll item=0;item<n;item++) {
         for(ll value_already=sum-value[item];value_already>=0;value_already--){
             dp[value_already+value[item]]=min(dp[value_already+value[item]],dp[value_already]+weight[item]);
         }
     }
     ll answer=0;
     for(ll i=0;i<=sum;i++) {
         if(dp[i]<=c) {
             answer=max(answer,(ll)i);
         }
     }
     cout<<answer<<'\n';
     
     
}    

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

inline int mul (int a, int b, int m = MOD) {
    return ((ll)a * b) % m;
}

inline int binpow (int a, int n, int m = MOD) {
    int ans = 1;
    for (; n; n >>= 1) {
        if (n & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
    }
    return ans;
}

inline void add (int &a, int x, int m = MOD) {
    a += x;
    if (a >= m) a -= m;
    if (a < 0) a += m;
}

inline int sum (int a, int b, int m = MOD) {
    a += b;
    if (a >= m) a -= m;
    if (a < 0) a += m;
    return a;
}




main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    ++n;
    int ans = 0, mn = 0, mx = 0;
    for (int i = 0; i < k; i++) {
        add(mn, i + 1);
        add(mx, n - i);
    }
    for (int i = k; i <= n; i++) {
        add(ans, mx + 1);
        add(ans, -mn);
        add(mn, i + 1);
        add(mx, n - i);
    }
    cout << ans << '\n';
}


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

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 200000 + 10;
const int MOD = 1000000007;
const int LOG = 20;
const int INF = 1000000010;

int dp[N][2], n, st[N], ft[N], Time, H[N], par[N][LOG], tav[N];
vector<int> h[N];
vi G[N];
vi g[N];

void DFS(int v = 0, int p = 0){
	st[v] = ++Time;
	par[v][0] = p;
	for (int lg = 1; lg < LOG; lg++){
		par[v][lg] = par[par[v][lg - 1]][lg - 1];
	}
	h[H[v]].pb(v);
	for (auto u:G[v]){
		H[u] = H[v] + 1;
		DFS(u, v);		
	}
	ft[v] = Time + 1;
}

int LCA(int v, int u){
	if (H[v] < H[u]) swap(v, u);
	int res = H[v] - H[u];
	for (int lg = 0; lg < LOG; lg++){
		if (res & (1 << lg)) v = par[v][lg];
	}
	if (v == u) return v;
	for (int lg = LOG - 1; lg >= 0; lg--){
		if (par[v][lg] != par[u][lg]) v = par[v][lg], u = par[u][lg];
	}
	return par[v][0];
}

bool cmp(int x, int y){
	return st[x] < st[y];
}

void DFS2(int v){
	if (g[v].size() == 0){
		dp[v][0] = dp[v][1] = 1;
		return;
	}
	ll Sum = 1;
	for (auto u:g[v]){
		DFS2(u);
		Sum = Sum * (dp[u][0] + dp[u][1]) % MOD;
	}
	int DP[g[v].size() + 10][2];
	memset(DP, 0, sizeof DP);
	DP[0][0] = 1;
	int pnt = 1;
	for (auto u:g[v]){
		DP[pnt][0] = DP[pnt - 1][0] * dp[u][0] % MOD;
		DP[pnt][1] = DP[pnt - 1][0] * dp[u][1] % MOD;
		DP[pnt][1] += DP[pnt - 1][1] * dp[u][0] % MOD;
		DP[pnt][1] %= MOD;
		pnt++;
	}
	Sum -= DP[pnt - 1][1];
	Sum %= MOD;
	Sum += MOD;
	Sum %= MOD;
	dp[v][0] = Sum;
	dp[v][1] = DP[pnt - 1][1];
	//cout << v << ' ' << dp[v][0] << ' ' << dp[v][1] << '\n';
}

int solve(int x){
	int cnt = 0;
	vector<int> node;
	for (auto u:h[x]) node.pb(u);
	if (h[x].size() == 0) return 0;
	cnt = h[x].size();
	node.pb(0);
	sort(all(node), cmp);
	int sz = node.size();
	for (int i = 1; i < sz; i++){
		node.pb(LCA(node[i - 1], node[i]));
		//cout << node[i - 1] <<  ' ' << node[i] << ' ' << LCA(node[i - 1], node[i]) << '\n';
	}
	sort(all(node), cmp);
	node.resize(unique(all(node)) - node.begin());
	for (auto u:node) g[u].clear(), g[u].shrink_to_fit(), dp[u][0] = dp[u][1] = 0;
	stack<int> St;
	St.push(0);
	//cout << x << '\n';
	for (int i = 1; i < node.size(); i++){
		while (ft[St.top()] <= st[node[i]]) St.pop();
		g[St.top()].pb(node[i]);
		//cout << St.top() << ' ' << node[i] << '\n';
		St.push(node[i]);
	}
	DFS2(0);
	//cout << dp[0][1] << ' ' << tav[n + 1 - cnt] << '\n';
	return dp[0][1] * tav[n + 1 - cnt] % MOD;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	tav[0] = 1;
	for (int i = 1; i < N; i++) tav[i] = tav[i - 1] * 2 % MOD;
	for (int i = 1; i <= n; i++){
		int p;
		cin >> p;
		G[p].pb(i);
	}
	DFS();
	//cout << "YES" << endl;
	ll ans = 0;
	for (int i = 0; i <= n; i++){
		//cout << i << endl;
		ans += solve(i);
		ans %= MOD;
	}
	cout << ans;



	return 0;
}




Measured memory_bytes: 76800
//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;

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

//main code

int main(int argc, char const* argv[])
{
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i+=2) {
        cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <deque>
#include <cstring>
#include <algorithm>

using namespace std;

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

int main(){
    int n,m;
    while(cin >> m >> n){
        if((n|m) == 0) break;
        bool field[n+2][m+2];
        bool visited[n+2][m+2];
        deque<pair<int,int> > q;
        int tmp;
        int ret = 0;

        memset(field, false, sizeof(field));
        memset(visited, false, sizeof(visited));
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cin >> tmp;
                field[i][j] = tmp?true:false;
            }
        }
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(visited[i][j] == false && field[i][j] == true){
                    q.push_back(make_pair(i,j));
                    ret++;
                }
                while(!q.empty()){
                    int x = q.front().first;
                    int y = q.front().second;
                    q.pop_front();
                    if(visited[x][y] == true){
                        continue;
                    }else{
                        visited[x][y] = true;
                    }
                    for(int k=0;k<8;k++){
                        if(field[x+dx[k]][y+dy[k]] == true &&
                           visited[x+dx[k]][y+dy[k]] == false){
                            q.push_back(make_pair(x+dx[k], y+dy[k]));
                        }
                    }
                }
            }
        }
        cout << ret << endl;
    }
}

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

#define INFTY 1000000001

using namespace std;

int n, s[200010];
long long cnt;

long long merge(int *A, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int i, j;
  cnt = 0;

  //generate L[0...n1], R[0...n2]
  int L[n1 + 10], R[n2 + 10];
  for(i = 0;i < n1;i++) L[i] = A[left + i];
  for(i = 0;i < n2;i++) R[i] = A[mid + i];

  L[n1] = INFTY;
  R[n2] = INFTY;

  i = 0;
  j = 0;

  for(int k = left;k < right;k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }else{
      cnt += n1 - i;
      A[k] = R[j];
      j++;
    }
  }

  return cnt;
}

long long mergeSort(int *A, int left, int right){
  long long a, b, c;

  if(left + 1 < right){
    int mid = (left + right) / 2;
    a = mergeSort(A, left, mid);
    b = mergeSort(A, mid, right);
    c = merge(A, left, mid, right);
    return a + b + c;
  }

  return 0;
}

int main(){

  cin >> n;
  for(int i = 0;i < n;i++) cin >> s[i];

  /*mergeSort(s, 0, n);

  for(int i = 0;i < n;i++){
    cout << (i?" ":"");
    cout << s[i];
  }
  cout << endl;*/

  cout << mergeSort(s, 0, n) << endl;

  return 0;
}



Measured memory_bytes: 4652
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define begin begin()
#define end end()

void _main(){
    long long a; 
    long double b; cin >> a >> b;
    int b2 = round(b*100);
    long long c = a*b2/100;
    cout << c << endl;
    return;
}
int main() {
    _main();
    return 0;
}
    

Measured memory_bytes: 3144
#include <stdio.h>

long long a[100010];

int main(void){

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

        int zero=0;
        for(int i=0;i<n;i++){
                if(a[i]==0){
                        zero++;
                }   
        }   

        if(zero>0){
                printf("0\n");
                return 0;
        }   

        long long prod=1;
        for(int i=0;i<n;i++){
                if(a[i]<=1000000000000000000/prod){
//掛け算したとき10^18を超えない内容にする
                        prod *= a[i];//prodは掛け算した塊
                }else{
                        printf("-1\n");
                        return 0;
                }   
        }   
        printf("%lld\n",prod);
}

Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    
        
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    ll happy = 0;
    happy = happy + (n/500)*1000;
    n = n%500;
    
    happy = happy + (n/5)*5;
    cout<<happy<<endl;
    return 0;
}

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

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int ant = 0;
	int ans = 0;
	int tam, X;
	int aux;

	cin >> tam >> X;

	vector <int> arr(tam);

	for (int i = 0; i < tam; ++i)
		cin >> arr[i];

	if(ant <= X)
		ans++;

	for (int i = 1; i <= tam; ++i)
	{
		aux = ant + arr[i - 1];

		if(aux <= X)
			ans++;

		ant = aux;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256