akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}

int main(){
  ll N;cin>>N;
  ll k=N;
  ll unko =0;
  while(k>0){
    unko+=k%10;
    k/=10;
  }
  if(N%unko==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

  


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

class Program
{
	public static void Main(String[] args)
	{
		var N = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(int.Parse).OrderBy(x => x).ToArray();

		var min = input[0];
		for (int i = 1; i < N; i++)
		{
			var value = input[i] % input[0];
			if (value != 0)
			{
				if (min > value)
					min = value;
			}
		}

		var flag = true;
		var targetValue = input[0];
		while (flag)
		{
			var value = targetValue % min;
			if (value == 0)
			{
				flag = false;
			}
			else
			{
				targetValue = min;
				min = value;
			}
		}

		Console.WriteLine(min);
	}
}



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

int KnapsackProblem01(int N, int W, vector<int> v, vector<int> w) {
	vector<int> dp(W + 1, 0);
	for (int i = 0; i < N; ++i) {
		for (int j = W - w[i]; j >= 0; --j) {
			dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
		}
	}
	return dp[W];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, W;
	cin >> N >> W;
	vector<int> v(N), w(N);
	rep(i, N) cin >> v[i] >> w[i];
	cout << KnapsackProblem01(N, W, v, w) << endl;
	return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll h,w,n,ans=INF,s,a;
vector<ll>p[200005];
set<ll>q[200005];
int main(void){
    cin>>w>>h>>n;
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        x--;
        y--;
        p[y].PB(x);
        q[y].insert(x);
    }
    for(int i=0;i<h;i++){
        p[i].PB(w);
        q[i].insert(w);
        sort(p[i].begin(),p[i].end());
    }
    bool o=true;
    for(int i=0;i<h&&o;i++){
        for(int j=0;j<p[i].size();j++){
            if(a+1==p[i][j]){
                ans=min(ans,s+1);
                s++;
                o=false;
                break;
            }
            if(a+1<p[i][j]){
                ans=min(ans,p[i][j]-a+s);
                a++;
                s++;
                if(i+1<h){
                    while(q[i+1].find(a)!=q[i+1].end()&&a<p[i][j]){
                        a++;
                        s++;
                        if(a==p[i][j])o=false;
                    }
                }
                break;
            }
        }
    }
    cout<<ans<<endl;
}


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

int main(){
    int r,c;
    cin >> r >> c;
    long long sheat[101][101];
    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            sheat[i][j] = 0;
        }
    }
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> sheat[i][j];
        }
    }
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            sheat[i][c] += sheat[i][j];
        }
    }
    for(int j = 0; j <= c; j++){
        for(int i = 0; i < r; i++){
            sheat[r][j] += sheat[i][j];
        }
    }
    for(int k = 0; k <= r; k++){
        for(int l = 0; l <= c; l++){
            (l != c)?cout << sheat[k][l] << " ":cout << sheat[k][l];
        }
        cout << endl;
    }
    return 0;

}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int N;
  bool flag=false;
  for(int i=1;i<=n;i++){
      if(n==int(i*1.08)){
        N=i;
        flag=true;
        break;
      }
  }
  if(flag) cout << N << endl;
  else cout <<":(" << endl;
  return 0;
}
  


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

