akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define mp make_pair
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int mod = (int)1e9 + 7;
vector<int> g[2020];
int dp[2020][2020];
int sz[2020];
int tmp[2020];
int D[2020];
int k;
int n;
int ans = mod;
void dfs(int v, int p) {
	sz[v] = 1;
	dp[v][0] = 0;
	for(int i = 1; i <= n; i++) dp[v][i] = mod;
	for(int to: g[v]) {
		if(to == p) continue;
		dfs(to, v);
		for(int i = 0; i <= sz[v] + sz[to]; i++) {
			tmp[i] = dp[v][i];
			dp[v][i] = mod;
		}
		for(int i = 0; i <= sz[v]; i++) {
			for(int j = 0; j <= sz[to]; j++) {
				//dp[v][i] = min(tmp[i]+dp[to][j] + 1, dp[v][i]);
				if(i + j + 1 <= k) {
					dp[v][max(i, j+1)] = min(tmp[i] + dp[to][j], dp[v][max(i, j+1)]);
				}
			}
			dp[v][i] = min(tmp[i] + sz[to], dp[v][i]);
		}
		sz[v] += sz[to];
	}
	for(int i = 0; i <= k; i++) ans = min(ans, dp[v][i]+n-sz[v]);
}

int main () {
	cin >> n >> k;
	for(int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}

	dfs(1, -1);
	//for(int i = 0; i <= k; i++) ans = min(ans, dp[1][i]);
	cout << ans << "\n";
 	return 0;
}



Measured memory_bytes: 16384
import java.util.*;
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int count0 = 0,count1=0;
        for(int i = 0;i<s.length;i++){
            if(s[i]=='0'){
                count0++;
            } else {
                count1++;
            }
        }
        System.out.println(Math.min(count0,count1)*2);
    }
}


Measured memory_bytes: 39540
#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	for (int i = 1; i < s.size(); i++) {
		if (s[i - 1] == s[i]) {
			cout << "Bad";
			return 0;
		}
	}
	cout << "Good";
	return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split();
            int a = int.Parse(l[0]), b = int.Parse(l[2]);

            if (l[1] == "+")
                Console.WriteLine(a+b);
            else
                Console.WriteLine(a-b);
        }
    }
}


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

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

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

  int cnt_o = 0;
  rep(i, n) if (a[i] % 2 != 0) cnt_o++;

  auto f = [](int x) {
    ll n = 2;
    while (--x > 0)
      n *= 2;
    return n;
  };

  if (cnt_o == 0) {
    if (p == 0)
      cout << f(n) << endl;
    else
      cout << 0 << endl;
  } else {
    cout << f(n - 1) << endl;
  }
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
s = []
for i in range(k):
    a, b = list(map(int, input().split()))
    s.append((a, b))
dp = [0]*(n+1)
v = 0
mod = 998244353
for i in range(1, n+1):
    if i == 1:
        for l, r in s:
            if i+l <= n:
                dp[i+l] += 1
            if i+r+1 <= n:
                dp[i+r+1] -= 1
    else:
        v += dp[i]
        v %= mod
        for l, r in s:
            if i+l <= n:
                dp[i+l] += v
            if i+r+1 <= n:
                dp[i+r+1] -= v


print(v % mod)


Measured memory_bytes: 75092
K, N = map(int, input().split())
A = list(map(int, input().split()))

dmax = 0
for i in range(N-1):
    d = A[i+1] - A[i]
    if d > dmax:
        dmax = d
if A[N-1] - A[0] < A[0] + (K - A[N-1]):
    d = A[N-1] - A[0]
    if d > dmax:
        dmax = d
    ans = dmax
else:
    d = A[0] + (K - A[N-1])
    if d > dmax:
        dmax = d
    ans = K - dmax

print(ans)

Measured memory_bytes: 26444
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int place[1005][1005][3];
int s[100005][3];
int main(){
	int m,n,t;
	int i,j,k;
	int a,b,c,d;
	string sa[1005];
	string sb="JOI";
	cin>>m>>n>>t;
	for(i=0;i<m;i++){
		cin>>sa[i];
	}
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			for(k=0;k<3;k++){
				place[i][j][k]=place[i-1][j][k]+place[i][j-1][k]-place[i-1][j-1][k];
				if(sa[i-1][j-1]==sb[k])place[i][j][k]++;
			}
		}
	}
	for(i=0;i<t;i++){
		cin>>a>>b>>c>>d;
		a--,b--;
		for(j=0;j<3;j++){
			s[i][j]=place[c][d][j]-place[a][d][j]-place[c][b][j]+place[a][b][j];
		}
	}
	for(i=0;i<t;i++){
		cout<<s[i][0]<<" "<<s[i][1]<<" "<<s[i][2]<<endl;
	}
	return 0;
}

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

int main()
{
    int A, B;
    bool flag = false;
    string S;
    cin >> A >> B >> S;
    if(S[A] == '-') flag = true;
    for(int i = 0; i < A + B + 1; i++) {
        if(i != A && !isdigit(S[i])) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return (0);
}
        

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

int main(){
  int n; cin >> n;
  vector<int> p(n);
  for(int i=0; i<n; ++i) cin >> p.at(i);
  
  int c = 0;
  for(int i=0; i<n-2; ++i){
    bool c1 = p.at(i) <= p.at(i+1) && p.at(i+1) <= p.at(i+2);
    bool c2 = p.at(i+2) <= p.at(i+1) && p.at(i+1) <= p.at(i);
    if(c1 || c2) ++c;
  }
  
  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

vector <vi> dp(26,vi(100005));
int n;

int fun(int l,int r){
	if (r<l)  return  r+(n-l+1); 
	else  return  (r-l+1); 
}

inline void solve(){ 
    string  s, t; 
    cin >> s >> t ; 
    n = sz(s);
    vi oc(26,0); 
    for (int i=0;i<n;i++) { 
    	oc[s[i]-'a']++ ; 
    	dp[s[i]-'a'][i+1] = i+1 ; 
    } 
    for (int i=0;i<sz(t);i++) { 
    	if (oc[t[i]-'a'] == 0) { 
    		cout << "-1" << endl ; 
    		return ; 
    	} 
    } 
    for (int i=0;i<26;i++){ 
    	for (int j=n-1;j>=0;j--) 
    		if ( !dp[i][j] )  dp[i][j] = dp[i][j+1]; 
    	dp[i][n+1]= dp[i][0]; 
    	for (int j=n;j>=0;j--) 
    		if ( !dp[i][j] ) dp[i][j] = dp[i][j+1]; 
    } 
    int ans=0; 
    for (int  i=0, idx= 1 ; i < sz(t) ; i++ ){ 
    	int  p = dp[t[i]-'a'][idx] ; 
    	ans += fun(idx,p); 
    	idx = p+1; 
    } 
    cout << ans << endl; 
} 

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}

Measured memory_bytes: 24192
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    string S;
    cin >> S;
    int N = S.size()+1;
    vector<ll> L(N,0),R(N,0);
    for(int i=0;i<N;i++){
        if(S[i]=='<') L[i+1] = L[i]+1;
    }
    for(int i=N-2;i>=0;i--){
        if(S[i]=='>') R[i] = R[i+1]+1;
    }
    ll ans = 0;
    for(int i=0;i<N;i++) ans += max(L[i],R[i]);
    cout << ans << endl;
}

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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	vector<int>w(n);
	int minv=100000;
	for(int i=0; i<n; i++)cin>>w[i];
	for(int i=1; i<n; i++){
		int sum1=accumulate(w.begin(), w.begin()+i, 0);
		int sum2=accumulate(w.begin()+i, w.end(), 0);
		int dif=abs(sum1-sum2);
		minv=min(minv, dif);
	}
	cout<<minv<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
using System;

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

            {
                var read = Console.ReadLine();
                //var temp_string = read.Split(' ');

                double radius=double.Parse(read);
                double area=radius*radius*Math.PI,
                        Circumference=radius*2*Math.PI;



                Console.WriteLine(area+" "+Circumference);
            }
        }
    }
}

Measured memory_bytes: 9240
/// --- In the name of ALLAH --- ///


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


typedef long long              ll;
typedef vector<int>            vi;
typedef vector<ll>             vl;
typedef vector<vi>             vvi;
typedef vector<vl>             vvl;
typedef pair<int,int>          pii;
typedef pair<double, double>   pdd;
typedef pair<ll, ll>           pll;
typedef vector<pii>            vii;
typedef vector<pll>            vll;
typedef double                 dl;

#define endl                   '\n'
#define PB                     push_back
#define F                      first
#define S                      second
#define all(a)                 (a).begin(),(a).end()
#define rall(a)                (a).rbegin(),(a).rend()
#define sz(x)                  (ll)x.size()
#define wt                     ll t; cin>>t; while(t--)
#define input(a,n)             for(int i=0;i<n;i++) cin>>a[i];

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define mod 10000007
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

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


const ll mx=1e9;



//q=51;