int main(){
 while(true){
  int x, y, s;
  cin >> x >> y >> s;

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

  int tmax = -1;

  for(int a=1; a<=s-1; a++){
   int ax = a*(100+x)/100;
   int ay = a*(100+y)/100;

   for(int b=1; b<=s-1; b++){
    int bx = b*(100+x)/100;
    int by = b*(100+y)/100;

    if(ax+bx==s){
     tmax = max(tmax, ay+by);
    }else if(ax+bx>s){
     break;
    }
   }
  }

  cout << tmax << endl;
 }

 return 0;
}



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

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	long MODULO = 1_000_000_000 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] t = new int[n];
		int[] p = new int[n];
		int[] x = new int[s];
		for (int i = 0; i < s; ++i) {
			x[i] = sc.nextInt();
		}
		for (int i = 0; i < n; ++i) {
			t[i] = sc.nextInt();
			p[i] = sc.nextInt();
			--p[i];
		}
		int[] w = new int[n];
		for (int i = 0; i < n; ++i) {
			w[i] = t[i] - x[p[i]];
		}
		Arrays.sort(w);
		long ans = 0;
		for (long v : w) {
			ans -= v;
		}
		long[][] f = new long[n + 1][m + 1];
		for (int i = 0; i < f.length; ++i) {
			for (int j = 0; j < f[i].length; ++j) {
				f[i][j] = Integer.MAX_VALUE / 16;
			}
		}
		for (int i = 1; i < f.length; ++i) {
			f[i][1] = w[i - 1] * i;
		}

		for (int j = 2; j <= m; ++j) {
			// j is fixed.
			// Attention: h[i][k]:=f[k][j-1]+w[i-1]*(i-k) is of Monge.
			// min(h[i][]) can be enumerated in O(n*log(n))
			// f[i][j]=min(h[i][])
			long[] v = calc(f, w, j);
			for (int i = 1; i <= n; ++i) {
				// for (int k = 1; k <= i - 1; ++k) {
				// f[i][j] = Math.min(f[i][j], h(f, w, i, j, k));
				// }
				f[i][j] = v[i];
			}
		}

		long min = Integer.MAX_VALUE / 16;
		for (int j = 1; j <= m; ++j) {
			min = Math.min(min, f[n][j]);
		}
		ans += min;
		System.out.println(ans);
	}

	long[] calc(long[][] f, int[] w, int j) {
		int n = f.length - 1;
		int m = f[0].length - 1;
		long[] ret = new long[n + 1];
		Arrays.fill(ret, Integer.MAX_VALUE / 16);
		rec(ret, 1, n, 2, n + 1, f, w, j);
		return ret;
	}

	// [low,high)
	// [left,right)
	long rec(long[] ret, int low, int high, int left, int right, long[][] f, int[] w, int j) {
		int mid = (left + right) / 2;// the value of the variable i
		long v = Long.MAX_VALUE / 16;
		int arg = -1;
		for (int k = Math.max(0, low); k <= Math.min(mid - 1, high); ++k) {
			v = Math.min(v, h(f, w, mid, j, k));
			if (v == h(f, w, mid, j, k))
				arg = k;
		}
		if (right - left > 1) {
			rec(ret, low, arg, left, mid, f, w, j);
			rec(ret, arg, high, mid, right, f, w, j);
		}
		ret[mid] = v;
		return v;
	}

	long h(long[][] f, int[] w, int i, int j, int k) {
		return f[k][j - 1] + w[i - 1] * (i - k);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

bool clause(const string& s, int& p)
{
  set<char> v, nv;
  while (s[p] != ')') {
    if (s[p] == '&') {
      ++p;
    }else if (s[p] == '~') {
      ++p;
      nv.insert(s[p++]);
    } else {
      v.insert(s[p++]);
    }
  }

  bool ret = true;
  for (set<char>::iterator it = v.begin(); it != v.end() && ret; ++it) {
    if (nv.find(*it) != nv.end())
      ret = false;
  }
  return ret;
}

bool exp(const string& s, int& p)
{
  bool ret = false;
  while (p < (int)s.size()) {
    if (s[p] == '(') {
      ++p;
      ret |= clause(s, p);
    } else {
      ++p;
    }
  }
  return ret;
}

int main()
{
  string s;
  while (cin >> s) {
    if (s == "#")
      break;

    int p = 0;
    if (exp(s, p))
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
  return 0;
}

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

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i <= (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+5; 

const double PI =  3.141592653589793;

int main(){
	IO;
	ll x,a;
	cin>>x>>a;
	(x<a)?cout<<"0\n":cout<<"10\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""

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

#define int long long

const int mod=1e9+7;
const int maxn=1e5+10;

int h,w,a,b,ans;
int f[maxn<<1];

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

inline int ksm(int x,int y){
    x%=mod;
    int res=1;
    while(y){
        if(y&1) (res*=x)%=mod;
        (x*=x)%=mod;
        y>>=1;
    }
    return res;
}

inline int get(int x1,int y1,int x2,int y2){
    int n=x2-x1+y2-y1,m=x2-x1;
    return ( f[n]*ksm( f[m]*f[n-m] , mod-2 ) )%mod;
}

signed main(){
    h=read(),w=read(),a=read(),b=read();
    f[0]=1;
    for(register int i=1;i<=(maxn<<1);i++)
        (f[i]=f[i-1]*i)%=mod;
    for(register int i=1;i<=h-a;i++){
        (ans+=get(1,1,i,b)*get(i,b+1,h,w))%=mod;
    }
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll a,b,c,x,y;
cin >> a >> b >> c >> x >> y;
ll costofa = min(a, 2 * c);
ll costofb = min(b, 2 * c);
ll ans = 1e17;
for (ll i = 0; i < 1e5+1;i++){
    ans = min(ans, i * 2 * c + max(0LL, x - i) * a + max(0LL, y - i) * b);
}
cout << ans << endl;
}


Measured memory_bytes: 256
S = input()

ten = [0] * (len(S) + 1)
ten[1] = 1
for i in range(1, len(S)):# ten の前計算
    ten[i + 1] = ten[i] * 10 % 2019

accum = [0] * (len(S) + 1)
for i, v in enumerate(S[::-1]):
    accum[i + 1] = (int(v) * ten[i + 1] + accum[i]) % 2019

import numpy as np
bc = np.bincount(accum)
res = (bc * (bc - 1) // 2).sum()
print(res)

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

int A[200005], B[200005];

inline int mod(int i, int m) { return i >= m ? i - m : i; }

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> A[i];
	for (int i = 0; i < N; ++i) cin >> B[i];

	priority_queue<pair<int, int>> pq;
	for (int i = 0; i < N; ++i) {
		if (A[i] < B[i]) {
			pq.emplace(B[i], i);
		}
		else if (A[i] > B[i]) {
			cout << -1 << '\n';
			return 0;
		}
	}

	ll ans = 0;
	while (!pq.empty()) {
		pair<int, int> p = pq.top();
		pq.pop();
		int i = p.second, d = B[mod(i - 1 + N, N)] + B[mod(i + 1, N)];
		if (B[i] - A[i] < d) {
			cout << -1 << '\n';
			return 0;
		}
		ans += (B[i] - A[i]) / d;
		B[i] -= d * ((B[i] - A[i]) / d);
		if (A[i] < B[i]) {
			pq.emplace(B[i], i);
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3956
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n, m := readI(), readI()
	fmt.Println(n*(n-1)/2 + m*(m-1)/2)
}

/*-----------Utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

lli calc(lli l,lli r,lli num){
    return (r/num) - ((l-1)/num);
}

lli GCD(lli x, lli y)
{
    if(x<y)swap(x,y);
    if (y == 0) {
        return x;
    } else {
        return GCD(y, x % y);
    }
}
lli LCM(lli a,lli b)
{
    return a/GCD(a,b)*b;
}

void func(long long A, long long B, long long C, long long D){

    lli ans = B-A + 1;
    LOG(ans);
    ans -= calc(A,B,C);
    LOG(ans);
    ans -= calc(A,B,D);
    LOG(ans);
    ans += calc(A,B,LCM(C,D));

    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    func(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int a[1005], b[1005], h, n, dp[20005], res(1e9);
int main() {
    DAU
    cin >> h >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i] >> b[i];
    for (int i = 1; i <= 20002; ++i)
        dp[i] = 1e9;
    for (int g = 0; g <= h; ++g)
        for (int i = 1; i <= n; ++i)
            if (dp[g] < 1e9)
                dp[g + a[i]] = min(dp[g + a[i]], dp[g] + b[i]);
    for (int i = h; i <= h + 10000; ++i)
        if (dp[i])
            res = min(res, dp[i]);
    cout << res;
    PLEC
}


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

int movei[] = {0, 0, 1, -1};
int movej[] = {1, -1, 0, 0};
const int S = 1e6+1;

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

    string str;
    cin >> str;
    str = '0'+str;
    for(int i=1; i<=str.size(); ++i){
        if((i&1) && (str[i] == 'L')){
            cout << "No";
            return 0;
        }
        if((!(i&1)) && (str[i] == 'R') ){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 256
/*
 * atcoder/abc112_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

template <class T>
bool allEqual(vector<T> &vec) {
  return adjacent_find(vec.begin(), vec.end(), not_equal_to<>()) == vec.end();
}

int N;
vector<ll> X, Y, H;

void solve() {
  cin >> N;
  ll x, y, h;
  loop(n,0,N) {
    cin >> x >> y >> h;
    if (h > 0) X.push_back(x), Y.push_back(y), H.push_back(h);
  }
  N = H.size();
  if (N == 1) {
    cout << X[0] << " " << Y[0] << " " << H[0] << endl;
    return;
  }

  loop(cx,0,101) loop(cy,0,101) {
    vector<ll> vec;
    loop(n,0,N) vec.push_back(H[n] + abs(cx - X[n]) + abs(cy - Y[n]));
    if (allEqual<ll>(vec)) {
      cout << cx << " " << cy << " " << vec[0] << endl;
      return;
    }
  }
}
int main() {
  // cout.precision(15);
  // cout << fixed << double

  solve();

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int S = Integer.parseInt(sc.next());//int型
		int bb = S%100;
		int aa = S/100;
		String aaIs = new String();
		String ans = new String();
		if (aa>=1 && aa<=12 && bb>=1 && bb<=12) {
			ans = "AMBIGUOUS";
		} else if (aa>=1 && aa<=12 && (bb==0 || bb>12)) {
			ans = "MMYY";
		} else if (bb>=1 && bb<=12 && (aa==0 || aa>12)) {
			ans = "YYMM";
		} else ans = "NA";
		System.out.println(ans);
	}

}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, x);
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  int ans = 1;
  int cx = 0;
  rep(i, n) {
    cx += l[i];
    if (cx <= x) ++ans;
  }
  out(ans);
}


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

int main(){
	int n, x;
	while (1){
		int way = 0;
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		
		for (int i = 1; i < n+1; i++){
			for (int j = i+1; j < n+1; j++){
				for (int k = j+1; k < n+1; k++){
					if (i + j + k == x) way++;
				}
			}
		}
		cout << way << "\n";
	}

	return 0;
}


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

template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main()
{
  int n;
  for(;cin>>n;)
    {
      int data[2*n];
      for(int i=0;i<2*n;i++)
	  data[i]=i+1;
      int m;
      cin>>m;
      for(int x=0;x<m;x++)
	{
	  int k;
	  cin>>k;
	  int tmp[2*n];
	  if(k==0)
	    {
	      //refull
	      for(int i=0;i<2*n;i++)
		{
		  if(i%2==0)
		      tmp[i]=data[i/2];
		  else
		      tmp[i]=data[n+(i/2)];
		}
	    }
	  else
	    {
	       for(int i=0;i<2*n;i++)
		 {
		   //	   cout<<"i="<<i<<" k+i="<<k+i<<" i-k="<<i-k<<endl;
		   if(i<2*n-k)
		     tmp[i]=data[k+i];
		   else
		     tmp[i]=data[i-(2*n-k)];
		 }
	    }
	  for(int i=0;i<2*n;i++)
	      data[i]=tmp[i];

	  /*	  
	  cout<<"aaa"<<x<<endl;
	  for(int i=0;i<2*n;i++)
	    cout<<data[i]<<endl;
	  */

	}

      for(int i=0;i<2*n;i++)
	cout<<data[i]<<endl;
    }
}

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

int main(){
  string s;
  long long int k;
  cin >> s >> k;
  int n=s.size();
  long long int cnt=0;
  char tmp=s.at(0);
  vector<int> memo;
  int same=1;
  for(int i=1;i<n;i++){
    if(s.at(i)==tmp){
      same++;
    }else{
      cnt+=same/2;
      memo.push_back(same);
      tmp=s.at(i);
      same=1;
    }
  }
  cnt+=same/2;
  memo.push_back(same);
  if(same==n){
    cout << n*k/2 << endl;
  }else{
    if(s.at(0)==s.at(n-1)&&memo.at(0)%2==1
       &&memo.back()%2==1){
      cout << cnt*k+k-1 << endl;
    }else{
      cout << cnt*k << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,m,f=0,c=0;
  string u[300],t;
  cin>>n;
  for(int i=0;i<n;i++)cin>>u[i];
  cin>>m;
  for(int i=0;i<m;i++){
    c=0;
    cin>>t;
    for(int j=0;j<n;j++){
      if(t==u[j]){
	if(f==0){
	  cout<<"Opened by "<<t<<endl;
	  f=1;
	  c++;
	}else{
	  cout<<"Closed by "<<t<<endl;
	  f=0;
	  c++;
	}
      }
    }if(c==0)cout<<"Unknown "<<t<<endl;
  }
  return 0;
}

Measured memory_bytes: 3204
#include <stdio.h>
   
int main(){

  int val[2] = {0};

  while (1){

    scanf("%d %d", &val[0], &val[1]);

    if (val[0] == 0 && val[1] == 0){
      break;
    }

    if (val[0] < val[1]){
        printf("%d %d\n", val[0], val[1]);
    }else{
        printf("%d %d\n", val[1], val[0]);
    }
  }

  return 0;

}

Measured memory_bytes: 1028
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m,sum = 0;
	cin >> n >> m;
	vector<vector<int> > vec(100001);
	priority_queue<int> que;
	rep(i,n){
		int a,b;
		cin >> a >> b;
		vec[a].emplace_back(b);
	}
	reps(i,m){
		rep(j,vec[i].size()){
			que.emplace(vec[i][j]);
		}
		if(!que.empty()){
			sum += que.top();
			que.pop();
		}
	}
	cout << sum << '\n';
	return 0;
}


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

int main() {
  int k;
  cin >> k;
  int t = 7;
  rep(i,1,1e7+1){
    if(t%k == 0){
      cout << i << endl;
      return 0;
    }
    t = t*10+7;
    t %= k;
  }
  cout << -1 << endl;
}

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

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

string solve(long long a, long long b, long long c, long long d) {
	if (b - d > 0) return "No";

	long long E = gcd(b, d);
	long long R = (c + 1) / E * E + (a % E); if (R < c + 1) R += E;

	if (min(a, R) < b) return "No";
	return "Yes";
}

int main() {
	long long T, A, B, C, D;
	cin >> T;
	for (int i = 1; i <= T; i++) {
		cin >> A >> B >> C >> D;
		cout << solve(A, B, C, D) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int N, M, L[100005], R[100005];
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		cin >> L[i] >> R[i];
	}

	sort(L, L + M);
	sort(R, R + M);

	if (R[0] - L[M - 1] + 1 > 0) cout << R[0] - L[M - 1] + 1;
	else cout << 0;

	return 0;
}


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

int main() {
    int Q;
    std::cin >> Q;
    std::deque<int> v;
    for (int q = 0; q < Q; ++q) {
        int t;
        std::cin >> t;
        if (t == 0) {
            int d, x;
            std::cin >> d >> x;
            if (d == 0) {
                v.push_front(x);
            } else {
                v.push_back(x);
            }
        } else if (t == 1) {
            int i;
            std::cin >> i;
            std::cout << v[i] << std::endl;
        } else {
            int d;
            std::cin >> d;
            if (d == 0) {
                v.pop_front();
            } else {
                v.pop_back();
            }
        }
    }
    return 0;
}



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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  string ans = "";
  int cnt = 0;
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    bool flag = true;
    for (int j = 0; j < t.size(); j++) {
      if (!(s[i + j] == t[j] || s[i + j] == '?')) {
        flag = false;
      }
    }
    if (flag) {
      string tmp = s;
      tmp.replace(i, t.size(), t);
      for (int i = 0; i < tmp.size(); i++) {
        if (tmp[i] == '?') {
          tmp.replace(i, 1, "a");
        }
      }
      if (cnt == 0) {
        ans = tmp;
        cnt++;
      }
      else if (tmp < ans) {
        ans = tmp;
      }
    }
  }
  if (cnt == 0) {
    cout << "UNRESTORABLE" << endl;
  }
  else {
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    string s;
    cin >> n >> s;
    for(char c: s) {
        char c2 = ('A'+((c-'A') + n) % 26);
        cout << c2;
    }
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, l, r) for (int i = l; i >= r; i--)
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back

const int maxn = 205;
const int maxm = 2005;
const int inf = 0x3f3f3f3f;

int n, m, l;
int d[maxn][maxn];

vector<int> g[maxm];
int match[maxm];
int vis[maxm];

void add_edge(int u, int v) {
    g[u].push_back(v);
    g[v].push_back(u);
}

bool dfs(int v) {
    vis[v] = 1;
    for (int i = 0; i < g[v].size(); i++) {
        int u = g[v][i], w = match[u];
        if (w < 0 || !vis[w] && dfs(w)) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bm() {
    int res = 0;
    memset(match, -1, sizeof(match));
    for (int i = 1; i <= l; i++) {
        if (match[i] < 0) {
            memset(vis, 0, sizeof(vis));
            if (dfs(i)) res++;
        }
    }
    return res;
}

void floyd() {
    inc(k, 1, n) inc(i, 1, n) inc(j, 1, n) d[i][j] =
        min(d[i][j], d[i][k] + d[k][j]);
}

int main() {
    int u, v, x;
    while (scanf("%d %d %d", &n, &m, &l) != EOF && n) {
        inc(i, 1, n) inc(j, 1, n) d[i][j] = inf;
        inc(i, 1, n) d[i][i] = 0;
        while (m--) {
            scanf("%d %d %d", &u, &v, &x);
            u++, v++;
            d[u][v] = d[v][u] = x;
        }
        floyd();
        inc(i, 1, 2 * l) g[i].clear();
        vector<pii> qq(l + 1);
        inc(i, 1, l) {
            scanf("%d %d", &qq[i].fi, &qq[i].se);
            qq[i].fi++;
        }
        inc(i, 1, l) inc(j, 1, l) {
            if (i != j && qq[i].se + d[qq[i].fi][qq[j].fi] <= qq[j].se) {
                add_edge(i, j + l);
               // printf("add_edge %d %d\n", i, j + l);
            }
        }
        printf("%d\n", l - bm());
    }
}


Measured memory_bytes: 11624
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;

typedef unsigned long long ll;

ll fact[200001];
ll inv_fact[200001];
vector<ll> size[200001];
ll mul[200001];
ll sum[200001];
int parent[200001];
vector<ll> G[200001];
vector<ll> dp[200001];
ll mod = 1e9 + 7;

ll pow(ll x, ll n) {
  if (n == 0) return 1;
  if (n % 2 == 0) {
    ll t = pow(x, n/2);
    return (t * t) % mod;
  }
  return (x * pow(x, n-1)) % mod;
}

void calc_fact(int n) {
  fact[0] = 1;
  for (ll i = 1; i <= n; i++) {
    fact[i] = (fact[i-1] * i) % mod;
  }
  inv_fact[n] = pow(fact[n], mod-2);
  for (int i = n-1; i >= 0; i--) {
    inv_fact[i] = (inv_fact[i+1] * (i+1)) % mod;
  }
}

ll calc_size(ll v, ll par) {
  ll s = 0;
  for (ll i = 0; i < G[v].size(); i++) {
    if (G[v][i] == par) continue;
    size[v][i] = calc_size(G[v][i], v);
    s += size[v][i];
    s %= mod;
  }
  return (s + 1) % mod;
}

ll dfs(ll v, ll par) {
  parent[v] = par;
  ll res = 1;
  ll sz = 0;
  for (ll i = 0; i < G[v].size(); i++) {
    if (G[v][i] == par) continue;
    dp[v][i] = dfs(G[v][i], v);
    res = (res * dp[v][i]) % mod;
    res = (res * inv_fact[size[v][i]]) % mod;
    sz += size[v][i];
    sz %= mod;
  }
  mul[v] = res;
  sum[v] = sz;
  return (fact[sz] * res) % mod;
}

ll calc_all_size(int s) {
  queue< pair<int, ll> > Q;
  Q.push({s, 0});
  while (!Q.empty()) {
    pair<int, ll> x = Q.front();
    Q.pop();

    int v = x.first;
    ll prev = x.second;

    ll s = 0;
    for (int i = 0; i < G[v].size(); i++) {
      if (G[v][i] == parent[v]) {
        size[v][i] = (sum[G[v][i]]+1 + mod - prev) % mod;
        s = (s + size[v][i]) % mod;
      } else {
        Q.push({G[v][i], size[v][i]});
      }
    }
    sum[v] = (sum[v] + s) % mod;
  }
}

struct Data {
  int v;
  ll size;
  ll dp;
};

ll bfs(int s) {
  queue< Data > Q;
  Q.push({s, 0, 0});
  while (!Q.empty()) {
    Data x = Q.front();
    Q.pop();

    int v = x.v;
    ll prev_size = x.size;
    ll prev_dp = x.dp;

    ll m = 1;
    for (int i = 0; i < G[v].size(); i++) {
      if (G[v][i] == parent[v]) {
        dp[v][i] = (mul[G[v][i]] * fact[prev_size]) % mod;
        dp[v][i] = (dp[v][i] * pow(prev_dp, mod-2)) % mod;
        dp[v][i] = (dp[v][i] * fact[size[v][i]-1]) % mod;
        m = (m * dp[v][i]) % mod;
        m = (m * inv_fact[size[v][i]]) % mod;
      } else {
        Data d;
        d.v = G[v][i];
        d.size = size[v][i];
        d.dp = dp[v][i];
        Q.push(d);
      }
    }
    mul[v] = (mul[v] * m) % mod;
  }
}

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

  for (ll i = 0; i < n-1; i++) {
    ll a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
    dp[a].push_back(0);
    dp[b].push_back(0);
    size[a].push_back(0);
    size[b].push_back(0);
  }
  calc_fact(n);
  calc_size(1, 0);
  dfs(1, 0);
  calc_all_size(1);
  bfs(1);

  for (int i = 1; i <= n; i++) {
    ll ans = fact[n - 1];
    for (int j = 0; j < G[i].size(); j++) {
      ans *= (dp[i][j] * inv_fact[size[i][j]]) % mod;
      ans %= mod;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 49664
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n,k;
int main(){FAST;
  cin>>n>>k;
ll ans = 0;
ll tot = n*(n+1)/2;
for(ll i=k;i<=n+1;++i){
  ll mi = i*(i-1)/2;
  ll mx = i*(n+(n-i+1))/2;
  ans+=mx-mi+1;
  ans%=MOD;
}
cout<<ans;
return 0;
}

/*
 WA? check edge cases, N=1,M=1 etc. Read code fully once and check all variables.
 Read the question again and see what you might have missed.
 Consider changing your solution or find more cases.
 */


Measured memory_bytes: 3692
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

typedef double P_type;
typedef complex<P_type> P;
const P_type P_eps = 1e-8; //整数の時はゼロ

namespace std{
  template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
  }
};

P rotate(P p, double theta){
  return p * P(cos(theta), sin(theta));
}

//内積
double dot(P a, P b) {
  return (a * conj(b)).real();
}

//外積
double cross(P a, P b) {
  return (conj(a) * b).imag();
}

/* 直線abと点cの距離 */
double distanceLP(P a, P b, P c) {
  return abs(cross(b-a, c-a)) / abs(b-a);
}

/* Line ax+by+c=0 */

struct Line{
  
  P_type a,b,c;
  
  Line(P_type A,P_type B,P_type C){
    a = A;
    b = B;
    c = C;
  }
  
  //2点(x1,y1),(x2,y2)を通る直線
  Line(P_type x1,P_type y1,P_type x2,P_type y2){
    a = y1-y2;
    b = x2-x1;
    c = y1*(x1-x2)-x1*(y1-y2);
  }
  
  /*以下はP_typeに係わらずdouble*/
  
  // y座標からx座標を取得
  double x(double y){
    return -(double)(b*y+c)/a;
  }
  
  // x座標からy座標を取得
  double y(double x){
    return -(double)(a*x+c)/b;
  }

  double dist(P p){
    return abs(a * p.real() + b * p.imag() + c) / sqrt(a*a + b*b);
  }
  
};

vector<Line> getCommonTangents(P c1, P_type r1, P c2, P_type r2) {
  vector<Line> res;
  c2 -= c1;

  // 内包
  if (abs(c2) + min(r1, r2) < max(r1, r2) - P_eps) return res;
  
  for (int i=-1;i<=1;i+=2) {
    for(int j=-1;j<=1;j+=2){
      P_type sr = r1 + r2 * i;
      P_type p = sqrt(norm(c2) - sr * sr) * j;

      P_type xq = r1 * (c2.real() * sr + c2.imag() * p) / norm(c2);
      P_type yq = r1 * (c2.imag() * sr - c2.real() * p) / norm(c2);

      res.push_back(Line(xq, yq, - r1*r1 - c1.real() * xq - c1.imag() * yq));
    }
    if (abs(c2) < (r1 + r2) - P_eps) break; //内接線無し
  }

  return res;
}

bool solve(){
  int n;
  int x[SIZE], y[SIZE], r[SIZE], m[SIZE];
  vector<Line> lines;
  
  scanf("%d", &n);

  if (n == 0) return false;

  for(int i=0;i<n;i++){
    scanf("%d%d%d%d", x+i, y+i, r+i, m+i);
  }

  for(int i=0;i<n;i++){
    for(int j=1;j<n;j++){
      for(int k=0;k<4;k++){
        auto res = getCommonTangents(P(x[i], y[i]), r[i] + m[i] * (k/2), P(x[j],y[j]), r[j] + m[j] * (k%2));
        lines.insert(lines.end(), res.begin(), res.end());
      }
    }
  }

  int ans = 1;
  
  for(int i=0;i<lines.size();i++){
    int counter = 0;
    for(int j=0;j<n;j++){
      double d = lines[i].dist(P(x[j], y[j]));
      counter += r[j] - P_eps < d && d < r[j] + m[j] + P_eps;
    }
    ans = max(ans, counter);
  }
  
  printf("%d\n", ans);

  return true;
}

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



Measured memory_bytes: 5328
H, W, M = gets.split.map(&:to_i)
hcounts = Array.new H+1, 0
wcounts = Array.new W+1, 0

B = Array.new M
M.times do |i|
    h, w = gets.split.map(&:to_i)
    B[i] = [h,w]
    hcounts[h] += 1
    wcounts[w] += 1
end

hmax = hcounts.max
wmax = wcounts.max
hmaxcount = hcounts.count hmax 
wmaxcount = wcounts.count wmax

count = B.count do |h,w|
    hcounts[h] == hmax && wcounts[w] == wmax
end

if count == hmaxcount * wmaxcount
    puts hmax + wmax - 1
else
    puts hmax + wmax
end

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

const int INF = 0x3f3f3f3f;
const int N = 4e5 + 7;


void bfs(vector<vector<int> > G, int used[], vector<pair<int, int> > vp){
	bool vis[N];
	memset(vis, 1, sizeof(vis));
	map<pair<int, int>, int> ans;
	int maxx = 0;
	queue<int> q;
	q.push(0);
	vis[0] = 0;
	while(!q.empty()){
		int u = q.front(); q.pop();
		//cout << u << endl;
		if(maxx < (int)G[u].size()) maxx = (int)G[u].size();
		int cnt = 1;
		for(int v:G[u]){
			if(!vis[v]) {
				continue;
			}
			if(used[u] == cnt) {
				cnt++;
			}
			q.push(v);
			vis[v] = 0;
			//cout << "u: " << u << " v: " << v << endl;
			//cout << "cnt :" << cnt << endl;
			used[v] = ans[make_pair(u, v)] = ans[make_pair(v, u)] = cnt++;
		}
	}
	cout << maxx << endl;
	for(auto i:vp) cout << ans[i] << endl;
}


int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<int>> G(n + 1);
	vector<pair<int, int> > vp;
	for(int i = 1; i <= n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
		vp.push_back(make_pair(a, b));
	}
	int used[N];
	memset(used, 0, sizeof(used));
	bfs(G, used, vp);
	return 0;
}

Measured memory_bytes: 27512
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N;
  cin>>N;
  vector<ll> X(N);
  ll ans=10000000000;
  for(ll i=0;i<N;i++) {
cin>>X[i];
  }
  
  sort(all(X));
  for(ll i=X[0];i<=X[N-1];i++) {
    ll count=0;
  for(ll j=0;j<N;j++) {
count+=abs(i-X[j])*abs(i-X[j]);
  }
    ans=min(ans,count);
  }
  
  cout<<ans<<endl;
}
  
 


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
static const int INF=1000000000;

int main() {
  int N;
  cin>>N;
  vector<int> dp(N+1,INF);
  vector<int> h(N+1);
  for(int i=1;i<=N;i++){
    cin>>h[i];
  }
  dp[1]=0;
  for(int i=1;i<=N;i++){
    if(i+1<=N && dp[i+1]>dp[i]+abs(h[i+1]-h[i])){
      dp[i+1]=dp[i]+abs(h[i+1]-h[i]);
    }
    if(i+2<=N && dp[i+2]>dp[i]+abs(h[i+2]-h[i])){
      dp[i+2]=dp[i]+abs(h[i+2]-h[i]);
    }
  }
  cout<<dp[N]<<endl;
  return 0;
}


Measured memory_bytes: 4004
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readTuple2' :: IO (String, Int)
readTuple2' = do
    [a, b] <- words <$> getLine
    return (a, read b)
    

main = do
    n <- readInt
    sps <- replicateM n readTuple2'
    let sps2 = zip [1..] sps
    let sorted = sortOn (fst . snd) $ sortOn (negate  . snd . snd) sps2
    forM_ sorted $ \(num, _) ->
        print num




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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int table[101][101];

void init(){
    REP(i,101){
        REP(j,101){
            table[i][j]=1e9;
            if(i==j)table[i][j]=0;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    init();
    int u,k,v;
    REP(i,n){
        cin >> u >> k;
        REP(j,k){
            cin >> v;
            table[u-1][v-1]=1;
        }
    }

    REP(k,n){
        REP(i,n){
            REP(j,n){
                table[i][j]=min(table[i][j],table[i][k]+table[k][j]);
            }
        }
    }
    REP(i,n){
        cout << i+1 << " " << ((table[0][i]<n)?table[0][i]:-1);
        cout << endl;
    }
}



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

typedef long long ll;

int main() {
   string s;
   cin >> s;
   string ans = "abcdefghijklmnopqrstuvwxyz";
   map<char,bool> m;
   for (int i = 0; i < (int)s.size(); ++i) {
		m[s[i]] = 1;
	}
	for (int i = 0; i < 26; ++i) {
		if (!m[ans[i]]) {
			cout << ans[i];
			return 0;
		}
	}
	cout << "None";
	return 0;
}



















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

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      ans++;
      continue;
    }

    bool flag = true;
    for (int j = 0; j < i; j++) if (H[j] > H[i]) flag = false;
    if (flag) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int n, m;
  cin >> n >> m;
  int r[n];
  for (int i = 0; i < n; i++) r[i] = 0;

  int a, b;
  for (int i = 0; i < m; i++){
    cin >> a >> b;
    r[a - 1] += 1;
    r[b - 1] += 1;
  }

  for (int i = 0; i < n; i++){
    cout << r[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
int main(){
	int n,k;
	cin >> n >> k;
  vector<pair<int,int>> p(n);
  	for(int i = 0; n > i; i++)
      	cin >> p[i].first >> p[i].second;
  
  long long int Min = -1;
  for(int i = 0; n > i; i++)
  for(int j = 0; n > j; j++)
  for(int kk = 0; n > kk; kk++)
  for(int l = 0; n > l; l++){
  	long long int top = p[i].second,btm=p[j].second,lft=p[kk].first,rgt=p[l].first;
    int count = 0;
    for(int c = 0; n > c; c++){
		if(p[c].first >= lft && p[c].first <= rgt && p[c].second >= btm && p[c].second <= top){
          count++;
        }
    }
    if(count >= k) {
     long long int area = (top - btm) * (rgt - lft);
     if(Min == -1 || Min >area) Min = area; 
    }
  }
    cout << Min << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b, c, n;
string s;



int main()
{
    cin>>a;
  if(a%2==0)
    cout<<a<<endl;
  else
    cout<<a*2<<endl;
}


Measured memory_bytes: 256
import Data.Char

main = do
    [h,w] <- map read . words <$> getLine
    ss <- lines <$> getContents
    let solve y = map (flip count y) [0..w-1]
        count x y
            | sample x y == '#' = '#'
            | otherwise = intToDigit . length $ filter (=='#') [sample (x+x') (y+y') | x' <- [-1..1], y' <- [-1..1]]
        sample x y
            | x < 0 || w <= x = '.'
            | y < 0 || h <= y = '.'
            | otherwise = ss!!y!!x
    mapM_ putStrLn $ map (solve) [0..h-1]


Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main(){
string N;
  cin>>N;
  bool t=false;
  if (N[0]=='7') t=true;
  if (N[1]=='7') t=true;
  if (N[2]=='7') t=true;
  if (t) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
           


Measured memory_bytes: 3628
NL = []
ML = []
sL = []
SL = []
N = int(input())
for i in range(N):
	s = input()
	NL.append(s)
	sL.append(s)

M = int(input())
for i in range(M):
	t = input()
	ML.append(t)
	sL.append(t)

sL = sorted(sL)
SL.append(sL[0])
for i in range(1, len(sL)):
	if sL[i] != sL[i - 1]:
		SL.append(sL[i])


c = 0
for i in range(len(SL)):
	if NL.count(SL[i]) - ML.count(SL[i]) > c:
		c = NL.count(SL[i]) - ML.count(SL[i])

print(c)

Measured memory_bytes: 3064
import java.util.*;

public class Main{

    public static void main(String a[])
        throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        int n =scan.nextInt();
        long sum=0;
        while(scan.hasNext()){
            sum+=scan.nextInt();
    }
        System.out.println(sum/n);
    }
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){cout << (v[i]) << " ";} cout << endl;
typedef long long int ll;

int main(void) {

  string s;
  cin >> s;

  int md = 2019;

  int now = 0;
  int ten = 1;
  vector<int> mp(2019, 0);
  mp[0] = 1;
  for(int i = s.size()-1; i >= 0; i--){
    (now += (s[i] - '0') * ten) %= md;
    mp[now]++;
    (ten *= 10) %= md;
  }

  ll ans = 0;
  for(auto m : mp) {
    ans += m * (m - 1) / 2;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    ll a[200005] = {}, z = 0, b[200005] = {};
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i], b[i] = b[i - 1] + a[i] + 1;
    for (int i = k; i <= n; i++) z = max(z, b[i] - b[i - k]);
    cout << setprecision(13) << 1.0 * z / 2 << '\n';
}


Measured memory_bytes: 6928
A=[]
for i in range(3):
    A.append(list(map(int,input().split())))
N=int(input())
B=[]
for _ in range(N):
    B.append(int(input()))

# まず横の列を検索する
bingo=False
for i in range(3):
    for j in range(3):
        if not A[i][j] in B:
            break
        if j == 2:
            bingo=True

# 次に縦の列を検索する
for i in range(3):
    for j in range(3):
        if not A[j][i] in B:
            break
        if j == 2:
            bingo=True

# 最後に斜め
for i in range(3):
    if not A[i][i] in B:
        break
    if i == 2:
        bingo = True

for i in range(3):
    if not A[2-i][i] in B:
        break
    if i == 2:
        bingo = True

if bingo:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064