//ll b[q+1][q+1];


 main()
{
    optimize();
   string s,t;
   vector<ll>v;
   ll n=753,i,j;
   cin>>s;
  ll p=sz(s)-3;

 /* if(sz(s)>3)
    t=s[0]+s[1]+s[2];
    //cout<<t<<endl;
   else
   {
       for(i=0;i<sz(s);i++)
       {
           t=t+s[i];
       }
       ll j=stoi(t);
       ll k=abs(n-j);
       cout<<k<<endl;
       return 0;
   }*/

  for(i=0;i<=p;i++)
   {
       t=t+s[i]+s[i+1]+s[i+2];

       //cout<<t<<endl;
       ll j=stoi(t);
       //cout<<j<<endl;
       ll k=abs(n-j);
       v.PB(k);
       t.clear();
   }
   sort(all(v));
   cout<<v[0]<<endl;

















    return 0;
}






























































































Measured memory_bytes: 3624
import sys

sys.setrecursionlimit(10000) # 再帰深度を変更しておく

l1 = sys.stdin.readline().strip()
N = int(l1.strip())
B = bin(N)

# index 2からlen(B)までとりたい
# 先頭の0bをぬかす
# 負の数だったら……（最初の2つを反転するのだが）

M = N
C = 0
i = 0
# これが元

if M == 0:
	C = 0

while M > 0:
	now = M % 2

	M = int(M/2) #次に進めるために割る
	#print("{},{},{}".format(i, M, now))
	
	if now != 0:
		C += pow(2,i)
	# 0,4などがあったら足す
	
	if i%2 == 1:
		# 奇数桁目
		# 2,8など。+1があったら繰上りする。
		if now != 0:
			M += 1 # 繰上りする
	i += 1

while M < 0:
	now = M % 2

	M = int(M/2) #次に進めるために割る
	#print("{},{},{}".format(i, M, now))
	
	if now != 0:
		C += pow(2,i)
	# 0,4などがあったら足す
	
	if i%2 == 0:
		# 偶数桁目
		# 0,4など。+-1があったら繰上りする。
		if now != 0:
			M -= 1 # 繰上りする
	i += 1



res = bin(C)[2:]

print(res)

Measured memory_bytes: 38256
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
using ll = long long;

int n, idx[5010], bmat[5010];
char s[5010];
int main() {
	scanf("%d", &n);
	scanf("%s", s);
	for (int i = 0; i < n; i++)
		idx[i] = i;

	sort(idx, idx + n, [](int a, int b) {
		while (s[a] == s[b])
			a++, b++;
		return s[a] < s[b];
	});

	for (int i = 0; i + 1 < n; i++) {
		int match = 0, a = idx[i], b = idx[i + 1];
		while (s[a] == s[b])
			match++, a++, b++;
		bmat[i] = match;
	}

	int max_m = 0;
	for (int i = 0; i + 1 < n; i++) {
		int common = bmat[i];
		for (int j = i + 1; j < n; j++) {
			max_m = max(max_m, min(common, abs(idx[j] - idx[i])));
			common = min(common, bmat[j]);
		}
	}
	printf("%d\n", max_m);
}

Measured memory_bytes: 256
import heapq
H,W = map(int,input().split())
S = [0 for i in range(H)]
s = [0,0]
g = [0,0]
for i in range(H):
    S[i] = ["#"] + [j for j in input()] + ["#"]
S = [["#" for i in range(W+2)]] + S + [["#" for i in range(W+2)]]
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
'''
枠を壁としているので，1 <= i <= H+1, 1<= j <= W+1
dp
'''
def search(x,y):
    if S[x+1][y+1] == "#" : return -1
    else :
        dp = [[-float("inf") for _ in range(W)] for p in range(H)]
        dp[x][y] = 0
        heap = []
        heapq.heapify(heap)
        heapq.heappush(heap,(0,x,y))
        m = 0
        while True :
            if len(heap) == 0 :
                break
            else:
                cost,a,b = heapq.heappop(heap)
                for i in range(4):
                    x_ = a + dx[i]
                    y_ = b + dy[i]
                    if S[x_+1][y_+1] == "#" :
                        continue
                    if dp[x_][y_] != -float("inf") :
                        continue
                    dp[x_][y_] = cost + 1
                    heapq.heappush(heap, (cost + 1, x_, y_))
                    if m < dp[x_][y_] : m = dp[x_][y_]
        return m
ans = 0
for i in range(H):
    for j in range(W):
        if ans < search(i,j):
            ans = search(i,j)
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,n) for(ll i=0;i<n;i++)
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

int main(){
    fast;
    ll x,y,f=0;
    cin>>x>>y;
    for(ll i = 0;i<=x;i++){
        if(i*2 + (x-i)*4 == y){
            f=1;
            break;
        }
    }
    if(f==1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    // A:0, C:1, G:2, T:3
    // AGC, A*GC, GAC, ACG, AG*C
    ll N;
    cin >> N;
    N-=2;
    ll dp[N][4][4][4] = {};

    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
                dp[0][i][j][k] = 1;
            }
        }
    }
    dp[0][0][2][1] = 0;
    dp[0][2][0][1] = 0;
    dp[0][0][1][2] = 0;
    for(int n=1;n<N;n++){
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                for(int k=0;k<4;k++){
                    dp[n][i][j][k] += dp[n-1][0][i][j];
                    dp[n][i][j][k] += dp[n-1][1][i][j];
                    dp[n][i][j][k] += dp[n-1][2][i][j];
                    dp[n][i][j][k] += dp[n-1][3][i][j];
                    if((i==2 || j==2) && k==1) dp[n][i][j][k] -= dp[n-1][0][i][j];
                    if(i==0 && j==2 && k==1) dp[n][i][j][k] = 0;
                    if(i==2 && j==0 && k==1) dp[n][i][j][k] = 0;
                    if(i==0 && j==1 && k==2) dp[n][i][j][k] = 0;
                    dp[n][i][j][k] %= 1000000007;
                }
            }
        }
    }
    ll res = 0;
    for(int i=0;i<4;i++){
        for(int j=0;j<4;j++){
            for(int k=0;k<4;k++){
               res += dp[N-1][i][j][k];
            }
        }
    }
    cout<<res%1000000007<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define filein freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);


void fun1(int* a,int* b){
    int sum=*a+*b;
    int dif=abs(*a-*b);
    //cout<<sum<<dif<<"\n";
    *a=sum;
    *b=dif;
}


int main() {


    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;


}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(void){
  // Your code here!
  int H,W;
  while(cin >> W >> H){
        if(H==0&&W==0)break;
   for(int i=0; i<W; i++){
       for(int j=0; j<H; j++){
            cout << '#';
       }
            cout << endl;
       }
    cout << endl;
}
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

struct UnionFind{
    vector<int> d;
    UnionFind(int n = 0): d(n, -1){}
    int find(int x){
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {return find(x) == find(y);}
    int size(int x){return -d[find(x)];}
};

const int inf = 1 << 30;
const ll INF = 1LL << 60;

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }

    set<int> st;
    rep(i,n){
        st.insert(uf.find(i));
    }
    view(sz(st)-1);
    return 0;
}

Measured memory_bytes: 7456
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n;
	cin >> n;
	vector <int> A(n), B(n);
	ll sum = 0;
	int mn = MOD;
	for (int i = 0; i < n; i++) {
		cin >> A[i] >> B[i];
		if(A[i] > B[i]) {
			mn = min(mn, B[i]);
		}
		sum += A[i];
	}
	if(mn == MOD) {
		cout << 0;
	}
	else {
		cout << sum - mn;
	}
}


Measured memory_bytes: 384
#include <iostream>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	bool ok = 1;
	map<char, int> fr;
	cin >> s;
	for (auto c : s)
		++fr[c];
	for (auto c : s)
		if (fr[c] != 2)
			ok = 0;
	if (ok)
		cout << "Yes";
	else
		cout << "No";
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Union_Find_Tree{
	public:
	vi p,r,s;
	Union_Find_Tree(int n){
		p=r=vi(n);
		s=vi(n,1);
		for(int i=0;i<n;i++) p[i]=i;
	}
	int Par(int x){
		if(p[x]==x) return x;
		return p[x]=Par(p[x]);
	}
	int Size(int x){return s[Par(x)];}
	bool Unite(int x,int y){
		x=Par(x);
		y=Par(y);
		if(x==y) return 0;
		if(r[x]<r[y]){
			p[x]=y;
			s[y]+=s[x];
		}
		else{
			p[y]=x;
			s[x]+=s[y];
			if(r[x]==r[y]) r[x]++;
		}
		return 1;
	}
	bool Same(int x,int y){return Par(x)==Par(y);}
};

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	ll res=0;
	vvi a(n,vi(n));
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];
	for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) res+=min(a[i][j],a[j][i]);
	cout<<res<<endl;
}


Measured memory_bytes: 3264
k = int(input())

mem = dict()
s = 0


def gcd(n1, n2):
    while n2 != 0:
        n3 = n1 % n2
        n1 = n2
        n2 = n3
    return n1


for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            tmp = gcd(a, b)
            s += gcd(tmp, c)


print(s)


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }

  return x;

}

Node treeSearch(Node u, int k){
  
if(u->key == k || u == NIL){
    return u;
  }
  if(k < u->key){
    return treeSearch(u->left,k);
  }
  else { return treeSearch(u->right,k);
  }

}

Node treeSuccessor(Node x){
Node y;

  if(x->right != NIL){
    return  treeMinimum(x->right);
  }
  y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
printf("treeDelete");
  if(z->left == NIL || z->right == NIL){
    y = z;
  }else{ y = treeSuccessor(z);}
    if(y->left != NIL){
      x = y->left;
    }else{x = y->right;}
    if(x !=NIL){
      x->parent = y->parent;
    }
    if(y->parent == NIL){
      root = x;//
    } else if(y == y->parent->left){
      y->parent->left = x;
    }else{y->parent->right = x;}
    if(y != z){
      z->key = y->key;
      
    }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y =x;
    if(z->key < x->key){
      x = x->left;

    }else{
      x = x->right;
    }
}
  z->parent = y;
  if(y == NIL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{y->right = z;}



}

void inorder(Node u){
  if(u!=NIL){
  inorder(u->left);
  printf(" %d",u->key);


 
  inorder(u->right);
  }
}
void preorder(Node u){
  if(u!=NIL){
 printf(" %d",u->key);
 
 
 preorder(u->left);
  
  preorder(u->right);
  }
}


int main(){
  int i,n,x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24036
#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()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=998244353;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,s;
  cin >> n >> s;
  vector<ll>a(n);
  rep(i,n) cin >> a[i];
  
  vector<vector<ll>>dp(n+1,vector<ll>(s+1,0));
  dp[0][0]=1;
  rep(i,n){
    rep(j,s+1){
      dp[i+1][j]+=2*dp[i][j];
      dp[i+1][j]%=MOD;
      if(j+a[i]<=s){
        dp[i+1][j+a[i]]+=dp[i][j];
        dp[i+1][j]%=MOD;
      }
    }
  }
  cout << dp[n][s] << endl;
  return 0;
}


Measured memory_bytes: 73684
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        int[] a = inta();
        int[] b = inta();
        WriteLine((a[0]-b[0]) * (a[1]-b[1]));
    
    
    }
    //各種読取
    static string rstr(){
        return ReadLine();
    }
    static int rint(){
        return int.Parse(ReadLine());
    }
    static long rlong(){
        return long.Parse(ReadLine());
    }
    static string[] stra(){
        return ReadLine().Split(' ');
    }
    static int[] inta(){
        string[] read_str_array = ReadLine().Split(' ');
        int[] return_int_array = new int[read_str_array.Length];
        for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
        }
        return return_int_array;
    }
    static int[,] inta2(int num_array,int in_array){
        int[,] int_array2 = new int[num_array,in_array];
        for(int i=0;i<num_array;i++){
            int[] temp_array = inta();
            for(int j=0;j<in_array;j++){
                int_array2[i,j] = temp_array[j];
            }
        }
        return int_array2;
    }
    static long[] longa(){
        string[] read_str_array = ReadLine().Split(' ');
        long[] return_long_array = new long[read_str_array.Length];
        for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_long_array[countup_i] = long.Parse(read_str_array[countup_i]);
        }
        return return_long_array;
    }
    static double[] doublea(){
        string[] read_str_array = ReadLine().Split(' ');
        double[] return_double_array = new double[read_str_array.Length];
        for(long countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_double_array[countup_i] = long.Parse(read_str_array[countup_i]);
        }
        return return_double_array;
    }
    // A/B小数点以下切上
    static long divideup(long divided,long divid){
        long temp_divide = divided/divid;
        if(divided % divid > 0){
            temp_divide++;
        }
        return temp_divide;
    }
    static long GCD(long a,long b){
        if(a < b){
            long temp = a;
            a = b;
            b = temp;
        }
        if(a % b == 0){ return b; }
        else{
            long temp = b;
            b = a%b;
            a = temp;
            return GCD(a,b);
        }
    }
    static long LCM(long a,long b){
        return a * b / GCD(a,b);
    }
}
//知見
// (string) hogestr -> (char[]) hoge
    // char hoge = hogestr.ToCharArray();
// (char[]) hoge -> (string) hogestr
    // string hoge = new string(hoge);
// Hashtable ×  Dictionary ○
// Dictionary hoge<string,int>
    // hoge.ContainsKey(string) -> return boolean
    // hoge[string] -> return int
    // hoge[int] -> CE
// Dictionary hoge<int1,int2>
    // hoge<int1,int2>: hoge[int1] -> return int2
    // KeyValuePair<int,int> k <-> k.Key == int1 / k.Value == int2
// SortedDictionary() > SortedList() ???
// キュー　-> 幅優先 ???
// スタック -> 深さ優先 ???


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

namespace ALDS1_4_A
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var S = new HashSet<string>(Console.ReadLine().Split(' '));
            Console.ReadLine();
            var T = Console.ReadLine().Split(' ');

            int cnt = 0;
            foreach (var a in T)
            {
                if (S.Contains(a)) cnt++;
            }
            Console.WriteLine(cnt);
        }
    }
}

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

struct UnionFind
{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int size(int x) {
    return sizes[find(x)];
  }
};

int main(){
    int n; cin>>n;
    int q; cin>>q;
    int a[q],b[q];
    rep(i,q){
         cin>>a[i]>>b[i];
         a[i]--;b[i]--;
    }
    int ans=0;
    rep(i,q){
        UnionFind uf(n);
        rep(j,q){
            if(i!=j) uf.unite(a[j],b[j]);
        }
        if(!uf.same(a[i],b[i])) ans++; 
    }
    
   cout<<ans<<endl;
}

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

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

  int h = x / 3600;
  int m = (x / 60) % 60;
  int s = x % 60;
  cout<<h<<":"<<m<<":"<<s<<endl;
  return 0;
}


Measured memory_bytes: 3100
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;

  int xr = 0;
  for(int i = 0;i < n;i++){
    int a;
    cin >> a;
    xr ^= a;
  }

  if(xr == 0)cout << "Yes" << endl;
  else cout << "No" << endl;
} 

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

using namespace std;

int main()
{
	int n;

	cin >> n;

	int arr[n + 1];
	int counter = 0;

	for(int i = 1; i <= n; i++)
	{
		cin >> arr[i];

		if(i % 2 != 0 && arr[i] % 2 != 0)
		{
			counter++;
		}
	}

	cout << counter << endl;

    return 0;
}



Measured memory_bytes: 3592
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  deque<int> q;
  int n = in();
  
  rep(i, n) {
    int a = in();
    if (i % 2 != 0) q.push_back(a);
    else q.push_front(a);
  }

  if (n % 2 != 0) {
    rep(i, n - 1) {
      cout << q[i] << " ";
    }
    print(q[q.size() - 1]);
  } else {
    rrep(i, q.size() - 1, 1) {
      cout << q[i] << " ";
    }
    print(q[0]);
  }
}


Measured memory_bytes: 3072
#include<stdio.h>
int main()
{
	char p[15];
	int j,k,n[9][5]={{66,68},{65,67,69},{66,70},{65,69,71},{66,68,70,72},{67,69,73},{68,72},{69,71,73},{70,72}};
	for(;gets(p);)
	{
		for(j=0;p[j+1];j++)
		{
			for(k=0;n[p[j]-65][k];k++)
				if(p[j+1]==n[p[j]-65][k])
					break;
			if(!n[p[j]-65][k])
				break;
		}
		if(!p[j+1])
			puts(p);
	}
	return 0;
}

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

int main()
{
    int x,a,b,c,s;
   while( scanf("%d",&x)!=EOF)
   {
    scanf("%d",&a);
    scanf("%d",&b);
    c=x-a;
    s=c-(c/b)*b;
    printf("%d\n",s);
   }
    return 0;
}



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

using namespace std;

int main(){
	int q,fc=0,d=0;
	string s;
	cin >> s;
	cin >> q;
	for(int i=0;i<q;++i){
		int f;
		cin >> f;
		if(f == 1){
			fc++;
			d = (d+1)%2;
		}
		if(f == 2){
			int ff;
			char c;
			cin >> ff >> c;
			if((ff+d)%2==0){
				s.push_back(c);
			}else{
				s.insert(s.begin(),c);
			}
		}
	}
	if(fc%2==1)reverse(s.begin(),s.end());
	cout << s << endl;
}

Measured memory_bytes: 900
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
const int inf=1e9;
int n,k,d[100010],v[100010],l[100010],r[100010];
bool used[100010];
int cnt,head[100010],to[200010],nxt[200010];
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
}
void dfs(int x,int fa)
{
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		d[y]=d[x]+1;
		dfs(y,x);
	}
}
void dfs2(int x,int fa)
{
	if (used[x])
	{
		l[x]=v[x];
		r[x]=v[x];
	}
	else
	{
		l[x]=-inf;
		r[x]=inf;
	}
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		dfs2(y,x);
		l[x]=max(l[x],l[y]-1);
		r[x]=min(r[x],r[y]+1);
	}
	if (l[x]>r[x])
	{
		puts("No");
		exit(0);
	}
}
void work(int x,int fa)
{
	if (!used[x])
	{
		if (v[fa]+1>=l[x] && v[fa]+1<=r[x])
		{
			v[x]=v[fa]+1;
		}
		else
		{
			v[x]=v[fa]-1;
		}
	}
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y==fa)
		{
			continue;
		}
		work(y,x);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	d[1]=1;
	dfs(1,0);
	scanf("%d",&k);
	int tmp;
	for (int i=0;i<k;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		used[x]=true;
		v[x]=y;
		if (!i)
		{
			tmp=x;
			continue;
		}
		if (((v[x]-v[tmp])&1)!=((d[x]-d[tmp])&1))
		{
			puts("No");
			return 0;
		}
	}
	dfs2(1,0);
	if (!used[1])
	{
		v[1]=l[1];
		used[1]=true;
	}
	work(1,0);
	puts("Yes");
	for (int i=1;i<=n;i++)
	{
		printf("%d\n",v[i]);
	}
    return 0;
}
//白雪淡淡长安，梅香阵阵静庭。

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

int main(){
	//freopen("3_max3","r",stdin);
	string s,t;
	cin>>s>>t;
	int ss[28]={0},tt[28]={0},b[28]={0},tmp1,tmp2;
	if(s.length()!=t.length()){
		cout<<"No";
		return 0;
	}
	for(int i=0;i<=s.length()-1;++i){
		if(s[i]==t[i])	{
			b[s[i]-'a'+1]=1;			//使用过，且没有交换，也就是说以后也不能交换。 
			b[t[i]-'a'+1]=1;
			continue;
		}
		tmp1=s[i]-'a'+1;
		tmp2=t[i]-'a'+1;		
		if(ss[tmp1]==0 && tt[tmp2]==0){

			if(b[tmp1] || b[tmp2]){
				cout<<"No";
				return 0;				
			}
			else
			{
				ss[tmp1]=tmp2;
				tt[tmp2]=tmp1;
				continue;			
			}
		}
		if(ss[tmp1]!=tmp2 || tt[tmp2]!=tmp1){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	string N; cin>>N;
	rpz(i,3) N[i] = N[i]=='1'?'9':'1';
	ote(N);
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
  int n,m;
  int in,out;
  scanf("%d %d",&n,&m);
  int ans = m;
  int now = m;
  if(now < 0){
    ans = 0;
    n = 0;
  }
  for(int i = 1 ; i <= n ; i++){
    scanf("%d",&in);
    scanf("%d",&out);
    now += (in - out);
    if(now < 0){
      ans = 0;
      break;
    }
    else if(now > ans)
      ans = now;
  }
  printf("%d\n",ans);
}



Measured memory_bytes: 2736
INPUT = input()

N = int(INPUT.split( )[0])
Y = int(INPUT.split( )[1]) / 1000

Y_mod5 = int(Y % 5)

for hideyo in range(Y_mod5, N + 1, 5):
    if (Y - hideyo > (N - hideyo) * 10) or (Y - hideyo < (N - hideyo) * 5):
        continue
    else:
        print("{} {} {}".format(int((Y - 5 * N + 4 * hideyo) / 5), int((10 * N - Y - 9 * hideyo) / 5), hideyo))
        break
        
if (Y - hideyo > (N - hideyo) * 10) or (Y - hideyo < (N - hideyo) * 5):
    print("-1 -1 -1")

Measured memory_bytes: 3188
import sys
import math
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()

rui = [0]
for i in range(1,N+1):
  rui.append(rui[-1] + i)

ans = 0
for i in range(K,N+1):
  ans += (rui[-1] - rui[-i-1]) - rui[i-1] +1
print((ans +1) %mod)

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

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

    if(b <= c || d <= a) cout << 0 << endl;
    else if(c<=a && b<=d) cout << b-a << endl;
    else if(a<=c && d<=b) cout << d-c << endl;
    else if(a<=c && b<=d) cout << b-c << endl;
    else if(c<=a && d<=b) cout << d-a << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n, e;

	while (scanf("%d", &n) != EOF)
	{
		printf("Christmas");
		n = 25 - n;
		for (e = 0; e < n; e++)
		{
			printf(" Eve");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int h, w, c;
int field[10][10][10];
bool visit[10][10];
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int dfs(int depth, int x, int y, int tc) {
  if (visit[y][x]) { return 0; }
  visit[y][x] = true;
  const int ndepth = depth + 1;
  const int pc = field[depth][0][0];
  field[ndepth][y][x] = tc;
  int ret = 1;
  REP(dir, 4) {
    int nx = x + dx[dir];
    int ny = y + dy[dir];
    if (nx < 0 || nx >= w || ny < 0 || ny >= h) { continue; }
    if (field[depth][ny][nx] != pc) { continue; }
    ret += dfs(depth, nx, ny, tc);
  }
  return ret;
}

int calc(int depth) {
  if (depth == 5) {
    if (field[depth][0][0] != c) { return 0; }
    MEMSET(visit, false);
    memcpy(field[depth + 1], field[depth], sizeof(field[depth]));
    return dfs(depth, 0, 0, c);
  }
  int ret = 0;
  FOREQ(i, 1, 6) {
    if (i == field[depth][0][0]) { continue; }
    if (depth == 4 && i != c) { continue; }
    MEMSET(visit, false);
    memcpy(field[depth + 1], field[depth], sizeof(field[depth]));
    dfs(depth, 0, 0, i);
    ret = max(ret, calc(depth + 1));
  }
  return ret;
}

int main() {
  while (scanf("%d %d %d", &h, &w, &c), h|w|c) {
    REP(y, h) {
      REP(x, w) {
        scanf("%d", &field[0][y][x]);
      }
    }
    cout << calc(0) << endl;
  }
}

Measured memory_bytes: 892
n, k, c = map(int, input().split())
S = input()

# 要素の値は何回目の働く日か(0は働いていない状態)
by_left = [0] * n
by_right = [0] * n

# 左から貪欲
rest = 0
cnt = 1
for itr, s in enumerate(S):
  rest -= 1
  if rest <= 0 and s == "o":
    by_left[itr] = cnt
    cnt += 1
    rest = c + 1
    
# 右から貪欲
rest = 0
cnt = k
for itr, s in enumerate(S[::-1]):
  rest -= 1
  if rest <= 0 and s == "o":
    by_right[n - itr- 1] = cnt
    cnt -= 1
    rest = c + 1

# 左右からの貪欲で、どちらでも同じ働く回数の値が入っている日が必ず働く日
ans = [itr + 1 for itr, (i, j) in enumerate(zip(by_left, by_right)) if i != 0 and i == j]

for a in ans:
  print(a)

Measured memory_bytes: 28480
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int n,m;
vv vec;
int dp[100001];
int solve(int node){
    if(dp[node]!=-1)
        return dp[node];
    int ans=0;
    for(auto child:vec[node]){
        ans=max(ans,1+solve(child));
    }
    return dp[node]=ans;
}
int main(){
    boost;
    memset(dp,-1,sizeof dp);
    cin>>n>>m;
    vec.resize(n);
    while(m--){
        int a,b;
        cin>>a>>b;
        a--,b--;
        vec[a].pb(b);
    }
    int ans=0;
    for (int i = 0; i < n; ++i)
        ans=max(ans,solve(i));
    cout<<ans;
    return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;

	long long ans = 1;
	
	for (char c = 'a'; c <= 'z'; ++c) {
		int m = count(S.begin(), S.end(), c);
		ans *= (m + 1);
		ans %= 1000 * 1000 * 1000 + 7;
	}
	ans -= 1;

	cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> G(h);
    for(int i = 0; i < h; i++) {
        cin >> G[i];
    }
    int ans = 0;
    for(int bit1 = 0; bit1 < (1 << h); bit1++) {
        for(int bit2 = 0; bit2 < (1 << w); bit2++) {
            vector<string> g = G;
            for(int i = 0; i < h; i++) {
                if(bit1 & (1 << i)) {
                    for(int j = 0; j < w; j++) {
                        g[i][j] = '-';
                    }
                }
            }
            for(int j = 0; j < w; j++) {
                if(bit2 & (1 << j)) {
                    for(int i = 0; i < h; i++) {
                        g[i][j] = '-';
                    }
                }
            }
            int cnt = 0;
            for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) {
                    cnt += (g[i][j] == '#');
                }
            }
            ans += (cnt == k);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int c1, c5, c10, c50, c100, c500;
	cin >> c1>>c5>> c10>> c50>> c100>> c500;
	if((c1+ 5 * c5 + 10 * c10 + 50 * c50 + 100 * c100 + 500 * c500) /1000 > 0){
		cout << "1" << endl;
	}
	else{
		cout << "0" << endl;
	}
	return 0;
	}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int a, b; scanf("%d %d", &a, &b);
  if (a > 9 || b > 9) printf("-1\n");
  else printf("%d\n", a * b);
  return 0;
}

Measured memory_bytes: 256
using System;

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

            int N = int.Parse(Console.ReadLine());
            string str = Console.ReadLine();

            string al = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int len = str.Length;
            char[] chr = new char[len];
            for (int i = 0; i < len; i++) chr[i] = str[i];
            for(int i = 0; i < len; i++)
            {
                for(int j = 0; j < 26; j++)
                {
                    if(al[j] ==chr[i])
                    {
                        chr[i] = al[j+N];
                        break;
                    }
                }
            }

            for (int i = 0; i < len - 1; i++) Console.Write(chr[i]);
            Console.Write(chr[len-1]);



        }
    }
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = long.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();

string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
 */


Measured memory_bytes: 11176